refactor:move build annotation to parent

上级 ee07ae94
// Generated from TypeScriptParser.g4 by ANTLR 4.8
package chapi.ast.antlr;
import chapi.domain.core.CodeAnnotation;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.jetbrains.annotations.NotNull;
/**
* This class provides an empty implementation of {@link TypeScriptParserListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class TypeScriptParserBaseListener implements TypeScriptParserListener {
public abstract class TypeScriptParserBaseListener implements TypeScriptParserListener {
/**
* {@inheritDoc}
*
......@@ -2592,4 +2594,10 @@ public class TypeScriptParserBaseListener implements TypeScriptParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}
\ No newline at end of file
@NotNull
protected abstract CodeAnnotation buildAnnotation(@NotNull TypeScriptParser.DecoratorContext decorator);
@NotNull
protected abstract CodeAnnotation buildAnnotation(@NotNull TypeScriptParser.DecoratorContext decorator);
}
......@@ -2,11 +2,12 @@ package chapi.ast.typescriptast
import chapi.ast.antlr.TypeScriptParser
import chapi.ast.antlr.TypeScriptParserBaseListener
import chapi.domain.core.CodeAnnotation
import chapi.domain.core.CodePosition
import chapi.domain.core.CodeProperty
import org.antlr.v4.runtime.ParserRuleContext
open class TypeScriptAstListener() : TypeScriptParserBaseListener() {
open class TypeScriptAstListener : TypeScriptParserBaseListener() {
fun buildParameters(
formalParameterListContext: TypeScriptParser.FormalParameterListContext?
): Array<CodeProperty> {
......@@ -112,7 +113,7 @@ open class TypeScriptAstListener() : TypeScriptParserBaseListener() {
}
private fun buildRequireParameter(paramCtx: TypeScriptParser.RequiredParameterContext?): CodeProperty {
var paramType: String = ""
var paramType = ""
if (paramCtx!!.typeAnnotation() != null) {
paramType = buildTypeAnnotation(paramCtx.typeAnnotation())!!
}
......@@ -124,4 +125,19 @@ open class TypeScriptAstListener() : TypeScriptParserBaseListener() {
return parameter
}
override fun buildAnnotation(decorator: TypeScriptParser.DecoratorContext): CodeAnnotation {
val annotation = CodeAnnotation()
val memberExpression = decorator.decoratorMemberExpression()
val callExpression = decorator.decoratorCallExpression()
if (memberExpression != null) {
annotation.Name = memberExpression.Identifier().text
}
if (callExpression != null) {
val member = callExpression.decoratorMemberExpression()
annotation.Name = member.Identifier().text
}
return annotation
}
}
......@@ -71,21 +71,6 @@ class TypeScriptFullIdentListener(private var node: TSIdentify) : TypeScriptAstL
}
}
private fun buildAnnotation(decorator: TypeScriptParser.DecoratorContext): CodeAnnotation {
val annotation = CodeAnnotation()
val memberExpression = decorator.decoratorMemberExpression()
val callExpression = decorator.decoratorCallExpression()
if (memberExpression != null) {
annotation.Name = memberExpression.Identifier().text
}
if (callExpression != null) {
val member = callExpression.decoratorMemberExpression()
annotation.Name = member.Identifier().text
}
return annotation
}
private fun handleClassBodyElements(classTailCtx: TypeScriptParser.ClassTailContext?) {
for (clzElementCtx in classTailCtx!!.classElement()) {
val childCtx = clzElementCtx.getChild(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册