From 431e885bbc1446748b1ca0871367dab4e6503281 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Tue, 13 Feb 2018 10:28:33 -0600 Subject: [PATCH] Fix for issue #468: record type reference for coercion expression "as T" --- .../search/TypeReferenceSearchTests.java | 25 +++++++++++++++++++ .../internal/GroovyIndexingVisitor.java | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/TypeReferenceSearchTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/TypeReferenceSearchTests.java index e2180cb9aa..bbc99480fa 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/TypeReferenceSearchTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/TypeReferenceSearchTests.java @@ -230,6 +230,31 @@ public void testShouldntFindClassDeclarationInScript() throws Exception { assertEquals("Should find no matches", 0, matches.size()); } + @Test // https://github.com/groovy/groovy-eclipse/issues/468 + public void testCoercion1() throws Exception { + String firstContents = + "package a\n" + + "interface First {\n" + + " void meth();\n" + + "}\n"; + + String secondContents = + "package a\n" + + "class Second {\n" + + " def m() {\n" + + " return {->\n" + + " } as First\n" + + " }\n" + + "}\n"; + + List matches = getAllMatches(firstContents, secondContents, "a", "a", false); + assertEquals("Wrong count", 1, matches.size()); + + SearchMatch match = matches.get(0); + assertEquals("Wrong length", "First".length(), match.getLength()); + assertEquals("Wrong offset", secondContents.indexOf("First"), match.getOffset()); + } + @Test // https://github.com/groovy/groovy-eclipse/issues/442 public void testGenerics1() throws Exception { String firstContents = diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyIndexingVisitor.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyIndexingVisitor.java index 41df4bdf86..6a05085d93 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyIndexingVisitor.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyIndexingVisitor.java @@ -124,7 +124,8 @@ public void visitArrayExpression(ArrayExpression expression) { @Override public void visitCastExpression(CastExpression expression) { // NOTE: expression.getType() may refer to ClassNode behind "this" or "super" - if (expression.getEnd() > 0 && expression.getStart() == expression.getType().getStart()) { + if (expression.getEnd() > 0 && (/*cast:*/expression.getStart() == expression.getType().getStart() || + /*coerce:*/expression.getEnd() == expression.getType().getEnd())) { visitTypeReference(expression.getType(), false, true); } super.visitCastExpression(expression);