Skip to content

Commit

Permalink
Add source offsets for classes and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 15, 2018
1 parent ab7c421 commit 82f1861
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last;

/**
* Building the AST from the parse tree generated by Antlr4
* Building the AST from the parse tree generated by Antlr4.
*/
public class AstBuilder extends GroovyParserBaseVisitor<Object> implements GroovyParserVisitor<Object> {
public class AstBuilder extends GroovyParserBaseVisitor<Object> {

public AstBuilder(SourceUnit sourceUnit) {
this.sourceUnit = sourceUnit;
this.moduleNode = new ModuleNode(sourceUnit);
Expand Down Expand Up @@ -407,8 +408,8 @@ private <T extends ASTNode> T configureAST(T astNode, ASTNode source) {
return configureAST(astNode);
}

private <T extends ASTNode> T configureAST(T astNode, ASTNode start, ASTNode stop) {
PositionConfigureUtils.configureAST(astNode, start, stop);
private <T extends ASTNode> T configureAST(T astNode, ASTNode start, ASTNode until) {
PositionConfigureUtils.configureAST(astNode, start, until);
return configureAST(astNode);
}

Expand All @@ -417,8 +418,8 @@ private <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserR
return configureAST(astNode);
}

private <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode stop) {
PositionConfigureUtils.configureAST(astNode, ctx, stop);
private <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode until) {
PositionConfigureUtils.configureAST(astNode, ctx, until);
return configureAST(astNode);
}
// GRECLIPSE end
Expand Down Expand Up @@ -530,6 +531,10 @@ public ModuleNode visitCompilationUnit(CompilationUnitContext ctx) {
throw createParsingFailedException(this.numberFormatError.getSecond().getMessage(), this.numberFormatError.getFirst());
}

// GRECLIPSE add
moduleNode.setEnd(locationSupport.getEnd());
// GRECLIPSE end

return moduleNode;
}

Expand Down Expand Up @@ -653,7 +658,7 @@ public ImportNode visitImportDeclaration(ImportDeclarationContext ctx) {
: name;
// GRECLIPSE edit
//configureAST(classNode, ctx);
ASTNode typeNode = configureAST(classNode instanceof ImmutableClassNode ? new ClassExpression(classNode) : classNode, ctx.qualifiedName());
ASTNode typeNode = configureAST(classNode instanceof ImmutableClassNode ? new ClassExpression(classNode) : classNode, last(ctx.qualifiedName().qualifiedNameElement()));
// GRECLIPSE end

moduleNode.addImport(alias, classNode, annotationNodeList);
Expand Down Expand Up @@ -1438,6 +1443,10 @@ public FieldNode visitEnumConstant(EnumConstantContext ctx) {

groovydocManager.handle(enumConstant, ctx);

// GRECLIPSE add
ASTNode nameNode = configureAST(new ConstantExpression(enumConstant.getName()), ctx.identifier());
enumConstant.setNameStart(nameNode.getStart()); enumConstant.setNameEnd(nameNode.getEnd() - 1);
// GRECLIPSE end
return configureAST(enumConstant, ctx);
}

Expand Down Expand Up @@ -4066,9 +4075,15 @@ public ClassNode visitType(TypeContext ctx) {
//classNode.setUsingGenerics(false);
// GRECLIPSE end
classNode = this.createArrayType(classNode, dimList);
// GRECLIPSE add
configureAST(classNode, ctx);
// GRECLIPSE end
}

return configureAST(classNode, ctx);
// GRECLIPSE edit
//return configureAST(classNode, ctx);
return classNode;
// GRECLIPSE end
}

@Override
Expand All @@ -4083,11 +4098,13 @@ public ClassNode visitClassOrInterfaceType(ClassOrInterfaceTypeContext ctx) {
}

if (asBoolean(ctx.typeArguments())) {
classNode.setGenericsTypes(
this.visitTypeArguments(ctx.typeArguments()));
classNode.setGenericsTypes(this.visitTypeArguments(ctx.typeArguments()));
}

return configureAST(classNode, ctx);
// GRECLIPSE edit
//return configureAST(classNode, ctx);
return classNode;
// GRECLIPSE end
}

@Override
Expand Down Expand Up @@ -4470,7 +4487,10 @@ private Parameter processFormalParameter(GroovyParserRuleContext ctx,
ClassNode classNode = this.visitType(typeContext);

if (asBoolean(ellipsis)) {
classNode = configureAST(classNode.makeArray(), classNode);
// GRECLIPSE edit
//classNode = configureAST(classNode.makeArray(), classNode);
classNode = configureAST(classNode.makeArray(), typeContext);
// GRECLIPSE end
}

Parameter parameter =
Expand Down Expand Up @@ -4598,7 +4618,7 @@ private boolean isSyntheticPublic(
* @param isAnonymousInnerEnumDeclaration whether the method is defined in an anonymous inner enum
* @param hasAnnotation whether the method declaration has annotations
* @param hasVisibilityModifier whether the method declaration contains visibility modifier(e.g. public, protected, private)
* @param hasModifier whether the method declaration has modifier(e.g. visibility modifier, final, static and so on)
* @param hasModifier whether the method declaration has modifier(e.g. final, static and so on)
* @param hasReturnType whether the method declaration has an return type(e.g. String, generic types)
* @param hasDef whether the method declaration using def keyword
* @return the result
Expand All @@ -4615,7 +4635,8 @@ private boolean isSyntheticPublic(
if (hasVisibilityModifier) {
return false;
}

return true;
/* GRECLIPSE edit
if (isAnnotationDeclaration) {
return true;
}
Expand All @@ -4629,7 +4650,7 @@ private boolean isSyntheticPublic(
}
return isAnonymousInnerEnumDeclaration;

*/
}

// the mixins of interface and annotation should be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,12 +1024,10 @@ protected void enumConstantDef(AST node) {
}
}
}
// GRECLIPSE edit
//FieldNode enumField = EnumHelper.addEnumConstant(classNode, identifier, init);
ClassNode nonDeclaredTypeOfEnumValue =
ClassHelper.make(classNode.getName());
nonDeclaredTypeOfEnumValue.setRedirect(classNode);
FieldNode enumField = EnumHelper.addEnumConstant(nonDeclaredTypeOfEnumValue, classNode, identifier, init, savedLine, savedColumn);
FieldNode enumField = EnumHelper.addEnumConstant(classNode, identifier, init);
// GRECLIPSE add
enumField.setLineNumber(savedLine);
enumField.setColumnNumber(savedColumn);
enumField.setNameStart(locations.findOffset(savedLine, savedColumn));
enumField.setNameEnd(enumField.getNameStart() + identifier.length() - 1);
// GRECLIPSE end
Expand Down

This file was deleted.

0 comments on commit 82f1861

Please sign in to comment.