Skip to content

Commit e2c2144

Browse files
committed
GROOVY-9510, GROOVY-10192
1 parent 3ac5083 commit e2c2144

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/SpockInferencingTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,20 @@ public void testDataTableChecks() {
151151
assertType(source, offset, offset + 1, "java.lang.Object");
152152
assertDeclaringType(source, offset, offset + 1, "SpockTests");
153153
}
154+
155+
@Test
156+
public void testRequiresCondition() {
157+
//@formatter:off
158+
String source =
159+
"final class SpockTests extends spock.lang.Specification {\n" +
160+
" @spock.lang.Requires({ owner })\n" + // owner is static
161+
" void testSomething() {\n" +
162+
" expect:\n" +
163+
" true\n" +
164+
" }\n" +
165+
"}\n";
166+
//@formatter:on
167+
168+
assertType(source, "owner", "java.lang.Class<SpockTests>");
169+
}
154170
}

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,21 @@ private void visitFieldInternal(final FieldNode node) {
658658
}
659659

660660
private void visitMethodInternal(final MethodNode node) {
661-
scopes.add(new VariableScope(scopes.getLast(), node, node.isStatic()));
662661
ASTNode enclosingDeclaration0 = enclosingDeclarationNode;
663662
enclosingDeclarationNode = node;
664663
try {
665-
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
664+
visitAnnotations(node); // annotations are in class scope
665+
scopes.add(new VariableScope(scopes.getLast(), node, node.isStatic()));
666+
try {
667+
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
668+
} finally {
669+
scopes.removeLast().bubbleUpdates();
670+
}
666671
} catch (VisitCompleted vc) {
667672
if (vc.status == VisitStatus.STOP_VISIT) {
668673
throw vc;
669674
}
670675
} finally {
671-
scopes.removeLast().bubbleUpdates();
672676
enclosingDeclarationNode = enclosingDeclaration0;
673677
}
674678
}
@@ -940,7 +944,7 @@ public void visitClosureExpression(final ClosureExpression node) {
940944
scope.addVariable("owner", closureType, VariableScope.CLOSURE_CLASS_NODE);
941945
scope.addVariable("getOwner", closureType, VariableScope.CLOSURE_CLASS_NODE);
942946
} else {
943-
ClassNode ownerType = scope.getThis();
947+
ClassNode ownerType = parent.getThis();
944948
// GRECLIPSE-1348: if someone is silly enough to have a variable named "owner"; don't override it
945949
VariableScope.VariableInfo info = scope.lookupName("owner");
946950
if (info == null || info.type == null || info.scopeNode instanceof ClosureExpression) {
@@ -1115,7 +1119,6 @@ public void visitConstructorOrMethod(final MethodNode node, final boolean isCons
11151119
}
11161120
}
11171121
if (handleParameters(node.getParameters())) {
1118-
visitAnnotations(node);
11191122
if (!isConstructor || !(node.getCode() instanceof BlockStatement)) {
11201123
visitClassCodeContainer(node.getCode());
11211124
} else {

0 commit comments

Comments
 (0)