Skip to content

Commit

Permalink
Fix for #395: record/resolve anon inner types with JDT for better assist
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 24, 2018
1 parent 60185b5 commit d0372b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5922,6 +5922,9 @@ public void testInnerClass1() {
" }\n" +
" public java.lang.Object run() {\n" +
" new Runnable() {\n" +
" x() {\n" +
" super();\n" +
" }\n" +
" public void run() {\n" +
" }\n" +
" };\n" +
Expand Down Expand Up @@ -5949,6 +5952,9 @@ public void testInnerClass1a() {
checkGCUDeclaration("A.groovy",
"public class A {\n" +
" private java.lang.Object foo = new Runnable() {\n" +
" x() {\n" +
" super();\n" +
" }\n" +
" public void run() {\n" +
" }\n" +
" };\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,17 @@ public void buildFieldsAndMethods() {
}

for (GroovyTypeDeclaration anonType : ((GroovyTypeDeclaration) referenceContext).getAnonymousTypes()) {
anonType.scope = new GroovyClassScope(this, anonType);
if (anonType.scope == null) {
if (anonType.getClassNode().isEnum()) {
anonType.scope = new GroovyClassScope(this, anonType);
// TODO: anonType.resolve(anonType.scope.parent); or ?
} else {
anonType.enclosingScope.parent = this;
anonType.allocation.resolveType(anonType.enclosingScope);
assert anonType.binding != null && anonType.scope != null;
// TODO: Replace anonType.scope with new GroovyClassScope?
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ private void createTypeDeclarations(ModuleNode moduleNode) {
innersToRecord.computeIfAbsent(outerClassNode, x -> new ArrayList<>()).add(typeDeclaration);

if (innerClassNode.isAnonymous()) {
typeDeclaration.name = CharOperation.NO_CHAR;
typeDeclaration.bits |= (ASTNode.IsAnonymousType | ASTNode.IsLocalType);
typeDeclaration.bits |= (typeDeclaration.superclass.bits & ASTNode.HasTypeAnnotations);
QualifiedAllocationExpression allocation = new QualifiedAllocationExpression(typeDeclaration);
Expand Down

0 comments on commit d0372b7

Please sign in to comment.