You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/07/30 09:43:38 UTC
[groovy] branch master updated: Remove unused field and other minor
clean-ups
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 905b9c5 Remove unused field and other minor clean-ups
905b9c5 is described below
commit 905b9c54ed3176bd140e383c6c2a0fddb5e200a0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jul 26 10:33:02 2019 -0500
Remove unused field and other minor clean-ups
---
.../apache/groovy/parser/antlr4/AstBuilder.java | 87 +++++-----------------
1 file changed, 19 insertions(+), 68 deletions(-)
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 5cb8e59..ee109cb 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -353,24 +353,21 @@ import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last;
/**
- * Building the AST from the parse tree generated by Antlr4
+ * Builds the AST from the parse tree generated by Antlr4.
*/
public class AstBuilder extends GroovyParserBaseVisitor<Object> implements GroovyParserVisitor<Object> {
public AstBuilder(SourceUnit sourceUnit, CompilerConfiguration compilerConfiguration) {
this.sourceUnit = sourceUnit;
- this.compilerConfiguration = compilerConfiguration;
this.moduleNode = new ModuleNode(sourceUnit);
+ CharStream charStream = createCharStream(sourceUnit);
- this.lexer = new GroovyLangLexer(createCharStream(sourceUnit));
- this.parser =
- new GroovyLangParser(
- new CommonTokenStream(this.lexer));
+ this.lexer = new GroovyLangLexer(charStream);
+ this.parser = new GroovyLangParser(new CommonTokenStream(this.lexer));
+ this.parser.setErrorHandler(new DescriptiveErrorStrategy(charStream));
- this.parser.setErrorHandler(new DescriptiveErrorStrategy(this.lexer.getInputStream()));
-
- this.tryWithResourcesASTTransformation = new TryWithResourcesASTTransformation(this);
this.groovydocManager = new GroovydocManager(compilerConfiguration);
+ this.tryWithResourcesASTTransformation = new TryWithResourcesASTTransformation(this);
}
private CharStream createCharStream(SourceUnit sourceUnit) {
@@ -809,7 +806,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
ctx);
}
-
@Override
public List<ExpressionStatement> visitResources(ResourcesContext ctx) {
return this.visitResourceList(ctx.resourceList());
@@ -902,7 +898,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
.collect(Collectors.toList());
}
-
@Override
public Statement visitFinallyBlock(FinallyBlockContext ctx) {
if (!asBoolean(ctx)) {
@@ -914,8 +909,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
ctx);
}
-
-
@Override
public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) {
visitingSwitchStatementCnt++;
@@ -961,9 +954,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return result;
}
-
@Override
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings("unchecked")
public List<Statement> visitSwitchBlockStatementGroup(SwitchBlockStatementGroupContext ctx) {
int labelCnt = ctx.switchLabel().size();
List<Token> firstLabelHolder = new ArrayList<>(1);
@@ -1108,7 +1100,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(this.visitTypeDeclaration(ctx.typeDeclaration()), ctx);
}
-
@Override
public Statement visitLocalVariableDeclarationStmtAlt(LocalVariableDeclarationStmtAltContext ctx) {
return configureAST(this.visitLocalVariableDeclaration(ctx.localVariableDeclaration()), ctx);
@@ -1274,7 +1265,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
classNode.addAnnotation(new AnnotationNode(ClassHelper.make(annotationClassName)));
}
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings("unchecked")
private boolean containsDefaultMethods(ClassDeclarationContext ctx) {
List<MethodDeclarationContext> methodDeclarationContextList =
(List<MethodDeclarationContext>) ctx.classBody().classBodyDeclaration().stream()
@@ -1426,7 +1417,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
: configureAST(listExpression, anonymousInnerClassNode);
}
-
@Override
public Void visitClassBodyDeclaration(ClassBodyDeclarationContext ctx) {
ClassNode classNode = ctx.getNodeMetaData(CLASS_DECLARATION_CLASS_NODE);
@@ -2091,23 +2081,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
ctx);
}
-/*
- @Override
- public Expression visitEnhancedExpression(EnhancedExpressionContext ctx) {
- Expression expression;
-
- if (asBoolean(ctx.expression())) {
- expression = (Expression) this.visit(ctx.expression());
- } else if (asBoolean(ctx.standardLambdaExpression())) {
- expression = this.visitStandardLambdaExpression(ctx.standardLambdaExpression());
- } else {
- throw createParsingFailedException("Unsupported enhanced expression: " + ctx.getText(), ctx);
- }
-
- return configureAST(expression, ctx);
- }
-*/
-
@Override
public ExpressionStatement visitCommandExprAlt(CommandExprAltContext ctx) {
return configureAST(new ExpressionStatement(this.visitCommandExpression(ctx.commandExpression())), ctx);
@@ -2241,7 +2214,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
);
}
-
// expression { --------------------------------------------------------------------
@Override
@@ -2266,7 +2238,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public Expression visitExpressionInPar(ExpressionInParContext ctx) {
- //return this.visitEnhancedExpression(ctx.enhancedExpression());
return this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression());
}
@@ -2285,12 +2256,9 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(expression, ctx);
}
-
@Override
public Expression visitPathExpression(PathExpressionContext ctx) {
- return //this.configureAST(
- this.createPathExpression((Expression) this.visit(ctx.primary()), ctx.pathElement());
- //ctx);
+ return this.createPathExpression((Expression) this.visit(ctx.primary()), ctx.pathElement());
}
@Override
@@ -3109,8 +3077,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
ctx);
}
-// } expression --------------------------------------------------------------------
-
+ // } expression --------------------------------------------------------------------
// primary { --------------------------------------------------------------------
@Override
@@ -3180,8 +3147,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(this.visitBuiltInType(ctx.builtInType()), ctx);
}
-
-// } primary --------------------------------------------------------------------
+ // } primary --------------------------------------------------------------------
@Override
public Expression visitCreator(CreatorContext ctx) {
@@ -3286,7 +3252,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return arrayType;
}
-
private static String nextAnonymousClassName(ClassNode outerClass) {
int anonymousClassCount = 0;
for (Iterator<InnerClassNode> it = outerClass.getInnerClasses(); it.hasNext();) {
@@ -3329,7 +3294,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return anonymousInnerClass;
}
-
@Override
public ClassNode visitCreatedName(CreatedNameContext ctx) {
ClassNode classNode = null;
@@ -3358,7 +3322,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return classNode;
}
-
@Override
public MapExpression visitMap(MapContext ctx) {
return configureAST(
@@ -3429,13 +3392,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(new ConstantExpression(ctx.getText()), ctx);
}
- /*
- @Override
- public VariableExpression visitIdentifier(IdentifierContext ctx) {
- return this.configureAST(new VariableExpression(ctx.getText()), ctx);
- }
- */
-
@Override
public VariableExpression visitBuiltInType(BuiltInTypeContext ctx) {
String text;
@@ -3507,8 +3463,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
}
}
-
// literal { --------------------------------------------------------------------
+
@Override
public ConstantExpression visitIntegerLiteralAlt(IntegerLiteralAltContext ctx) {
String text = ctx.IntegerLiteral().getText();
@@ -3562,11 +3518,10 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(new ConstantExpression(null), ctx);
}
-
-// } literal --------------------------------------------------------------------
-
+ // } literal --------------------------------------------------------------------
// gstring { --------------------------------------------------------------------
+
@Override
public GStringExpression visitGstring(GstringContext ctx) {
final List<ConstantExpression> stringLiteralList = new LinkedList<>();
@@ -3696,7 +3651,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(variableExpression, ctx);
}
-// } gstring --------------------------------------------------------------------
+
+ // } gstring --------------------------------------------------------------------
@Override
public LambdaExpression visitStandardLambdaExpression(StandardLambdaExpressionContext ctx) {
@@ -3852,7 +3808,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
.collect(Collectors.toList());
}
-
@Override
public ModifierNode visitClassOrInterfaceModifier(ClassOrInterfaceModifierContext ctx) {
if (asBoolean(ctx.annotation())) {
@@ -3895,7 +3850,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return Collections.emptyList();
}
-
@Override
public ModifierNode visitVariableModifier(VariableModifierContext ctx) {
if (asBoolean(ctx.annotation())) {
@@ -3947,6 +3901,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
}
// type { --------------------------------------------------------------------
+
@Override
public ClassNode visitType(TypeContext ctx) {
if (!asBoolean(ctx)) {
@@ -4066,7 +4021,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
public ClassNode visitPrimitiveType(PrimitiveTypeContext ctx) {
return configureAST(ClassHelper.make(ctx.getText()), ctx);
}
-// } type --------------------------------------------------------------------
+
+ // } type --------------------------------------------------------------------
@Override
public VariableExpression visitVariableDeclaratorId(VariableDeclaratorIdContext ctx) {
@@ -4183,7 +4139,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return annotationElementValues;
}
-
@Override
public String visitAnnotationName(AnnotationNameContext ctx) {
return this.visitQualifiedClassName(ctx.qualifiedClassName()).getName();
@@ -4240,7 +4195,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return ctx.getText();
}
-
@Override
public String visitQualifiedName(QualifiedNameContext ctx) {
return ctx.qualifiedNameElement().stream()
@@ -4314,7 +4268,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return super.visit(tree);
}
-
// e.g. obj.a(1, 2) or obj.a 1, 2
private MethodCallExpression createMethodCallExpression(PropertyExpression propertyExpression, Expression arguments) {
MethodCallExpression methodCallExpression =
@@ -4649,7 +4602,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
node.getLastColumnNumber()));
}
-
private CompilationFailedException createParsingFailedException(String msg, TerminalNode node) {
return createParsingFailedException(msg, node.getSymbol());
}
@@ -4771,7 +4723,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
private final ModuleNode moduleNode;
private final SourceUnit sourceUnit;
- private final CompilerConfiguration compilerConfiguration;
private final GroovyLangLexer lexer;
private final GroovyLangParser parser;
private final TryWithResourcesASTTransformation tryWithResourcesASTTransformation;