未验证 提交 4acf652a 编写于 作者: P Phodal Huang

feat: support for ident find override

上级 4419bae9
......@@ -27,7 +27,7 @@ var analysisCmd *cobra.Command = &cobra.Command{
}
callApp := new(JavaCallApp)
callNodes := callApp.AnalysisPath(importPath, classes)
callNodes := callApp.AnalysisPath(importPath, classes, iNodes)
cModel, _ := json.MarshalIndent(callNodes, "", "\t")
WriteToFile("deps.json", string(cModel))
......
......@@ -15,7 +15,7 @@ var nodeInfos []models.JClassNode
type JavaCallApp struct {
}
func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string) []models.JClassNode {
func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string, identNodes []models.JsonIdentifier) []models.JClassNode {
nodeInfos = nil
files := (*JavaCallApp)(nil).javaFiles(codeDir)
for index := range files {
......@@ -28,7 +28,7 @@ func (j *JavaCallApp) AnalysisPath(codeDir string, classes []string) []models.JC
parser := (*JavaCallApp)(nil).processFile(file)
context := parser.CompilationUnit()
listener := NewJavaCallListener()
listener := NewJavaCallListener(identNodes)
listener.appendClasses(classes)
antlr.NewParseTreeWalker().Walk(listener, context)
......
......@@ -25,11 +25,13 @@ var currentMethod models.JMethod
var methodMap = make(map[string]models.JMethod)
var methodQueue []models.JMethod
var identNodes []models.JsonIdentifier
func NewJavaCallListener() *JavaCallListener {
func NewJavaCallListener(nodes []models.JsonIdentifier) *JavaCallListener {
currentClz = ""
currentPkg = ""
currentMethod = models.NewJMethod()
identNodes = nodes
methodMap = make(map[string]models.JMethod)
......@@ -85,7 +87,7 @@ func (s *JavaCallListener) EnterInterfaceMethodDeclaration(ctx *parser.Interface
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil}
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil, false}
methods = append(methods, *method)
}
......@@ -123,7 +125,7 @@ func (s *JavaCallListener) EnterMethodDeclaration(ctx *parser.MethodDeclarationC
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil}
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil, false}
if ctx.FormalParameters() != nil {
if ctx.FormalParameters().GetChild(0) == nil || ctx.FormalParameters().GetText() == "()" || ctx.FormalParameters().GetChild(1) == nil {
......@@ -207,13 +209,6 @@ func (s *JavaCallListener) EnterLocalTypeDeclaration(ctx *parser.LocalTypeDeclar
// TODO
}
func (s *JavaCallListener) EnterAnnotation(ctx *parser.AnnotationContext) {
annotationName := ctx.QualifiedName().GetText()
if annotationName == "Override" {
}
}
func (s *JavaCallListener) EnterMethodCall(ctx *parser.MethodCallContext) {
var targetCtx = ctx.GetParent().GetChild(0).(antlr.ParseTree).GetText()
var targetType = parseTargetType(targetCtx)
......
......@@ -37,7 +37,6 @@ func (j *JavaIdentifierApp) AnalysisPath(codeDir string) []models.JsonIdentifier
if clzInfo.Name != "" {
node = &models.JsonIdentifier{clzInfo.Pkg, clzInfo.Name, clzInfo.Type, clzInfo.GetMethods()}
nodeInfos = append(nodeInfos, *node)
}
}
......
......@@ -31,10 +31,12 @@ func (s *JavaIdentifierListener) EnterInterfaceMethodDeclaration(ctx *parser.Int
//XXX: find the start position of {, not public
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil}
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil, isOverrideMethod}
node.AddMethod(*method)
}
var isOverrideMethod = false
func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclarationContext) {
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetColumn()
......@@ -45,8 +47,18 @@ func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclar
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil}
method := &models.JMethod{name, typeType, startLine, startLinePosition, stopLine, stopLinePosition, nil, nil, isOverrideMethod}
node.AddMethod(*method)
isOverrideMethod = false
}
func (s *JavaIdentifierListener) EnterAnnotation(ctx *parser.AnnotationContext) {
// Todo: support override method
annotationName := ctx.QualifiedName().GetText()
if annotationName == "Override" {
isOverrideMethod = true
}
}
func (s *JavaIdentifierListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
......
......@@ -9,6 +9,7 @@ type JMethod struct {
StopLinePosition int
Parameters []JParameter
MethodCalls []JMethodCall
Override bool
}
func NewJMethod() JMethod {
......
......@@ -18,7 +18,7 @@ func main() {
}
callApp := new(JavaCallApp)
callNodes := callApp.AnalysisPath("examples/lambda/LambdaExample.java", classes)
callNodes := callApp.AnalysisPath("examples/lambda/LambdaExample.java", classes, nil)
cModel, _ := json.MarshalIndent(callNodes, "", "\t")
......
......@@ -76,7 +76,7 @@ func startParse(nodes []JClassNode, relates []support2.RefactorChangeRelate) {
}
func methodCallToMethodModel(call JMethodCall) *JMethod {
return &JMethod{call.MethodName, call.Type, call.StartLine, call.StartLinePosition, call.StopLine, call.StopLinePosition, nil, nil}
return &JMethod{call.MethodName, call.Type, call.StartLine, call.StartLinePosition, call.StopLine, call.StopLinePosition, nil, nil, false}
}
func updateSelfRefs(node JClassNode, method JMethod, info *support2.PackageClassInfo) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册