Skip to content

Commit

Permalink
Fix for #1195: drop declaring class type parameters for static members
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 12, 2020
1 parent 465f3e0 commit 11aa9a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ final class CodeSelectGenericsTests extends BrowsingTestSuite {
assertCodeSelect([structureContents, javaContents, groovyContents], toFind)
}

@Test
void testCodeSelectGenericTypeAndMethod6() {
String contents = '''\
|class C<T> {
| static <U> C<U> of(U item) {}
|}
|def c = C.of(123)
|'''.stripMargin()
assertCodeSelect([contents], 'of')
}

@Test // GRECLIPSE-1238
void testCodeSelectTypeParam0() {
String name = 'SomeInterface'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
Expand Down Expand Up @@ -654,7 +653,24 @@ private IJavaElement resolveRequestedElement(final IJavaElement maybeRequested,
private static String createUniqueKey(final AnnotatedNode declaration, final IJavaElement maybeRequested, final TypeLookupResult result) {
ClassNode resolvedDeclaringType = result.declaringType;
if (resolvedDeclaringType == null) {
resolvedDeclaringType = Optional.ofNullable(declaration.getDeclaringClass()).orElse(VariableScope.OBJECT_CLASS_NODE);
resolvedDeclaringType = declaration.getDeclaringClass();
if (resolvedDeclaringType == null) {
resolvedDeclaringType = VariableScope.OBJECT_CLASS_NODE;
}
}
if (resolvedDeclaringType.getGenericsTypes() != null) {
boolean isStatic = false;
if (declaration instanceof ClassNode) {
isStatic = Flags.isStatic(
((ClassNode) declaration).getModifiers());
} else if (declaration instanceof FieldNode) {
isStatic = ((FieldNode) declaration).isStatic();
} else if (declaration instanceof MethodNode) {
isStatic = ((MethodNode) declaration).isStatic();
}
if (isStatic) {
resolvedDeclaringType = resolvedDeclaringType.getPlainNodeReference();
}
}

StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit 11aa9a9

Please sign in to comment.