Skip to content

Commit 02de577

Browse files
committed
minor fixes
1 parent ce114e7 commit 02de577

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/GroovyPropertyTester.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.codehaus.groovy.ast.Parameter;
2626
import org.eclipse.core.expressions.PropertyTester;
2727
import org.eclipse.core.runtime.Adapters;
28-
import org.eclipse.core.runtime.IAdaptable;
2928

3029
public class GroovyPropertyTester extends PropertyTester {
3130

@@ -50,17 +49,15 @@ private static boolean oneStringArray(Parameter[] p) {
5049

5150
@Override
5251
public boolean test(Object receiver, String property, Object[] arguments, Object expectedValue) {
53-
if (receiver instanceof IAdaptable) {
54-
ModuleNode node = Adapters.adapt(receiver, ModuleNode.class);
55-
if (node != null && !Boolean.TRUE.equals(node.getNodeMetaData("ParseError"))) {
56-
switch (property) {
57-
case "hasMain":
58-
return node.getClasses().stream().flatMap(cn -> cn.getDeclaredMethods("main").stream()).anyMatch(JAVA_MAIN);
59-
case "isScript":
60-
return !node.getStatementBlock().isEmpty() || (!node.getClasses().isEmpty() &&
61-
node.getClasses().get(0).getNameEnd() < 1 /* un-named */ && getGroovyVersion().getMajor() >= 5 &&
62-
node.getClasses().get(0).getDeclaredMethods("main").stream().anyMatch(JEP_445_MAIN.and(JAVA_MAIN.negate())));
63-
}
52+
ModuleNode node = Adapters.adapt(receiver, ModuleNode.class);
53+
if (node != null && !node.encounteredUnrecoverableError()) {
54+
switch (property) {
55+
case "hasMain":
56+
return node.getClasses().stream().flatMap(cn -> cn.getDeclaredMethods("main").stream()).anyMatch(JAVA_MAIN);
57+
case "isScript":
58+
return !node.getStatementBlock().isEmpty() || (!node.getClasses().isEmpty() &&
59+
node.getClasses().get(0).getNameEnd() < 1 /* un-named */ && getGroovyVersion().getMajor() >= 5 &&
60+
node.getClasses().get(0).getDeclaredMethods("main").stream().anyMatch(JEP_445_MAIN.and(JAVA_MAIN.negate())));
6461
}
6562
}
6663
return false;

base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/GroovyUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.codehaus.groovy.ast.Parameter;
4747
import org.codehaus.groovy.ast.PropertyNode;
4848
import org.codehaus.groovy.ast.Variable;
49+
import org.codehaus.groovy.ast.expr.ConstantExpression;
4950
import org.codehaus.groovy.ast.expr.Expression;
5051
import org.codehaus.groovy.ast.expr.MethodCallExpression;
5152
import org.codehaus.groovy.ast.expr.TernaryExpression;
@@ -427,7 +428,7 @@ public static Expression getTraitFieldExpression(MethodCallExpression call) {
427428
} else if (objType.equals(ClassHelper.CLASS_Type) && asBoolean(objType.getGenericsTypes())) {
428429
objType = objType.getGenericsTypes()[0].getType(); // look for $static$self.T__name$get()
429430
}
430-
if (Traits.isTrait(objType)) {
431+
if (Traits.isTrait(objType) && call.getMethod() instanceof ConstantExpression) {
431432
Matcher m = Pattern.compile(".+__(\\p{javaJavaIdentifierPart}+)\\$[gs]et").matcher(call.getMethodAsString());
432433
if (m.matches()) {
433434
String fieldName = m.group(1);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2071,14 +2071,14 @@ private boolean handleSimpleExpression(final Expression node) {
20712071
primaryType = null; // implicit-this calls are handled like free variables
20722072
isStatic = scope.isStatic();
20732073
} else {
2074-
isStatic = mce.getObjectExpression() instanceof ClassExpression || primaryType.equals(VariableScope.CLASS_CLASS_NODE);
2074+
isStatic = mce.getObjectExpression() instanceof ClassExpression || VariableScope.CLASS_CLASS_NODE.equals(primaryType);
20752075
}
20762076
} else if (enclosingNode instanceof PropertyExpression) {
20772077
PropertyExpression pe = (PropertyExpression) enclosingNode;
2078-
isStatic = pe.getObjectExpression() instanceof ClassExpression || primaryType.equals(VariableScope.CLASS_CLASS_NODE);
2078+
isStatic = pe.getObjectExpression() instanceof ClassExpression || VariableScope.CLASS_CLASS_NODE.equals(primaryType);
20792079
} else if (enclosingNode instanceof MethodPointerExpression) {
20802080
MethodPointerExpression mpe = (MethodPointerExpression) enclosingNode;
2081-
isStatic = mpe.getExpression() instanceof ClassExpression || primaryType.equals(VariableScope.CLASS_CLASS_NODE);
2081+
isStatic = mpe.getExpression() instanceof ClassExpression || VariableScope.CLASS_CLASS_NODE.equals(primaryType);
20822082
} else /*if (enclosingNode instanceof ImportNode)*/ {
20832083
isStatic = true;
20842084
}

ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/adapters/IsScriptTesterTests.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import org.junit.Test
2323

2424
final class IsScriptTesterTests extends GroovyEclipseTestSuite {
2525

26-
private void doTest(String name = 'Main', String text, boolean expected) {
27-
boolean isScript = new GroovyPropertyTester().test(addGroovySource(text, name), 'isScript', null, null)
26+
private void doTest(String text, boolean expected) {
27+
boolean isScript = new GroovyPropertyTester().test(addGroovySource(text, nextUnitName()), 'isScript', null, null)
2828
assert (isScript == expected) : "Should have ${expected ? '' : '*not*'} found a script class in:\n$text"
2929
}
3030

0 commit comments

Comments
 (0)