Skip to content

Commit 95a5bf9

Browse files
committed
GROOVY-9510, GROOVY-10192 (pt.3)
1 parent 67588cd commit 95a5bf9

File tree

3 files changed

+33
-49
lines changed

3 files changed

+33
-49
lines changed

base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/TypeInferencingVisitorWithRequestor.java

+24-32
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,7 @@ public void visitJDT(final IField field, final ITypeRequestor requestor) {
440440
IJavaElement enclosingElement0 = enclosingElement;
441441
enclosingElement = field;
442442
try {
443-
visitField(fieldNode);
444-
} catch (VisitCompleted vc) {
445-
if (vc.status == VisitStatus.STOP_VISIT) {
446-
throw vc;
447-
}
443+
visitFieldInternal(fieldNode);
448444
} finally {
449445
enclosingElement = enclosingElement0;
450446
}
@@ -658,31 +654,22 @@ private void visitFieldInternal(final FieldNode node) {
658654
}
659655

660656
private void visitMethodInternal(final MethodNode node) {
657+
scopes.add(new VariableScope(scopes.getLast(), node, true));
661658
ASTNode enclosingDeclaration0 = enclosingDeclarationNode;
662659
enclosingDeclarationNode = node;
663660
try {
664-
VariableScope classScope = scopes.getLast();
665-
if (isNotEmpty(node.getAnnotations())) {
666-
// assert(!node.isScriptBody());
667-
classScope.setCurrentNode(node);
668-
try {
669-
visitAnnotations(node); // annotations are in class scope
670-
} finally {
671-
classScope.forgetCurrentNode();
672-
}
673-
}
674-
675-
scopes.add(new VariableScope(classScope, node, node.isStatic()));
676-
try {
677-
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
678-
} finally {
679-
scopes.removeLast().bubbleUpdates();
661+
visitAnnotations(node);
662+
if (!node.isStatic()) {
663+
scopes.removeLast();
664+
scopes.add(new VariableScope(scopes.getLast(), node, false));
680665
}
666+
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
681667
} catch (VisitCompleted vc) {
682668
if (vc.status == VisitStatus.STOP_VISIT) {
683669
throw vc;
684670
}
685671
} finally {
672+
scopes.removeLast().bubbleUpdates();
686673
enclosingDeclarationNode = enclosingDeclaration0;
687674
}
688675
}
@@ -1186,21 +1173,26 @@ public void visitFieldExpression(final FieldExpression node) {
11861173

11871174
@Override
11881175
public void visitField(final FieldNode node) {
1189-
visitAnnotations(node);
1190-
if (node.getEnd() > 0 && node.getDeclaringClass().isScript()) {
1191-
for (ASTNode anno : GroovyUtils.getTransformNodes(node.getDeclaringClass(), FieldASTTransformation.class)) {
1192-
if (anno.getStart() >= node.getStart() && anno.getEnd() < node.getEnd()) {
1193-
visitAnnotation((AnnotationNode) anno);
1176+
ASTNode enclosingDeclaration = enclosingDeclarationNode;
1177+
enclosingDeclarationNode = node;
1178+
try {
1179+
VariableScope classScope = scopes.getLast(), fieldScope = new VariableScope(classScope, node, true);
1180+
scopes.add(fieldScope);
1181+
1182+
visitAnnotations(node);
1183+
if (node.getEnd() > 0 && node.getDeclaringClass().isScript()) {
1184+
for (ASTNode anno : GroovyUtils.getTransformNodes(node.getDeclaringClass(), FieldASTTransformation.class)) {
1185+
if (anno.getStart() >= node.getStart() && anno.getEnd() < node.getEnd()) {
1186+
visitAnnotation((AnnotationNode) anno);
1187+
}
11941188
}
11951189
}
1196-
}
11971190

1198-
VariableScope classScope = scopes.getLast(), fieldScope = new VariableScope(classScope, node, node.isStatic());
1199-
scopes.add(fieldScope);
1191+
if (!node.isStatic()) {
1192+
scopes.removeLast();
1193+
scopes.add(fieldScope = new VariableScope(classScope, node, false));
1194+
}
12001195

1201-
ASTNode enclosingDeclaration = enclosingDeclarationNode;
1202-
enclosingDeclarationNode = node;
1203-
try {
12041196
if (node.isDynamicTyped()) {
12051197
ClassNode type = node.getType();
12061198
if (node.hasInitialExpression()) {

base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/VariableScope.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ public boolean isStatic() {
402402
}
403403

404404
public boolean isOwnerStatic() {
405-
VariableScope scope = this;
406-
do {
405+
for (VariableScope scope = this; scope != null; scope = scope.parent) {
407406
if (scope.isStatic()) {
408407
return true;
409408
}
@@ -412,8 +411,7 @@ public boolean isOwnerStatic() {
412411
scope.scopeNode instanceof MethodNode) {
413412
break;
414413
}
415-
} while ((scope = scope.parent) != null);
416-
414+
}
417415
return false;
418416
}
419417

@@ -452,18 +450,13 @@ public FieldNode getEnclosingFieldDeclaration() {
452450
}
453451

454452
public MethodNode getEnclosingMethodDeclaration() {
455-
for (Iterator<ASTNode> it = shared.nodeStack.descendingIterator(); it.hasNext();) {
456-
ASTNode node = it.next();
457-
if (node instanceof MethodNode) {
458-
return (MethodNode) node;
459-
}
460-
}
461-
for (VariableScope scope = this; scope != null; scope = scope.parent) {
462-
if (scope.scopeNode instanceof MethodNode) {
463-
return (MethodNode) scope.scopeNode;
464-
}
453+
if (scopeNode instanceof MethodNode) {
454+
return (MethodNode) scopeNode;
455+
} else if (parent != null) {
456+
return parent.getEnclosingMethodDeclaration();
457+
} else {
458+
return null;
465459
}
466-
return null;
467460
}
468461

469462
public ClosureExpression getEnclosingClosure() {

ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/PointcutEvaluationTests.groovy

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.codehaus.groovy.eclipse.dsl.tests
1717

18-
import groovy.test.NotYetImplemented
1918
import groovy.transform.ToString
2019
import groovy.transform.TupleConstructor
2120

@@ -669,7 +668,7 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
669668
new BindingResult('b', '@java.lang.Deprecated, @java.lang.Deprecated'))
670669
}
671670

672-
@NotYetImplemented @Test
671+
@Test
673672
void testEnclosingFieldBinding() {
674673
addGroovySource('@interface Tag {\n Class<? extends Closure> value()\n}', 'Tag', 'p')
675674

0 commit comments

Comments
 (0)