Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 162376 Details for
Bug 306078
Navigate to Inaccessible Field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression test
patch_306078.txt (text/plain), 13.03 KB, created by
Olivier Thomann
on 2010-03-17 22:18:09 EDT
(
hide
)
Description:
Proposed fix + regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-03-17 22:18:09 EDT
Size:
13.03 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java,v >retrieving revision 1.156 >diff -u -r1.156 SelectionEngine.java >--- codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 7 Jan 2010 20:18:50 -0000 1.156 >+++ codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 18 Mar 2010 02:17:19 -0000 >@@ -1096,126 +1096,139 @@ > this.actualSelectionEnd); > } > this.acceptedAnswer = true; >- } else >- if (binding instanceof MethodBinding) { >- MethodBinding methodBinding = (MethodBinding) binding; >- this.noProposal = false; >+ } else if (binding instanceof MethodBinding) { >+ MethodBinding methodBinding = (MethodBinding) binding; >+ this.noProposal = false; > >- boolean isValuesOrValueOf = false; >- if(binding instanceof SyntheticMethodBinding) { >- SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding; >- if(syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues >- || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) { >- isValuesOrValueOf = true; >- } >+ boolean isValuesOrValueOf = false; >+ if(binding instanceof SyntheticMethodBinding) { >+ SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding; >+ if(syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues >+ || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) { >+ isValuesOrValueOf = true; > } >+ } > >- if(!isValuesOrValueOf && !methodBinding.isSynthetic()) { >- TypeBinding[] parameterTypes = methodBinding.original().parameters; >- int length = parameterTypes.length; >- char[][] parameterPackageNames = new char[length][]; >- char[][] parameterTypeNames = new char[length][]; >- String[] parameterSignatures = new String[length]; >- for (int i = 0; i < length; i++) { >- parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName(); >- parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName(); >- parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.'); >+ if(!isValuesOrValueOf && !methodBinding.isSynthetic()) { >+ TypeBinding[] parameterTypes = methodBinding.original().parameters; >+ int length = parameterTypes.length; >+ char[][] parameterPackageNames = new char[length][]; >+ char[][] parameterTypeNames = new char[length][]; >+ String[] parameterSignatures = new String[length]; >+ for (int i = 0; i < length; i++) { >+ parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName(); >+ parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName(); >+ parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.'); >+ } >+ >+ TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables; >+ length = typeVariables == null ? 0 : typeVariables.length; >+ char[][] typeParameterNames = new char[length][]; >+ char[][][] typeParameterBoundNames = new char[length][][]; >+ for (int i = 0; i < length; i++) { >+ TypeVariableBinding typeVariable = typeVariables[i]; >+ typeParameterNames[i] = typeVariable.sourceName; >+ if (typeVariable.firstBound == null) { >+ typeParameterBoundNames[i] = new char[0][]; >+ } else if (typeVariable.firstBound == typeVariable.superclass) { >+ int boundCount = 1 + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length); >+ typeParameterBoundNames[i] = new char[boundCount][]; >+ typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName; >+ for (int j = 1; j < boundCount; j++) { >+ typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName; >+ } >+ } else { >+ int boundCount = typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length; >+ typeParameterBoundNames[i] = new char[boundCount][]; >+ for (int j = 0; j < boundCount; j++) { >+ typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName; >+ } > } >+ } > >- TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables; >- length = typeVariables == null ? 0 : typeVariables.length; >- char[][] typeParameterNames = new char[length][]; >- char[][][] typeParameterBoundNames = new char[length][][]; >- for (int i = 0; i < length; i++) { >- TypeVariableBinding typeVariable = typeVariables[i]; >- typeParameterNames[i] = typeVariable.sourceName; >- if (typeVariable.firstBound == null) { >- typeParameterBoundNames[i] = new char[0][]; >- } else if (typeVariable.firstBound == typeVariable.superclass) { >- int boundCount = 1 + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length); >- typeParameterBoundNames[i] = new char[boundCount][]; >- typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName; >- for (int j = 1; j < boundCount; j++) { >- typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName; >- } >+ ReferenceBinding declaringClass = methodBinding.declaringClass; >+ if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { >+ ((SelectionRequestor)this.requestor).acceptLocalMethod(methodBinding); >+ } else { >+ this.requestor.acceptMethod( >+ declaringClass.qualifiedPackageName(), >+ declaringClass.qualifiedSourceName(), >+ declaringClass.enclosingType() == null ? null : new String(getSignature(declaringClass.enclosingType())), >+ methodBinding.isConstructor() >+ ? declaringClass.sourceName() >+ : methodBinding.selector, >+ parameterPackageNames, >+ parameterTypeNames, >+ parameterSignatures, >+ typeParameterNames, >+ typeParameterBoundNames, >+ methodBinding.isConstructor(), >+ isDeclaration, >+ methodBinding.computeUniqueKey(), >+ this.actualSelectionStart, >+ this.actualSelectionEnd); >+ } >+ } >+ this.acceptedAnswer = true; >+ } else if (binding instanceof FieldBinding) { >+ FieldBinding fieldBinding = (FieldBinding) binding; >+ ReferenceBinding declaringClass = fieldBinding.declaringClass; >+ if (declaringClass != null) { // arraylength >+ this.noProposal = false; >+ if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { >+ ((SelectionRequestor)this.requestor).acceptLocalField(fieldBinding); >+ } else { >+ // if the binding is a problem field binding, we want to make sure >+ // we can retrieve the closestMatch if the problem reason is NotVisible >+ FieldBinding currentFieldBinding = fieldBinding; >+ while (currentFieldBinding instanceof ProblemFieldBinding) { >+ ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) currentFieldBinding; >+ if (problemFieldBinding.problemId() == ProblemReasons.NotVisible) { >+ currentFieldBinding = problemFieldBinding.closestMatch; > } else { >- int boundCount = typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length; >- typeParameterBoundNames[i] = new char[boundCount][]; >- for (int j = 0; j < boundCount; j++) { >- typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName; >- } >+ currentFieldBinding = null; > } > } >- >- ReferenceBinding declaringClass = methodBinding.declaringClass; >- if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { >- ((SelectionRequestor)this.requestor).acceptLocalMethod(methodBinding); >+ char[] fieldName = null; >+ char[] key = null; >+ if (currentFieldBinding != null) { >+ fieldName = currentFieldBinding.name; >+ key = currentFieldBinding.computeUniqueKey(); > } else { >- this.requestor.acceptMethod( >- declaringClass.qualifiedPackageName(), >- declaringClass.qualifiedSourceName(), >- declaringClass.enclosingType() == null ? null : new String(getSignature(declaringClass.enclosingType())), >- methodBinding.isConstructor() >- ? declaringClass.sourceName() >- : methodBinding.selector, >- parameterPackageNames, >- parameterTypeNames, >- parameterSignatures, >- typeParameterNames, >- typeParameterBoundNames, >- methodBinding.isConstructor(), >- isDeclaration, >- methodBinding.computeUniqueKey(), >- this.actualSelectionStart, >- this.actualSelectionEnd); >+ fieldName = fieldBinding.name; >+ key = fieldBinding.computeUniqueKey(); > } >+ this.requestor.acceptField( >+ declaringClass.qualifiedPackageName(), >+ declaringClass.qualifiedSourceName(), >+ fieldName, >+ false, >+ key, >+ this.actualSelectionStart, >+ this.actualSelectionEnd); > } > this.acceptedAnswer = true; >- } else >- if (binding instanceof FieldBinding) { >- FieldBinding fieldBinding = (FieldBinding) binding; >- ReferenceBinding declaringClass = fieldBinding.declaringClass; >- if (declaringClass != null) { // arraylength >- this.noProposal = false; >- if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { >- ((SelectionRequestor)this.requestor).acceptLocalField(fieldBinding); >- } else { >- this.requestor.acceptField( >- declaringClass.qualifiedPackageName(), >- declaringClass.qualifiedSourceName(), >- fieldBinding.name, >- false, >- fieldBinding.computeUniqueKey(), >- this.actualSelectionStart, >- this.actualSelectionEnd); >- } >- this.acceptedAnswer = true; >- } >- } else >- if (binding instanceof LocalVariableBinding) { >- if (this.requestor instanceof SelectionRequestor) { >- ((SelectionRequestor)this.requestor).acceptLocalVariable((LocalVariableBinding)binding); >- this.acceptedAnswer = true; >- } else { >- // open on the type of the variable >- selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false); >- } >- } else >- if (binding instanceof ArrayBinding) { >- selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false); >- // open on the type of the array >- } else >- if (binding instanceof PackageBinding) { >- PackageBinding packageBinding = (PackageBinding) binding; >- this.noProposal = false; >- this.requestor.acceptPackage(packageBinding.readableName()); >- this.acceptedAnswer = true; >- } else >- if(binding instanceof BaseTypeBinding) { >- this.acceptedAnswer = true; >- } >+ } >+ } else if (binding instanceof LocalVariableBinding) { >+ if (this.requestor instanceof SelectionRequestor) { >+ ((SelectionRequestor)this.requestor).acceptLocalVariable((LocalVariableBinding)binding); >+ this.acceptedAnswer = true; >+ } else { >+ // open on the type of the variable >+ selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false); >+ } >+ } else if (binding instanceof ArrayBinding) { >+ selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false); >+ // open on the type of the array >+ } else if (binding instanceof PackageBinding) { >+ PackageBinding packageBinding = (PackageBinding) binding; >+ this.noProposal = false; >+ this.requestor.acceptPackage(packageBinding.readableName()); >+ this.acceptedAnswer = true; >+ } else if(binding instanceof BaseTypeBinding) { >+ this.acceptedAnswer = true; >+ } > } >- > /* > * Checks if a local declaration got selected in this method/initializer/field. > */ >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/ResolveTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java,v >retrieving revision 1.91 >diff -u -r1.91 ResolveTests.java >--- src/org/eclipse/jdt/core/tests/model/ResolveTests.java 8 Mar 2010 16:08:49 -0000 1.91 >+++ src/org/eclipse/jdt/core/tests/model/ResolveTests.java 18 Mar 2010 02:17:21 -0000 >@@ -2587,5 +2587,25 @@ > elements > ); > } >+public void test306078() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[2]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Resolve/src/A.java", >+ "public class A { private static final int X = 0; }"); > >+ this.workingCopies[1] = getWorkingCopy( >+ "/Resolve/src/B.java", >+ "public class B { int x = A.X; }"); >+ >+ String str = this.workingCopies[1].getSource(); >+ int start = str.lastIndexOf("X"); >+ int length = "X".length(); >+ IJavaElement[] elements = this.workingCopies[1].codeSelect(start, length, this.wcOwner); >+ >+ assertElementsEqual( >+ "Unexpected elements", >+ "X [in A [in [Working copy] A.java [in <default> [in src [in Resolve]]]]]", >+ elements >+ ); >+} > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 306078
: 162376