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

feat: add annotation to identifer

上级 a7cd90f8
......@@ -7,6 +7,10 @@ import (
var node *JIdentifier
var currentMethod models.JMethod
var hasEnterClass = false
var hasEnterMethod = false
type JavaIdentifierListener struct {
parser.BaseJavaParserListener
}
......@@ -16,6 +20,8 @@ func (s *JavaIdentifierListener) EnterPackageDeclaration(ctx *parser.PackageDecl
}
func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) {
hasEnterClass = true
node.Type = "Class"
if ctx.IDENTIFIER() != nil {
node.Name = ctx.IDENTIFIER().GetText()
......@@ -26,7 +32,14 @@ func (s *JavaIdentifierListener) EnterClassDeclaration(ctx *parser.ClassDeclarat
}
}
func (s *JavaIdentifierListener) ExitClassDeclaration(ctx *parser.ClassDeclarationContext) {
hasEnterClass = false
}
func (s *JavaIdentifierListener) EnterInterfaceMethodDeclaration(ctx *parser.InterfaceMethodDeclarationContext) {
hasEnterMethod = true
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetColumn()
stopLine := ctx.GetStop().GetLine()
......@@ -35,22 +48,31 @@ func (s *JavaIdentifierListener) EnterInterfaceMethodDeclaration(ctx *parser.Int
//XXX: find the start position of {, not public
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{
Name: name,
Type: typeType,
StartLine: startLine,
annotations := currentMethod.Annotations
currentMethod = *&models.JMethod{
Name: name,
Type: typeType,
StartLine: startLine,
StartLinePosition: startLinePosition,
StopLine: stopLine,
StopLinePosition: stopLinePosition,
Override: isOverrideMethod,
Annotation: nil,
StopLine: stopLine,
StopLinePosition: stopLinePosition,
Override: isOverrideMethod,
Annotations: annotations,
}
node.AddMethod(*method)
}
func (s *JavaIdentifierListener) ExitInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
hasEnterMethod = false
node.AddMethod(currentMethod)
currentMethod = models.NewJMethod()
}
var isOverrideMethod = false
func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclarationContext) {
hasEnterMethod = true
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetColumn()
stopLine := ctx.GetStop().GetLine()
......@@ -60,28 +82,39 @@ func (s *JavaIdentifierListener) EnterMethodDeclaration(ctx *parser.MethodDeclar
typeType := ctx.TypeTypeOrVoid().GetText()
method := &models.JMethod{
Name: name,
Type: typeType,
StartLine: startLine,
annotations := currentMethod.Annotations
currentMethod = *&models.JMethod{
Name: name,
Type: typeType,
StartLine: startLine,
StartLinePosition: startLinePosition,
StopLine: stopLine,
StopLinePosition: stopLinePosition,
Override: isOverrideMethod,
Annotation: nil,
StopLine: stopLine,
StopLinePosition: stopLinePosition,
Override: isOverrideMethod,
Annotations: annotations,
}
node.AddMethod(*method)
isOverrideMethod = false
}
func (s *JavaIdentifierListener) ExitMethodDeclaration(ctx *parser.MethodDeclarationContext) {
hasEnterMethod = false
node.AddMethod(currentMethod)
currentMethod = models.NewJMethod()
}
func (s *JavaIdentifierListener) EnterAnnotation(ctx *parser.AnnotationContext) {
// Todo: support override method
annotationName := ctx.QualifiedName().GetText()
if annotationName == "Override" {
isOverrideMethod = true
}
if hasEnterClass {
if !hasEnterMethod {
currentMethod.Annotations = append(currentMethod.Annotations, annotationName)
}
}
}
func (s *JavaIdentifierListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
......
......@@ -10,14 +10,14 @@ type JMethod struct {
Parameters []JParameter
MethodCalls []JMethodCall
Override bool
Annotation []string
Annotations []string
}
func NewJMethod() JMethod {
return *&JMethod{
Name: "",
Type: "",
Annotation: nil,
Annotations: nil,
StartLine: 0,
StartLinePosition: 0,
StopLine: 0,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册