Skip to content

Commit

Permalink
Prep for #706: add @OverRide to Groovy script run() method
Browse files Browse the repository at this point in the history
- prevents missing @OverRide error/warning in next commit
  • Loading branch information
eric-milles committed Oct 15, 2018
1 parent 4cc8f8a commit 49ac31d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testParsingRecovery_IncompleteAssignment1() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand All @@ -118,7 +118,7 @@ public void testParsingRecovery_IncompleteAssignment1a() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand All @@ -145,7 +145,7 @@ public void testParsingRecovery_IncompleteAssignment1b() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand All @@ -172,7 +172,7 @@ public void testParsingRecovery_IncompleteAssignment1c() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -345,7 +345,7 @@ public void testParsingRecovery_IncompleteRangeExpression1() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -373,7 +373,7 @@ public void testParsingRecovery_IncompleteRangeExpression2() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -401,7 +401,7 @@ public void testParsingRecovery_IncompleteRangeExpression3() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -429,7 +429,7 @@ public void testParsingRecovery_IncompleteRangeExpression4() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -1024,7 +1024,7 @@ public void testParsingRecovery_GRE468_4() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public void testParsingRecovery_GRE468_9() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" }\n" +
"}\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4518,7 +4518,7 @@ public void testAnonymousInnerClass1() {
" }\n" +
" public static void main(java.lang.String... args) {\n" +
" }\n" +
" public java.lang.Object run() {\n" +
" public @java.lang.Override java.lang.Object run() {\n" +
" new Runnable() {\n" +
" x() {\n" +
" super();\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,10 @@ protected void innerClassDef(AST classDef) {
List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();

if (isType(TRAIT_DEF, classDef)) {
annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
// GRECLIPSE edit
//annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
annotations.add(makeAnnotationNode("groovy.transform.Trait"));
// GRECLIPSE end
}

AST node = classDef.getFirstChild();
Expand Down Expand Up @@ -3712,6 +3715,15 @@ protected void configureAST(AnnotatedNode node, AST ast, AST name0, AST name1) {
node.setNameEnd(locations.findOffset(nameStop.getLineLast(), nameStop.getColumnLast()) - 1);
}

protected static AnnotationNode makeAnnotationNode(String name) {
AnnotationNode node = new AnnotationNode(ClassHelper.make(name));
node.getClassNode().setStart(-1);
node.getClassNode().setEnd(-2);
node.setStart(-1);
node.setEnd(-2);
return node;
}

protected static ClassNode makeClassNode(String name) {
ClassNode node = ClassHelper.make(name);
if (node instanceof ImmutableClassNode) {
Expand Down Expand Up @@ -3829,6 +3841,7 @@ private void fixModuleNodeLocations() {
runMethod.setEnd(last.getEnd());
runMethod.setLastLineNumber(last.getLastLineNumber());
runMethod.setLastColumnNumber(last.getLastColumnNumber());
runMethod.addAnnotation(makeAnnotationNode("java.lang.Override"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,10 @@ protected void innerClassDef(AST classDef) {
List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();

if (isType(TRAIT_DEF, classDef)) {
annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
// GRECLIPSE edit
//annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
annotations.add(makeAnnotationNode("groovy.transform.Trait"));
// GRECLIPSE end
}

AST node = classDef.getFirstChild();
Expand Down Expand Up @@ -3743,6 +3746,15 @@ protected void configureAST(AnnotatedNode node, AST ast, AST name0, AST name1) {
node.setNameEnd(locations.findOffset(nameStop.getLineLast(), nameStop.getColumnLast()) - 1);
}

protected static AnnotationNode makeAnnotationNode(String name) {
AnnotationNode node = new AnnotationNode(ClassHelper.make(name));
node.getClassNode().setStart(-1);
node.getClassNode().setEnd(-2);
node.setStart(-1);
node.setEnd(-2);
return node;
}

protected static ClassNode makeClassNode(String name) {
ClassNode node = ClassHelper.make(name);
if (node instanceof ImmutableClassNode) {
Expand Down Expand Up @@ -3859,6 +3871,7 @@ private void fixModuleNodeLocations() {
runMethod.setEnd(last.getEnd());
runMethod.setLastLineNumber(last.getLastLineNumber());
runMethod.setLastColumnNumber(last.getLastColumnNumber());
runMethod.addAnnotation(makeAnnotationNode("java.lang.Override"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ public ModuleNode visitCompilationUnit(CompilationUnitContext ctx) {
runMethod.setEnd(omega.getEnd());
runMethod.setLastLineNumber(omega.getLastLineNumber());
runMethod.setLastColumnNumber(omega.getLastColumnNumber());
runMethod.addAnnotation(makeAnnotationNode("java.lang.Override"));
}
}
moduleNode.putNodeMetaData(LocationSupport.class, locationSupport);
Expand Down Expand Up @@ -773,6 +774,15 @@ public ImportNode visitImportDeclaration(ImportDeclarationContext ctx) {
}

// GRECLIPSE add
private static AnnotationNode makeAnnotationNode(String name) {
AnnotationNode node = new AnnotationNode(ClassHelper.make(name));
node.getClassNode().setStart(-1);
node.getClassNode().setEnd(-2);
node.setStart(-1);
node.setEnd(-2);
return node;
}

private static ClassNode makeClassNode(String name) {
ClassNode node = ClassHelper.make(name);
if (node instanceof ImmutableClassNode) {
Expand Down Expand Up @@ -1536,12 +1546,17 @@ public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) {
}

private void attachTraitAnnotation(ClassNode classNode) {
attachAnnotation(classNode, GROOVY_TRANSFORM_TRAIT);
// GRECLIPSE edit
//attachAnnotation(classNode, GROOVY_TRANSFORM_TRAIT);
classNode.addAnnotation(makeAnnotationNode(GROOVY_TRANSFORM_TRAIT));
// GRECLIPSE end
}

/* GRECLIPSE edit
private void attachAnnotation(ClassNode classNode, String annotationClassName) {
classNode.addAnnotation(new AnnotationNode(ClassHelper.make(annotationClassName)));
}
*/

private boolean containsDefaultMethods(ClassDeclarationContext ctx) {
for (ClassBodyDeclarationContext c : ctx.classBody().classBodyDeclaration()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ public ModuleNode buildAST(SourceUnit sourceUnit, ClassLoader classLoader, Reduc
runMethod.setEnd(last.getEnd());
runMethod.setLastLineNumber(last.getLastLineNumber());
runMethod.setLastColumnNumber(last.getLastColumnNumber());
runMethod.addAnnotation(makeAnnotationNode("java.lang.Override"));
}
}
output.putNodeMetaData(LocationSupport.class, locations);
Expand Down Expand Up @@ -867,7 +868,10 @@ protected void innerClassDef(AST classDef) {
List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();

if (isType(TRAIT_DEF, classDef)) {
annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
// GRECLIPSE edit
//annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
annotations.add(makeAnnotationNode("groovy.transform.Trait"));
// GRECLIPSE end
}

AST node = classDef.getFirstChild();
Expand Down Expand Up @@ -3854,6 +3858,15 @@ protected void configureAST(AnnotatedNode node, AST ast, AST name0, AST name1) {
node.setNameEnd(locations.findOffset(nameStop.getLineLast(), nameStop.getColumnLast()) - 1);
}

protected static AnnotationNode makeAnnotationNode(String name) {
AnnotationNode node = new AnnotationNode(ClassHelper.make(name));
node.getClassNode().setStart(-1);
node.getClassNode().setEnd(-2);
node.setStart(-1);
node.setEnd(-2);
return node;
}

protected static ClassNode makeClassNode(String name) {
ClassNode node = ClassHelper.make(name);
if (node instanceof ImmutableClassNode) {
Expand Down

0 comments on commit 49ac31d

Please sign in to comment.