2727import org .eclipse .core .runtime .ILog ;
2828import org .eclipse .jdt .core .IJavaProject ;
2929import org .eclipse .jdt .core .WorkingCopyOwner ;
30- import org .eclipse .jdt .internal .codeassist .DOMCompletionUtil ;
3130import org .eclipse .jdt .internal .javac .dom .JavacAnnotationBinding ;
3231import org .eclipse .jdt .internal .javac .dom .JavacErrorMethodBinding ;
3332import org .eclipse .jdt .internal .javac .dom .JavacErrorTypeBinding ;
@@ -342,11 +341,11 @@ public JavacTypeVariableBinding getTypeVariableBinding(TypeVar typeVar) {
342341 }
343342 //
344343 private Map <String , JavacVariableBinding > variableBindings = new HashMap <>();
345- public JavacVariableBinding getVariableBinding (VarSymbol varSymbol , boolean isUnique ) {
344+ public JavacVariableBinding getVariableBinding (VarSymbol varSymbol ) {
346345 if (varSymbol == null ) {
347346 return null ;
348347 }
349- JavacVariableBinding newInstance = new JavacVariableBinding (varSymbol , JavacBindingResolver .this , isUnique ) { };
348+ JavacVariableBinding newInstance = new JavacVariableBinding (varSymbol , JavacBindingResolver .this ) { };
350349 String k = newInstance .getKey ();
351350 if ( k != null ) {
352351 variableBindings .putIfAbsent (k , newInstance );
@@ -397,15 +396,7 @@ public IBinding getBinding(final Symbol owner, final com.sun.tools.javac.code.Ty
397396 return getMethodBinding (methodType , other , null , false );
398397 }
399398 } else if (owner instanceof final VarSymbol other ) {
400- if (JavacBindingResolver .this .symbolToDeclaration != null ) {
401- ASTNode ownerDecl = JavacBindingResolver .this .symbolToDeclaration .get (owner .owner );
402- MethodDeclaration methodDecl = (MethodDeclaration ) DOMCompletionUtil .findParent (ownerDecl , new int [] { ASTNode .METHOD_DECLARATION });
403- if (methodDecl != null ) {
404- boolean isUnique = calculateIsUnique (methodDecl , other .name .toString ());
405- return getVariableBinding (other , isUnique );
406- }
407- return getVariableBinding (other , true );
408- }
399+ return getVariableBinding (other );
409400 }
410401 return null ;
411402 }
@@ -776,7 +767,7 @@ IVariableBinding resolveField(FieldAccess fieldAccess) {
776767 resolve ();
777768 JCTree javacElement = this .converter .domToJavac .get (fieldAccess );
778769 if (javacElement instanceof JCFieldAccess javacFieldAccess && javacFieldAccess .sym instanceof VarSymbol varSymbol ) {
779- return this .bindings .getVariableBinding (varSymbol , true );
770+ return this .bindings .getVariableBinding (varSymbol );
780771 }
781772 return null ;
782773 }
@@ -786,7 +777,7 @@ IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
786777 resolve ();
787778 JCTree javacElement = this .converter .domToJavac .get (fieldAccess );
788779 if (javacElement instanceof JCFieldAccess javacFieldAccess && javacFieldAccess .sym instanceof VarSymbol varSymbol ) {
789- return this .bindings .getVariableBinding (varSymbol , true );
780+ return this .bindings .getVariableBinding (varSymbol );
790781 }
791782 return null ;
792783 }
@@ -1253,7 +1244,7 @@ IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
12531244 if (this .converter .domToJavac .get (enumConstant ) instanceof JCVariableDecl decl ) {
12541245 // the decl.type can be null when there are syntax errors
12551246 if ((decl .type != null && !decl .type .isErroneous ()) || this .isRecoveringBindings ()) {
1256- return this .bindings .getVariableBinding (decl .sym , true );
1247+ return this .bindings .getVariableBinding (decl .sym );
12571248 }
12581249 }
12591250 return null ;
@@ -1262,69 +1253,17 @@ IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
12621253 @ Override
12631254 IVariableBinding resolveVariable (VariableDeclaration variable ) {
12641255 resolve ();
1265- boolean isUnique = calculateIsUnique (variable );
12661256 if (this .converter .domToJavac .get (variable ) instanceof JCVariableDecl decl ) {
12671257 // the decl.type can be null when there are syntax errors
12681258 if ((decl .type != null && !decl .type .isErroneous ()) || this .isRecoveringBindings ()) {
12691259 if (decl .name != Names .instance (this .context ).error ) { // cannot recover if name is error
1270- return this .bindings .getVariableBinding (decl .sym , isUnique );
1260+ return this .bindings .getVariableBinding (decl .sym );
12711261 }
12721262 }
12731263 }
12741264 return null ;
12751265 }
12761266
1277- public static boolean calculateIsUnique (VariableDeclaration variable ) {
1278- MethodDeclaration parentMethod = (MethodDeclaration )DOMCompletionUtil .findParent (variable , new int [] { ASTNode .METHOD_DECLARATION });
1279- if (parentMethod == null ) {
1280- return true ;
1281- }
1282- final String variableName = variable .getName ().toString ();
1283- class UniquenessVisitor extends ASTVisitor {
1284- boolean isUnique = true ;
1285- @ Override
1286- public boolean visit (VariableDeclarationFragment node ) {
1287- if (node != variable && variableName .equals (node .getName ().toString ())) {
1288- isUnique = false ;
1289- }
1290- return super .visit (node );
1291- }
1292- @ Override
1293- public boolean visit (SingleVariableDeclaration node ) {
1294- if (node != variable && variableName .equals (node .getName ().toString ())) {
1295- isUnique = false ;
1296- }
1297- return super .visit (node );
1298- }
1299- }
1300- UniquenessVisitor uniquenessVisitor = new UniquenessVisitor ();
1301- parentMethod .accept (uniquenessVisitor );
1302- return uniquenessVisitor .isUnique ;
1303- }
1304-
1305- public static boolean calculateIsUnique (MethodDeclaration methodDecl , String name ) {
1306- class UniquenessVisitor extends ASTVisitor {
1307- int count = 0 ;
1308- @ Override
1309- public boolean visit (VariableDeclarationFragment node ) {
1310- if (name .equals (node .getName ().toString ())) {
1311- this .count ++;
1312- }
1313- return super .visit (node );
1314- }
1315- @ Override
1316- public boolean visit (SingleVariableDeclaration node ) {
1317- if (name .equals (node .getName ().toString ())) {
1318- this .count ++;
1319- }
1320- return super .visit (node );
1321- }
1322- }
1323- UniquenessVisitor uniquenessVisitor = new UniquenessVisitor ();
1324- methodDecl .accept (uniquenessVisitor );
1325- return uniquenessVisitor .count <= 1 ;
1326- }
1327-
13281267 @ Override
13291268 public IPackageBinding resolvePackage (PackageDeclaration decl ) {
13301269 resolve ();
@@ -1571,7 +1510,7 @@ public Object getValueFromAttribute(Attribute attribute) {
15711510 } else if (attribute instanceof Attribute .Class clazz ) {
15721511 return this .bindings .getTypeBinding (clazz .classType );
15731512 } else if (attribute instanceof Attribute .Enum enumm ) {
1574- return this .bindings .getVariableBinding (enumm .value , true );
1513+ return this .bindings .getVariableBinding (enumm .value );
15751514 } else if (attribute instanceof Attribute .Array array ) {
15761515 return Stream .of (array .values ) //
15771516 .map (nestedAttr -> {
@@ -1580,11 +1519,10 @@ public Object getValueFromAttribute(Attribute attribute) {
15801519 } else if (nestedAttr instanceof Attribute .Class clazz ) {
15811520 return this .bindings .getTypeBinding (clazz .classType );
15821521 } else if (nestedAttr instanceof Attribute .Enum enumerable ) {
1583- return this .bindings .getVariableBinding (enumerable .value , true );
1522+ return this .bindings .getVariableBinding (enumerable .value );
15841523 }
15851524 throw new IllegalArgumentException ("Unexpected attribute type: " + nestedAttr .getClass ().getCanonicalName ());
1586- }) //
1587- .toArray (Object []::new );
1525+ }).toArray (Object []::new );
15881526 }
15891527 throw new IllegalArgumentException ("Unexpected attribute type: " + attribute .getClass ().getCanonicalName ());
15901528 }
0 commit comments