### Eclipse Workspace Patch 1.0 #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.67 diff -u -r1.67 BatchASTCreationTests.java --- src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java 6 Nov 2006 14:20:14 -0000 1.67 +++ src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java 7 Nov 2006 17:03:50 -0000 @@ -13,17 +13,29 @@ import java.io.IOException; import java.util.ArrayList; +import junit.framework.Test; + import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.BindingKey; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IProblemRequestor; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; -import org.eclipse.jdt.core.dom.*; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTRequestor; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.IBinding; +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.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.tests.util.Util; -import junit.framework.Test; - public class BatchASTCreationTests extends AbstractASTTests { public class TestASTRequestor extends ASTRequestor { @@ -200,6 +212,21 @@ protected ICompilationUnit[] createWorkingCopies(String[] pathAndSources) throws JavaModelException { return createWorkingCopies(pathAndSources, this.owner); } + + protected ICompilationUnit[] createWorkingCopies(String[] pathAndSources, boolean resolve) throws JavaModelException { + IProblemRequestor problemRequestor = resolve + ? new IProblemRequestor() { + public void acceptProblem(IProblem problem) {} + public void beginReporting() {} + public void endReporting() {} + public boolean isActive() { + return true; + } + } + : null; + MarkerInfo[] markerInfos = createMarkerInfos(pathAndSources); + return createWorkingCopies(markerInfos, this.owner, problemRequestor); + } private void resolveASTs(ICompilationUnit[] cus, TestASTRequestor requestor) { resolveASTs(cus, new String[0], requestor, getJavaProject("P"), this.owner); @@ -1710,37 +1737,95 @@ }, "LX;.foo()V|Ljava/lang/InterruptedException;|Ljava/lang/IllegalMonitorStateException;" ); + String content = "public class X {\n" + + " public void foo() throws InterruptedException, IllegalMonitorStateException {\n" + + " }\n" + + " void test() throws InterruptedException, IllegalMonitorStateException {\n" + + " /*start*/foo()/*end*/;\n" + + " }\n" + + "}"; + this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/); + ASTNode node = buildAST(content, this.workingCopies[0]); + assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType()); + IBinding binding = resolveBinding(node); + BindingKey bindingKey = new BindingKey(binding.getKey()); + assertStringsEqual("Unexpected thrown exceptions", + "Ljava.lang.InterruptedException;\n" + + "Ljava.lang.IllegalMonitorStateException;\n", + bindingKey.getThrownExceptions() + ); } public void test075_Bug155003() throws CoreException { - assertBindingCreated( - new String[] { - "/P/X.java", - "public class X {\n" + - " X foo(X x) throws RuntimeException, U {\n" + - " return null;\n" + - " }\n" + - " void test() throws Exception {\n" + - " /*start*/foo(this)/*end*/;\n" + - " }\n" + - "}" - }, - "LX;.foo(LX;)LX;^Ljava/lang/RuntimeException;^TU;%" + String content = "public class X {\n" + + " X foo(X x) throws RuntimeException, U {\n" + + " return null;\n" + + " }\n" + + " void test() throws Exception {\n" + + " /*start*/foo(this)/*end*/;\n" + + " }\n" + + "}"; + this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/); + ASTNode node = buildAST(content, this.workingCopies[0]); + assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType()); + IBinding binding = resolveBinding(node); + BindingKey bindingKey = new BindingKey(binding.getKey()); + assertStringsEqual("Unexpected thrown exceptions", + "Ljava.lang.RuntimeException;\n" + + "TU;\n", + bindingKey.getThrownExceptions() ); } public void test076_Bug155003() throws CoreException { - assertBindingCreated( - new String[] { - "/P/X.java", - "public class X {\n" + - " V bar(K key, V value) throws Exception {\n" + - " return value;\n" + - " }\n" + - " void test() throws Exception {\n" + - " /*start*/bar(\"\", \"\")/*end*/;\n" + - " }\n" + - "}" - }, - "LX;.bar(TK;TV;)TV;|Ljava/lang/Exception;%" + String content = "public class X {\n" + + " V bar(K key, V value) throws Exception {\n" + + " return value;\n" + + " }\n" + + " void test() throws Exception {\n" + + " /*start*/bar(\"\", \"\")/*end*/;\n" + + " }\n" + + "}"; + this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/); + ASTNode node = buildAST(content, this.workingCopies[0]); + assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType()); + IBinding binding = resolveBinding(node); + BindingKey bindingKey = new BindingKey(binding.getKey()); + assertStringsEqual("Unexpected thrown exceptions", + "Ljava.lang.Exception;\n", + bindingKey.getThrownExceptions() + ); +} + +/** + * @bug 163647: [model] Thrown exceptions are not found in method binding key which have a capture as declaring class + * @test Ensure that thrown exceptions are added in method unique key (not in signature) + * even when declaring class is a capture + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=163647" + */ +public void test077_Bug163647() throws CoreException { + String content = "public class Test {\n" + + " public X getX() { return null; }\n" + + " public void bar() {\n" + + " try {\n" + + " /*start*/getX().foo()/*end*/;\n" + + " } catch (Exception e) {\n" + + " // skip\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " public void foo() throws CloneNotSupportedException, IllegalMonitorStateException, InterruptedException {\n" + + " }\n" + + "}"; + this.workingCopies = createWorkingCopies(new String[] { "/P/Test.java", content }, true /*resolve*/); + ASTNode node = buildAST(content, this.workingCopies[0]); + assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType()); + IBinding binding = resolveBinding(node); + BindingKey bindingKey = new BindingKey(binding.getKey()); + assertStringsEqual("Unexpected thrown exceptions", + "Ljava.lang.CloneNotSupportedException;\n" + + "Ljava.lang.IllegalMonitorStateException;\n" + + "Ljava.lang.InterruptedException;\n", + bindingKey.getThrownExceptions() ); } } Index: src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java,v retrieving revision 1.28 diff -u -r1.28 AbstractASTTests.java --- src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java 13 Jul 2006 14:23:28 -0000 1.28 +++ src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java 7 Nov 2006 17:03:50 -0000 @@ -19,6 +19,7 @@ import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IProblemRequestor; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.compiler.CharOperation; @@ -379,11 +380,15 @@ } protected ICompilationUnit[] createWorkingCopies(MarkerInfo[] markerInfos, WorkingCopyOwner owner) throws JavaModelException { + return createWorkingCopies(markerInfos, owner, null); + } + + protected ICompilationUnit[] createWorkingCopies(MarkerInfo[] markerInfos, WorkingCopyOwner owner, IProblemRequestor problemRequestor) throws JavaModelException { int length = markerInfos.length; ICompilationUnit[] copies = new ICompilationUnit[length]; for (int i = 0; i < length; i++) { MarkerInfo markerInfo = markerInfos[i]; - ICompilationUnit workingCopy = getCompilationUnit(markerInfo.path).getWorkingCopy(owner, null, null); + ICompilationUnit workingCopy = getCompilationUnit(markerInfo.path).getWorkingCopy(owner, problemRequestor, null); workingCopy.getBuffer().setContents(markerInfo.source); workingCopy.makeConsistent(null); copies[i] = workingCopy; #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/util/KeyToSignature.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/KeyToSignature.java,v retrieving revision 1.24 diff -u -r1.24 KeyToSignature.java --- model/org/eclipse/jdt/internal/core/util/KeyToSignature.java 6 Nov 2006 14:19:55 -0000 1.24 +++ model/org/eclipse/jdt/internal/core/util/KeyToSignature.java 7 Nov 2006 17:03:53 -0000 @@ -275,6 +275,7 @@ KeyToSignature keyToSignature = (KeyToSignature) this.arguments.get(0); this.signature = keyToSignature.signature; this.arguments = keyToSignature.arguments; + this.thrownExceptions = keyToSignature.thrownExceptions; } public void consumeWildCard(int wildCardKind) {