Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 408230 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java (-1 / +357 lines)
Lines 1-11 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
15
package org.eclipse.jdt.core.tests.model;
Lines 832-837 Link Here
832
	}
836
	}
833
	finally {
837
	finally {
834
		deleteProject("Test342393");
838
		deleteProject("Test342393");
835
	}
839
	}
836
}
840
}
841
// Bug 408230 - [1.8][hovering] NPE on hovering over a type inferred parameter in lambda expression
842
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=408230
843
public void testBug408230a() throws CoreException {
844
	try {
845
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
846
		String source = "package p;\n" +
847
				"public class X {\n" +
848
				"  FI i1 = (a, barg) -> a+barg;\n" +
849
				"}\n" +
850
				"interface FI { int f1(int a, int b); }\n";
851
		createFolder("/P/src/p");
852
		createFile(
853
			"/P/src/p/X.java",
854
			source
855
		);
856
		waitForAutoBuild();
857
		
858
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
859
		String selectString = "barg";
860
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
861
		assertEquals(1, variable.length);
862
	} finally {
863
		deleteProject("P");
864
	}
865
}
866
public void testBug408230b() throws CoreException {
867
	try {
868
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
869
		String source = "package p;\n" +
870
				"public class X {\n" +
871
				"  void foo() {\n" +
872
				"	FI i2 = (a, barg) -> { return a+barg; };\n" +
873
				"  }\n" +
874
				"}\n" +
875
				"interface FI { int f1(int a, int b); }\n";
876
		createFolder("/P/src/p");
877
		createFile(
878
			"/P/src/p/X.java",
879
			source
880
		);
881
		waitForAutoBuild();
882
		
883
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
884
		String selectString = "barg";
885
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
886
		assertEquals(1, variable.length);
887
	} finally {
888
		deleteProject("P");
889
	}
890
}
891
public void testBug408230c() throws CoreException {
892
	try {
893
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
894
		String source = "package p;\n" +
895
				"public class X {\n" +
896
				"  void foo() {\n" +
897
				"	FI i2 = (a, barg) -> { int x = 2; while (x < 2) { x++; } return a+barg; };\n" +
898
				"  }\n" +
899
				"}\n" +
900
				"interface FI { int f1(int a, int b); }\n";
901
		createFolder("/P/src/p");
902
		createFile(
903
			"/P/src/p/X.java",
904
			source
905
		);
906
		waitForAutoBuild();
907
		
908
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
909
		String selectString = "barg";
910
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
911
		assertEquals(1, variable.length);
912
	} finally {
913
		deleteProject("P");
914
	}
915
}
916
public void testBug408230d() throws CoreException {
917
	try {
918
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
919
		String source = "package p;\n" +
920
				"public class X {\n" +
921
				"  FI i1 = (barg) -> ++barg;\n" +
922
				"}\n" +
923
				"interface FI { int f1(int b); }\n";
924
		createFolder("/P/src/p");
925
		createFile(
926
			"/P/src/p/X.java",
927
			source
928
		);
929
		waitForAutoBuild();
930
		
931
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
932
		String selectString = "barg";
933
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
934
		assertEquals(1, variable.length);
935
	} finally {
936
		deleteProject("P");
937
	}
938
}
939
public void testBug408230e() throws CoreException {
940
	try {
941
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
942
		String source = "package p;\n" +
943
				"public class X {\n" +
944
				"  FI i1 = (aarg) -> { return aarg++;};\n" +
945
				"}\n" +
946
				"interface FI { int f1(int a); }\n";
947
		createFolder("/P/src/p");
948
		createFile(
949
			"/P/src/p/X.java",
950
			source
951
		);
952
		waitForAutoBuild();
953
		
954
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
955
		String selectString = "aarg";
956
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
957
		assertEquals(1, variable.length);
958
	} finally {
959
		deleteProject("P");
960
	}
961
}
962
public void testBug408230f() throws CoreException {
963
	try {
964
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
965
		String source = "package p;\n" +
966
				"public class X {\n" +
967
				"  FI i1 = (aarg) -> {  int x = aarg; return aarg++;};\n" +
968
				"}\n" +
969
				"interface FI { int f1(int a); }\n";
970
		createFolder("/P/src/p");
971
		createFile(
972
			"/P/src/p/X.java",
973
			source
974
		);
975
		waitForAutoBuild();
976
		
977
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
978
		String selectString = "aarg";
979
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
980
		assertEquals(1, variable.length);
981
	} finally {
982
		deleteProject("P");
983
	}
984
}
985
public void testBug408230g() throws CoreException {
986
	try {
987
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
988
		String source = "package p;\n" +
989
				"public class X {\n" +
990
				" public void boo(FI fi) {}\n" +
991
				"  void foo() {\n" +
992
				"	boo((aarg) -> aarg++);\n" +
993
				"  }\n" +
994
				"}\n" +
995
				"interface FI { int f1(int a); }\n";
996
		createFolder("/P/src/p");
997
		createFile(
998
			"/P/src/p/X.java",
999
			source
1000
		);
1001
		waitForAutoBuild();
1002
		
1003
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1004
		String selectString = "aarg";
1005
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1006
		assertEquals(1, variable.length);
1007
	} finally {
1008
		deleteProject("P");
1009
	}
1010
}
1011
public void testBug408230h() throws CoreException {
1012
	try {
1013
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1014
		String source = "package p;\n" +
1015
				"public class X {\n" +
1016
				" public void boo(FI fi) {}\n" +
1017
				"  void foo() {\n" +
1018
				"	boo((aarg) -> {int b = 10; return aarg++;});\n" +
1019
				"  }\n" +
1020
				"}\n" +
1021
				"interface FI { int f1(int a); }\n";
1022
		createFolder("/P/src/p");
1023
		createFile(
1024
			"/P/src/p/X.java",
1025
			source
1026
		);
1027
		waitForAutoBuild();
1028
		
1029
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1030
		String selectString = "aarg";
1031
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1032
		assertEquals(1, variable.length);
1033
	} finally {
1034
		deleteProject("P");
1035
	}
1036
}
1037
public void testBug408230i() throws CoreException {
1038
	try {
1039
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1040
		String source = "package p;\n" +
1041
				"public class X {\n" +
1042
				" public void boo(FI fi) {}\n" +
1043
				"  void foo() {\n" +
1044
				"	boo((aarg, x) -> x + aarg++);\n" +
1045
				"  }\n" +
1046
				"}\n" +
1047
				"interface FI { int f1(int a, int b); }\n";
1048
		createFolder("/P/src/p");
1049
		createFile(
1050
			"/P/src/p/X.java",
1051
			source
1052
		);
1053
		waitForAutoBuild();
1054
		
1055
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1056
		String selectString = "aarg";
1057
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1058
		assertEquals(1, variable.length);
1059
	} finally {
1060
		deleteProject("P");
1061
	}
1062
}
1063
public void testBug408230j() throws CoreException {
1064
	try {
1065
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1066
		String source = "package p;\n" +
1067
				"public class X {\n" +
1068
				" public void boo(FI fi) {}\n" +
1069
				"  void foo() {\n" +
1070
				"	boo((aarg, x) -> {int b = 10; return x + aarg++;});\n" +
1071
				"  }\n" +
1072
				"}\n" +
1073
				"interface FI { int f1(int a, int b); }\n";
1074
		createFolder("/P/src/p");
1075
		createFile(
1076
			"/P/src/p/X.java",
1077
			source
1078
		);
1079
		waitForAutoBuild();
1080
		
1081
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1082
		String selectString = "aarg";
1083
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1084
		assertEquals(1, variable.length);
1085
	} finally {
1086
		deleteProject("P");
1087
	}
1088
}
1089
public void testBug408230k() throws CoreException {
1090
	try {
1091
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1092
		String source = "package p;\n" +
1093
				"public class X {\n" +
1094
				" public void boo(int x, int y, FI fi) {}\n" +
1095
				"  void foo() {\n" +
1096
				"	boo(2, 4, (aarg) -> aarg++);\n" +
1097
				"  }\n" +
1098
				"}\n" +
1099
				"interface FI { int f1(int a); }\n";
1100
		createFolder("/P/src/p");
1101
		createFile(
1102
			"/P/src/p/X.java",
1103
			source
1104
		);
1105
		waitForAutoBuild();
1106
		
1107
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1108
		String selectString = "aarg";
1109
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1110
		assertEquals(1, variable.length);
1111
	} finally {
1112
		deleteProject("P");
1113
	}
1114
}
1115
public void testBug408230l() throws CoreException {
1116
	try {
1117
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1118
		String source = "package p;\n" +
1119
				"public class X {\n" +
1120
				" public void boo(int x, FI fi) {}\n" +
1121
				"  void foo() {\n" +
1122
				"	boo(2, (aarg) -> {int b = 10; return aarg++;});\n" +
1123
				"  }\n" +
1124
				"}\n" +
1125
				"interface FI { int f1(int a); }\n";
1126
		createFolder("/P/src/p");
1127
		createFile(
1128
			"/P/src/p/X.java",
1129
			source
1130
		);
1131
		waitForAutoBuild();
1132
		
1133
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1134
		String selectString = "aarg";
1135
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1136
		assertEquals(1, variable.length);
1137
	} finally {
1138
		deleteProject("P");
1139
	}
1140
}
1141
public void testBug408230m() throws CoreException {
1142
	try {
1143
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1144
		String source = "package p;\n" +
1145
				"public class X {\n" +
1146
				" public void boo(int x, int y, FI fi) {}\n" +
1147
				"  void foo() {\n" +
1148
				"	boo(2, 5+6, (aarg, x) -> x + aarg++);\n" +
1149
				"  }\n" +
1150
				"}\n" +
1151
				"interface FI { int f1(int a, int b); }\n";
1152
		createFolder("/P/src/p");
1153
		createFile(
1154
			"/P/src/p/X.java",
1155
			source
1156
		);
1157
		waitForAutoBuild();
1158
		
1159
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1160
		String selectString = "aarg";
1161
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1162
		assertEquals(1, variable.length);
1163
	} finally {
1164
		deleteProject("P");
1165
	}
1166
}
1167
public void testBug408230n() throws CoreException {
1168
	try {
1169
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
1170
		String source = "package p;\n" +
1171
				"public class X {\n" +
1172
				" public void boo(int x, FI fi) {}\n" +
1173
				"  void foo() {\n" +
1174
				"	boo(2, (aarg, x) -> {int b = 10; return x + aarg++;});\n" +
1175
				"  }\n" +
1176
				"}\n" +
1177
				"interface FI { int f1(int a, int b); }\n";
1178
		createFolder("/P/src/p");
1179
		createFile(
1180
			"/P/src/p/X.java",
1181
			source
1182
		);
1183
		waitForAutoBuild();
1184
		
1185
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
1186
		String selectString = "aarg";
1187
		IJavaElement [] variable = ((ICodeAssist) unit).codeSelect(source.lastIndexOf(selectString), selectString.length());
1188
		assertEquals(1, variable.length);
1189
	} finally {
1190
		deleteProject("P");
1191
	}
1192
}
837
}
1193
}
(-)a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-1 / +1 lines)
Lines 1095-1105 Link Here
1095
		int instanceOfIndex = lastIndexOfElement(K_BETWEEN_INSTANCEOF_AND_RPAREN);
1095
		int instanceOfIndex = lastIndexOfElement(K_BETWEEN_INSTANCEOF_AND_RPAREN);
1096
		index = blockIndex != -1 && instanceOfIndex < blockIndex ? blockIndex : instanceOfIndex;
1096
		index = blockIndex != -1 && instanceOfIndex < blockIndex ? blockIndex : instanceOfIndex;
1097
	}
1097
	}
1098
	while (index >= 0) {
1098
	while (index >= 0) {
1099
		// Try to find an enclosing if statement even if one is not found immediately preceding the completion node.
1099
		// Try to find an enclosing if statement even if one is not found immediately preceding the completion node.
1100
		if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) {
1100
		if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null && !(this.elementObjectInfoStack[index] instanceof Integer)) {
1101
			Expression condition = (Expression)this.elementObjectInfoStack[index];
1101
			Expression condition = (Expression)this.elementObjectInfoStack[index];
1102
	
1102
	
1103
			// If currentElement is a RecoveredLocalVariable then it can be contained in the if statement
1103
			// If currentElement is a RecoveredLocalVariable then it can be contained in the if statement
1104
			if (this.currentElement instanceof RecoveredLocalVariable &&
1104
			if (this.currentElement instanceof RecoveredLocalVariable &&
1105
					this.currentElement.parent instanceof RecoveredBlock) {
1105
					this.currentElement.parent instanceof RecoveredBlock) {
(-)a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java (-4 / +106 lines)
Lines 17-26 Link Here
17
/*
17
/*
18
 * Parser extension for code assist task
18
 * Parser extension for code assist task
19
 *
19
 *
20
 */
20
 */
21
21
22
import org.eclipse.jdt.internal.codeassist.select.SelectionOnSingleNameReference;
22
import org.eclipse.jdt.internal.compiler.ast.*;
23
import org.eclipse.jdt.internal.compiler.ast.*;
23
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.jdt.internal.compiler.lookup.Binding;
25
import org.eclipse.jdt.internal.compiler.lookup.Binding;
25
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
26
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
26
import org.eclipse.jdt.internal.compiler.parser.Parser;
27
import org.eclipse.jdt.internal.compiler.parser.Parser;
Lines 70-79 Link Here
70
	protected static final int K_TYPE_DELIMITER = ASSIST_PARSER + 2; // whether we are inside a type declaration
71
	protected static final int K_TYPE_DELIMITER = ASSIST_PARSER + 2; // whether we are inside a type declaration
71
	protected static final int K_METHOD_DELIMITER = ASSIST_PARSER + 3; // whether we are inside a method declaration
72
	protected static final int K_METHOD_DELIMITER = ASSIST_PARSER + 3; // whether we are inside a method declaration
72
	protected static final int K_FIELD_INITIALIZER_DELIMITER = ASSIST_PARSER + 4; // whether we are inside a field initializer
73
	protected static final int K_FIELD_INITIALIZER_DELIMITER = ASSIST_PARSER + 4; // whether we are inside a field initializer
73
	protected static final int K_ATTRIBUTE_VALUE_DELIMITER = ASSIST_PARSER + 5; // whether we are inside a annotation attribute valuer
74
	protected static final int K_ATTRIBUTE_VALUE_DELIMITER = ASSIST_PARSER + 5; // whether we are inside a annotation attribute valuer
74
	protected static final int K_ENUM_CONSTANT_DELIMITER = ASSIST_PARSER + 6; // whether we are inside a field initializer
75
	protected static final int K_ENUM_CONSTANT_DELIMITER = ASSIST_PARSER + 6; // whether we are inside a field initializer
76
	protected static final int K_INSIDE_LAMBDA_EXPRESSION = ASSIST_PARSER + 7; // whether we are inside a field initializer
75
77
76
	// selector constants
78
	// selector constants
77
	protected static final int THIS_CONSTRUCTOR = -1;
79
	protected static final int THIS_CONSTRUCTOR = -1;
78
	protected static final int SUPER_CONSTRUCTOR = -2;
80
	protected static final int SUPER_CONSTRUCTOR = -2;
79
81
Lines 191-201 Link Here
191
				block.sourceStart = lastStart = -this.blockStarts[j];
193
				block.sourceStart = lastStart = -this.blockStarts[j];
192
				element = element.add(block, 1);
194
				element = element.add(block, 1);
193
			}
195
			}
194
			blockIndex = j+1; // shift the index to the new block
196
			blockIndex = j+1; // shift the index to the new block
195
		}
197
		}
196
		if (node instanceof LocalDeclaration){
198
		if (node instanceof Argument && ((Argument)node).hasElidedType()){
199
			Argument local = (Argument) node;
200
			if (local.declarationSourceEnd == 0){
201
				element = element.add(local, 0);
202
				if (local.initialization == null){
203
					this.lastCheckPoint = local.sourceEnd + 1;
204
				} else {
205
					this.lastCheckPoint = local.initialization.sourceEnd + 1;
206
				}
207
			} else {
208
				element = element.add(local, 0);
209
				this.lastCheckPoint = local.declarationSourceEnd + 1;
210
			}
211
			while (i <= this.astPtr && this.astStack[i+1] instanceof Argument && ((Argument)this.astStack[i+1]).hasElidedType()) {
212
				i++;
213
			}
214
			continue;
215
		} else if (node instanceof LocalDeclaration){
197
			LocalDeclaration local = (LocalDeclaration) node;
216
			LocalDeclaration local = (LocalDeclaration) node;
198
			if (local.declarationSourceEnd == 0){
217
			if (local.declarationSourceEnd == 0){
199
				element = element.add(local, 0);
218
				element = element.add(local, 0);
200
				if (local.initialization == null){
219
				if (local.initialization == null){
201
					this.lastCheckPoint = local.sourceEnd + 1;
220
					this.lastCheckPoint = local.sourceEnd + 1;
Lines 769-785 Link Here
769
		switch (token) {
788
		switch (token) {
770
			case TokenNameLPAREN :
789
			case TokenNameLPAREN :
771
				this.bracketDepth++;
790
				this.bracketDepth++;
772
				switch (this.previousToken) {
791
				switch (this.previousToken) {
773
					case TokenNameIdentifier:
792
					case TokenNameIdentifier:
774
						this.pushOnElementStack(K_SELECTOR, this.identifierPtr);
793
						this.pushOnElementStack(K_SELECTOR, this.identifierPtr, new Integer(this.expressionPtr));
775
						break;
794
						break;
776
					case TokenNamethis: // explicit constructor invocation, e.g. this(1, 2)
795
					case TokenNamethis: // explicit constructor invocation, e.g. this(1, 2)
777
						this.pushOnElementStack(K_SELECTOR, THIS_CONSTRUCTOR);
796
						this.pushOnElementStack(K_SELECTOR, THIS_CONSTRUCTOR, new Integer(this.expressionPtr));
778
						break;
797
						break;
779
					case TokenNamesuper: // explicit constructor invocation, e.g. super(1, 2)
798
					case TokenNamesuper: // explicit constructor invocation, e.g. super(1, 2)
780
						this.pushOnElementStack(K_SELECTOR, SUPER_CONSTRUCTOR);
799
						this.pushOnElementStack(K_SELECTOR, SUPER_CONSTRUCTOR, new Integer(this.expressionPtr));
781
						break;
800
						break;
782
					case TokenNameGREATER: // explicit constructor invocation, e.g. Fred<X>[(]1, 2)
801
					case TokenNameGREATER: // explicit constructor invocation, e.g. Fred<X>[(]1, 2)
783
					case TokenNameRIGHT_SHIFT: // or fred<X<X>>[(]1, 2)
802
					case TokenNameRIGHT_SHIFT: // or fred<X<X>>[(]1, 2)
784
					case TokenNameUNSIGNED_RIGHT_SHIFT: //or Fred<X<X<X>>>[(]1, 2)
803
					case TokenNameUNSIGNED_RIGHT_SHIFT: //or Fred<X<X<X>>>[(]1, 2)
785
						if(this.identifierPtr > -1) {
804
						if(this.identifierPtr > -1) {
Lines 814-823 Link Here
814
		}
833
		}
815
	}
834
	}
816
	this.previousToken = token;
835
	this.previousToken = token;
817
	if (token == TokenNameIdentifier) {
836
	if (token == TokenNameIdentifier) {
818
		this.previousIdentifierPtr = this.identifierPtr;
837
		this.previousIdentifierPtr = this.identifierPtr;
838
	} else if (token == TokenNameBeginLambda) {
839
		pushOnElementStack(K_INSIDE_LAMBDA_EXPRESSION, this.expressionPtr);
819
	}
840
	}
820
}
841
}
821
protected void consumeTypeImportOnDemandDeclarationName() {
842
protected void consumeTypeImportOnDemandDeclarationName() {
822
	// TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
843
	// TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
823
	/* push an ImportRef build from the last name
844
	/* push an ImportRef build from the last name
Lines 1736-1745 Link Here
1736
	return null;
1757
	return null;
1737
}
1758
}
1738
protected Object topKnownElementObjectInfo(int owner) {
1759
protected Object topKnownElementObjectInfo(int owner) {
1739
	return topKnownElementObjectInfo(owner, 0);
1760
	return topKnownElementObjectInfo(owner, 0);
1740
}
1761
}
1762
protected void consumeLambdaExpression() {
1763
	super.consumeLambdaExpression();
1764
	popUntilElement(K_INSIDE_LAMBDA_EXPRESSION);
1765
}
1741
/**
1766
/**
1742
 * If the given ast node is inside an explicit constructor call
1767
 * If the given ast node is inside an explicit constructor call
1743
 * then wrap it with a fake constructor call.
1768
 * then wrap it with a fake constructor call.
1744
 * Returns the wrapped completion node or the completion node itself.
1769
 * Returns the wrapped completion node or the completion node itself.
1745
 */
1770
 */
Lines 1759-1764 Link Here
1759
		return call;
1784
		return call;
1760
	} else {
1785
	} else {
1761
		return ast;
1786
		return ast;
1762
	}
1787
	}
1763
}
1788
}
1789
public MessageSend collectLambdaExpressionInformationFromParserWithoutDisturbingStacks () {
1790
	if(this.expressionPtr >= 0 && this.expressionStack[this.expressionPtr] instanceof SelectionOnSingleNameReference) {
1791
		int argumentsRoof = this.elementInfoStack[lastIndexOfElement(K_INSIDE_LAMBDA_EXPRESSION)];
1792
		if (topKnownElementKind(ASSIST_PARSER) == K_SELECTOR || topKnownElementKind(ASSIST_PARSER, 1) == K_SELECTOR || topKnownElementKind(ASSIST_PARSER, 2) == K_SELECTOR) {
1793
			int argumentsFloor = ((Integer)this.elementObjectInfoStack[lastIndexOfElement(K_SELECTOR)]).intValue();
1794
			MessageSend sentMessage = new MessageSend();
1795
			sentMessage.selector = this.identifierStack[this.identifierPtr];
1796
			if (this.expressionPtr > argumentsFloor && argumentsFloor <= argumentsRoof) {
1797
				int noOfSeenArguments = argumentsRoof - argumentsFloor;
1798
				if (noOfSeenArguments > 0) {
1799
					System.arraycopy(this.expressionStack, argumentsFloor + 1, sentMessage.arguments = new Expression[noOfSeenArguments], 0, noOfSeenArguments);
1800
				}
1801
				this.expressionPtr = argumentsFloor;
1802
			}
1803
			return sentMessage;
1804
		}
1805
	}
1806
	return null;
1807
}
1808
public LambdaExpression collectLambdaExpressionInformation () {
1809
	ASTNode arg;
1810
	if(this.expressionPtr >= 0 && this.expressionStack[this.expressionPtr] instanceof SelectionOnSingleNameReference) {
1811
		Argument [] arguments = ASTNode.NO_ARGUMENTS;
1812
		if (this.astPtr >= 0 && this.astStack[this.astPtr] instanceof Argument) {
1813
			arguments = new Argument[this.astLengthStack[this.astLengthPtr]];
1814
			int k;
1815
			for (int i = k = this.astPtr + 1 - this.astLengthStack[this.astLengthPtr], j = this.astPtr; i <= j && (arg = this.astStack[i]) instanceof Argument; i++) {
1816
				arguments[i - k] = (Argument)arg;
1817
			}
1818
1819
		}
1820
		LambdaExpression lExp;
1821
		int argumentsRoof = this.elementInfoStack[lastIndexOfElement(K_INSIDE_LAMBDA_EXPRESSION)];
1822
		popElement(K_INSIDE_LAMBDA_EXPRESSION);
1823
		lExp = new LambdaExpression(this.compilationUnit.compilationResult, arguments, this.expressionStack[this.expressionPtr--]);
1824
		this.expressionLengthPtr--;
1825
		if (topKnownElementKind(ASSIST_PARSER) == K_SELECTOR) {
1826
			int argumentsFloor = ((Integer)this.elementObjectInfoStack[lastIndexOfElement(K_SELECTOR)]).intValue();
1827
			lExp.sentMessage = new MessageSend();
1828
			lExp.sentMessage.selector = this.identifierStack[this.identifierPtr];
1829
			if (this.expressionPtr > argumentsFloor && argumentsFloor <= argumentsRoof) {
1830
				int noOfSeenArguments = argumentsRoof - argumentsFloor;
1831
				if (noOfSeenArguments > 0) {
1832
					System.arraycopy(this.expressionStack, argumentsFloor + 1, lExp.sentMessage.arguments = new Expression[noOfSeenArguments], 0, noOfSeenArguments);
1833
				}
1834
				this.expressionPtr = argumentsFloor;
1835
				this.expressionLengthPtr--;
1836
			}
1837
		}
1838
		return lExp;
1839
	}
1840
	return null;
1841
}
1842
public Argument [] getLambdaArgumentsOnwards (Argument arg) {
1843
	boolean started = false;
1844
	ASTNode [] nodeStack = this.astStack;
1845
	Argument [] lArgs = null;
1846
	for (int i = 0, j = this.astPtr; i <= j; i++) {
1847
		if (started) {
1848
			if( nodeStack[i] instanceof Argument && ((Argument)nodeStack[i]).hasElidedType()) {
1849
				if (lArgs == null) {
1850
					lArgs = new Argument[1];
1851
				} else {
1852
					int len = lArgs.length;
1853
					System.arraycopy(lArgs, 0, lArgs = new Argument[len + 1], 0, len);
1854
				}
1855
				lArgs[lArgs.length - 1] = (Argument)nodeStack[i];
1856
			} else {
1857
				return lArgs;
1858
			}
1859
		}
1860
		if (nodeStack[i] == arg) {
1861
			started = true;
1862
		}
1863
	}
1864
	return lArgs;
1865
}
1764
}
1866
}
(-)a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java (-1 / +9 lines)
Lines 25-35 Link Here
25
 */
25
 */
26
26
27
import org.eclipse.jdt.internal.compiler.*;
27
import org.eclipse.jdt.internal.compiler.*;
28
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
28
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
29
import org.eclipse.jdt.internal.compiler.env.*;
29
import org.eclipse.jdt.internal.compiler.env.*;
30
31
import org.eclipse.jdt.core.compiler.CharOperation;
30
import org.eclipse.jdt.core.compiler.CharOperation;
32
import org.eclipse.jdt.internal.codeassist.impl.*;
31
import org.eclipse.jdt.internal.codeassist.impl.*;
33
import org.eclipse.jdt.internal.compiler.ast.*;
32
import org.eclipse.jdt.internal.compiler.ast.*;
34
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
33
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
35
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
34
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
Lines 142-151 Link Here
142
					cast.sourceStart = castType.sourceStart;
141
					cast.sourceStart = castType.sourceStart;
143
					cast.sourceEnd= expression.sourceEnd;
142
					cast.sourceEnd= expression.sourceEnd;
144
					parentNode = cast;
143
					parentNode = cast;
145
					this.assistNodeParent = parentNode;
144
					this.assistNodeParent = parentNode;
146
				}
145
				}
146
				break nextElement;
147
			case K_INSIDE_LAMBDA_EXPRESSION :
148
				this.assistNodeParent = parentNode = collectLambdaExpressionInformation();
147
				break nextElement;
149
				break nextElement;
148
		}
150
		}
149
	}
151
	}
150
	if(parentNode != null) {
152
	if(parentNode != null) {
151
		this.currentElement = this.currentElement.add((Statement)parentNode, 0);
153
		this.currentElement = this.currentElement.add((Statement)parentNode, 0);
Lines 1434-1443 Link Here
1434
		this action is also performed when shifting token after recovery
1436
		this action is also performed when shifting token after recovery
1435
		got activated once.
1437
		got activated once.
1436
	*/
1438
	*/
1437
	recoveryTokenCheck();
1439
	recoveryTokenCheck();
1438
}
1440
}
1441
protected void consumeTypeElidedLambdaParameter(boolean parenthesized) {
1442
	if (this.astPtr > -1 && this.astStack[this.astPtr] instanceof LocalDeclaration) {
1443
		this.astStack[this.astPtr].bits |= ASTNode.IsInitializedByLamdaExpression;
1444
	}
1445
	super.consumeTypeElidedLambdaParameter(parenthesized);
1446
}
1439
1447
1440
public  String toString() {
1448
public  String toString() {
1441
	String s = Util.EMPTY_STRING;
1449
	String s = Util.EMPTY_STRING;
1442
	s = s + "elementKindStack : int[] = {"; //$NON-NLS-1$
1450
	s = s + "elementKindStack : int[] = {"; //$NON-NLS-1$
1443
	for (int i = 0; i <= this.elementPtr; i++) {
1451
	for (int i = 0; i <= this.elementPtr; i++) {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (-1 / +2 lines)
Lines 69-79 Link Here
69
	public final static int Bit3 = 0x4;					// return type (operator) | name reference kind (name ref) | implicit this (this ref) | is argument(local)
69
	public final static int Bit3 = 0x4;					// return type (operator) | name reference kind (name ref) | implicit this (this ref) | is argument(local)
70
	public final static int Bit4 = 0x8;					// return type (operator) | first assignment to local (name ref,local decl) | undocumented empty block (block, type and method decl)
70
	public final static int Bit4 = 0x8;					// return type (operator) | first assignment to local (name ref,local decl) | undocumented empty block (block, type and method decl)
71
	public final static int Bit5 = 0x10;					// value for return (expression) | has all method bodies (unit) | supertype ref (type ref) | resolved (field decl)
71
	public final static int Bit5 = 0x10;					// value for return (expression) | has all method bodies (unit) | supertype ref (type ref) | resolved (field decl)
72
	public final static int Bit6 = 0x20;					// depth (name ref, msg) | ignore need cast check (cast expression) | error in signature (method declaration/ initializer) | is recovered (annotation reference)
72
	public final static int Bit6 = 0x20;					// depth (name ref, msg) | ignore need cast check (cast expression) | error in signature (method declaration/ initializer) | is recovered (annotation reference)
73
	public final static int Bit7 = 0x40;					// depth (name ref, msg) | operator (operator) | need runtime checkcast (cast expression) | label used (labelStatement) | needFreeReturn (AbstractMethodDeclaration)
73
	public final static int Bit7 = 0x40;					// depth (name ref, msg) | operator (operator) | need runtime checkcast (cast expression) | label used (labelStatement) | needFreeReturn (AbstractMethodDeclaration)
74
	public final static int Bit8 = 0x80;					// depth (name ref, msg) | operator (operator) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement)
74
	public final static int Bit8 = 0x80;					// depth (name ref, msg) | operator (operator) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement) | IsInitializedByLambdaExpression (local declaration)
75
	public final static int Bit9 = 0x100;				// depth (name ref, msg) | operator (operator) | is local type (type decl) | isThenStatementUnreachable (if statement) | can be static
75
	public final static int Bit9 = 0x100;				// depth (name ref, msg) | operator (operator) | is local type (type decl) | isThenStatementUnreachable (if statement) | can be static
76
	public final static int Bit10= 0x200;				// depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
76
	public final static int Bit10= 0x200;				// depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
77
	public final static int Bit11 = 0x400;				// depth (name ref, msg) | operator (operator) | is member type (type decl)
77
	public final static int Bit11 = 0x400;				// depth (name ref, msg) | operator (operator) | is member type (type decl)
78
	public final static int Bit12 = 0x800;				// depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
78
	public final static int Bit12 = 0x800;				// depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
79
	public final static int Bit13 = 0x1000;			// depth (name ref, msg) | is secondary type (type decl)
79
	public final static int Bit13 = 0x1000;			// depth (name ref, msg) | is secondary type (type decl)
Lines 154-163 Link Here
154
	public static final int IsTypeElided = Bit2;  // type elided lambda argument.
154
	public static final int IsTypeElided = Bit2;  // type elided lambda argument.
155
	public static final int IsArgument = Bit3;
155
	public static final int IsArgument = Bit3;
156
	public static final int IsLocalDeclarationReachable = Bit31;
156
	public static final int IsLocalDeclarationReachable = Bit31;
157
	public static final int IsForeachElementVariable = Bit5;
157
	public static final int IsForeachElementVariable = Bit5;
158
	public static final int ShadowsOuterLocal = Bit22;
158
	public static final int ShadowsOuterLocal = Bit22;
159
	public static final int IsInitializedByLamdaExpression = Bit8;
159
160
160
	// for name refs or local decls
161
	// for name refs or local decls
161
	public static final int FirstAssignmentToLocal = Bit4;
162
	public static final int FirstAssignmentToLocal = Bit4;
162
163
163
	// for msg or field references
164
	// for msg or field references
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java (-4 / +58 lines)
Lines 34-43 Link Here
34
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
34
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
35
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
35
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
36
import org.eclipse.jdt.internal.compiler.impl.Constant;
36
import org.eclipse.jdt.internal.compiler.impl.Constant;
37
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
37
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
38
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.Binding;
40
import org.eclipse.jdt.internal.compiler.lookup.Binding;
40
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
41
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
41
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
42
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
42
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
43
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
43
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
44
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
Lines 77-86 Link Here
77
	private LambdaExpression original = this;
78
	private LambdaExpression original = this;
78
	private SyntheticArgumentBinding[] outerLocalVariables = NO_SYNTHETIC_ARGUMENTS;
79
	private SyntheticArgumentBinding[] outerLocalVariables = NO_SYNTHETIC_ARGUMENTS;
79
	private int outerLocalVariablesSlotSize = 0;
80
	private int outerLocalVariablesSlotSize = 0;
80
	public boolean shouldCaptureInstance = false;
81
	public boolean shouldCaptureInstance = false;
81
	private static final SyntheticArgumentBinding [] NO_SYNTHETIC_ARGUMENTS = new SyntheticArgumentBinding[0];
82
	private static final SyntheticArgumentBinding [] NO_SYNTHETIC_ARGUMENTS = new SyntheticArgumentBinding[0];
83
	public MessageSend sentMessage = null;
82
	
84
	
83
	public LambdaExpression(CompilationResult compilationResult, Argument [] arguments, Statement body) {
85
	public LambdaExpression(CompilationResult compilationResult, Argument [] arguments, Statement body) {
84
		super(compilationResult);
86
		super(compilationResult);
85
		this.arguments = arguments != null ? arguments : ASTNode.NO_ARGUMENTS;
87
		this.arguments = arguments != null ? arguments : ASTNode.NO_ARGUMENTS;
86
		this.body = body;
88
		this.body = body;
Lines 128-138 Link Here
128
				currentScope.problemReporter().lambdaExpressionCannotImplementGenericMethod(this, sam);
130
				currentScope.problemReporter().lambdaExpressionCannotImplementGenericMethod(this, sam);
129
			return false;
131
			return false;
130
		}
132
		}
131
		return super.kosherDescriptor(currentScope, sam, shouldChatter);
133
		return super.kosherDescriptor(currentScope, sam, shouldChatter);
132
	}
134
	}
133
	
135
136
	private void handleSelectionNode (BlockScope blockScope) {
137
		final int smallQSize = 10;
138
		MessageSend msgSend = this.sentMessage;
139
		ReferenceBinding [] typeArray = new ReferenceBinding[smallQSize];
140
		int typeArrayIndx = 0, typeArrayMax = 0;
141
		typeArray[0] = this.scope.classScope().enclosingReceiverType();
142
		do {
143
			if (!typeArray[typeArrayIndx].compoundName.equals(JAVA_LANG_OBJECT)) {
144
				MethodBinding [] methods = typeArray[typeArrayIndx].methods();
145
				for (int i = 0, j = methods.length, noOfArgsSeen = msgSend.arguments == null ? 0 : msgSend.arguments.length; i < j; i++) {
146
					TypeBinding [] params = null;
147
					if (methods[i].selector.equals(msgSend.selector) && (params = methods[i].parameters) != null && params.length > noOfArgsSeen && (this.descriptor = params[noOfArgsSeen].getSingleAbstractMethod(blockScope)) != null) {
148
						this.expectedType = this.resolvedType = params[noOfArgsSeen];
149
						i = j;
150
					}
151
				}
152
				if (this.descriptor == null) {
153
					ReferenceBinding sc = null;
154
					ReferenceBinding [] si = null;
155
					if (typeArray[typeArrayIndx] instanceof SourceTypeBinding) {
156
						sc = ((SourceTypeBinding)typeArray[typeArrayIndx]).superclass();
157
						si = ((SourceTypeBinding)typeArray[typeArrayIndx]).superInterfaces();
158
					} else if (typeArray[typeArrayIndx] instanceof BinaryTypeBinding) {
159
						sc = ((BinaryTypeBinding)typeArray[typeArrayIndx]).superclass();
160
						si = ((BinaryTypeBinding)typeArray[typeArrayIndx]).superInterfaces();
161
					}
162
					int additionalLength = (si == null ? 0 : si.length) + (sc == null ? 0 : 1);
163
					if (typeArrayMax + 1 + additionalLength > typeArray.length) {
164
						System.arraycopy(typeArray, typeArrayIndx + 1, 
165
								typeArrayMax - typeArrayIndx + 1 + additionalLength <= typeArray.length ? 
166
										typeArray : (typeArray = new ReferenceBinding[typeArrayMax - typeArrayIndx + (additionalLength > smallQSize ? additionalLength : smallQSize)]), 
167
								0, typeArrayMax - typeArrayIndx);
168
						typeArrayMax -= (typeArrayIndx + 1);
169
						typeArrayIndx = -1;
170
					}
171
					if (sc != null){
172
						typeArray[++typeArrayMax] = sc;
173
					}
174
					if (si != null && si.length > 0) {
175
						System.arraycopy(si, 0, typeArray, ++typeArrayMax, si.length);
176
						typeArrayMax += si.length - 1;
177
					}
178
				}
179
				typeArrayIndx++;
180
			}
181
		} while (this.descriptor == null && typeArrayIndx <= typeArrayMax);
182
	}
183
134
	/* This code is arranged so that we can continue with as much analysis as possible while avoiding 
184
	/* This code is arranged so that we can continue with as much analysis as possible while avoiding 
135
	 * mine fields that would result in a slew of spurious messages. This method is a merger of:
185
	 * mine fields that would result in a slew of spurious messages. This method is a merger of:
136
	 * @see org.eclipse.jdt.internal.compiler.lookup.MethodScope.createMethod(AbstractMethodDeclaration)
186
	 * @see org.eclipse.jdt.internal.compiler.lookup.MethodScope.createMethod(AbstractMethodDeclaration)
137
	 * @see org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(MethodBinding)
187
	 * @see org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(MethodBinding)
138
	 * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(ClassScope)
188
	 * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(ClassScope)
Lines 156-167 Link Here
156
		final boolean haveDescriptor = this.descriptor != null;
206
		final boolean haveDescriptor = this.descriptor != null;
157
		
207
		
158
		if (haveDescriptor && this.descriptor.typeVariables != Binding.NO_TYPE_VARIABLES) // already complained in kosher*
208
		if (haveDescriptor && this.descriptor.typeVariables != Binding.NO_TYPE_VARIABLES) // already complained in kosher*
159
			return null;
209
			return null;
160
		
210
		
161
		if (!haveDescriptor && argumentsTypeElided) 
211
		if (!haveDescriptor && argumentsTypeElided) {
162
			return null; // FUBAR, bail out...
212
			if (this.sentMessage == null) {
213
				return null; // FUBAR, bail out...
214
			}
215
			handleSelectionNode(blockScope);
216
		}
163
217
164
		this.binding = new MethodBinding(ClassFileConstants.AccPrivate | ClassFileConstants.AccSynthetic | ExtraCompilerModifiers.AccUnresolved,
218
		this.binding = new MethodBinding(ClassFileConstants.AccPrivate | ClassFileConstants.AccSynthetic | ExtraCompilerModifiers.AccUnresolved,
165
							TypeConstants.ANONYMOUS_METHOD, // will be fixed up later.
219
							TypeConstants.ANONYMOUS_METHOD, // will be fixed up later.
166
							haveDescriptor ? this.descriptor.returnType : null, 
220
							haveDescriptor ? this.descriptor.returnType : null, 
167
							Binding.NO_PARAMETERS, // for now. 
221
							Binding.NO_PARAMETERS, // for now. 
Lines 194-204 Link Here
194
					buggyArguments = true;
248
					buggyArguments = true;
195
				}
249
				}
196
			}
250
			}
197
			
251
			
198
			TypeBinding parameterType;
252
			TypeBinding parameterType;
199
			final TypeBinding expectedParameterType = haveDescriptor && i < this.descriptor.parameters.length ? this.descriptor.parameters[i] : null;
253
			final TypeBinding expectedParameterType = this.descriptor != null && i < this.descriptor.parameters.length ? this.descriptor.parameters[i] : null;
200
			parameterType = argumentsTypeElided ? expectedParameterType : argument.type.resolveType(this.scope, true /* check bounds*/);
254
			parameterType = argumentsTypeElided ? expectedParameterType : argument.type.resolveType(this.scope, true /* check bounds*/);
201
			if (parameterType == null) {
255
			if (parameterType == null) {
202
				buggyArguments = true;
256
				buggyArguments = true;
203
			} else if (parameterType == TypeBinding.VOID) {
257
			} else if (parameterType == TypeBinding.VOID) {
204
				this.scope.problemReporter().argumentTypeCannotBeVoid(this, argument);
258
				this.scope.problemReporter().argumentTypeCannotBeVoid(this, argument);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java (-10 / +88 lines)
Lines 1-26 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
15
package org.eclipse.jdt.internal.compiler.parser;
12
16
13
import java.util.HashSet;
17
import java.util.HashSet;
14
import java.util.Set;
18
import java.util.Set;
15
19
16
import org.eclipse.jdt.core.compiler.*;
20
import org.eclipse.jdt.core.compiler.*;
21
import org.eclipse.jdt.internal.codeassist.impl.AssistParser;
17
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
22
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.Argument;
23
import org.eclipse.jdt.internal.compiler.ast.Argument;
19
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
24
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
20
import org.eclipse.jdt.internal.compiler.ast.Block;
25
import org.eclipse.jdt.internal.compiler.ast.Block;
21
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
26
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
27
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
22
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
28
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
23
import org.eclipse.jdt.internal.compiler.ast.Statement;
29
import org.eclipse.jdt.internal.compiler.ast.Statement;
24
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
30
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
31
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
Lines 29-39 Link Here
29
35
30
	public Block blockDeclaration;
36
	public Block blockDeclaration;
31
	public RecoveredStatement[] statements;
37
	public RecoveredStatement[] statements;
32
	public int statementCount;
38
	public int statementCount;
33
	public boolean preserveContent = false;
39
	public boolean preserveContent = false;
34
	public RecoveredLocalVariable pendingArgument;
40
	public RecoveredLocalVariable [] pendingArguments = null;
35
41
36
	int pendingModifiers;
42
	int pendingModifiers;
37
	int pendingModifersSourceStart = -1;
43
	int pendingModifersSourceStart = -1;
38
	RecoveredAnnotation[] pendingAnnotations;
44
	RecoveredAnnotation[] pendingAnnotations;
39
	int pendingAnnotationCount;
45
	int pendingAnnotationCount;
Lines 54-63 Link Here
54
			return this; // ignore this element
60
			return this; // ignore this element
55
		}
61
		}
56
	}
62
	}
57
	return super.add(methodDeclaration, bracketBalanceValue);
63
	return super.add(methodDeclaration, bracketBalanceValue);
58
}
64
}
65
public void addPendingArgument(RecoveredLocalVariable pendingArg) {
66
	if (this.pendingArguments == null) {
67
		RecoveredLocalVariable recoveredLocalVariable [] = {pendingArg};
68
		this.pendingArguments = recoveredLocalVariable;
69
	}
70
	else {
71
		int length = this.pendingArguments.length;
72
		System.arraycopy(this.pendingArguments, 0, this.pendingArguments = new RecoveredLocalVariable[length+1], 0, length);
73
		this.pendingArguments[length] = pendingArg;
74
	}
75
}
59
/*
76
/*
60
 * Record a nested block declaration
77
 * Record a nested block declaration
61
 */
78
 */
62
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {
79
public RecoveredElement add(Block nestedBlockDeclaration, int bracketBalanceValue) {
63
	resetPendingModifiers();
80
	resetPendingModifiers();
Lines 70-82 Link Here
70
	}
87
	}
71
88
72
	RecoveredBlock element = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue);
89
	RecoveredBlock element = new RecoveredBlock(nestedBlockDeclaration, this, bracketBalanceValue);
73
90
74
	// if we have a pending Argument, promote it into the new block
91
	// if we have a pending Argument, promote it into the new block
75
	if (this.pendingArgument != null){
92
	if (this.pendingArguments != null) {
76
		element.attach(this.pendingArgument);
93
		for (int indx = 0; indx < this.pendingArguments.length; indx++) {
77
		this.pendingArgument = null;
94
			element.attach(this.pendingArguments[indx]);			
95
		}
96
		this.pendingArguments = null;
78
	}
97
	}
79
	if(parser().statementRecoveryActivated) {
98
	if(parser().statementRecoveryActivated) {
80
		addBlockStatement(element);
99
		addBlockStatement(element);
81
	}
100
	}
82
	attach(element);
101
	attach(element);
Lines 129-139 Link Here
129
				this.pendingModifersSourceStart);
148
				this.pendingModifersSourceStart);
130
	}
149
	}
131
	resetPendingModifiers();
150
	resetPendingModifiers();
132
151
133
	if (localDeclaration instanceof Argument){
152
	if (localDeclaration instanceof Argument){
134
		this.pendingArgument = element;
153
		if (((Argument)localDeclaration).hasElidedType()) {
154
			RecoveredLambdaExpression rLexp = new RecoveredLambdaExpression(new Block(0), this, bracketBalanceValue);
155
			Parser currParser = parser();
156
			if (currParser instanceof AssistParser) {
157
				AssistParser aParser = (AssistParser)currParser;
158
				rLexp.sentMessage = aParser.collectLambdaExpressionInformationFromParserWithoutDisturbingStacks();
159
				rLexp.insertLambdaArgument((Argument)localDeclaration);
160
				rLexp.insertLambdaArgument(aParser.getLambdaArgumentsOnwards((Argument)localDeclaration));
161
			}
162
			attach(rLexp);
163
			return rLexp;
164
		}
165
		addPendingArgument(element);
135
		return this;
166
		return this;
136
	}
167
	}
137
168
138
	attach(element);
169
	attach(element);
139
	if (localDeclaration.declarationSourceEnd == 0) return element;
170
	if (localDeclaration.declarationSourceEnd == 0) return element;
Lines 277-287 Link Here
277
	return result.toString();
308
	return result.toString();
278
}
309
}
279
/*
310
/*
280
 * Rebuild a block from the nested structure which is in scope
311
 * Rebuild a block from the nested structure which is in scope
281
 */
312
 */
282
public Block updatedBlock(int depth, Set knownTypes){
313
public Block updatedBlock(int depth, Set knownTypes) {
314
	return updatedBlock(depth, knownTypes, false);
315
}
316
public Block updatedBlock(int depth, Set knownTypes, boolean lambdaExpressionExpected) {
283
317
284
	// if block was not marked to be preserved or empty, then ignore it
318
	// if block was not marked to be preserved or empty, then ignore it
285
	if (!this.preserveContent || this.statementCount == 0) return null;
319
	if (!this.preserveContent || this.statementCount == 0) return null;
286
320
287
	Statement[] updatedStatements = new Statement[this.statementCount];
321
	Statement[] updatedStatements = new Statement[this.statementCount];
Lines 323-335 Link Here
323
357
324
	int lastEnd = this.blockDeclaration.sourceStart;
358
	int lastEnd = this.blockDeclaration.sourceStart;
325
359
326
	// only collect the non-null updated statements
360
	// only collect the non-null updated statements
327
	for (int i = 0; i < this.statementCount; i++){
361
	for (int i = 0; i < this.statementCount; i++){
328
		Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes);
362
		boolean lambdaExprInit = i > 0 && lambdaExpressionInitializable(this.statements[i-1]);
363
		Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes, lambdaExprInit);
329
		if (updatedStatement != null){
364
		if (updatedStatement != null){
330
			updatedStatements[updatedCount++] = updatedStatement;
365
			LambdaExpression lambdaExpr = getLambdaExpression(updatedStatement);
366
			if (lambdaExprInit && lambdaExpr != null) {
367
				((LocalDeclaration)updatedStatements[updatedCount-1]).initialization = lambdaExpr;
368
			}
369
			else {
370
				updatedStatements[updatedCount++] = updatedStatement;
371
			}
331
372
332
			if (updatedStatement instanceof LocalDeclaration) {
373
			if (updatedStatement instanceof LocalDeclaration) {
333
				LocalDeclaration localDeclaration = (LocalDeclaration) updatedStatement;
374
				LocalDeclaration localDeclaration = (LocalDeclaration) updatedStatement;
334
				if(localDeclaration.declarationSourceEnd > lastEnd) {
375
				if(localDeclaration.declarationSourceEnd > lastEnd) {
335
					lastEnd = localDeclaration.declarationSourceEnd;
376
					lastEnd = localDeclaration.declarationSourceEnd;
Lines 351-361 Link Here
351
	// resize statement collection if necessary
392
	// resize statement collection if necessary
352
	if (updatedCount != this.statementCount){
393
	if (updatedCount != this.statementCount){
353
		this.blockDeclaration.statements = new Statement[updatedCount];
394
		this.blockDeclaration.statements = new Statement[updatedCount];
354
		System.arraycopy(updatedStatements, 0, this.blockDeclaration.statements, 0, updatedCount);
395
		System.arraycopy(updatedStatements, 0, this.blockDeclaration.statements, 0, updatedCount);
355
	} else {
396
	} else {
356
		this.blockDeclaration.statements = updatedStatements;
397
		LambdaExpression lambda = null;
398
		if (lambdaExpressionExpected && !(updatedStatements[0] instanceof LambdaExpression) && (lambda = canGetLambdaExpression(updatedStatements, updatedCount)) != null) {
399
			Statement [] stmt = {lambda};
400
			this.blockDeclaration.statements = stmt;
401
		}
402
		else {
403
			this.blockDeclaration.statements = updatedStatements;
404
		}
357
	}
405
	}
358
406
359
	if (this.blockDeclaration.sourceEnd == 0) {
407
	if (this.blockDeclaration.sourceEnd == 0) {
360
		if(lastEnd < bodyEndValue) {
408
		if(lastEnd < bodyEndValue) {
361
			this.blockDeclaration.sourceEnd = bodyEndValue;
409
			this.blockDeclaration.sourceEnd = bodyEndValue;
Lines 364-380 Link Here
364
		}
412
		}
365
	}
413
	}
366
414
367
	return this.blockDeclaration;
415
	return this.blockDeclaration;
368
}
416
}
417
public LambdaExpression getLambdaExpression (Statement stmnt) {
418
	if (stmnt instanceof LambdaExpression) {
419
		return (LambdaExpression)stmnt;
420
	}
421
	else if (stmnt instanceof Block && ((Block)stmnt).statements[0] instanceof LambdaExpression) {
422
		return (LambdaExpression)((Block)stmnt).statements[0];
423
	}
424
	return null;
425
}
426
public LambdaExpression canGetLambdaExpression (Statement [] statementsArray, int count) {
427
	for (int indx = 0; indx < count - 1; indx++) {
428
		if (!(statementsArray[indx] instanceof Argument)) {
429
			return null;
430
		}
431
	}
432
	Argument [] arguments = new Argument [count-1];
433
	System.arraycopy(statementsArray, 0, arguments, 0, count-1);
434
	return new LambdaExpression(parser().compilationUnit.compilationResult, arguments, statementsArray[count-1]);
435
}
369
/*
436
/*
370
 * Rebuild a statement from the nested structure which is in scope
437
 * Rebuild a statement from the nested structure which is in scope
371
 */
438
 */
372
public Statement updatedStatement(int depth, Set knownTypes){
439
public Statement updatedStatement(int depth, Set knownTypes){
373
440
374
	return updatedBlock(depth, knownTypes);
441
	return updatedBlock(depth, knownTypes);
375
}
442
}
443
public Statement updatedStatement(int depth, Set knownTypes, boolean lambdaExpressionExpected) {
444
445
	return lambdaExpressionExpected ? updatedBlock(depth, knownTypes, true) : updatedStatement(depth, knownTypes);
446
}
447
boolean lambdaExpressionInitializable(RecoveredStatement stmnt) {
448
	if (stmnt instanceof RecoveredLocalVariable) {
449
		RecoveredLocalVariable recLocVar = (RecoveredLocalVariable) stmnt;
450
		return recLocVar.localDeclaration != null && (recLocVar.localDeclaration.bits & ASTNode.IsInitializedByLamdaExpression) != 0;
451
	}
452
	return false;
453
}
376
/*
454
/*
377
 * A closing brace got consumed, might have closed the current element,
455
 * A closing brace got consumed, might have closed the current element,
378
 * in which case both the currentElement is exited
456
 * in which case both the currentElement is exited
379
 */
457
 */
380
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
458
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredLambdaExpression.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.internal.compiler.parser;
16
17
import java.util.Set;
18
19
import org.eclipse.jdt.internal.compiler.ast.Argument;
20
import org.eclipse.jdt.internal.compiler.ast.Block;
21
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
22
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
23
import org.eclipse.jdt.internal.compiler.ast.Statement;
24
25
public class RecoveredLambdaExpression extends RecoveredBlock {
26
	
27
	public Argument [] lambdaArguments = null;
28
	public MessageSend sentMessage = null;
29
30
	public RecoveredLambdaExpression(Block block, RecoveredElement parent, int bracketBalance) {
31
		super(block, parent, bracketBalance);
32
	}
33
34
	public void insertLambdaArgument (Argument arg) {
35
		if (this.lambdaArguments == null) {
36
			(this.lambdaArguments = new Argument[1])[0] = arg;
37
		} else {
38
			int len;
39
			System.arraycopy(this.lambdaArguments, 0, this.lambdaArguments = new Argument[(len = this.lambdaArguments.length) + 1], 0, len);
40
			this.lambdaArguments[len] = arg;
41
		}
42
	}
43
	
44
	public void insertLambdaArgument (Argument [] args) {
45
		if (args != null) {
46
			if (this.lambdaArguments == null) {
47
				this.lambdaArguments = args;
48
			} else {
49
				int len = this.lambdaArguments.length;
50
				System.arraycopy(this.lambdaArguments, 0, this.lambdaArguments = new Argument[len + args.length], 0, len);
51
				System.arraycopy(args, 0, this.lambdaArguments, len, args.length);
52
			}
53
		}
54
	}
55
	
56
	public Statement updatedStatement(int depth, Set knownTypes, boolean lambdaExpressionExpected) {
57
		return updatedBlock(depth, knownTypes, true);
58
	}
59
	
60
	public LambdaExpression canGetLambdaExpression (Statement [] statementsArray, int count) {
61
		if (statementsArray.length == 1 && this.lambdaArguments != null) {
62
			LambdaExpression lExp = new LambdaExpression(parser().compilationUnit.compilationResult, this.lambdaArguments, statementsArray[0]);
63
			lExp.sentMessage = this.sentMessage;
64
			return lExp;
65
		}
66
		return super.canGetLambdaExpression(statementsArray, count);
67
	}
68
	
69
	public String toString(int tab) {
70
		StringBuffer result = new StringBuffer(tabString(tab));
71
		result.append("Recovered Lambda Expression:\n"); //$NON-NLS-1$
72
		this.blockDeclaration.print(tab + 1, result);
73
		if (this.statements != null) {
74
			for (int i = 0; i < this.statementCount; i++) {
75
				result.append("\n"); //$NON-NLS-1$
76
				result.append(this.statements[i].toString(tab + 1));
77
			}
78
		}
79
		return result.toString();
80
	}
81
82
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java (-1 / +8 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
15
package org.eclipse.jdt.internal.compiler.parser;
12
16
Lines 42-51 Link Here
42
	return tabString(tab) + "Recovered statement:\n" + this.statement.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
46
	return tabString(tab) + "Recovered statement:\n" + this.statement.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
43
}
47
}
44
public Statement updatedStatement(int depth, Set knownTypes){
48
public Statement updatedStatement(int depth, Set knownTypes){
45
	return this.statement;
49
	return this.statement;
46
}
50
}
51
public Statement updatedStatement(int depth, Set knownTypes, boolean lambdaExpressionExpected) {
52
	return updatedStatement(depth, knownTypes);
53
}
47
public void updateParseTree(){
54
public void updateParseTree(){
48
	updatedStatement(0, new HashSet());
55
	updatedStatement(0, new HashSet());
49
}
56
}
50
/*
57
/*
51
 * Update the declarationSourceEnd of the corresponding parse node
58
 * Update the declarationSourceEnd of the corresponding parse node
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java (-2 / +6 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
15
package org.eclipse.jdt.internal.core;
12
16
Lines 449-459 Link Here
449
				new String(local.name),
453
				new String(local.name),
450
				local.declarationSourceStart,
454
				local.declarationSourceStart,
451
				local.declarationSourceEnd,
455
				local.declarationSourceEnd,
452
				local.sourceStart,
456
				local.sourceStart,
453
				local.sourceEnd,
457
				local.sourceEnd,
454
				Util.typeSignature(local.type),
458
				local.type == null ? Signature.createTypeSignature(local.binding.type.readableName(), false) : Util.typeSignature(local.type),
455
				local.annotations,
459
				local.annotations,
456
				local.modifiers,
460
				local.modifiers,
457
				local.getKind() == AbstractVariableDeclaration.PARAMETER);
461
				local.getKind() == AbstractVariableDeclaration.PARAMETER);
458
	}
462
	}
459
	if (localVar != null) {
463
	if (localVar != null) {

Return to bug 408230