Skip to content

Commit

Permalink
GROOVY-10197
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 13, 2021
1 parent 0db55ae commit 248b14e
Show file tree
Hide file tree
Showing 7 changed files with 759 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6327,4 +6327,25 @@ public void testCompileStatic10089() {

runConformTest(sources, "[[id:x, name:null, count:1]]");
}

@Test
public void testCompileStatic10197() {
for (String override : new String[]{"int getBaz() {1}", "final int baz = 1"}) {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"enum Foo {\n" +
" BAR {\n" +
" " + override + "\n" +
" }\n" +
" int getBaz() { -1 }\n" +
"}\n" +
"print Foo.BAR.baz\n",
};
//@formatter:on

runConformTest(sources, "1");
}
}
}
1 change: 1 addition & 0 deletions base/org.codehaus.groovy25/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<file-match-pattern match-pattern="groovy/transform/LazyASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/NewifyASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/TupleConstructorASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/StaticCompilationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/transformers/(Binary|MethodCall|Variable)ExpressionTransformer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/transformers/ConstructorCallTransformer.java" include-pattern="false" />
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base/org.codehaus.groovy30/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/TupleConstructorASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/StaticCompilationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/transformers/(Binary|MethodCall)ExpressionTransformer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/stc/AbstractExtensionMethodCache.java" include-pattern="false" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ private void visitEnumConstBody(final ClassNode node) {
visitMethodInternal(method);
}
}
for (FieldNode field : node.getFields()) {
if (field.getEnd() > 0) {
enclosingElement = ((IType) enumConstant.getChildren()[0]).getField(field.getName());
visitFieldInternal(field);
}
}
} catch (JavaModelException e) {
log(e, "Error visiting children of %s", enclosingDeclarationNode);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
}

@Test
void testEnumInner() {
void testEnumInner1() {
String contents = '''\
|import groovy.transform.*
|@CompileStatic
Expand Down Expand Up @@ -1806,6 +1806,26 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
new HighlightedTypedPosition(contents.lastIndexOf('meth'), 4, METHOD))
}

@Test
void testEnumInner2() {
String contents = '''\
|enum X {
| WHY {
| final int value = 1
| }
| def getValue() { -1 }
|}
|'''.stripMargin()

assertHighlighting(contents,
new HighlightedTypedPosition(contents.indexOf('X'), 1, ENUMERATION),
new HighlightedTypedPosition(contents.indexOf('WHY'), 3, STATIC_VALUE),
new HighlightedTypedPosition(contents.indexOf('value'), 5, FIELD),
new HighlightedTypedPosition(contents.indexOf('1'), 1, NUMBER),
new HighlightedTypedPosition(contents.indexOf('getValue'), 8, METHOD),
new HighlightedTypedPosition(contents.indexOf('-1'), 2, NUMBER))
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1004
void testEnumMethod() {
String contents = '''\
Expand Down

0 comments on commit 248b14e

Please sign in to comment.