Skip to content

Commit

Permalink
Fix for #961: allow trait$super$methods to highlight as unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 23, 2019
1 parent 2afed9d commit 059f726
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,9 @@ private MethodNode processMethod(ClassNode traitClass, ClassNode traitHelperClas
} else {
methodNode.addAnnotation(new AnnotationNode(Traits.IMPLEMENTED_CLASSNODE));
}
// GRECLIPSE edit
//methodNode.setCode(null);
// GRECLIPSE end

/* GRECLIPSE edit
methodNode.setCode(null);
*/
if (!methodNode.isPrivate() && !methodNode.isStatic()) {
methodNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ private Expression transformSuperMethodCall(final MethodCallExpression call) {
Traits.getSuperTraitMethodName(traitClass, method),
superCallArgs
);
/* GRECLIPSE edit
transformed.setSourcePosition(call);
*/
transformed.getMethod().setSourcePosition(call.getMethod());
// GRECLIPSE end
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,9 @@ private MethodNode processMethod(ClassNode traitClass, ClassNode traitHelperClas
} else {
methodNode.addAnnotation(new AnnotationNode(Traits.IMPLEMENTED_CLASSNODE));
}
// GRECLIPSE edit
//methodNode.setCode(null);
// GRECLIPSE end

/* GRECLIPSE edit
methodNode.setCode(null);
*/
if (!methodNode.isPrivate() && !methodNode.isStatic()) {
methodNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ private Expression transformSuperMethodCall(final MethodCallExpression call) {
Traits.getSuperTraitMethodName(traitClass, method),
superCallArgs
);
/* GRECLIPSE edit
transformed.setSourcePosition(call);
*/
transformed.getMethod().setSourcePosition(call.getMethod());
// GRECLIPSE end
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,9 @@ private MethodNode processMethod(ClassNode traitClass, ClassNode traitHelperClas
} else {
methodNode.addAnnotation(new AnnotationNode(Traits.IMPLEMENTED_CLASSNODE));
}
// GRECLIPSE edit
//methodNode.setCode(null);
// GRECLIPSE end

/* GRECLIPSE edit
methodNode.setCode(null);
*/
if (!methodNode.isPrivate() && !methodNode.isStatic()) {
methodNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ private Expression transformSuperMethodCall(final MethodCallExpression call) {
Traits.getSuperTraitMethodName(traitClass, method),
superCallArgs
);
/* GRECLIPSE edit
transformed.setSourcePosition(call);
*/
transformed.getMethod().setSourcePosition(call.getMethod());
// GRECLIPSE end
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,37 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
new HighlightedTypedPosition(contents.lastIndexOf('bar'), 3, STATIC_CALL))
}

@Test // https://github.com/groovy/groovy-eclipse/issues/961
void testTraits11() {
// http://docs.groovy-lang.org/latest/html/documentation/#_semantics_of_super_inside_a_trait
String contents = '''\
|trait Filtering {
| StringBuilder append(String str) {
| def sub = str.replace('o', '')
| super.append(sub)
| }
| String toString() {
| super.toString()
| }
|}
|'''.stripMargin()

assertHighlighting(contents,
new HighlightedTypedPosition(contents.indexOf('Filtering'), 9, TRAIT),
new HighlightedTypedPosition(contents.indexOf('StringBuilder'), 13, CLASS),
new HighlightedTypedPosition(contents.indexOf('append'), 6, METHOD),
new HighlightedTypedPosition(contents.indexOf('String '), 6, CLASS),
new HighlightedTypedPosition(contents.indexOf('str'), 3, PARAMETER),
new HighlightedTypedPosition(contents.indexOf('sub'), 3, VARIABLE),
new HighlightedTypedPosition(contents.indexOf('replace'), 7, METHOD_CALL),
new HighlightedTypedPosition(contents.lastIndexOf('str'), 3, PARAMETER),
new HighlightedTypedPosition(contents.lastIndexOf('append'), 6, UNKNOWN),
new HighlightedTypedPosition(contents.lastIndexOf('sub'), 3, VARIABLE),
new HighlightedTypedPosition(contents.lastIndexOf('String '), 6, CLASS),
new HighlightedTypedPosition(contents.indexOf('toString'), 8, METHOD),
new HighlightedTypedPosition(contents.lastIndexOf('toString'), 8, UNKNOWN))
}

//
private int counter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public VisitStatus acceptASTNode(ASTNode node, TypeLookupResult result, IJavaEle
HighlightedTypedPosition pos = null;
if (result.confidence == TypeLookupResult.TypeConfidence.UNKNOWN && node.getEnd() > 0) {
// GRECLIPSE-1327: check to see if this is a synthetic call() on a closure reference
if (isRealASTNode(node)) {
if (isRealASTNode(node) || node.getText().contains("trait$super$")) {
Position p = getPosition(node);
typedPositions.add(new HighlightedTypedPosition(p, HighlightKind.UNKNOWN));
// don't continue past an unknown reference
Expand Down Expand Up @@ -510,7 +510,7 @@ private boolean isRealASTNode(ASTNode node) {
}
int contentsLength = unitLength();
char[] textArr = text.toCharArray();
for (int i = 0, j = node.getStart(); i < textArr.length && j < contentsLength; i++, j++) {
for (int i = 0, j = node.getStart(); i < textArr.length && j < contentsLength; i += 1, j += 1) {
if (textArr[i] != contents[j]) {
return false;
}
Expand Down

0 comments on commit 059f726

Please sign in to comment.