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

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java (+70 lines)
Lines 12844-12849 Link Here
12844
		JavaCore.setOptions(oldOptions);
12844
		JavaCore.setOptions(oldOptions);
12845
	}
12845
	}
12846
}
12846
}
12847
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=178982
12848
public void testONLY_FavoriteImports032() throws JavaModelException {
12849
	this.oldOptions = JavaCore.getOptions();
12850
	
12851
	try {
12852
		Hashtable options = new Hashtable(this.oldOptions);
12853
		options.put(JavaCore.CODEASSIST_SUGGEST_STATIC_IMPORTS, JavaCore.ENABLED);
12854
		JavaCore.setOptions(options);
12855
		
12856
		this.workingCopies = new ICompilationUnit[3];
12857
		this.workingCopies[0] = getWorkingCopy(
12858
				"/Completion/src3/test/Test.java",
12859
				"package test;\n" +
12860
				"public class Test extends Test2 {\n" +
12861
				"    public void method() {\n" +
12862
				"        int zelement1\n" +
12863
				"        float zelement2\n" +
12864
				"        double zelement3\n" +
12865
				"        foo(0, zelement);\n" +
12866
				"    }\n" +
12867
				"}");
12868
		
12869
		this.workingCopies[1] = getWorkingCopy(
12870
				"/Completion/src3/test/Test2.java",
12871
				"package test;\n" +
12872
				"public class Test2 {\n" +
12873
				"    public void foo(double i, double j) {}\n" +
12874
				"    public void foo(float i, float j) {}\n" +
12875
				"    public void foo(int i, int j) {}\n" +
12876
				"}");
12877
		
12878
		this.workingCopies[2] = getWorkingCopy(
12879
				"/Completion/src3/test/p/ZZZ.java",
12880
				"package test.p;\n" +
12881
				"public class ZZZ {\n" +
12882
				"    public static int zelement4(){}\n" +
12883
				"    public static float zelement5(){}\n" +
12884
				"    public static double zelement6(){}\n" +
12885
				"}");
12886
		
12887
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
12888
		requestor.allowAllRequiredProposals();
12889
		requestor.setFavoriteReferences(new String[]{"test.p.ZZZ.*"});
12890
		
12891
		String str = this.workingCopies[0].getSource();
12892
		String completeBehind = "zelement";
12893
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
12894
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
12895
		
12896
		int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED;
12897
		int relevance2 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED;
12898
		int start1 = str.lastIndexOf("zelement") + "".length();
12899
		int end1 = start1 + "zelement".length();
12900
		int start2 = str.lastIndexOf("public class");
12901
		int end2 = start2 + "".length();
12902
		assertResults(
12903
			"zelement4[METHOD_REF]{zelement4(), Ltest.p.ZZZ;, ()I, zelement4, null, ["+start1+", "+end1+"], "+(relevance1)+"}\n" +
12904
			"   zelement4[METHOD_IMPORT]{import static test.p.ZZZ.zelement4;\n, Ltest.p.ZZZ;, ()I, zelement4, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n"+
12905
			"zelement5[METHOD_REF]{zelement5(), Ltest.p.ZZZ;, ()F, zelement5, null, ["+start1+", "+end1+"], "+(relevance1)+"}\n" +
12906
			"   zelement5[METHOD_IMPORT]{import static test.p.ZZZ.zelement5;\n, Ltest.p.ZZZ;, ()F, zelement5, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n"+
12907
			"zelement6[METHOD_REF]{zelement6(), Ltest.p.ZZZ;, ()D, zelement6, null, ["+start1+", "+end1+"], "+(relevance1)+"}\n" +
12908
			"   zelement6[METHOD_IMPORT]{import static test.p.ZZZ.zelement6;\n, Ltest.p.ZZZ;, ()D, zelement6, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n"+
12909
			"zelement1[LOCAL_VARIABLE_REF]{zelement1, null, I, zelement1, null, ["+start1+", "+end1+"], "+(relevance2)+"}\n" +
12910
			"zelement2[LOCAL_VARIABLE_REF]{zelement2, null, F, zelement2, null, ["+start1+", "+end1+"], "+(relevance2)+"}\n" +
12911
			"zelement3[LOCAL_VARIABLE_REF]{zelement3, null, D, zelement3, null, ["+start1+", "+end1+"], "+(relevance2)+"}",
12912
			requestor.getResults());
12913
	} finally {
12914
		JavaCore.setOptions(oldOptions);
12915
	}
12916
}
12847
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162865
12917
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162865
12848
public void testNameWithUnresolvedReferences001() throws JavaModelException {
12918
public void testNameWithUnresolvedReferences001() throws JavaModelException {
12849
	this.workingCopies = new ICompilationUnit[2];
12919
	this.workingCopies = new ICompilationUnit[2];
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-9 / +18 lines)
Lines 6660-6680 Link Here
6660
	}
6660
	}
6661
	private int computeRelevanceForExpectingType(TypeBinding proposalType){
6661
	private int computeRelevanceForExpectingType(TypeBinding proposalType){
6662
		if(this.expectedTypes != null && proposalType != null) {
6662
		if(this.expectedTypes != null && proposalType != null) {
6663
			int relevance = 0;
6663
			for (int i = 0; i <= this.expectedTypesPtr; i++) {
6664
			for (int i = 0; i <= this.expectedTypesPtr; i++) {
6664
                int relevance = R_EXPECTED_TYPE;
6665
				if(CharOperation.equals(this.expectedTypes[i].qualifiedPackageName(), proposalType.qualifiedPackageName()) &&
6666
					CharOperation.equals(this.expectedTypes[i].qualifiedSourceName(), proposalType.qualifiedSourceName())) {
6667
                    relevance = R_EXACT_EXPECTED_TYPE;
6668
				}
6669
				if((this.expectedTypesFilter & SUBTYPE) != 0
6665
				if((this.expectedTypesFilter & SUBTYPE) != 0
6670
					&& proposalType.isCompatibleWith(this.expectedTypes[i])) {
6666
						&& proposalType.isCompatibleWith(this.expectedTypes[i])) {
6671
						return relevance;
6667
					
6668
					if(CharOperation.equals(this.expectedTypes[i].qualifiedPackageName(), proposalType.qualifiedPackageName()) &&
6669
							CharOperation.equals(this.expectedTypes[i].qualifiedSourceName(), proposalType.qualifiedSourceName())) {
6670
						return R_EXACT_EXPECTED_TYPE;
6671
					}
6672
					
6673
					relevance = R_EXPECTED_TYPE;
6672
				}
6674
				}
6673
				if((this.expectedTypesFilter & SUPERTYPE) != 0
6675
				if((this.expectedTypesFilter & SUPERTYPE) != 0
6674
					&& this.expectedTypes[i].isCompatibleWith(proposalType)) {
6676
						&& this.expectedTypes[i].isCompatibleWith(proposalType)) {
6675
					return relevance;
6677
					
6678
					if(CharOperation.equals(this.expectedTypes[i].qualifiedPackageName(), proposalType.qualifiedPackageName()) &&
6679
							CharOperation.equals(this.expectedTypes[i].qualifiedSourceName(), proposalType.qualifiedSourceName())) {
6680
						return R_EXACT_EXPECTED_TYPE;
6681
					}
6682
					
6683
					relevance = R_EXPECTED_TYPE;
6676
				}
6684
				}
6677
			}
6685
			}
6686
			return relevance;
6678
		} 
6687
		} 
6679
		return 0;
6688
		return 0;
6680
	}
6689
	}

Return to bug 178982