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

build: init refactor module

上级 ab0016a5
package com.phodal;
import java.io.IOException;
public class Example {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
......@@ -3,20 +3,20 @@ package main
import (
"os"
//. "./adapter/call"
. "./adapter/call"
. "./adapter/identifier"
)
func main() {
//cmd.Execute()
path := "/Users/fdhuang/learn/coca/poc/src/main/"
path := "/Users/fdhuang/test/mall"
if len(os.Args) > 1 {
path = os.Args[1:][0]
}
//callApp := new(JavaCallApp)
//callApp.AnalysisPath(path)
callApp := new(JavaCallApp)
callApp.AnalysisPath(path)
identifierApp := new(JavaIdentifierApp)
identifierApp.AnalysisPath(path)
......
package base
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"os"
"path/filepath"
"strings"
. "../../language/java"
)
type JavaRefactorApp struct {
}
func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
files := (*JavaRefactorApp)(nil).javaFiles(codeDir)
for index := range files {
file := files[index]
displayName := filepath.Base(file)
fmt.Println("Start parse java call: " + displayName)
parser := (*JavaRefactorApp)(nil).processFile(file)
context := parser.CompilationUnit()
listener := new(JavaRefactorCallListener)
antlr.NewParseTreeWalker().Walk(listener, context)
}
}
func (j *JavaRefactorApp) javaFiles(codeDir string) []string {
files := make([]string, 0)
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
if strings.HasSuffix(path, ".java") && !strings.Contains(path, "Test.java") {
files = append(files, path)
}
return nil
})
return files
}
func (j *JavaRefactorApp) processFile(path string) *JavaParser {
is, _ := antlr.NewFileStream(path)
lexer := NewJavaLexer(is)
stream := antlr.NewCommonTokenStream(lexer, 0);
parser := NewJavaParser(stream)
return parser
}
package base
import (
. "../../language/java"
"fmt"
)
type JavaRefactorCallListener struct {
BaseJavaParserListener
}
func (s *JavaRefactorCallListener) EnterCompilationUnit(ctx *CompilationUnitContext) {
declaration := ctx.AllImportDeclaration()
fmt.Println(declaration)
}
\ No newline at end of file
package main
import (
. "./base"
"os"
)
func main() {
//cmd.Execute()
path := "examples/unused-import"
if len(os.Args) > 1 {
path = os.Args[1:][0]
}
callApp := new(JavaRefactorApp)
callApp.AnalysisPath(path)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册