|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 38-43
Link Here
|
| 38 |
import org.eclipse.jdt.core.IJavaProject; |
38 |
import org.eclipse.jdt.core.IJavaProject; |
| 39 |
import org.eclipse.jdt.core.IType; |
39 |
import org.eclipse.jdt.core.IType; |
| 40 |
import org.eclipse.jdt.core.JavaCore; |
40 |
import org.eclipse.jdt.core.JavaCore; |
|
|
41 |
import org.eclipse.jdt.core.JavaModelException; |
| 41 |
import org.eclipse.jdt.core.tests.util.Util; |
42 |
import org.eclipse.jdt.core.tests.util.Util; |
| 42 |
import org.eclipse.jdt.internal.codeassist.RelevanceConstants; |
43 |
import org.eclipse.jdt.internal.codeassist.RelevanceConstants; |
| 43 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
44 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
|
Lines 45-50
Link Here
|
| 45 |
import org.eclipse.jdt.internal.core.search.indexing.IndexManager; |
46 |
import org.eclipse.jdt.internal.core.search.indexing.IndexManager; |
| 46 |
|
47 |
|
| 47 |
public class CompletionTests2 extends ModifyingResourceTests implements RelevanceConstants { |
48 |
public class CompletionTests2 extends ModifyingResourceTests implements RelevanceConstants { |
|
|
49 |
|
| 50 |
static { |
| 51 |
// TESTS_NAMES = new String[]{"testBug340945"}; |
| 52 |
} |
| 48 |
|
53 |
|
| 49 |
public static class CompletionContainerInitializer implements ContainerInitializer.ITestInitializer { |
54 |
public static class CompletionContainerInitializer implements ContainerInitializer.ITestInitializer { |
| 50 |
|
55 |
|
|
Lines 5591-5594
Link Here
|
| 5591 |
deleteProject(project); |
5596 |
deleteProject(project); |
| 5592 |
} |
5597 |
} |
| 5593 |
} |
5598 |
} |
|
|
5599 |
|
| 5600 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087 |
| 5601 |
public void testBug340945() throws JavaModelException { |
| 5602 |
this.workingCopies = new ICompilationUnit[1]; |
| 5603 |
this.workingCopies[0] = getWorkingCopy( |
| 5604 |
"/Completion/src/test/Try.java", |
| 5605 |
"package test;\n" + |
| 5606 |
"public class Try extends Thread{\n" + |
| 5607 |
" int inty = 1;\n" + |
| 5608 |
" void foo() {\n" + |
| 5609 |
" int i = 1;\n" + |
| 5610 |
" Object o = new Object() {\n" + |
| 5611 |
" void running() {\n" + |
| 5612 |
" int j = 1;\n" + |
| 5613 |
" int k = " + |
| 5614 |
" }\n" + |
| 5615 |
" }\n" + |
| 5616 |
" }\n" + |
| 5617 |
"}\n"); |
| 5618 |
|
| 5619 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 5620 |
requestor.setRequireExtendedContext(true); |
| 5621 |
requestor.allowAllRequiredProposals(); |
| 5622 |
requestor.setComputeVisibleElements(true); |
| 5623 |
// requestor.setAssignableType("I"); |
| 5624 |
String str = this.workingCopies[0].getSource(); |
| 5625 |
String completeBehind = "int k ="; |
| 5626 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 5627 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 5628 |
assertResults( |
| 5629 |
"<CompleteOnName:>", |
| 5630 |
requestor.getCompletionNode()); |
| 5631 |
assertResults( |
| 5632 |
"int k = <CompleteOnName:>;", |
| 5633 |
requestor.getCompletionNodeParent()); |
| 5634 |
assertResults( |
| 5635 |
"int j[pos: unused][id:2]\n" + |
| 5636 |
"int i[pos: unused][id:0]\n" + |
| 5637 |
"java.lang.Object o[pos: unused][id:1]\n", |
| 5638 |
requestor.getVisibleLocalVariables()); |
| 5639 |
assertResults( |
| 5640 |
"int inty\n", |
| 5641 |
requestor.getVisibleFields()); |
| 5642 |
assertResults( |
| 5643 |
"void running() \n" + |
| 5644 |
"public final void wait(long, int) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5645 |
"public final void wait(long) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5646 |
"public final void wait() throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5647 |
"public java.lang.String toString() \n" + |
| 5648 |
"public final void notifyAll() throws java.lang.IllegalMonitorStateException\n" + |
| 5649 |
"public final void notify() throws java.lang.IllegalMonitorStateException\n" + |
| 5650 |
"public int hashCode() \n" + |
| 5651 |
"public final java.lang.Class getClass() \n" + |
| 5652 |
"protected void finalize() throws java.lang.Throwable\n" + |
| 5653 |
"public boolean equals(java.lang.Object) \n" + |
| 5654 |
"protected java.lang.Object clone() throws java.lang.CloneNotSupportedException\n" + |
| 5655 |
"void foo() \n", |
| 5656 |
requestor.getVisibleMethods()); |
| 5657 |
} |
| 5658 |
|
| 5659 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087 |
| 5660 |
public void testBug340945a() throws JavaModelException { |
| 5661 |
this.workingCopies = new ICompilationUnit[1]; |
| 5662 |
this.workingCopies[0] = getWorkingCopy( |
| 5663 |
"/Completion/src/test/Try.java", |
| 5664 |
"package test;\n" + |
| 5665 |
"public class Try extends Thread{\n" + |
| 5666 |
" int int1 = 1;\n" + |
| 5667 |
" int int2 = 2;\n" + |
| 5668 |
" int int3 = " + |
| 5669 |
"}\n"); |
| 5670 |
|
| 5671 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 5672 |
requestor.setRequireExtendedContext(true); |
| 5673 |
requestor.allowAllRequiredProposals(); |
| 5674 |
requestor.setComputeVisibleElements(true); |
| 5675 |
String str = this.workingCopies[0].getSource(); |
| 5676 |
String completeBehind = "int int3 ="; |
| 5677 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 5678 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 5679 |
assertResults( |
| 5680 |
"<CompleteOnName:>", |
| 5681 |
requestor.getCompletionNode()); |
| 5682 |
assertResults( |
| 5683 |
"int int3 = <CompleteOnName:>;", |
| 5684 |
requestor.getCompletionNodeParent()); |
| 5685 |
assertResults( |
| 5686 |
"", |
| 5687 |
requestor.getVisibleLocalVariables()); |
| 5688 |
assertResults( |
| 5689 |
"int int2\n" + |
| 5690 |
"int int1\n", |
| 5691 |
requestor.getVisibleFields()); |
| 5692 |
assertResults( |
| 5693 |
"public final void wait(long, int) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5694 |
"public final void wait(long) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5695 |
"public final void wait() throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5696 |
"public java.lang.String toString() \n" + |
| 5697 |
"public final void notifyAll() throws java.lang.IllegalMonitorStateException\n" + |
| 5698 |
"public final void notify() throws java.lang.IllegalMonitorStateException\n" + |
| 5699 |
"public int hashCode() \n" + |
| 5700 |
"public final java.lang.Class getClass() \n" + |
| 5701 |
"protected void finalize() throws java.lang.Throwable\n" + |
| 5702 |
"public boolean equals(java.lang.Object) \n" + |
| 5703 |
"protected java.lang.Object clone() throws java.lang.CloneNotSupportedException\n", |
| 5704 |
requestor.getVisibleMethods()); |
| 5705 |
} |
| 5706 |
|
| 5707 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087 |
| 5708 |
public void testBug340945b() throws JavaModelException { |
| 5709 |
this.workingCopies = new ICompilationUnit[1]; |
| 5710 |
this.workingCopies[0] = getWorkingCopy( |
| 5711 |
"/Completion/src/test/Try.java", |
| 5712 |
"package test;\n" + |
| 5713 |
"public class Try extends Thread{\n" + |
| 5714 |
"Object field;\n" + |
| 5715 |
"void foo() {\n" + |
| 5716 |
" int int1 = 1;\n" + |
| 5717 |
" int int2 = 2;\n" + |
| 5718 |
" int int3 = " + |
| 5719 |
"}\n" + |
| 5720 |
"}\n"); |
| 5721 |
|
| 5722 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 5723 |
requestor.setRequireExtendedContext(true); |
| 5724 |
requestor.allowAllRequiredProposals(); |
| 5725 |
requestor.setComputeVisibleElements(true); |
| 5726 |
String str = this.workingCopies[0].getSource(); |
| 5727 |
String completeBehind = "int int3 ="; |
| 5728 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 5729 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 5730 |
assertResults( |
| 5731 |
"<CompleteOnName:>", |
| 5732 |
requestor.getCompletionNode()); |
| 5733 |
assertResults( |
| 5734 |
"int int3 = <CompleteOnName:>;", |
| 5735 |
requestor.getCompletionNodeParent()); |
| 5736 |
assertResults( |
| 5737 |
"int int1[pos: unused][id:0]\n" + |
| 5738 |
"int int2[pos: unused][id:1]\n", |
| 5739 |
requestor.getVisibleLocalVariables()); |
| 5740 |
assertResults( |
| 5741 |
"java.lang.Object field\n", |
| 5742 |
requestor.getVisibleFields()); |
| 5743 |
assertResults( |
| 5744 |
"void foo() \n" + |
| 5745 |
"public final void wait(long, int) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5746 |
"public final void wait(long) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5747 |
"public final void wait() throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5748 |
"public java.lang.String toString() \n" + |
| 5749 |
"public final void notifyAll() throws java.lang.IllegalMonitorStateException\n" + |
| 5750 |
"public final void notify() throws java.lang.IllegalMonitorStateException\n" + |
| 5751 |
"public int hashCode() \n" + |
| 5752 |
"public final java.lang.Class getClass() \n" + |
| 5753 |
"protected void finalize() throws java.lang.Throwable\n" + |
| 5754 |
"public boolean equals(java.lang.Object) \n" + |
| 5755 |
"protected java.lang.Object clone() throws java.lang.CloneNotSupportedException\n", |
| 5756 |
requestor.getVisibleMethods()); |
| 5757 |
} |
| 5758 |
|
| 5759 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087 |
| 5760 |
public void testBug340945c() throws JavaModelException { |
| 5761 |
this.workingCopies = new ICompilationUnit[1]; |
| 5762 |
this.workingCopies[0] = getWorkingCopy( |
| 5763 |
"/Completion/src/test/Try.java", |
| 5764 |
"package test;\n" + |
| 5765 |
"public class Try extends Thread{\n" + |
| 5766 |
"Object field;\n" + |
| 5767 |
"void foo() {\n" + |
| 5768 |
" int int1 = 1;\n" + |
| 5769 |
" int int2 = 2;\n" + |
| 5770 |
" Object o1 = new Object();\n" + |
| 5771 |
" o1." + |
| 5772 |
"}\n" + |
| 5773 |
"}\n"); |
| 5774 |
|
| 5775 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 5776 |
requestor.setRequireExtendedContext(true); |
| 5777 |
requestor.allowAllRequiredProposals(); |
| 5778 |
requestor.setComputeVisibleElements(true); |
| 5779 |
String str = this.workingCopies[0].getSource(); |
| 5780 |
String completeBehind = "o1."; |
| 5781 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 5782 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 5783 |
assertResults( |
| 5784 |
"<CompleteOnName:o1.>", |
| 5785 |
requestor.getCompletionNode()); |
| 5786 |
assertNull( |
| 5787 |
"should be null", |
| 5788 |
requestor.getCompletionNodeParent()); |
| 5789 |
assertResults( |
| 5790 |
"int int1[pos: unused][id:0]\n" + |
| 5791 |
"int int2[pos: unused][id:1]\n" + |
| 5792 |
"java.lang.Object o1[pos: unused][id:2]\n", |
| 5793 |
requestor.getVisibleLocalVariables()); |
| 5794 |
assertResults( |
| 5795 |
"java.lang.Object field\n", |
| 5796 |
requestor.getVisibleFields()); |
| 5797 |
assertResults( |
| 5798 |
"void foo() \n" + |
| 5799 |
"public final void wait(long, int) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5800 |
"public final void wait(long) throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5801 |
"public final void wait() throws java.lang.IllegalMonitorStateException, java.lang.InterruptedException\n" + |
| 5802 |
"public java.lang.String toString() \n" + |
| 5803 |
"public final void notifyAll() throws java.lang.IllegalMonitorStateException\n" + |
| 5804 |
"public final void notify() throws java.lang.IllegalMonitorStateException\n" + |
| 5805 |
"public int hashCode() \n" + |
| 5806 |
"public final java.lang.Class getClass() \n" + |
| 5807 |
"protected void finalize() throws java.lang.Throwable\n" + |
| 5808 |
"public boolean equals(java.lang.Object) \n" + |
| 5809 |
"protected java.lang.Object clone() throws java.lang.CloneNotSupportedException\n", |
| 5810 |
requestor.getVisibleMethods()); |
| 5811 |
} |
| 5812 |
|
| 5813 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087 |
| 5814 |
public void testBug340945d() throws JavaModelException { |
| 5815 |
this.workingCopies = new ICompilationUnit[1]; |
| 5816 |
this.workingCopies[0] = getWorkingCopy( |
| 5817 |
"/Completion/src/test/Try.java", |
| 5818 |
"package test;\n" + |
| 5819 |
"public class Try extends Thread{\n" + |
| 5820 |
"Object field;\n" + |
| 5821 |
"static void foo() {\n" + // field should not be visible here |
| 5822 |
" int int1 = 1;\n" + |
| 5823 |
" int int2 = 2;\n" + |
| 5824 |
" Object o1 = new Object();\n" + |
| 5825 |
" o1." + |
| 5826 |
"}\n" + |
| 5827 |
"}\n"); |
| 5828 |
|
| 5829 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 5830 |
requestor.setRequireExtendedContext(true); |
| 5831 |
requestor.allowAllRequiredProposals(); |
| 5832 |
requestor.setComputeVisibleElements(true); |
| 5833 |
String str = this.workingCopies[0].getSource(); |
| 5834 |
String completeBehind = "o1."; |
| 5835 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 5836 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 5837 |
assertResults( |
| 5838 |
"<CompleteOnName:o1.>", |
| 5839 |
requestor.getCompletionNode()); |
| 5840 |
assertNull( |
| 5841 |
"should be null", |
| 5842 |
requestor.getCompletionNodeParent()); |
| 5843 |
assertResults( |
| 5844 |
"int int1[pos: unused][id:0]\n" + |
| 5845 |
"int int2[pos: unused][id:1]\n" + |
| 5846 |
"java.lang.Object o1[pos: unused][id:2]\n", |
| 5847 |
requestor.getVisibleLocalVariables()); |
| 5848 |
assertResults( |
| 5849 |
"", |
| 5850 |
requestor.getVisibleFields()); |
| 5851 |
assertResults( |
| 5852 |
"static void foo() \n", |
| 5853 |
requestor.getVisibleMethods()); |
| 5854 |
} |
| 5594 |
} |
5855 |
} |