未验证 提交 c60fcd39 编写于 作者: P Phodal HUANG

build: happy copy paste

上级 1855dca3
......@@ -4,12 +4,11 @@ import (
"os"
. "./adapter/call"
. "./adapter/identifier"
)
func main() {
//cmd.Execute()
path := "/Users/fdhuang/test/mall"
path := "/Users/fdhuang/learn/coca/poc/src/main"
if len(os.Args) > 1 {
path = os.Args[1:][0]
......@@ -17,7 +16,7 @@ func main() {
callApp := new(JavaCallApp)
callApp.AnalysisPath(path)
identifierApp := new(JavaIdentifierApp)
identifierApp.AnalysisPath(path)
//
//identifierApp := new(JavaIdentifierApp)
//identifierApp.AnalysisPath(path)
}
......@@ -8,6 +8,7 @@ import (
"strings"
. "../../language/java"
. "./models"
)
type JavaRefactorApp struct {
......@@ -25,9 +26,15 @@ func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
parser := (*JavaRefactorApp)(nil).processFile(file)
context := parser.CompilationUnit()
listener := new(JavaRefactorCallListener)
interfaceIdent := NewJFullIdentifier()
listener := new(JavaRefactorListener)
listener.InitNode(interfaceIdent)
antlr.NewParseTreeWalker().Walk(listener, context)
if interfaceIdent.Name != "" {
fmt.Println(interfaceIdent.Type, interfaceIdent.Pkg, interfaceIdent.Name, interfaceIdent.GetMethods())
}
}
}
......
package base
import (
. "../../language/java"
"fmt"
)
type JavaRefactorCallListener struct {
BaseJavaParserListener
}
func (s *JavaRefactorCallListener) EnterCompilationUnit(ctx *CompilationUnitContext) {
declaration := ctx.AllImportDeclaration()
fmt.Println(declaration)
}
func (s *JavaRefactorCallListener) EnterImportDeclaration(ctx *ImportDeclarationContext) {
importText := ctx.QualifiedName().GetText()
fmt.Println(importText)
}
\ No newline at end of file
package base
import (
. "../../language/java"
. "./models"
)
var node *JFullIdentifier;
type JavaRefactorListener struct {
BaseJavaParserListener
}
func (s *JavaRefactorListener) EnterPackageDeclaration(ctx *PackageDeclarationContext) {
node.Pkg = ctx.QualifiedName().GetText()
}
func (s *JavaRefactorListener) EnterClassDeclaration(ctx *ClassDeclarationContext) {
node.Type = "Class"
node.Name = ctx.IDENTIFIER().GetText()
}
func (s *JavaRefactorListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMethodDeclarationContext) {
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetTokenSource().GetCharPositionInLine()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetTokenSource().GetCharPositionInLine()
name := ctx.IDENTIFIER().GetText()
//XXX: find the start position of {, not public
method := &JFullMethod{name, startLine, startLinePosition, stopLine, stopLinePosition}
node.AddMethod(*method)
}
func (s *JavaRefactorListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) {
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetTokenSource().GetCharPositionInLine()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetTokenSource().GetCharPositionInLine()
name := ctx.IDENTIFIER().GetText()
//XXX: find the start position of {, not public
method := &JFullMethod{name, startLine, startLinePosition, stopLine, stopLinePosition}
node.AddMethod(*method)
}
func (s *JavaRefactorListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarationContext) {
node.Type = "Interface"
node.Name = ctx.IDENTIFIER().GetText()
}
func (s *JavaRefactorListener) InitNode(identifier *JFullIdentifier) {
node = identifier
}
package models
type JFullMethod struct {
Name string
StartLine int
StartLinePosition int
StopLine int
StopLinePosition int
}
var methods []JFullMethod
type JFullIdentifier struct {
Pkg string
Name string
Type string
}
func NewJFullIdentifier() *JFullIdentifier {
identifier := &JFullIdentifier{"", "", ""}
methods = nil
return identifier
}
func (identifier *JFullIdentifier) AddMethod(method JFullMethod) {
methods = append(methods, method)
}
func (identifier *JFullIdentifier) GetMethods() []JFullMethod {
return methods
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册