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

feat: support for ident find override

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