Skip to content

Commit

Permalink
Fix testTypeReference26
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Nov 26, 2024
1 parent 58d514c commit 8215c7e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
}
if (fieldAccess.getExpression() instanceof JCIdent qualifier) {
Name qualifierName = convertName(qualifier.getName());
commonSettings(qualifierName, qualifier);
SimpleName qualifiedName = (SimpleName)convertName(fieldAccess.getIdentifier());
if (qualifiedName == null) {
// when there are syntax errors where the statement is not completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ protected int resolveLevelForTypeSourceName(char[] qualifiedPattern, char[] sour
}
break;
default:
if( type.isLocal() ) {
if( type != null && type.isLocal() ) {
if (CharOperation.prefixEquals(qualifiedPattern, sourceName, this.isCaseSensitive)) {
return ACCURATE_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core.search.matching;

import static org.eclipse.jdt.internal.core.search.matching.DOMASTNodeUtils.insideDocComment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -1025,6 +1027,29 @@ private boolean hasPackageDeclarationAncestor(org.eclipse.jdt.core.dom.ASTNode n
@Override
public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) {
if (binding == null) {
if( node instanceof SimpleName sn) {
int accuracy = resolveLevelForSimpleName(node, sn.getIdentifier());
if( accuracy != -1 ) {
// Add directly
IResource r = null;
IJavaElement enclosing = DOMASTNodeUtils.getEnclosingJavaElement(node);
IJavaElement ancestor = enclosing == null ? null : enclosing.getAncestor(IJavaElement.COMPILATION_UNIT);
try {
r = ancestor == null ? null : ancestor.getCorrespondingResource();
} catch(JavaModelException jme) {
// ignore
}

TypeReferenceMatch typeMatch = new TypeReferenceMatch(enclosing, accuracy, node.getStartPosition(), node.getLength(), insideDocComment(node), locator.getParticipant(), r);
try {
locator.report(typeMatch);
} catch(CoreException ce) {
// ignore
}
// Then return not possible so it doesn't get added again
return IMPOSSIBLE_MATCH;
}
}
return INACCURATE_MATCH;
}
if (binding instanceof ITypeBinding typeBinding) {
Expand All @@ -1049,30 +1074,40 @@ public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding,
return IMPOSSIBLE_MATCH;
}

/*
* Returns a match flag OR -1 if it cannot determine at all.
*/
private int resolveLevelForSimpleName(org.eclipse.jdt.core.dom.ASTNode node, String simpleNameNeedle) {
if( !simpleNameNeedle.contains(".") && this.pattern.qualification != null && this.pattern.qualification.length > 0 ) { //$NON-NLS-1$
// we need to find out if we import this thing at all
org.eclipse.jdt.core.dom.CompilationUnit cu = findCU(node);
List imports = cu.imports();
for( Object id : imports) {
ImportDeclaration idd = (ImportDeclaration)id;
if( idd.getName() instanceof QualifiedName qn) {
if( qn.getName().toString().equals(simpleNameNeedle)) {
char[] qualifiedPattern = getQualifiedPattern(this.pattern.simpleName, this.pattern.qualification);
// we were imported as qualified name...
int level3 = resolveLevelForTypeSourceName(qualifiedPattern, qn.toString().toCharArray(), null);
if( level3 == ACCURATE_MATCH ) {
return INACCURATE_MATCH;
}
return INACCURATE_MATCH;
}
}
}
}
return -1;
}

private int resolveLevelForTypeBinding(org.eclipse.jdt.core.dom.ASTNode node, ITypeBinding typeBinding,
MatchLocator locator) {
int newLevel = resolveLevelForType(this.pattern.simpleName, this.pattern.qualification, typeBinding);
if( newLevel == IMPOSSIBLE_MATCH ) {
String qualNameFromBinding = typeBinding.getQualifiedName();
if( !qualNameFromBinding.contains(".") && this.pattern.qualification != null && this.pattern.qualification.length > 0 ) { //$NON-NLS-1$
// we need to find out if we import this thing at all
org.eclipse.jdt.core.dom.CompilationUnit cu = findCU(node);
List imports = cu.imports();
for( Object id : imports) {
ImportDeclaration idd = (ImportDeclaration)id;
if( idd.getName() instanceof QualifiedName qn) {
if( qn.getName().toString().equals(qualNameFromBinding)) {
char[] qualifiedPattern = getQualifiedPattern(this.pattern.simpleName, this.pattern.qualification);
// we were imported as qualified name...
int level3 = resolveLevelForTypeSourceName(qualifiedPattern, qn.toString().toCharArray(), typeBinding);
if( level3 == ACCURATE_MATCH ) {
return INACCURATE_MATCH;
}
return INACCURATE_MATCH;
}
}

}
int simpleNameMatch = resolveLevelForSimpleName(node, qualNameFromBinding);
if( simpleNameMatch != -1 ) {
return simpleNameMatch;
}
}
if( this.isDeclarationOfReferencedTypesPattern) {
Expand Down

0 comments on commit 8215c7e

Please sign in to comment.