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

(-)src/org/eclipse/jdt/core/tests/compiler/parser/GenericsSelectionTest.java (+41 lines)
Lines 893-896 Link Here
893
		expectedReplacedSource,
893
		expectedReplacedSource,
894
		testName);
894
		testName);
895
}
895
}
896
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
897
public void test0023() {
898
899
	String str =
900
		"package test;\n" +
901
		"public class Test  {\n" +
902
		"	public List<String> foo() {\n" +
903
		"		return Collections.emptyList();\n" +
904
		"	}\n" +
905
		"}";
906
907
	String selection = "emptyList";
908
909
	String expectedCompletionNodeToString = "<SelectOnMessageSend:Collections.emptyList()>";
910
911
	String completionIdentifier = "emptyList";
912
	String expectedUnitDisplayString =
913
		"package test;\n" + 
914
		"public class Test {\n" + 
915
		"  public Test() {\n" + 
916
		"  }\n" + 
917
		"  public List<String> foo() {\n" + 
918
		"    return <SelectOnMessageSend:Collections.emptyList()>;\n" + 
919
		"  }\n" + 
920
		"}\n";
921
	String expectedReplacedSource = "Collections.emptyList()";
922
	String testName = "<select method>";
923
924
	int selectionStart = str.lastIndexOf(selection);
925
	int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1;
926
927
	this.checkMethodParse(
928
		str.toCharArray(),
929
		selectionStart,
930
		selectionEnd,
931
		expectedCompletionNodeToString,
932
		expectedUnitDisplayString,
933
		completionIdentifier,
934
		expectedReplacedSource,
935
		testName);
936
}
896
}
937
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java (-3 / +3 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
		"    <SelectOnName:Object>;\n" +
797
		"    return <SelectOnName:Object>;\n" +
798
		"  }\n" +
798
		"  }\n" +
799
		"}\n";
799
		"}\n";
800
800
Lines 1064-1070 Link Here
1064
		"  public G() {\n" +
1064
		"  public G() {\n" +
1065
		"  }\n" +
1065
		"  }\n" +
1066
		"  Object foo() {\n" +
1066
		"  Object foo() {\n" +
1067
		"    <SelectOnSuper:super>;\n" +
1067
		"    return <SelectOnSuper:super>;\n" +
1068
		"  }\n" +
1068
		"  }\n" +
1069
		"}\n";
1069
		"}\n";
1070
1070
Lines 1113-1119 Link Here
1113
		"  Object foo() {\n" +
1113
		"  Object foo() {\n" +
1114
		"    new X() {\n" +
1114
		"    new X() {\n" +
1115
		"      Object bar() {\n" +
1115
		"      Object bar() {\n" +
1116
		"        <SelectOnQualifiedSuper:G.super>;\n" +
1116
		"        return <SelectOnQualifiedSuper:G.super>;\n" +
1117
		"      }\n" +
1117
		"      }\n" +
1118
		"    };\n" +
1118
		"    };\n" +
1119
		"  }\n" +
1119
		"  }\n" +
(-)src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java (+134 lines)
Lines 2775-2778 Link Here
2775
		assertTrue("Unexpected elements", false);
2775
		assertTrue("Unexpected elements", false);
2776
	}
2776
	}
2777
}
2777
}
2778
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
2779
public void test0119() throws Exception {
2780
	this.workingCopies = new ICompilationUnit[3];
2781
	this.workingCopies[0] = getWorkingCopy(
2782
			"/Resolve/src/test/Test.java",
2783
			"package test;\n" +
2784
			"public class Test  {\n" +
2785
			"	public List<String> foo() {\n" +
2786
			"		return Collections.emptyList();\n" +
2787
			"	}\n" +
2788
			"}");
2789
	
2790
	this.workingCopies[1] = getWorkingCopy(
2791
			"/Resolve/src/test/Collections.java",
2792
			"package test;\n" +
2793
			"public class Collections  {\n" +
2794
			"	public static final <T> List<T> emptyList() {return null;}\n" +
2795
			"}");
2796
	
2797
	this.workingCopies[1] = getWorkingCopy(
2798
			"/Resolve/src/test/List.java",
2799
			"package test;\n" +
2800
			"public class List<E>  {\n" +
2801
			"}");
2802
2803
	String str = this.workingCopies[0].getSource();
2804
	int start = str.lastIndexOf("emptyList");
2805
	int length = "emptyList".length();
2806
	IJavaElement[] elements =  this.workingCopies[0].codeSelect(start, length, this.wcOwner);
2807
2808
	assertElementsEqual(
2809
			"Unexpected elements",
2810
			"emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]",
2811
			elements,
2812
			true
2813
		);
2814
}
2815
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
2816
public void test0120() throws Exception {
2817
	this.workingCopies = new ICompilationUnit[3];
2818
	this.workingCopies[0] = getWorkingCopy(
2819
			"/Resolve/src/test/Test.java",
2820
			"package test;\n" +
2821
			"public class Test  {\n" +
2822
			"	public void foo() {\n" +
2823
			"		List<String> local = Collections.emptyList();\n" +
2824
			"	}\n" +
2825
			"}");
2826
	
2827
	this.workingCopies[1] = getWorkingCopy(
2828
			"/Resolve/src/test/Collections.java",
2829
			"package test;\n" +
2830
			"public class Collections  {\n" +
2831
			"	public static final <T> List<T> emptyList() {return null;}\n" +
2832
			"}");
2833
	
2834
	this.workingCopies[1] = getWorkingCopy(
2835
			"/Resolve/src/test/List.java",
2836
			"package test;\n" +
2837
			"public class List<E>  {\n" +
2838
			"}");
2839
2840
	String str = this.workingCopies[0].getSource();
2841
	int start = str.lastIndexOf("emptyList");
2842
	int length = "emptyList".length();
2843
	IJavaElement[] elements =  this.workingCopies[0].codeSelect(start, length, this.wcOwner);
2844
2845
	assertElementsEqual(
2846
			"Unexpected elements",
2847
			"emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]",
2848
			elements,
2849
			true
2850
		);
2851
}
2852
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
2853
public void test0121() throws Exception {
2854
	this.workingCopies = new ICompilationUnit[3];
2855
	this.workingCopies[0] = getWorkingCopy(
2856
			"/Resolve/src/test/Test.java",
2857
			"package test;\n" +
2858
			"public class Test  {\n" +
2859
			"	List<String> field = Collections.emptyList();\n" +
2860
			"	public void foo() {\n" +
2861
			"	}\n" +
2862
			"}");
2863
	
2864
	this.workingCopies[1] = getWorkingCopy(
2865
			"/Resolve/src/test/Collections.java",
2866
			"package test;\n" +
2867
			"public class Collections  {\n" +
2868
			"	public static final <T> List<T> emptyList() {return null;}\n" +
2869
			"}");
2870
	
2871
	this.workingCopies[1] = getWorkingCopy(
2872
			"/Resolve/src/test/List.java",
2873
			"package test;\n" +
2874
			"public class List<E>  {\n" +
2875
			"}");
2876
2877
	String str = this.workingCopies[0].getSource();
2878
	int start = str.lastIndexOf("emptyList");
2879
	int length = "emptyList".length();
2880
	IJavaElement[] elements =  this.workingCopies[0].codeSelect(start, length, this.wcOwner);
2881
2882
	assertElementsEqual(
2883
			"Unexpected elements",
2884
			"emptyList() {key=Ltest/Collections;.emptyList<T:Ljava/lang/Object;>()Ltest/List<TT;>;%<Ljava/lang/String;>} [in Collections [in [Working copy] Collections.java [in test [in src [in Resolve]]]]]",
2885
			elements,
2886
			true
2887
		);
2888
}
2889
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209639
2890
public void test0122() throws Exception {
2891
	this.workingCopies = new ICompilationUnit[1];
2892
	this.workingCopies[0] = getWorkingCopy(
2893
			"/Resolve/src/test/Test.java",
2894
			"package test;\n" +
2895
			"public class Test  {\n" +
2896
			"	static <T> T foo() { return null; }\n" +
2897
			"	String[] strings = { foo() };\n" +
2898
			"}");
2899
2900
	String str = this.workingCopies[0].getSource();
2901
	int start = str.lastIndexOf("foo");
2902
	int length = "foo".length();
2903
	IJavaElement[] elements =  this.workingCopies[0].codeSelect(start, length, this.wcOwner);
2904
2905
	assertElementsEqual(
2906
			"Unexpected elements",
2907
			"foo() {key=Ltest/Test;.foo<T:Ljava/lang/Object;>()TT;%<Ljava/lang/String;>} [in Test [in [Working copy] Test.java [in test [in src [in Resolve]]]]]",
2908
			elements,
2909
			true
2910
		);
2911
}
2778
}
2912
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java (-3 / +24 lines)
Lines 40-45 Link Here
40
40
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
44
	
43
45
44
	public ASTNode assistNodeParent; // the parent node of assist node
46
	public ASTNode assistNodeParent; // the parent node of assist node
45
47
Lines 90-97 Link Here
90
92
91
	int kind = topKnownElementKind(SELECTION_OR_ASSIST_PARSER);
93
	int kind = topKnownElementKind(SELECTION_OR_ASSIST_PARSER);
92
	if(kind != 0) {
94
	if(kind != 0) {
93
//		int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER);
95
		int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER);
94
		switch (kind) {
96
		nextElement : switch (kind) {
95
			case K_BETWEEN_CASE_AND_COLON :
97
			case K_BETWEEN_CASE_AND_COLON :
96
				if(this.expressionPtr > 0) {
98
				if(this.expressionPtr > 0) {
97
					SwitchStatement switchStatement = new SwitchStatement();
99
					SwitchStatement switchStatement = new SwitchStatement();
Lines 119-125 Link Here
119
					parentNode = switchStatement;
121
					parentNode = switchStatement;
120
					this.assistNodeParent = parentNode;
122
					this.assistNodeParent = parentNode;
121
				}
123
				}
122
				break;
124
				break nextElement;
125
			case K_INSIDE_RETURN_STATEMENT :
126
				if(info == this.bracketDepth) {
127
					ReturnStatement returnStatement = new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd);
128
					parentNode = returnStatement;
129
					this.assistNodeParent = parentNode;
130
				}
131
				break nextElement;
123
		}
132
		}
124
	}
133
	}
125
	if(parentNode != null) {
134
	if(parentNode != null) {
Lines 918-923 Link Here
918
					popElement(K_BETWEEN_CASE_AND_COLON);
927
					popElement(K_BETWEEN_CASE_AND_COLON);
919
				}
928
				}
920
				break;
929
				break;
930
			case TokenNamereturn:
931
				pushOnElementStack(K_INSIDE_RETURN_STATEMENT, this.bracketDepth);
932
				break;
933
			case TokenNameSEMICOLON:
934
				switch(topKnownElementKind(SELECTION_OR_ASSIST_PARSER)) {
935
					case K_INSIDE_RETURN_STATEMENT :
936
						if(topKnownElementInfo(SELECTION_OR_ASSIST_PARSER) == this.bracketDepth) {
937
							popElement(K_INSIDE_RETURN_STATEMENT);
938
						}
939
						break;
940
				}
941
				break;
921
		}
942
		}
922
	}
943
	}
923
}
944
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-14 lines)
Lines 135-143 Link Here
135
	// used to find if there is unused modifiers when building completion inside a method or an initializer
135
	// used to find if there is unused modifiers when building completion inside a method or an initializer
136
	boolean hasUnusedModifiers;
136
	boolean hasUnusedModifiers;
137
137
138
	// depth of '(', '{' and '[]'
139
	int bracketDepth;
140
141
	// show if the current token can be an explicit constructor
138
	// show if the current token can be an explicit constructor
142
	int canBeExplicitConstructor = NO;
139
	int canBeExplicitConstructor = NO;
143
	static final int NO = 0;
140
	static final int NO = 0;
Lines 3262-3268 Link Here
3262
				pushOnElementStack(K_BETWEEN_CATCH_AND_RIGHT_PAREN);
3259
				pushOnElementStack(K_BETWEEN_CATCH_AND_RIGHT_PAREN);
3263
				break;
3260
				break;
3264
			case TokenNameLPAREN:
3261
			case TokenNameLPAREN:
3265
				this.bracketDepth++;
3266
				if (this.invocationType == NO_RECEIVER || this.invocationType == NAME_RECEIVER || this.invocationType == SUPER_RECEIVER) {
3262
				if (this.invocationType == NO_RECEIVER || this.invocationType == NAME_RECEIVER || this.invocationType == SUPER_RECEIVER) {
3267
					this.qualifier = this.expressionPtr; // remenber the last expression so that arguments are correctly computed
3263
					this.qualifier = this.expressionPtr; // remenber the last expression so that arguments are correctly computed
3268
				}
3264
				}
Lines 3323-3329 Link Here
3323
				}
3319
				}
3324
				break;
3320
				break;
3325
			case TokenNameLBRACE:
3321
			case TokenNameLBRACE:
3326
				this.bracketDepth++;
3327
				int kind = topKnownElementKind(COMPLETION_OR_ASSIST_PARSER);
3322
				int kind = topKnownElementKind(COMPLETION_OR_ASSIST_PARSER);
3328
				if(kind == K_FIELD_INITIALIZER_DELIMITER
3323
				if(kind == K_FIELD_INITIALIZER_DELIMITER
3329
					|| kind == K_LOCAL_INITIALIZER_DELIMITER
3324
					|| kind == K_LOCAL_INITIALIZER_DELIMITER
Lines 3380-3395 Link Here
3380
						this.qualifier = -1;
3375
						this.qualifier = -1;
3381
					}
3376
					}
3382
				}
3377
				}
3383
				this.bracketDepth++;
3384
				break;
3385
			case TokenNameRBRACE:
3386
				this.bracketDepth--;
3387
				break;
3388
			case TokenNameRBRACKET:
3389
				this.bracketDepth--;
3390
				break;
3378
				break;
3391
			case TokenNameRPAREN:
3379
			case TokenNameRPAREN:
3392
			this.bracketDepth--;
3393
				switch(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER)) {
3380
				switch(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER)) {
3394
					case K_BETWEEN_CATCH_AND_RIGHT_PAREN :
3381
					case K_BETWEEN_CATCH_AND_RIGHT_PAREN :
3395
						popElement(K_BETWEEN_CATCH_AND_RIGHT_PAREN);
3382
						popElement(K_BETWEEN_CATCH_AND_RIGHT_PAREN);
Lines 4209-4215 Link Here
4209
private void initializeForBlockStatements() {
4196
private void initializeForBlockStatements() {
4210
	this.previousToken = -1;
4197
	this.previousToken = -1;
4211
	this.previousIdentifierPtr = -1;
4198
	this.previousIdentifierPtr = -1;
4212
	this.bracketDepth = 0;
4213
	this.invocationType = NO_RECEIVER;
4199
	this.invocationType = NO_RECEIVER;
4214
	this.qualifier = -1;
4200
	this.qualifier = -1;
4215
	popUntilElement(K_SWITCH_LABEL);
4201
	popUntilElement(K_SWITCH_LABEL);
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java (+21 lines)
Lines 42-47 Link Here
42
42
43
	// the index in the identifier stack of the previous identifier
43
	// the index in the identifier stack of the previous identifier
44
	protected int previousIdentifierPtr;
44
	protected int previousIdentifierPtr;
45
	
46
	// depth of '(', '{' and '[]'
47
	protected int bracketDepth;
45
48
46
	// element stack
49
	// element stack
47
	protected static final int ElementStackIncrement = 100;
50
	protected static final int ElementStackIncrement = 100;
Lines 740-745 Link Here
740
	if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) {
743
	if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) {
741
		switch (token) {
744
		switch (token) {
742
			case TokenNameLPAREN :
745
			case TokenNameLPAREN :
746
				this.bracketDepth++;
743
				switch (this.previousToken) {
747
				switch (this.previousToken) {
744
					case TokenNameIdentifier:
748
					case TokenNameIdentifier:
745
						this.pushOnElementStack(K_SELECTOR, this.identifierPtr);
749
						this.pushOnElementStack(K_SELECTOR, this.identifierPtr);
Lines 759-764 Link Here
759
						break;
763
						break;
760
				}
764
				}
761
				break;
765
				break;
766
			case TokenNameLBRACE:
767
				this.bracketDepth++;
768
				break;
769
			case TokenNameLBRACKET:
770
				this.bracketDepth++;
771
				break;
772
			case TokenNameRBRACE:
773
				this.bracketDepth--;
774
				break;
775
			case TokenNameRBRACKET:
776
				this.bracketDepth--;
777
				break;
778
			case TokenNameRPAREN:
779
				this.bracketDepth--;
780
				break;
762
		}
781
		}
763
	} else {
782
	} else {
764
		switch (token) {
783
		switch (token) {
Lines 1119-1130 Link Here
1119
	flushAssistState();
1138
	flushAssistState();
1120
	flushElementStack();
1139
	flushElementStack();
1121
	this.previousIdentifierPtr = -1;
1140
	this.previousIdentifierPtr = -1;
1141
	this.bracketDepth = 0;
1122
}
1142
}
1123
public void initialize(boolean initializeNLS) {
1143
public void initialize(boolean initializeNLS) {
1124
	super.initialize(initializeNLS);
1144
	super.initialize(initializeNLS);
1125
	flushAssistState();
1145
	flushAssistState();
1126
	flushElementStack();
1146
	flushElementStack();
1127
	this.previousIdentifierPtr = -1;
1147
	this.previousIdentifierPtr = -1;
1148
	this.bracketDepth = 0;
1128
}
1149
}
1129
public abstract void initializeScanner();
1150
public abstract void initializeScanner();
1130
protected boolean isIndirectlyInsideFieldInitialization(){
1151
protected boolean isIndirectlyInsideFieldInitialization(){

Return to bug 209639