|
11 | 11 | package org.eclipse.jdt.internal.core.search.matching; |
12 | 12 |
|
13 | 13 | import org.eclipse.jdt.core.IJavaElement; |
| 14 | +import org.eclipse.jdt.core.IJavaProject; |
14 | 15 | import org.eclipse.jdt.core.dom.ASTNode; |
15 | 16 | import org.eclipse.jdt.core.dom.IBinding; |
16 | 17 | import org.eclipse.jdt.core.dom.IPackageBinding; |
17 | 18 | import org.eclipse.jdt.core.dom.Name; |
18 | 19 | import org.eclipse.jdt.core.dom.PackageDeclaration; |
19 | 20 | import org.eclipse.jdt.internal.core.search.LocatorResponse; |
20 | | -import org.eclipse.jdt.internal.javac.dom.JavacPackageBinding; |
21 | 21 |
|
22 | 22 | public class DOMPackageReferenceLocator extends DOMPatternLocator { |
23 | 23 |
|
@@ -61,10 +61,17 @@ public LocatorResponse resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBind |
61 | 61 | working = working.getParent(); |
62 | 62 | } |
63 | 63 | if( fullName != null ) { |
64 | | - String typeName = fullName.toString(); |
65 | | - IJavaElement je = binding instanceof JavacPackageBinding jpb ? jpb.findJavaElementForClass(typeName) : ipb.getJavaElement(); |
66 | | - if( je != null && !this.locator.pattern.focus.equals(je)) { |
67 | | - return toResponse(IMPOSSIBLE_MATCH); |
| 64 | + |
| 65 | + IJavaElement je = fullName.resolveBinding().getJavaElement(); |
| 66 | + je = je.getAncestor(IJavaElement.PACKAGE_FRAGMENT); |
| 67 | + if( je != null) { |
| 68 | + IJavaProject otherProject = (IJavaProject)je.getAncestor(IJavaElement.JAVA_PROJECT); |
| 69 | + if (otherProject == null || !otherProject.equals(this.locator.pattern.focus.getAncestor(IJavaElement.JAVA_PROJECT))) { |
| 70 | + return toResponse(IMPOSSIBLE_MATCH); |
| 71 | + } |
| 72 | + if (!this.locator.pattern.focus.getElementName().equals(je.getElementName())) { |
| 73 | + return toResponse(IMPOSSIBLE_MATCH); |
| 74 | + } |
68 | 75 | } |
69 | 76 | // If we can't find a java element, let's give some leeway |
70 | 77 | return toResponse(ACCURATE_MATCH); |
|
0 commit comments