Skip to content

Commit 420921e

Browse files
committed
Fix testBug221081 and others
Signed-off-by: Rob Stryker <[email protected]>
1 parent 7916ee2 commit 420921e

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -854,23 +854,6 @@ public void scan(JCTree tree) {
854854
javac.genEndPos = false;
855855
javac.lineDebugInfo = false;
856856
}
857-
boolean forceProblemDetection = (flags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0;
858-
boolean forceBindingRecovery = (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
859-
var aptPath = fileManager.getLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH);
860-
boolean aptPathForceAnalyze = (aptPath != null && aptPath.iterator().hasNext());
861-
if (forceProblemDetection || forceBindingRecovery || aptPathForceAnalyze ) {
862-
// Let's run analyze until it finishes without error
863-
Throwable caught = null;
864-
do {
865-
caught = null;
866-
try {
867-
task.analyze();
868-
} catch (Throwable t) {
869-
caught = t;
870-
ILog.get().error("Error while analyzing", t);
871-
}
872-
} while(caught != null);
873-
}
874857

875858
Throwable cachedThrown = null;
876859

@@ -999,6 +982,26 @@ public void postVisit(ASTNode node) {
999982
ILog.get().error(thrown.getMessage(), thrown);
1000983
}
1001984
}
985+
986+
boolean forceProblemDetection = (flags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0;
987+
boolean forceBindingRecovery = (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
988+
var aptPath = fileManager.getLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH);
989+
boolean aptPathForceAnalyze = (aptPath != null && aptPath.iterator().hasNext());
990+
if (forceProblemDetection || forceBindingRecovery || aptPathForceAnalyze ) {
991+
// Let's run analyze until it finishes without error
992+
Throwable caught = null;
993+
do {
994+
caught = null;
995+
try {
996+
task.analyze();
997+
} catch (Throwable t) {
998+
caught = t;
999+
ILog.get().error("Error while analyzing", t);
1000+
}
1001+
} while(caught != null);
1002+
}
1003+
1004+
10021005
if (!resolveBindings) {
10031006
destroy(context);
10041007
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ public LocatorResponse match(Name name, NodeSetWrapper nodeSet, MatchLocator loc
114114
if (this.fieldLocator.pattern.fineGrain != 0 ? matchesFineGrain(name) :
115115
((this.fieldLocator.pattern.readAccess && DOMLocalVariableLocator.isRead(name))
116116
|| (this.fieldLocator.pattern.writeAccess && DOMLocalVariableLocator.isWrite(name)))) {
117-
int level = nodeSet.addMatch(name, getPossibleOrAccurateViaMustResolve());
118-
if( level != IMPOSSIBLE_MATCH ) {
117+
int possibleOrAccurate = getPossibleOrAccurateViaMustResolve();
118+
if( possibleOrAccurate != IMPOSSIBLE_MATCH ) {
119119
IBinding b = name.resolveBinding();
120+
if( b != null && b instanceof IVariableBinding vb) {
121+
if( !vb.isField() && !vb.isRecordComponent()) {
122+
return toResponse(IMPOSSIBLE_MATCH);
123+
}
124+
}
120125
if( b == null ) {
121126
if( name instanceof SimpleName sn && name.getParent() instanceof QualifiedName qn && sn == qn.getQualifier()) {
122127
boolean shadowed = methodHasShadowedVariable(name);
@@ -125,7 +130,7 @@ public LocatorResponse match(Name name, NodeSetWrapper nodeSet, MatchLocator loc
125130
}
126131
}
127132
}
128-
return toResponse(level, true);
133+
return toResponse(possibleOrAccurate, true);
129134
}
130135
return toResponse(IMPOSSIBLE_MATCH);
131136
}

0 commit comments

Comments
 (0)