Skip to content

Commit 8df4aec

Browse files
committed
Filter reported matches
+ improve rule for generic methods
1 parent 0f4407f commit 8df4aec

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/core/search/matching/DOMMethodLocator.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ private int matchMethodTypeArguments(ASTNode node, IMethodBinding method,
410410
boolean isErasurePattern = isPatternErasureMatch();
411411
boolean isEquivPattern = isPatternEquivalentMatch();
412412
boolean methodIsRaw = method.isRawMethod();
413-
ITypeBinding[] argBindings = method.getTypeArguments();
413+
ITypeBinding[] argBindings = node instanceof MethodDeclaration ?
414+
method.getTypeParameters() :
415+
method.getTypeArguments();
414416
char[][] goal = this.locator.pattern.methodArguments;
415417

416418
if( goal.length > 0 && methodIsRaw && isExactPattern) {
@@ -467,11 +469,14 @@ private int matchMethodTypeArguments(ASTNode node, IMethodBinding method,
467469
for( int i = 0; i < argBindings.length; i++ ) {
468470
// Compare each
469471
String goaliString = new String(goal[i]);
470-
IBinding patternBinding = findPossiblyUnresolvedBindingForType(node, goaliString);
471-
if( argBindings[i].isTypeVariable() && patternBinding == null ) {
472+
ITypeBinding patternBinding = findPossiblyUnresolvedBindingForType(node, goaliString);
473+
ITypeBinding argBinding = argBindings[i];
474+
if(argBinding.isTypeVariable() && patternBinding == null ) {
472475
continue;
473476
}
474-
boolean match = TypeArgumentMatchingUtility.validateSingleTypeArgMatches(isExactPattern, goaliString, patternBinding, argBindings[i]);
477+
boolean match =
478+
TypeArgumentMatchingUtility.validateSingleTypeArgMatches(isExactPattern, goaliString, patternBinding, argBindings[i])
479+
| (bindingIsDeclaration && patternBinding != null && patternBinding.isCastCompatible(argBinding));
475480
if( !match ) {
476481
if( isExactPattern || (!isErasurePattern && !isEquivPattern)) {
477482
return IMPOSSIBLE_MATCH;
@@ -662,8 +667,7 @@ protected int resolveLevelForNodeWithMethodBinding(ASTNode messageSend,
662667
int declarationLevel = IMPOSSIBLE_MATCH;
663668
if (invocationLevel == IMPOSSIBLE_MATCH) {
664669
declarationBinding = invocationBinding.getMethodDeclaration();
665-
if (invocationBinding != declarationBinding)
666-
declarationLevel = matchMethod(messageSend, declarationBinding, skipVerif, true);
670+
declarationLevel = matchMethod(messageSend, declarationBinding, skipVerif, true);
667671
if (declarationLevel == IMPOSSIBLE_MATCH)
668672
return IMPOSSIBLE_MATCH;
669673
invocationOrDeclarationBinding = declarationBinding;
@@ -1111,6 +1115,17 @@ private IMethodBinding getMethodBindingFromPattern(AST context) {
11111115
*/
11121116
@Override
11131117
public void reportSearchMatch(MatchLocator locator, ASTNode node, SearchMatch match) throws CoreException {
1118+
if (!(node instanceof MethodDeclaration)
1119+
&& !(node instanceof AnnotationTypeMemberDeclaration)
1120+
&& DOMASTNodeUtils.getBinding(node) instanceof IMethodBinding methodBinding
1121+
&& (methodBinding.isGenericMethod() || methodBinding.isParameterizedMethod())
1122+
&& pattern.focus instanceof IMethod method
1123+
&& !pattern.hasMethodArguments()) {
1124+
int rule = match.getRule();
1125+
rule &= ~SearchPattern.R_FULL_MATCH;
1126+
rule |= SearchPattern.R_EQUIVALENT_MATCH | SearchPattern.R_ERASURE_MATCH;
1127+
match.setRule(rule);
1128+
}
11141129
if( preferParamaterizedNode() ) {
11151130
if( node instanceof MethodInvocation iv) {
11161131
List<?> l = iv.typeArguments();

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/core/search/matching/SearchMatchingUtility.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
public class SearchMatchingUtility {
2020
public static void reportSearchMatch(MatchLocator locator, SearchMatch match) throws CoreException {
21-
locator.report(match);
21+
if ((match.getRule() & locator.pattern.getMatchRule()) != 0) {
22+
locator.report(match);
23+
}
2224
}
2325
}

0 commit comments

Comments
 (0)