View | Details | Raw Unified | Return to bug 163647
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java (-29 / +114 lines)
Lines 13-29 Link Here
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
15
16
import junit.framework.Test;
17
16
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jdt.core.BindingKey;
19
import org.eclipse.jdt.core.BindingKey;
18
import org.eclipse.jdt.core.ICompilationUnit;
20
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IProblemRequestor;
20
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.WorkingCopyOwner;
24
import org.eclipse.jdt.core.WorkingCopyOwner;
22
import org.eclipse.jdt.core.dom.*;
25
import org.eclipse.jdt.core.compiler.IProblem;
26
import org.eclipse.jdt.core.dom.AST;
27
import org.eclipse.jdt.core.dom.ASTNode;
28
import org.eclipse.jdt.core.dom.ASTParser;
29
import org.eclipse.jdt.core.dom.ASTRequestor;
30
import org.eclipse.jdt.core.dom.CompilationUnit;
31
import org.eclipse.jdt.core.dom.IBinding;
32
import org.eclipse.jdt.core.dom.IMethodBinding;
33
import org.eclipse.jdt.core.dom.ITypeBinding;
34
import org.eclipse.jdt.core.dom.IVariableBinding;
35
import org.eclipse.jdt.core.dom.Type;
36
import org.eclipse.jdt.core.dom.TypeDeclaration;
23
import org.eclipse.jdt.core.tests.util.Util;
37
import org.eclipse.jdt.core.tests.util.Util;
24
38
25
import junit.framework.Test;
26
27
public class BatchASTCreationTests extends AbstractASTTests {
39
public class BatchASTCreationTests extends AbstractASTTests {
28
	
40
	
29
	public class TestASTRequestor extends ASTRequestor {
41
	public class TestASTRequestor extends ASTRequestor {
Lines 200-205 Link Here
200
	protected ICompilationUnit[] createWorkingCopies(String[] pathAndSources) throws JavaModelException {
212
	protected ICompilationUnit[] createWorkingCopies(String[] pathAndSources) throws JavaModelException {
201
		return createWorkingCopies(pathAndSources, this.owner);
213
		return createWorkingCopies(pathAndSources, this.owner);
202
	}
214
	}
215
216
	protected ICompilationUnit[] createWorkingCopies(String[] pathAndSources, boolean resolve) throws JavaModelException {
217
		IProblemRequestor problemRequestor = resolve
218
			? new IProblemRequestor() {
219
				public void acceptProblem(IProblem problem) {}
220
				public void beginReporting() {}
221
				public void endReporting() {}
222
				public boolean isActive() {
223
					return true;
224
				}
225
			} 
226
			: null;
227
		MarkerInfo[] markerInfos = createMarkerInfos(pathAndSources);
228
		return createWorkingCopies(markerInfos, this.owner, problemRequestor);
229
	}
203
	
230
	
204
	private void resolveASTs(ICompilationUnit[] cus, TestASTRequestor requestor) {
231
	private void resolveASTs(ICompilationUnit[] cus, TestASTRequestor requestor) {
205
		resolveASTs(cus, new String[0], requestor, getJavaProject("P"), this.owner);
232
		resolveASTs(cus, new String[0], requestor, getJavaProject("P"), this.owner);
Lines 1710-1746 Link Here
1710
		},
1737
		},
1711
		"LX;.foo()V|Ljava/lang/InterruptedException;|Ljava/lang/IllegalMonitorStateException;"
1738
		"LX;.foo()V|Ljava/lang/InterruptedException;|Ljava/lang/IllegalMonitorStateException;"
1712
	);
1739
	);
1740
	String content = "public class X {\n" + 
1741
			"    public void foo() throws InterruptedException, IllegalMonitorStateException {\n" + 
1742
			"    }\n" + 
1743
			"    void test() throws InterruptedException, IllegalMonitorStateException {\n" + 
1744
			"    	/*start*/foo()/*end*/;\n" + 
1745
			"    }\n" + 
1746
			"}";
1747
	this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/);
1748
	ASTNode node = buildAST(content, this.workingCopies[0]);
1749
	assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType());
1750
	IBinding binding = resolveBinding(node);
1751
	BindingKey bindingKey = new BindingKey(binding.getKey());
1752
	assertStringsEqual("Unexpected thrown exceptions",
1753
		"Ljava.lang.InterruptedException;\n" + 
1754
		"Ljava.lang.IllegalMonitorStateException;\n",
1755
		bindingKey.getThrownExceptions()
1756
	);
1713
}
1757
}
1714
public void test075_Bug155003() throws CoreException {
1758
public void test075_Bug155003() throws CoreException {
1715
	assertBindingCreated(
1759
	String content = "public class X<T> {\n" + 
1716
		new String[] {
1760
		"	<U extends Exception> X<T> foo(X<T> x) throws RuntimeException, U {\n" + 
1717
			"/P/X.java",
1761
		"		return null;\n" + 
1718
			"public class X<T> {\n" + 
1762
		"	}\n" + 
1719
			"	<U extends Exception> X<T> foo(X<T> x) throws RuntimeException, U {\n" + 
1763
		"	void test() throws Exception {\n" + 
1720
			"		return null;\n" + 
1764
		"		/*start*/foo(this)/*end*/;\n" + 
1721
			"	}\n" + 
1765
		"	}\n" + 
1722
			"	void test() throws Exception {\n" + 
1766
		"}";
1723
			"		/*start*/foo(this)/*end*/;\n" + 
1767
	this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/);
1724
			"	}\n" + 
1768
	ASTNode node = buildAST(content, this.workingCopies[0]);
1725
			"}"
1769
	assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType());
1726
		},
1770
	IBinding binding = resolveBinding(node);
1727
		"LX<LX;:TT;>;.foo<U:Ljava/lang/Exception;>(LX<TT;>;)LX<TT;>;^Ljava/lang/RuntimeException;^TU;%<Ljava/lang/Exception;>"
1771
	BindingKey bindingKey = new BindingKey(binding.getKey());
1772
	assertStringsEqual("Unexpected thrown exceptions",
1773
		"Ljava.lang.RuntimeException;\n" + 
1774
		"TU;\n",
1775
		bindingKey.getThrownExceptions()
1728
	);
1776
	);
1729
}
1777
}
1730
public void test076_Bug155003() throws CoreException {
1778
public void test076_Bug155003() throws CoreException {
1731
	assertBindingCreated(
1779
	String content = "public class X<T> {\n" + 
1732
		new String[] {
1780
		"	<K, V> V bar(K key, V value) throws Exception {\n" + 
1733
			"/P/X.java",
1781
		"		return value;\n" + 
1734
			"public class X<T> {\n" + 
1782
		"	}\n" + 
1735
			"	<K, V> V bar(K key, V value) throws Exception {\n" + 
1783
		"	void test() throws Exception {\n" + 
1736
			"		return value;\n" + 
1784
		"		/*start*/bar(\"\", \"\")/*end*/;\n" + 
1737
			"	}\n" + 
1785
		"	}\n" + 
1738
			"	void test() throws Exception {\n" + 
1786
		"}";
1739
			"		/*start*/bar(\"\", \"\")/*end*/;\n" + 
1787
	this.workingCopies = createWorkingCopies(new String[] { "/P/X.java", content }, true /*resolve*/);
1740
			"	}\n" + 
1788
	ASTNode node = buildAST(content, this.workingCopies[0]);
1741
			"}"
1789
	assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType());
1742
		},
1790
	IBinding binding = resolveBinding(node);
1743
		"LX<LX;:TT;>;.bar<K:Ljava/lang/Object;V:Ljava/lang/Object;>(TK;TV;)TV;|Ljava/lang/Exception;%<Ljava/lang/String;Ljava/lang/String;>"
1791
	BindingKey bindingKey = new BindingKey(binding.getKey());
1792
	assertStringsEqual("Unexpected thrown exceptions",
1793
		"Ljava.lang.Exception;\n",
1794
		bindingKey.getThrownExceptions()
1795
	);
1796
}
1797
1798
/**
1799
 * @bug 163647: [model] Thrown exceptions are not found in method binding key which have a capture as declaring class
1800
 * @test Ensure that thrown exceptions are added in method unique key (not in signature)
1801
 * 			even when declaring class is a capture 
1802
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=163647"
1803
 */
1804
public void test077_Bug163647() throws CoreException {
1805
	String content = 	"public class Test {\n" + 
1806
		"    public X<? extends Object> getX() { return null; }\n" + 
1807
		"    public void bar() {\n" + 
1808
		"		try {\n" + 
1809
		"			/*start*/getX().foo()/*end*/;\n" + 
1810
		"		} catch (Exception e) {\n" + 
1811
		"			// skip\n" + 
1812
		"		}\n" + 
1813
		"    }\n" + 
1814
		"}\n" + 
1815
		"class X<T> {\n" + 
1816
		"    public void foo() throws CloneNotSupportedException, IllegalMonitorStateException, InterruptedException {\n" + 
1817
		"    }\n" + 
1818
		"}";
1819
	this.workingCopies = createWorkingCopies(new String[] { "/P/Test.java", content }, true /*resolve*/);
1820
	ASTNode node = buildAST(content, this.workingCopies[0]);
1821
	assertEquals("Invalid node type!", ASTNode.METHOD_INVOCATION, node.getNodeType());
1822
	IBinding binding = resolveBinding(node);
1823
	BindingKey bindingKey = new BindingKey(binding.getKey());
1824
	assertStringsEqual("Unexpected thrown exceptions",
1825
		"Ljava.lang.CloneNotSupportedException;\n" + 
1826
		"Ljava.lang.IllegalMonitorStateException;\n" + 
1827
		"Ljava.lang.InterruptedException;\n",
1828
		bindingKey.getThrownExceptions()
1744
	);
1829
	);
1745
}
1830
}
1746
}
1831
}
(-)src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java (-1 / +6 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.IClassFile;
19
import org.eclipse.jdt.core.IClassFile;
20
import org.eclipse.jdt.core.ICompilationUnit;
20
import org.eclipse.jdt.core.ICompilationUnit;
21
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IProblemRequestor;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.WorkingCopyOwner;
24
import org.eclipse.jdt.core.WorkingCopyOwner;
24
import org.eclipse.jdt.core.compiler.CharOperation;
25
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 379-389 Link Here
379
	}
380
	}
380
	
381
	
381
	protected ICompilationUnit[] createWorkingCopies(MarkerInfo[] markerInfos, WorkingCopyOwner owner) throws JavaModelException {
382
	protected ICompilationUnit[] createWorkingCopies(MarkerInfo[] markerInfos, WorkingCopyOwner owner) throws JavaModelException {
383
		return createWorkingCopies(markerInfos, owner, null);
384
	}
385
386
	protected ICompilationUnit[] createWorkingCopies(MarkerInfo[] markerInfos, WorkingCopyOwner owner, IProblemRequestor problemRequestor) throws JavaModelException {
382
		int length = markerInfos.length;
387
		int length = markerInfos.length;
383
		ICompilationUnit[] copies = new ICompilationUnit[length];
388
		ICompilationUnit[] copies = new ICompilationUnit[length];
384
		for (int i = 0; i < length; i++) {
389
		for (int i = 0; i < length; i++) {
385
			MarkerInfo markerInfo = markerInfos[i];
390
			MarkerInfo markerInfo = markerInfos[i];
386
			ICompilationUnit workingCopy = getCompilationUnit(markerInfo.path).getWorkingCopy(owner, null, null);
391
			ICompilationUnit workingCopy = getCompilationUnit(markerInfo.path).getWorkingCopy(owner, problemRequestor, null);
387
			workingCopy.getBuffer().setContents(markerInfo.source);
392
			workingCopy.getBuffer().setContents(markerInfo.source);
388
			workingCopy.makeConsistent(null);
393
			workingCopy.makeConsistent(null);
389
			copies[i] = workingCopy;
394
			copies[i] = workingCopy;
(-)model/org/eclipse/jdt/internal/core/util/KeyToSignature.java (+1 lines)
Lines 275-280 Link Here
275
		KeyToSignature keyToSignature = (KeyToSignature) this.arguments.get(0);
275
		KeyToSignature keyToSignature = (KeyToSignature) this.arguments.get(0);
276
		this.signature = keyToSignature.signature;
276
		this.signature = keyToSignature.signature;
277
		this.arguments = keyToSignature.arguments;
277
		this.arguments = keyToSignature.arguments;
278
		this.thrownExceptions = keyToSignature.thrownExceptions;
278
	}
279
	}
279
	
280
	
280
	public void consumeWildCard(int wildCardKind) {
281
	public void consumeWildCard(int wildCardKind) {

Return to bug 163647