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

feat: [ident] add consturactor support

上级 e4b1c5a5
......@@ -37,6 +37,7 @@ func TestPolymorphism_Constructor(t *testing.T) {
identApp := new(JavaIdentifierApp)
identifiers := identApp.AnalysisPath("../../../_fixtures/suggest/factory")
fmt.Println(identifiers)
g.Expect(len(identifiers)).To(Equal(2))
g.Expect(identifiers[0].ClassName).To(Equal("Insect"))
g.Expect(identifiers[1].ClassName).To(Equal("Bee"))
......
......@@ -69,6 +69,36 @@ func (s *JavaIdentifierListener) ExitClassBody(ctx *parser.ClassBodyContext) {
currentNode = models.NewJIdentifier()
}
func (s *JavaIdentifierListener) EnterConstructorDeclaration(ctx *parser.ConstructorDeclarationContext) {
hasEnterMethod = true
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetColumn()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetColumn()
name := ctx.IDENTIFIER().GetText()
annotations := currentMethod.Annotations
currentMethod = *&models.JMethod{
Name: name,
Type: "",
StartLine: startLine,
StartLinePosition: startLinePosition,
StopLine: stopLine,
StopLinePosition: stopLinePosition,
Override: isOverrideMethod,
Annotations: annotations,
IsConstructor: true,
}
}
func (s *JavaIdentifierListener) ExitConstructorDeclaration(ctx *parser.ConstructorDeclarationContext) {
hasEnterMethod = false
currentNode.AddMethod(currentMethod)
currentMethod = models.NewJMethod()
}
func (s *JavaIdentifierListener) EnterInterfaceBodyDeclaration(ctx *parser.InterfaceBodyDeclarationContext) {
for _, modifier := range ctx.AllModifier() {
modifier := modifier.(*parser.ModifierContext).GetChild(0)
......
package unused
import (
"encoding/json"
models2 "github.com/phodal/coca/core/domain/refactor/base/models"
support3 "github.com/phodal/coca/core/domain/refactor/rename/support"
. "github.com/phodal/coca/core/models"
"github.com/phodal/coca/core/support"
"encoding/json"
"io/ioutil"
"log"
"strings"
......@@ -76,7 +76,7 @@ func startParse(nodes []JClassNode, relates []support3.RefactorChangeRelate) {
}
func methodCallToMethodModel(call JMethodCall) JMethod {
return *&JMethod{call.MethodName, call.Type, call.StartLine, call.StartLinePosition, call.StopLine, call.StopLinePosition, nil, nil, false, nil}
return *&JMethod{call.MethodName, call.Type, call.StartLine, call.StartLinePosition, call.StopLine, call.StopLinePosition, nil, nil, false, nil, false}
}
func updateSelfRefs(node JClassNode, method JMethod, info *support3.PackageClassInfo) {
......
......@@ -11,6 +11,7 @@ type JMethod struct {
MethodCalls []JMethodCall
Override bool
Annotations []Annotation
IsConstructor bool
}
type Annotation struct {
......@@ -31,7 +32,6 @@ func NewAnnotation() Annotation {
}
// TODO support annnotation
func NewJMethod() JMethod {
return *&JMethod{
Name: "",
......@@ -43,6 +43,7 @@ func NewJMethod() JMethod {
StopLinePosition: 0,
Parameters: nil,
MethodCalls: nil,
IsConstructor: false,
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册