diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 3986ed6d291..06815dfc951 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -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. diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java index db71b70ada6..4d3bad42102 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java @@ -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; } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java index 7dbfc7b1fd4..992a9587a6b 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java @@ -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; @@ -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) { @@ -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) {