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 161014 Details for
Bug 129804
[dom] Local variable bindings from ASTParser#createASTs(.., String[], .., ..) have no declaring method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression test
patch_129804.txt (text/plain), 7.79 KB, created by
Olivier Thomann
on 2010-03-04 14:34:48 EST
(
hide
)
Description:
Proposed fix + regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-03-04 14:34:48 EST
Size:
7.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: dom/org/eclipse/jdt/core/dom/VariableBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java,v >retrieving revision 1.63 >diff -u -r1.63 VariableBinding.java >--- dom/org/eclipse/jdt/core/dom/VariableBinding.java 21 Feb 2010 03:35:51 -0000 1.63 >+++ dom/org/eclipse/jdt/core/dom/VariableBinding.java 4 Mar 2010 19:34:22 -0000 >@@ -14,10 +14,13 @@ > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.util.IModifierConstants; >+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; >+import org.eclipse.jdt.internal.compiler.ast.Initializer; > import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.impl.Constant; > import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; >+import org.eclipse.jdt.internal.compiler.lookup.BlockScope; > import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; > import org.eclipse.jdt.internal.compiler.lookup.TagBits; >@@ -127,7 +130,22 @@ > if (!isField()) { > ASTNode node = this.resolver.findDeclaringNode(this); > while (true) { >- if (node == null) break; >+ if (node == null) { >+ if (this.binding instanceof LocalVariableBinding) { >+ LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding; >+ BlockScope blockScope = localVariableBinding.declaringScope; >+ if (blockScope != null) { >+ ReferenceContext referenceContext = blockScope.referenceContext(); >+ if (referenceContext instanceof Initializer) { >+ return null; >+ } >+ if (referenceContext instanceof AbstractMethodDeclaration) { >+ return this.resolver.getMethodBinding(((AbstractMethodDeclaration) referenceContext).binding); >+ } >+ } >+ } >+ return null; >+ } > switch(node.getNodeType()) { > case ASTNode.INITIALIZER : > return null; >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java,v >retrieving revision 1.87 >diff -u -r1.87 BatchASTCreationTests.java >--- src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java 27 Nov 2009 17:51:18 -0000 1.87 >+++ src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java 4 Mar 2010 19:34:22 -0000 >@@ -32,8 +32,11 @@ > import org.eclipse.jdt.core.dom.IMethodBinding; > import org.eclipse.jdt.core.dom.ITypeBinding; > import org.eclipse.jdt.core.dom.IVariableBinding; >+import org.eclipse.jdt.core.dom.MethodDeclaration; > import org.eclipse.jdt.core.dom.Type; > import org.eclipse.jdt.core.dom.TypeDeclaration; >+import org.eclipse.jdt.core.dom.VariableDeclarationFragment; >+import org.eclipse.jdt.core.dom.VariableDeclarationStatement; > import org.eclipse.jdt.core.tests.util.Util; > > public class BatchASTCreationTests extends AbstractASTTests { >@@ -104,10 +107,10 @@ > // All specified tests which do not belong to the class are skipped... > static { > // TESTS_PREFIX = "testBug86380"; >-// TESTS_NAMES = new String[] { "test056" }; >-// TESTS_NUMBERS = new int[] { 78, 79, 80 }; >+// TESTS_NAMES = new String[] { "test072a" }; >+// TESTS_NUMBERS = new int[] { 72 }; > // TESTS_RANGE = new int[] { 83304, -1 }; >- } >+ } > > public void setUpSuite() throws Exception { > super.setUpSuite(); >@@ -1692,7 +1695,7 @@ > * is not null > * (regression test for bug 129804 Local variable bindings from ASTParser#createASTs(.., String[], .., ..) have no declaring method) > */ >- public void _test072() throws CoreException { >+ public void test072() throws CoreException { > IVariableBinding[] bindings = createVariableBindings( > new String[] { > "/P/X.java", >@@ -1710,6 +1713,49 @@ > "LX;.m()V", > bindings[0].getDeclaringMethod()); > } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=152060 >+ public void test072a() throws CoreException, IOException { >+ try { >+ IJavaProject project = createJavaProject("P072a", new String[] {"src"}, Util.getJavaClassLibs(), "bin", "1.5"); >+ createFile("/P072a/src/X.java", >+ "public class X {\n" + >+ " void m() {\n" + >+ " Object o;\n" + >+ " }\n" + >+ "}"); >+ final ICompilationUnit compilationUnits[] = new ICompilationUnit[1]; >+ compilationUnits[0] = getCompilationUnit("P072a", "src", "", "X.java"); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setResolveBindings(true); >+ parser.setProject(project); >+ final String[] keys = new String[] { "LX;.m()V#o" }; >+ final ASTNode[] nodes = new ASTNode[1]; >+ BindingRequestor bindingRequestor = new BindingRequestor() { >+ public void acceptAST(ICompilationUnit source, CompilationUnit ast) { >+ if (compilationUnits[0].equals(source)) { >+ nodes[0] = ast; >+ } >+ } >+ }; >+ parser.createASTs( >+ compilationUnits, >+ keys, >+ bindingRequestor, >+ null); >+ IBinding[] bindings = bindingRequestor.getBindings(keys); >+ IBinding binding = bindings[0]; >+ assertNotNull("Should not be null", binding); >+ assertEquals("Not a type binding", IBinding.VARIABLE, binding.getKind()); >+ MethodDeclaration declaration = ((TypeDeclaration)((CompilationUnit) nodes[0]).types().get(0)).getMethods()[0]; >+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) ((VariableDeclarationStatement) declaration.getBody().statements().get(0)).fragments().get(0); >+ IVariableBinding resolveBinding = fragment.resolveBinding(); >+ assertTrue("Not equals", binding.isEqualTo(resolveBinding)); >+ assertNotNull("No java element", resolveBinding.getJavaElement()); >+ assertNotNull("No java element", binding.getJavaElement()); >+ } finally { >+ deleteProject("P072a"); >+ } >+ } > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159631 > public void test073() throws CoreException, IOException { >@@ -1936,30 +1982,30 @@ > " }\n" + > " public void extra() {\n" + > " }\n" + >- "}"); >+ "}"); > ICompilationUnit compilationUnits[] = new ICompilationUnit[1]; > compilationUnits[0] = getCompilationUnit("P079", "src", "test", "Test.java"); > ASTParser parser = ASTParser.newParser(AST.JLS3); > parser.setResolveBindings(true); > parser.setProject(project); >- final IBinding[] bindings = new IBinding[1]; >+ final IBinding[] bindings = new IBinding[1]; > final String key = "Ltest/Test~ExtraIterator<>;"; > parser.createASTs( >- compilationUnits, >- new String[] { >- key >- }, >- new ASTRequestor() { >- public void acceptAST(ICompilationUnit source, CompilationUnit localAst) { >- // do nothing >- } >- public void acceptBinding(String bindingKey, IBinding binding) { >- if (key.equals(bindingKey)) { >- bindings[0] = binding; >- } >- } >- }, >- null); >+ compilationUnits, >+ new String[] { >+ key >+ }, >+ new ASTRequestor() { >+ public void acceptAST(ICompilationUnit source, CompilationUnit localAst) { >+ // do nothing >+ } >+ public void acceptBinding(String bindingKey, IBinding binding) { >+ if (key.equals(bindingKey)) { >+ bindings[0] = binding; >+ } >+ } >+ }, >+ null); > IBinding binding = bindings[0]; > assertNotNull("Should not be null", binding); > assertEquals("Not a type binding", IBinding.TYPE, binding.getKind());
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 129804
: 161014