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

(-)src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java (+27 lines)
Lines 2909-2912 Link Here
2909
			true
2909
			true
2910
		);
2910
		);
2911
}
2911
}
2912
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
2913
public void test0123() throws Exception {
2914
	this.workingCopies = new ICompilationUnit[1];
2915
	this.workingCopies[0] = getWorkingCopy(
2916
			"/Resolve/src/test/Test.java",
2917
			"package test;\n" +
2918
			"public class Test {\n" + 
2919
			"        <T> T bar(T t) { return t; }\n" + 
2920
			"        void foo(boolean b, Runnable r) {\n" + 
2921
			"                Zork z = null;\n" + 
2922
			"                String s = (String) bar(z); // 5\n" + 
2923
			"        }\n" + 
2924
			"}\n" + 
2925
			"\n");
2926
2927
	String str = this.workingCopies[0].getSource();
2928
	int start = str.lastIndexOf("bar");
2929
	int length = "bar".length();
2930
	IJavaElement[] elements =  this.workingCopies[0].codeSelect(start, length, this.wcOwner);
2931
2932
	assertElementsEqual(
2933
			"Unexpected elements",
2934
			"bar(T) {key=Ltest/Test;.bar<T:Ljava/lang/Object;>(TT;)TT;%<Ljava/lang/Object;>} [in Test [in [Working copy] Test.java [in test [in src [in Resolve]]]]]",
2935
			elements,
2936
			true
2937
		);
2938
}
2912
}
2939
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java (+47 lines)
Lines 934-937 Link Here
934
		expectedReplacedSource,
934
		expectedReplacedSource,
935
		testName);
935
		testName);
936
}
936
}
937
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255142
938
public void test0024() {
939
940
	String str =
941
		"import java.util.List;\n" + 
942
		"public class X {\n" + 
943
		"        <T> T bar(T t) { return t; }\n" + 
944
		"        void foo(boolean b, Runnable r) {\n" + 
945
		"                Zork z = null;\n" + 
946
		"                String s = (String) bar(z); // 5\n" + 
947
		"        }\n" + 
948
		"}\n" + 
949
		"\n";
950
951
	String selection = "bar";
952
953
	String expectedCompletionNodeToString = "<SelectOnMessageSend:bar(z)>";
954
955
	String completionIdentifier = "bar";
956
	String expectedUnitDisplayString =
957
		"import java.util.List;\n" + 
958
		"public class X {\n" + 
959
		"  public X() {\n" + 
960
		"  }\n" + 
961
		"  <T>T bar(T t) {\n" + 
962
		"  }\n" + 
963
		"  void foo(boolean b, Runnable r) {\n" + 
964
		"    Zork z;\n" + 
965
		"    String s = (String) <SelectOnMessageSend:bar(z)>;\n" + 
966
		"  }\n" + 
967
		"}\n";
968
	String expectedReplacedSource = "bar(z)";
969
	String testName = "<select method>";
970
971
	int selectionStart = str.lastIndexOf(selection);
972
	int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1;
973
974
	this.checkMethodParse(
975
		str.toCharArray(),
976
		selectionStart,
977
		selectionEnd,
978
		expectedCompletionNodeToString,
979
		expectedUnitDisplayString,
980
		completionIdentifier,
981
		expectedReplacedSource,
982
		testName);
983
}
937
}
984
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java (-1 / +1 lines)
Lines 794-800 Link Here
794
		"  public X() {\n" +
794
		"  public X() {\n" +
795
		"  }\n" +
795
		"  }\n" +
796
		"  Object foo() {\n" +
796
		"  Object foo() {\n" +
797
		"    return <SelectOnName:Object>;\n" +
797
		"    <SelectOnName:Object>;\n" +
798
		"  }\n" +
798
		"  }\n" +
799
		"}\n";
799
		"}\n";
800
800
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java (+45 lines)
Lines 41-46 Link Here
41
	// KIND : all values known by SelectionParser are between 1025 and 1549
41
	// KIND : all values known by SelectionParser are between 1025 and 1549
42
	protected static final int K_BETWEEN_CASE_AND_COLON = SELECTION_PARSER + 1; // whether we are inside a block
42
	protected static final int K_BETWEEN_CASE_AND_COLON = SELECTION_PARSER + 1; // whether we are inside a block
43
	protected static final int K_INSIDE_RETURN_STATEMENT = SELECTION_PARSER + 2; // whether we are between the keyword 'return' and the end of a return statement
43
	protected static final int K_INSIDE_RETURN_STATEMENT = SELECTION_PARSER + 2; // whether we are between the keyword 'return' and the end of a return statement
44
	protected static final int K_CAST_STATEMENT = SELECTION_PARSER + 3; // whether we are between ')' and the end of a cast statement
44
	
45
	
45
46
46
	public ASTNode assistNodeParent; // the parent node of assist node
47
	public ASTNode assistNodeParent; // the parent node of assist node
Lines 129-134 Link Here
129
					this.assistNodeParent = parentNode;
130
					this.assistNodeParent = parentNode;
130
				}
131
				}
131
				break nextElement;
132
				break nextElement;
133
			case K_CAST_STATEMENT :
134
				Expression castType;
135
				if(this.expressionPtr > 0
136
					&& ((castType = this.expressionStack[this.expressionPtr-1]) instanceof TypeReference
137
						|| castType instanceof NameReference)) {
138
					CastExpression cast = new CastExpression(expression, getTypeReference(castType));
139
					cast.sourceStart = castType.sourceStart;
140
					cast.sourceEnd= expression.sourceEnd;
141
					parentNode = cast;
142
					this.assistNodeParent = parentNode;
143
				}
144
				break nextElement;
132
		}
145
		}
133
	}
146
	}
134
	if(parentNode != null) {
147
	if(parentNode != null) {
Lines 249-254 Link Here
249
		this.isOrphanCompletionNode = true;
262
		this.isOrphanCompletionNode = true;
250
	}
263
	}
251
}
264
}
265
protected void consumeCastExpressionLL1() {
266
	popElement(K_CAST_STATEMENT);
267
	super.consumeCastExpressionLL1();
268
}
269
protected void consumeCastExpressionWithGenericsArray() {
270
	popElement(K_CAST_STATEMENT);
271
	super.consumeCastExpressionWithGenericsArray();
272
}
273
protected void consumeCastExpressionWithNameArray() {
274
	popElement(K_CAST_STATEMENT);
275
	super.consumeCastExpressionWithNameArray();
276
}
277
protected void consumeCastExpressionWithPrimitiveType() {
278
	popElement(K_CAST_STATEMENT);
279
	super.consumeCastExpressionWithPrimitiveType();
280
}
281
protected void consumeCastExpressionWithQualifiedGenericsArray() {
282
	popElement(K_CAST_STATEMENT);
283
	super.consumeCastExpressionWithQualifiedGenericsArray();
284
}
252
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
285
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
253
	// ClassInstanceCreationExpression ::= Primary '.' 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
286
	// ClassInstanceCreationExpression ::= Primary '.' 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
254
	// ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
287
	// ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
Lines 562-567 Link Here
562
		this.listLength++;
595
		this.listLength++;
563
	}
596
	}
564
}
597
}
598
protected void consumeInsideCastExpression() {
599
	super.consumeInsideCastExpression();
600
	pushOnElementStack(K_CAST_STATEMENT);
601
}
602
protected void consumeInsideCastExpressionLL1() {
603
	super.consumeInsideCastExpressionLL1();
604
	pushOnElementStack(K_CAST_STATEMENT);
605
}
606
protected void consumeInsideCastExpressionWithQualifiedGenerics() {
607
	super.consumeInsideCastExpressionWithQualifiedGenerics();
608
	pushOnElementStack(K_CAST_STATEMENT);
609
}
565
protected void consumeInstanceOfExpression() {
610
protected void consumeInstanceOfExpression() {
566
	if (indexOfAssistIdentifier() < 0) {
611
	if (indexOfAssistIdentifier() < 0) {
567
		super.consumeInstanceOfExpression();
612
		super.consumeInstanceOfExpression();

Return to bug 255142