@@ -70,9 +70,6 @@ private boolean hasPackageDeclarationAncestor(org.eclipse.jdt.core.dom.ASTNode n
7070 return node == null ? false : hasPackageDeclarationAncestor (node .getParent ());
7171 }
7272
73-
74-
75-
7673 @ Override
7774 public LocatorResponse match (org .eclipse .jdt .core .dom .Annotation node , NodeSetWrapper nodeSet , MatchLocator locator ) {
7875 return match (node .getTypeName (), nodeSet , locator );
@@ -242,14 +239,14 @@ private int validateTypeParameters(Type node) {
242239 return TYPE_PARAMS_MATCH ;
243240 }
244241
242+ int r = this .locator .pattern .getMatchRule ();
243+ boolean erasureMatch = (r & SearchPattern .R_ERASURE_MATCH ) == SearchPattern .R_ERASURE_MATCH ;
244+ boolean equivMatch = (r & SearchPattern .R_EQUIVALENT_MATCH ) == SearchPattern .R_EQUIVALENT_MATCH ;
245245 if ( node instanceof SimpleType st && (st .getName () instanceof QualifiedName || st .getName () instanceof SimpleName )) {
246246 // JavaSearchGenericTypeEquivalentTests.testTypeMultipleArguments03 needs to return no_match
247247 // JavaSearchGenericTypeTests.testTypeMultipleArguments03 needs to return params_match
248248
249249 if ( fromPattern != null && fromPattern .length > 0 && fromPattern [0 ] != null && fromPattern [0 ].length != 0 ) {
250- int r = this .locator .pattern .getMatchRule ();
251- boolean erasureMatch = (r & SearchPattern .R_ERASURE_MATCH ) == SearchPattern .R_ERASURE_MATCH ;
252- //boolean equivMatch = (r & SearchPattern.R_EQUIVALENT_MATCH) == SearchPattern.R_EQUIVALENT_MATCH;
253250 if ( !erasureMatch )
254251 return TYPE_PARAMS_NO_MATCH ;
255252 }
@@ -390,6 +387,9 @@ public LocatorResponse resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBind
390387 return toResponse (INACCURATE_MATCH );
391388 }
392389 if (binding instanceof ITypeBinding typeBinding ) {
390+ if ( node .getParent () instanceof ImportDeclaration id ) {
391+ return resolveLevelForImportBinding (node , typeBinding , locator );
392+ }
393393 int v = resolveLevelForTypeBinding (node , typeBinding , locator );
394394 return toResponse (v );
395395 }
@@ -412,6 +412,12 @@ public LocatorResponse resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBind
412412 return toResponse (IMPOSSIBLE_MATCH );
413413 }
414414
415+ private LocatorResponse resolveLevelForImportBinding (ASTNode node , ITypeBinding typeBinding ,
416+ MatchLocator locator2 ) {
417+ int newLevel = this .resolveLevelForTypeFQN (this .locator .pattern .simpleName ,
418+ this .locator .pattern .qualification , typeBinding , null );
419+ return toResponse (newLevel );
420+ }
415421 private static boolean failsFineGrain (ASTNode node , int fineGrain ) {
416422 if (fineGrain == 0 ) {
417423 return false ;
@@ -470,72 +476,89 @@ public String findImportForString(String s) {
470476 }
471477 }
472478 if ( this .locator .isDeclarationOfReferencedTypesPattern ) {
473- IJavaElement enclosing = ((DeclarationOfReferencedTypesPattern )this .locator .pattern ).enclosingElement ;
474- // We don't add this node. We manually add the declaration
475- ITypeBinding t2 = typeBinding .getTypeDeclaration ();
476- IJavaElement je = t2 == null ? null : t2 .getJavaElement ();
477- if ( je != null && !this .foundElements .contains (je ) && DOMASTNodeUtils .isWithinRange (node , enclosing )) {
478- ISourceReference sr = je instanceof ISourceReference ? (ISourceReference )je : null ;
479- IResource r = null ;
480- ISourceRange srg = null ;
481- ISourceRange nameRange = null ;
482- try {
483- srg = sr .getSourceRange ();
484- nameRange = sr .getNameRange ();
485- IJavaElement ancestor = je .getAncestor (IJavaElement .COMPILATION_UNIT );
486- r = ancestor == null ? null : ancestor .getCorrespondingResource ();
487- } catch (JavaModelException jme ) {
488- // ignore
489- }
490- ISourceRange rangeToUse = (nameRange == null ) ? srg : nameRange ;
491- if ( rangeToUse != null ) {
492- TypeDeclarationMatch tdm = new TypeDeclarationMatch (je , newLevel ,
493- rangeToUse .getOffset (), rangeToUse .getLength (),
494- locator .getParticipant (), r );
495- try {
496- this .foundElements .add (je );
497- locator .report (tdm );
498- } catch (CoreException ce ) {
499- // ignore
500- }
501- }
502- }
503- return IMPOSSIBLE_MATCH ;
479+ return resolveLevelForTypeBindingDeclarationOfReferencedTypes (typeBinding , node , newLevel , locator );
504480 }
505481 if ( newLevel == ACCURATE_MATCH && this .locator .pattern .hasTypeArguments () ) {
506- int matchRule = newLevel ;
507- boolean hasTypeParameters = this .locator .pattern .hasTypeParameters ();
508- char [][][] patternTypeArgArray = this .locator .pattern .getTypeArguments ();
509- int patternTypeArgsLength = patternTypeArgArray == null ? -1 :
510- patternTypeArgArray [0 ] == null ? -1 :
511- patternTypeArgArray [0 ].length == 0 ? -1 : patternTypeArgArray [0 ].length ;
512- boolean raw = typeBinding .isRawType ();
513- boolean generic = typeBinding .isGenericType ();
514- boolean parameterized = typeBinding .isParameterizedType ();
515- ITypeBinding [] args = typeBinding .getTypeArguments ();
516- int typeArgumentsLength = args == null ? -1 : args .length ;
517- // Compare arguments lengthes
518- if (patternTypeArgsLength == typeArgumentsLength ) {
519- if (!raw && hasTypeParameters ) {
520- // generic patterns are always not compatible match
521- return ERASURE_MATCH ;
482+ return resolveLevelForTypeBindingWithTypeArguments (typeBinding , node , newLevel , locator );
483+ }
484+ return newLevel ;
485+ }
486+
487+ private int resolveLevelForTypeBindingWithTypeArguments (ITypeBinding typeBinding , ASTNode node , int newLevel ,
488+ MatchLocator locator2 ) {
489+ boolean patternHasTypeParameters = this .locator .pattern .hasTypeParameters ();
490+ char [][][] patternTypeArgArray = this .locator .pattern .getTypeArguments ();
491+ int patternTypeArgsLength = patternTypeArgArray == null ? -1 :
492+ patternTypeArgArray [0 ] == null ? -1 :
493+ patternTypeArgArray [0 ].length == 0 ? -1 : patternTypeArgArray [0 ].length ;
494+ boolean bindingIsRaw = typeBinding .isRawType ();
495+ boolean bindingIsGeneric = typeBinding .isGenericType ();
496+ boolean bindingIsParameterized = typeBinding .isParameterizedType ();
497+ int patternRule = this .locator .pattern .getMatchRule ();
498+ boolean patternIsErasureMatch = (patternRule & SearchPattern .R_ERASURE_MATCH ) == SearchPattern .R_ERASURE_MATCH ;
499+ boolean patternIsEquivMatch = (patternRule & SearchPattern .R_EQUIVALENT_MATCH ) == SearchPattern .R_EQUIVALENT_MATCH ;
500+
501+ ITypeBinding [] bindingArgs = typeBinding .getTypeArguments ();
502+ ITypeBinding [] bindingParams = typeBinding .getTypeParameters ();
503+ int bindingTypeArgsLength = bindingArgs == null ? -1 : bindingArgs .length ;
504+ // Compare arguments lengths
505+ if (patternTypeArgsLength == bindingTypeArgsLength ) {
506+ if (!bindingIsRaw && patternHasTypeParameters ) {
507+ // generic patterns are always not compatible match
508+ return ERASURE_MATCH ;
509+ }
510+ } else {
511+ if (patternTypeArgsLength ==0 ) {
512+ if (!bindingIsRaw || patternHasTypeParameters ) {
513+ return newLevel ;
522514 }
523- } else {
524- if (patternTypeArgsLength ==0 ) {
525- if (!match .isRaw () || hasTypeParameters ) {
526- return matchRule ;
527- }
528- } else if (typeArgumentsLength ==0 ) {
529- // raw binding is always compatible
530- return matchRule ;
531- } else {
532- return IMPOSSIBLE_MATCH ;
515+ } else if (bindingTypeArgsLength ==0 ) {
516+ // If this is an import, we have to treat it differently
517+
518+ // pattern looking for args but binding has none.
519+ // ITypeBinding decl = typeBinding.getTypeDeclaration();
520+ // ITypeBinding[] declArgs = decl.getTypeArguments();
521+ // ITypeBinding[] declParams = decl.getTypeParameters();
522+ // raw binding is always compatible
523+ if ( !patternIsEquivMatch )
524+ return newLevel ;
525+ }
526+ }
527+ return IMPOSSIBLE_MATCH ;
528+ }
529+ private int resolveLevelForTypeBindingDeclarationOfReferencedTypes (ITypeBinding typeBinding , ASTNode node , int newLevel , MatchLocator locator ) {
530+ IJavaElement enclosing = ((DeclarationOfReferencedTypesPattern )this .locator .pattern ).enclosingElement ;
531+ // We don't add this node. We manually add the declaration
532+ ITypeBinding t2 = typeBinding .getTypeDeclaration ();
533+ IJavaElement je = t2 == null ? null : t2 .getJavaElement ();
534+ if ( je != null && !this .foundElements .contains (je ) && DOMASTNodeUtils .isWithinRange (node , enclosing )) {
535+ ISourceReference sr = je instanceof ISourceReference ? (ISourceReference )je : null ;
536+ IResource r = null ;
537+ ISourceRange srg = null ;
538+ ISourceRange nameRange = null ;
539+ try {
540+ srg = sr .getSourceRange ();
541+ nameRange = sr .getNameRange ();
542+ IJavaElement ancestor = je .getAncestor (IJavaElement .COMPILATION_UNIT );
543+ r = ancestor == null ? null : ancestor .getCorrespondingResource ();
544+ } catch (JavaModelException jme ) {
545+ // ignore
546+ }
547+ ISourceRange rangeToUse = (nameRange == null ) ? srg : nameRange ;
548+ if ( rangeToUse != null ) {
549+ TypeDeclarationMatch tdm = new TypeDeclarationMatch (je , newLevel ,
550+ rangeToUse .getOffset (), rangeToUse .getLength (),
551+ locator .getParticipant (), r );
552+ try {
553+ this .foundElements .add (je );
554+ locator .report (tdm );
555+ } catch (CoreException ce ) {
556+ // ignore
533557 }
534558 }
535559 }
536- return newLevel ;
560+ return IMPOSSIBLE_MATCH ;
537561 }
538-
539562 private org .eclipse .jdt .core .dom .CompilationUnit findCU (org .eclipse .jdt .core .dom .ASTNode node ) {
540563 if ( node == null )
541564 return null ;
0 commit comments