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 203277 Details for
Bug 357471
ASTParser cannot resolve binding of PackageDeclaration if class name is equal to the first segment of the package name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch v1
patch_357471.txt (text/plain), 6.38 KB, created by
Olivier Thomann
on 2011-09-13 14:13:34 EDT
(
hide
)
Description:
Patch v1
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2011-09-13 14:13:34 EDT
Size:
6.38 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v >retrieving revision 1.382 >diff -u -r1.382 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 28 Jul 2011 17:07:22 -0000 1.382 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 13 Sep 2011 16:11:26 -0000 >@@ -2389,6 +2389,40 @@ > return new ProblemReferenceBinding(compoundName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); > } > >+ /* Answer the package from the compoundName or null if it begins with a type. >+ * Intended to be used while resolving a package name only. >+ * >+ * Internal use only >+ */ >+ public final Binding getOnlyPackage(char[][] compoundName) { >+ compilationUnitScope().recordQualifiedReference(compoundName); >+ Binding binding = getTypeOrPackage(compoundName[0], Binding.PACKAGE, true); >+ if (binding == null || !binding.isValidBinding()) { >+ char[][] qName = new char[][] { compoundName[0] }; >+ return new ProblemReferenceBinding(qName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); >+ } >+ if (!(binding instanceof PackageBinding)) { >+ return null; // compoundName does not start with a package >+ } >+ >+ int currentIndex = 1, length = compoundName.length; >+ PackageBinding packageBinding = (PackageBinding) binding; >+ while (currentIndex < length) { >+ binding = packageBinding.getPackage(compoundName[currentIndex++]); >+ if (binding == null) { >+ return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null /* no closest match since search for pkg*/, ProblemReasons.NotFound); >+ } >+ if (!binding.isValidBinding()) { >+ return new ProblemReferenceBinding( >+ CharOperation.subarray(compoundName, 0, currentIndex), >+ binding instanceof ReferenceBinding ? (ReferenceBinding)((ReferenceBinding)binding).closestMatch() : null, >+ binding.problemId()); >+ } >+ packageBinding = (PackageBinding) binding; >+ } >+ return packageBinding; >+ } >+ > /* Answer the type binding that corresponds the given name, starting the lookup in the receiver. > * The name provided is a simple source name (e.g., "Object" , "Point", ...) > */ >Index: dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v >retrieving revision 1.176 >diff -u -r1.176 DefaultBindingResolver.java >--- dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 28 Jul 2011 17:07:34 -0000 1.176 >+++ dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 13 Sep 2011 16:11:27 -0000 >@@ -1384,7 +1384,7 @@ > org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg); > if (node instanceof ImportReference) { > ImportReference importReference = (ImportReference) node; >- Binding binding = this.scope.getTypeOrPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length)); >+ Binding binding = this.scope.getOnlyPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length)); > if ((binding != null) && (binding.isValidBinding())) { > if (binding instanceof ReferenceBinding) { > // this only happens if a type name has the same name as its package >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java,v >retrieving revision 1.3 >diff -u -r1.3 ASTConverterTestAST4_2.java >--- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java 8 Sep 2011 18:36:15 -0000 1.3 >+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java 13 Sep 2011 16:11:28 -0000 >@@ -122,7 +122,7 @@ > static { > // TESTS_NAMES = new String[] {"test0602"}; > // TESTS_RANGE = new int[] { 721, -1 }; >-// TESTS_NUMBERS = new int[] { 723, 724 }; >+// TESTS_NUMBERS = new int[] { 725 }; > } > public static Test suite() { > return buildModelTestSuite(ASTConverterTestAST4_2.class); >@@ -10684,4 +10684,47 @@ > assertFalse(isRecovered((ASTNode) statements.get(1))); > assertFalse(isRecovered((ASTNode) statements.get(2))); > } >+ /* >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=357471 >+ */ >+ public void test0725() throws JavaModelException { >+ ICompilationUnit workingCopy = null; >+ try { >+ String contents = >+ "package one.two;\n" + >+ "public class one {}"; >+ workingCopy = getWorkingCopy("/Converter/src/one/two/one.java", true/*resolve*/); >+ CompilationUnit unit = (CompilationUnit) buildAST( >+ AST.JLS3, >+ contents, >+ workingCopy, >+ true, >+ true, >+ true); >+ PackageDeclaration packageDeclaration = unit.getPackage(); >+ IPackageBinding packageBinding = packageDeclaration.resolveBinding(); >+ assertNotNull("No binding", packageBinding); >+ assertEquals("Wrong name", "one.two", packageBinding.getName()); >+ Name packageName = packageDeclaration.getName(); >+ IBinding binding = packageName.resolveBinding(); >+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); >+ packageBinding = (IPackageBinding) binding; >+ assertEquals("Wrong name", "one.two", packageBinding.getName()); >+ packageName = ((QualifiedName) packageName).getQualifier(); >+ binding = packageName.resolveBinding(); >+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); >+ packageBinding = (IPackageBinding) binding; >+ assertEquals("Wrong name", "one", packageBinding.getName()); >+ packageName = packageDeclaration.getName(); >+ packageName = ((QualifiedName) packageName).getName(); >+ binding = packageName.resolveBinding(); >+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); >+ packageBinding = (IPackageBinding) binding; >+ assertEquals("Wrong name", "one.two", packageBinding.getName()); >+ } finally { >+ if (workingCopy != null) { >+ workingCopy.discardWorkingCopy(); >+ } >+ } >+ } > } >\ No newline at end of file
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 357471
: 203277