|
28 | 28 | import org.eclipse.jdt.core.compiler.CharOperation; |
29 | 29 | import org.eclipse.jdt.core.dom.ASTNode; |
30 | 30 | import org.eclipse.jdt.core.dom.ASTVisitor; |
| 31 | +import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; |
31 | 32 | import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; |
32 | 33 | import org.eclipse.jdt.core.dom.BreakStatement; |
33 | 34 | import org.eclipse.jdt.core.dom.CastExpression; |
@@ -428,8 +429,29 @@ private String getQualifiedNameFromType(Type query) { |
428 | 429 | return getQualifiedNameFromType(ptt.getType()); |
429 | 430 | } |
430 | 431 | if( query instanceof SimpleType st) { |
431 | | - String fqqn = fqqnFromImport(st.getName().toString()); |
432 | | - return fqqn != null ? fqqn : st.getName().toString(); |
| 432 | + String stName = st.getName().toString(); |
| 433 | + if( stName.contains(".")) { |
| 434 | + return stName; |
| 435 | + } |
| 436 | + String fqqn = fqqnFromImport(stName); |
| 437 | + if( fqqn != null ) { |
| 438 | + return fqqn; |
| 439 | + } |
| 440 | + // Check if node's top level type has class of sought name |
| 441 | + org.eclipse.jdt.core.dom.CompilationUnit cu = findCompilationUnitAncestor(query); |
| 442 | + if( cu != null ) { |
| 443 | + List<AbstractTypeDeclaration> types = cu.types(); |
| 444 | + if( types != null ) { |
| 445 | + for( AbstractTypeDeclaration ad : types ) { |
| 446 | + if( ad.getName().toString().equals(stName)) { |
| 447 | + if( cu.getPackage() != null ) { |
| 448 | + String pkg = cu.getPackage().getName().toString(); |
| 449 | + return pkg + "." + stName; |
| 450 | + } |
| 451 | + } |
| 452 | + } |
| 453 | + } |
| 454 | + } |
433 | 455 | } |
434 | 456 | return null; |
435 | 457 | } |
@@ -721,7 +743,8 @@ private int resolveLevelForTypeBinding(org.eclipse.jdt.core.dom.ASTNode node, IT |
721 | 743 | } |
722 | 744 |
|
723 | 745 | if (trp.focus != null) { |
724 | | - return Objects.equals(typeBinding.getJavaElement(), locator.pattern.focus) ? |
| 746 | + IJavaElement je = typeBinding.getJavaElement(); |
| 747 | + return Objects.equals(je, locator.pattern.focus) ? |
725 | 748 | ACCURATE_MATCH : IMPOSSIBLE_MATCH; |
726 | 749 | } |
727 | 750 | IImportDiscovery importDiscovery = new IImportDiscovery() { |
@@ -937,6 +960,16 @@ private boolean hasImportAncestor(ASTNode node) { |
937 | 960 | return false; |
938 | 961 | } |
939 | 962 |
|
| 963 | + private org.eclipse.jdt.core.dom.CompilationUnit findCompilationUnitAncestor(ASTNode node) { |
| 964 | + ASTNode working = node; |
| 965 | + while(working != null) { |
| 966 | + if( working instanceof org.eclipse.jdt.core.dom.CompilationUnit wk) |
| 967 | + return wk; |
| 968 | + working = working.getParent(); |
| 969 | + } |
| 970 | + return null; |
| 971 | + } |
| 972 | + |
940 | 973 | @Override |
941 | 974 | public void reportSearchMatch(MatchLocator locator, ASTNode node, SearchMatch match) throws CoreException { |
942 | 975 | IResource resource = match.getResource(); |
|
0 commit comments