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

feat: exploe apis

上级 c60fcd39
......@@ -12,7 +12,6 @@ import (
)
type JavaRefactorApp struct {
}
func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
......@@ -26,18 +25,23 @@ func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
parser := (*JavaRefactorApp)(nil).processFile(file)
context := parser.CompilationUnit()
interfaceIdent := NewJFullIdentifier()
node := NewJFullIdentifier()
listener := new(JavaRefactorListener)
listener.InitNode(interfaceIdent)
listener.InitNode(node)
antlr.NewParseTreeWalker().Walk(listener, context)
if interfaceIdent.Name != "" {
fmt.Println(interfaceIdent.Type, interfaceIdent.Pkg, interfaceIdent.Name, interfaceIdent.GetMethods())
if node.Name != "" {
handleNode(node)
}
}
}
func handleNode(identifier *JFullIdentifier) {
fmt.Println(node.Pkg+"."+node.Name, node.GetImports(), node.GetMethods(), node.GetFields())
}
func (j *JavaRefactorApp) javaFiles(codeDir string) []string {
files := make([]string, 0)
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
......
......@@ -3,6 +3,7 @@ package base
import (
. "../../language/java"
. "./models"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
var node *JFullIdentifier;
......@@ -15,6 +16,16 @@ func (s *JavaRefactorListener) EnterPackageDeclaration(ctx *PackageDeclarationCo
node.Pkg = ctx.QualifiedName().GetText()
}
func (s *JavaRefactorListener) EnterImportDeclaration(ctx *ImportDeclarationContext) {
importText := ctx.QualifiedName().GetText()
startLine := ctx.GetStart().GetLine()
stopLine := ctx.GetStop().GetLine()
jImport := &JImport{importText, startLine, stopLine}
node.AddImport(*jImport)
}
func (s *JavaRefactorListener) EnterClassDeclaration(ctx *ClassDeclarationContext) {
node.Type = "Class"
node.Name = ctx.IDENTIFIER().GetText()
......@@ -42,6 +53,20 @@ func (s *JavaRefactorListener) EnterMethodDeclaration(ctx *MethodDeclarationCont
node.AddMethod(*method)
}
func (s *JavaRefactorListener) EnterFieldDeclaration(ctx *FieldDeclarationContext) {
declarators := ctx.VariableDeclarators()
variableName := declarators.GetParent().GetChild(0).(antlr.ParseTree).GetText()
startLine := ctx.GetStart().GetLine()
stopLine := ctx.GetStop().GetLine()
text := ctx.TypeType().GetText()
if variableName != "" && text != "" {
field := &JField{variableName, node.Pkg, startLine, stopLine}
node.AddField(*field)
}
}
func (s *JavaRefactorListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarationContext) {
node.Type = "Interface"
node.Name = ctx.IDENTIFIER().GetText()
......@@ -50,4 +75,3 @@ func (s *JavaRefactorListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarati
func (s *JavaRefactorListener) InitNode(identifier *JFullIdentifier) {
node = identifier
}
......@@ -8,7 +8,24 @@ type JFullMethod struct {
StopLinePosition int
}
type JField struct {
Name string
Source string
StartLine int
StopLine int
//StartLinePosition int
//StopLinePosition int
}
type JImport struct {
Name string
StartLine int
StopLine int
}
var methods []JFullMethod
var fields = make(map[string]JField)
var imports = make(map[string]JImport)
type JFullIdentifier struct {
Pkg string
......@@ -19,6 +36,8 @@ type JFullIdentifier struct {
func NewJFullIdentifier() *JFullIdentifier {
identifier := &JFullIdentifier{"", "", ""}
methods = nil
fields = make(map[string]JField)
imports = make(map[string]JImport)
return identifier
}
......@@ -29,3 +48,19 @@ func (identifier *JFullIdentifier) AddMethod(method JFullMethod) {
func (identifier *JFullIdentifier) GetMethods() []JFullMethod {
return methods
}
func (identifier *JFullIdentifier) AddField(field JField) {
fields[field.Name] = field
}
func (identifier *JFullIdentifier) GetFields() map[string]JField {
return fields
}
func (identifier *JFullIdentifier) AddImport(jImport JImport) {
imports[jImport.Name] = jImport
}
func (identifier *JFullIdentifier) GetImports() map[string]JImport {
return imports
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册