feat: make inner class to inner class node

上级 e3594aeb
package com.phodal.coca.abug;
public class Outer {
final int z=10;
class Inner extends HasStatic {
static final int x = 3;
static int y = 4;
public static void pr() {
}
}
public static void main(String[] args) {
......
......@@ -77,6 +77,7 @@ func TestInterface(t *testing.T) {
callNodes := getCallNodes(codePath)
methodMap := make(map[string]domain.JMethod)
for _, c := range callNodes[0].Methods {
methodMap[c.Name] = c
}
......@@ -238,5 +239,7 @@ func Test_InnerClass(t *testing.T) {
callNodes := getCallNodes(codePath)
g.Expect(len(callNodes)).To(Equal(1))
g.Expect(callNodes[0].Class).To(Equal("Outer"))
g.Expect(callNodes[0].InnerClass[0].Class).To(Equal("Inner"))
}
......@@ -13,6 +13,7 @@ type JClassNode struct {
Extend string
Implements []string
Annotations []Annotation
InnerClass []JClassNode
}
type JAppField struct {
......@@ -21,7 +22,7 @@ type JAppField struct {
}
func NewClassNode() *JClassNode {
return &JClassNode{"", "", "", "", nil, nil, nil, "", nil, nil}
return &JClassNode{"", "", "", "", nil, nil, nil, "", nil, nil, nil}
}
func (j *JClassNode) IsUtilClass() bool {
......
......@@ -88,7 +88,6 @@ func (s *JavaFullListener) ExitInterfaceBody(ctx *parser.InterfaceBodyContext) {
func (s *JavaFullListener) exitBody() {
if currentNode.Class != "" {
currentNode.Fields = fields
currentNode.Type = currentType
currentNode.Path = fileName
currentNode.SetMethodFromMap(methodMap)
}
......@@ -98,11 +97,29 @@ func (s *JavaFullListener) exitBody() {
return
}
if currentNode.Class != "" {
if currentNode.Class == "" {
currentNode = domain.NewClassNode()
initClass()
return
}
if currentNode.Type == "InnerClass" && len(classNodeQueue) >= 1 {
classNodeQueue[0].InnerClass = append(currentNode.InnerClass, *currentNode)
} else {
classNodes = append(classNodes, *currentNode)
}
currentNode = domain.NewClassNode()
if len(classNodeQueue) >= 1 {
if len(classNodeQueue) == 1 {
currentNode = &classNodeQueue[0]
} else {
classNodeQueue = classNodeQueue[0 : len(classNodeQueue)-1]
currentNode = &classNodeQueue[len(classNodeQueue)-1]
}
} else {
currentNode = domain.NewClassNode()
}
initClass()
}
......@@ -119,12 +136,14 @@ func (s *JavaFullListener) EnterImportDeclaration(ctx *parser.ImportDeclarationC
func (s *JavaFullListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) {
// TODO: support inner class
if currentNode.Class != "" {
return
classNodeQueue = append(classNodeQueue, *currentNode)
currentType = "InnerClass"
} else {
currentType = "Class"
}
hasEnterClass = true
currentClzExtend = ""
currentType = "Class"
if ctx.IDENTIFIER() != nil {
currentClz = ctx.IDENTIFIER().GetText()
currentNode.Class = currentClz
......@@ -143,6 +162,7 @@ func (s *JavaFullListener) EnterClassDeclaration(ctx *parser.ClassDeclarationCon
}
}
currentNode.Type = currentType
// TODO: 支持依赖注入
}
......@@ -157,6 +177,8 @@ func (s *JavaFullListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclar
buildExtend(typ.GetText())
}
}
currentNode.Type = currentType
}
func (s *JavaFullListener) EnterInterfaceBodyDeclaration(ctx *parser.InterfaceBodyDeclarationContext) {
......@@ -399,7 +421,6 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
createdName := identifier.GetText()
localVars[variableName] = createdName
classNodeQueue = append(classNodeQueue, *currentNode)
buildCreatedCall(createdName, ctx)
if currentMethod.Name == "" {
......@@ -414,6 +435,8 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
return
}
//classNodeQueue = append(classNodeQueue, *currentNode)
currentType = "CreatorClass"
text := ctx.CreatedName().GetText()
creatorNode := &domain.JClassNode{
......@@ -441,7 +464,9 @@ func (s *JavaFullListener) ExitCreator(ctx *parser.CreatorContext) {
methodMap[getMethodMapName(currentMethod)] = method
}
currentType = ""
if currentType == "CreatorClass" {
currentType = ""
}
currentCreatorNode = *domain.NewClassNode()
if classNodeQueue == nil || len(classNodeQueue) < 1 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册