Lines 74-79
Link Here
|
74 |
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); |
74 |
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); |
75 |
} |
75 |
} |
76 |
|
76 |
|
|
|
77 |
@Override |
77 |
protected void tearDown() throws Exception { |
78 |
protected void tearDown() throws Exception { |
78 |
JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); |
79 |
JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); |
79 |
} |
80 |
} |
Lines 930-935
Link Here
|
930 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
931 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
931 |
} |
932 |
} |
932 |
|
933 |
|
|
|
934 |
// Bug 421479 |
935 |
public void testConvertToLambda19() throws Exception { |
936 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
937 |
StringBuffer buf= new StringBuffer(); |
938 |
buf.append("package test1;\n"); |
939 |
buf.append("@FunctionalInterface\n"); |
940 |
buf.append("interface Func2 {\n"); |
941 |
buf.append(" enum En {\n"); |
942 |
buf.append(" A, B;\n"); |
943 |
buf.append(" enum COLOR {\n"); |
944 |
buf.append(" D, E\n"); |
945 |
buf.append(" }\n"); |
946 |
buf.append(" }\n"); |
947 |
buf.append("\n"); |
948 |
buf.append(" void foo();\n"); |
949 |
buf.append("\n"); |
950 |
buf.append(" String NAME = \"\";\n"); |
951 |
buf.append("\n"); |
952 |
buf.append(" static String staticName() {\n"); |
953 |
buf.append(" return NAME;\n"); |
954 |
buf.append(" }\n"); |
955 |
buf.append("}\n"); |
956 |
buf.append("\n"); |
957 |
buf.append("class Test2 {\n"); |
958 |
buf.append(" void bar() {\n"); |
959 |
buf.append(" Func2 f = new Func2() {\n"); |
960 |
buf.append(" @Override\n"); |
961 |
buf.append(" public void foo() {\n"); |
962 |
buf.append(" System.out.println(NAME);\n"); |
963 |
buf.append(" System.out.println(Func2.NAME);\n"); |
964 |
buf.append(" System.out.println(En.A);\n"); |
965 |
buf.append(" System.out.println(Func2.En.A);\n"); |
966 |
buf.append(" System.out.println(En.COLOR.D);\n"); |
967 |
buf.append(" System.out.println(Func2.En.COLOR.D);\n"); |
968 |
buf.append(" System.out.println(Test2.this);\n"); |
969 |
buf.append(" bar();\n"); |
970 |
buf.append(" }\n"); |
971 |
buf.append(" };\n"); |
972 |
buf.append(" }\n"); |
973 |
buf.append("}\n"); |
974 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
975 |
|
976 |
int offset= buf.toString().indexOf("public void"); |
977 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
978 |
assertNoErrors(context); |
979 |
List proposals= collectAssists(context, false); |
980 |
|
981 |
assertNumberOfProposals(proposals, 1); |
982 |
assertCorrectLabels(proposals); |
983 |
|
984 |
buf= new StringBuffer(); |
985 |
buf.append("package test1;\n\n"); |
986 |
buf.append("import test1.Func2.En;\n\n"); |
987 |
buf.append("@FunctionalInterface\n"); |
988 |
buf.append("interface Func2 {\n"); |
989 |
buf.append(" enum En {\n"); |
990 |
buf.append(" A, B;\n"); |
991 |
buf.append(" enum COLOR {\n"); |
992 |
buf.append(" D, E\n"); |
993 |
buf.append(" }\n"); |
994 |
buf.append(" }\n"); |
995 |
buf.append("\n"); |
996 |
buf.append(" void foo();\n"); |
997 |
buf.append("\n"); |
998 |
buf.append(" String NAME = \"\";\n"); |
999 |
buf.append("\n"); |
1000 |
buf.append(" static String staticName() {\n"); |
1001 |
buf.append(" return NAME;\n"); |
1002 |
buf.append(" }\n"); |
1003 |
buf.append("}\n"); |
1004 |
buf.append("\n"); |
1005 |
buf.append("class Test2 {\n"); |
1006 |
buf.append(" void bar() {\n"); |
1007 |
buf.append(" Func2 f = () -> {\n"); |
1008 |
buf.append(" System.out.println(Func2.NAME);\n"); |
1009 |
buf.append(" System.out.println(Func2.NAME);\n"); |
1010 |
buf.append(" System.out.println(Func2.En.A);\n"); |
1011 |
buf.append(" System.out.println(Func2.En.A);\n"); |
1012 |
buf.append(" System.out.println(En.COLOR.D);\n"); |
1013 |
buf.append(" System.out.println(Func2.En.COLOR.D);\n"); |
1014 |
buf.append(" System.out.println(Test2.this);\n"); |
1015 |
buf.append(" bar();\n"); |
1016 |
buf.append(" };\n"); |
1017 |
buf.append(" }\n"); |
1018 |
buf.append("}\n"); |
1019 |
String expected1= buf.toString(); |
1020 |
|
1021 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1022 |
} |
1023 |
|
1024 |
// Bug 421479 |
1025 |
public void testConvertToLambda20() throws Exception { |
1026 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1027 |
StringBuffer buf= new StringBuffer(); |
1028 |
buf.append("package test1;\n"); |
1029 |
buf.append("interface Func<T> {\n"); |
1030 |
buf.append(" void go();\n"); |
1031 |
buf.append(" String NAME = Func.class.getName();\n"); |
1032 |
buf.append("}\n"); |
1033 |
buf.append("\n"); |
1034 |
buf.append("public class Test {\n"); |
1035 |
buf.append(" void foo() {\n"); |
1036 |
buf.append(" Func<String> f= new Func<String>() {\n"); |
1037 |
buf.append(" @Override\n"); |
1038 |
buf.append(" public void go() {\n"); |
1039 |
buf.append(" System.out.println(NAME);\n"); |
1040 |
buf.append(" }\n"); |
1041 |
buf.append(" };\n"); |
1042 |
buf.append(" }\n"); |
1043 |
buf.append("}\n"); |
1044 |
ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); |
1045 |
|
1046 |
int offset= buf.toString().indexOf("public void"); |
1047 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1048 |
assertNoErrors(context); |
1049 |
List proposals= collectAssists(context, false); |
1050 |
|
1051 |
assertNumberOfProposals(proposals, 1); |
1052 |
assertCorrectLabels(proposals); |
1053 |
|
1054 |
buf= new StringBuffer(); |
1055 |
buf.append("package test1;\n"); |
1056 |
buf.append("interface Func<T> {\n"); |
1057 |
buf.append(" void go();\n"); |
1058 |
buf.append(" String NAME = Func.class.getName();\n"); |
1059 |
buf.append("}\n"); |
1060 |
buf.append("\n"); |
1061 |
buf.append("public class Test {\n"); |
1062 |
buf.append(" void foo() {\n"); |
1063 |
buf.append(" Func<String> f= () -> System.out.println(Func.NAME);\n"); |
1064 |
buf.append(" }\n"); |
1065 |
buf.append("}\n"); |
1066 |
String expected1= buf.toString(); |
1067 |
|
1068 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1069 |
} |
1070 |
|
1071 |
// Bug 421479 |
1072 |
public void testConvertToLambda21() throws Exception { |
1073 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1074 |
StringBuffer buf= new StringBuffer(); |
1075 |
buf.append("package test1;\n"); |
1076 |
buf.append("import test1.Func2.En.COLOR;\n"); |
1077 |
buf.append("@FunctionalInterface\n"); |
1078 |
buf.append("interface Func2 {\n"); |
1079 |
buf.append(" enum En {\n"); |
1080 |
buf.append(" A, B;\n"); |
1081 |
buf.append(" enum COLOR {\n"); |
1082 |
buf.append(" D, E\n"); |
1083 |
buf.append(" }\n"); |
1084 |
buf.append(" }\n"); |
1085 |
buf.append("\n"); |
1086 |
buf.append(" void foo();\n"); |
1087 |
buf.append("\n"); |
1088 |
buf.append(" String NAME = \"\";\n"); |
1089 |
buf.append("\n"); |
1090 |
buf.append(" static String staticName() {\n"); |
1091 |
buf.append(" return NAME;\n"); |
1092 |
buf.append(" }\n"); |
1093 |
buf.append("}\n"); |
1094 |
buf.append("\n"); |
1095 |
buf.append("class Test2 {\n"); |
1096 |
buf.append(" void bar() {\n"); |
1097 |
buf.append(" Func2 f = new Func2() {\n"); |
1098 |
buf.append(" @Override\n"); |
1099 |
buf.append(" public void foo() {\n"); |
1100 |
buf.append(" System.out.println(COLOR.D);\n"); |
1101 |
buf.append(" }\n"); |
1102 |
buf.append(" };\n"); |
1103 |
buf.append(" }\n"); |
1104 |
buf.append("}\n"); |
1105 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
1106 |
|
1107 |
int offset= buf.toString().indexOf("public void"); |
1108 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1109 |
assertNoErrors(context); |
1110 |
List proposals= collectAssists(context, false); |
1111 |
|
1112 |
assertNumberOfProposals(proposals, 1); |
1113 |
assertCorrectLabels(proposals); |
1114 |
|
1115 |
buf= new StringBuffer(); |
1116 |
buf.append("package test1;\n"); |
1117 |
buf.append("import test1.Func2.En.COLOR;\n"); |
1118 |
buf.append("@FunctionalInterface\n"); |
1119 |
buf.append("interface Func2 {\n"); |
1120 |
buf.append(" enum En {\n"); |
1121 |
buf.append(" A, B;\n"); |
1122 |
buf.append(" enum COLOR {\n"); |
1123 |
buf.append(" D, E\n"); |
1124 |
buf.append(" }\n"); |
1125 |
buf.append(" }\n"); |
1126 |
buf.append("\n"); |
1127 |
buf.append(" void foo();\n"); |
1128 |
buf.append("\n"); |
1129 |
buf.append(" String NAME = \"\";\n"); |
1130 |
buf.append("\n"); |
1131 |
buf.append(" static String staticName() {\n"); |
1132 |
buf.append(" return NAME;\n"); |
1133 |
buf.append(" }\n"); |
1134 |
buf.append("}\n"); |
1135 |
buf.append("\n"); |
1136 |
buf.append("class Test2 {\n"); |
1137 |
buf.append(" void bar() {\n"); |
1138 |
buf.append(" Func2 f = () -> System.out.println(COLOR.D);\n"); |
1139 |
buf.append(" }\n"); |
1140 |
buf.append("}\n"); |
1141 |
String expected1= buf.toString(); |
1142 |
|
1143 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1144 |
} |
1145 |
|
1146 |
// Bug 421479 |
1147 |
public void testConvertToLambda22() throws Exception { |
1148 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1149 |
StringBuffer buf= new StringBuffer(); |
1150 |
buf.append("package test1;\n"); |
1151 |
buf.append("@FunctionalInterface\n"); |
1152 |
buf.append("interface Func {\n"); |
1153 |
buf.append(" class C {\n"); |
1154 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1155 |
buf.append(" static String NAME = \"\";\n"); |
1156 |
buf.append(" }\n"); |
1157 |
buf.append(" void foo();\n"); |
1158 |
buf.append("}\n"); |
1159 |
buf.append("\n"); |
1160 |
buf.append("class Test {\n"); |
1161 |
buf.append(" static class C {\n"); |
1162 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1163 |
buf.append(" static String NAME = \"\";\n"); |
1164 |
buf.append(" }\n"); |
1165 |
buf.append(" void bar() {\n"); |
1166 |
buf.append(" Func f = new Func() {\n"); |
1167 |
buf.append(" @Override\n"); |
1168 |
buf.append(" public void foo() {\n"); |
1169 |
buf.append(" System.out.println(C.CIn.i);\n"); |
1170 |
buf.append(" System.out.println(C.NAME);\n"); |
1171 |
buf.append(" }\n"); |
1172 |
buf.append(" };\n"); |
1173 |
buf.append(" }\n"); |
1174 |
buf.append("}\n"); |
1175 |
ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); |
1176 |
|
1177 |
int offset= buf.toString().indexOf("public void"); |
1178 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1179 |
assertNoErrors(context); |
1180 |
List proposals= collectAssists(context, false); |
1181 |
|
1182 |
assertNumberOfProposals(proposals, 1); |
1183 |
assertCorrectLabels(proposals); |
1184 |
|
1185 |
buf= new StringBuffer(); |
1186 |
buf.append("package test1;\n"); |
1187 |
buf.append("@FunctionalInterface\n"); |
1188 |
buf.append("interface Func {\n"); |
1189 |
buf.append(" class C {\n"); |
1190 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1191 |
buf.append(" static String NAME = \"\";\n"); |
1192 |
buf.append(" }\n"); |
1193 |
buf.append(" void foo();\n"); |
1194 |
buf.append("}\n"); |
1195 |
buf.append("\n"); |
1196 |
buf.append("class Test {\n"); |
1197 |
buf.append(" static class C {\n"); |
1198 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1199 |
buf.append(" static String NAME = \"\";\n"); |
1200 |
buf.append(" }\n"); |
1201 |
buf.append(" void bar() {\n"); |
1202 |
buf.append(" Func f = () -> {\n"); |
1203 |
buf.append(" System.out.println(test1.Func.C.CIn.i);\n"); |
1204 |
buf.append(" System.out.println(Func.C.NAME);\n"); |
1205 |
buf.append(" };\n"); |
1206 |
buf.append(" }\n"); |
1207 |
buf.append("}\n"); |
1208 |
String expected1= buf.toString(); |
1209 |
|
1210 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1211 |
} |
1212 |
|
1213 |
// Bug 421479 |
1214 |
public void testConvertToLambda23() throws Exception { |
1215 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1216 |
StringBuffer buf= new StringBuffer(); |
1217 |
buf.append("package test1;\n"); |
1218 |
buf.append("@FunctionalInterface\n"); |
1219 |
buf.append("interface Func {\n"); |
1220 |
buf.append(" class C {\n"); |
1221 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1222 |
buf.append(" }\n"); |
1223 |
buf.append(" void foo();\n"); |
1224 |
buf.append("}\n"); |
1225 |
buf.append("\n"); |
1226 |
buf.append("class Test extends TT {\n"); |
1227 |
buf.append(" static class C {\n"); |
1228 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1229 |
buf.append(" }\n"); |
1230 |
buf.append(" void bar() {\n"); |
1231 |
buf.append(" test1.Func f = new test1.Func() {\n"); |
1232 |
buf.append(" @Override\n"); |
1233 |
buf.append(" public void foo() {\n"); |
1234 |
buf.append(" System.out.println(C.CIn.i); // [1]\n"); |
1235 |
buf.append(" }\n"); |
1236 |
buf.append(" };\n"); |
1237 |
buf.append(" }\n"); |
1238 |
buf.append("}\n"); |
1239 |
buf.append("\n"); |
1240 |
buf.append("class TT {\n"); |
1241 |
buf.append(" class Func {\n"); |
1242 |
buf.append(" }\n"); |
1243 |
buf.append("}\n"); |
1244 |
ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); |
1245 |
|
1246 |
int offset= buf.toString().indexOf("public void"); |
1247 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1248 |
assertNoErrors(context); |
1249 |
List proposals= collectAssists(context, false); |
1250 |
|
1251 |
assertNumberOfProposals(proposals, 1); |
1252 |
assertCorrectLabels(proposals); |
1253 |
|
1254 |
buf= new StringBuffer(); |
1255 |
buf.append("package test1;\n"); |
1256 |
buf.append("@FunctionalInterface\n"); |
1257 |
buf.append("interface Func {\n"); |
1258 |
buf.append(" class C {\n"); |
1259 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1260 |
buf.append(" }\n"); |
1261 |
buf.append(" void foo();\n"); |
1262 |
buf.append("}\n"); |
1263 |
buf.append("\n"); |
1264 |
buf.append("class Test extends TT {\n"); |
1265 |
buf.append(" static class C {\n"); |
1266 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1267 |
buf.append(" }\n"); |
1268 |
buf.append(" void bar() {\n"); |
1269 |
buf.append(" test1.Func f = () -> System.out.println(test1.Func.C.CIn.i);\n"); |
1270 |
buf.append(" }\n"); |
1271 |
buf.append("}\n"); |
1272 |
buf.append("\n"); |
1273 |
buf.append("class TT {\n"); |
1274 |
buf.append(" class Func {\n"); |
1275 |
buf.append(" }\n"); |
1276 |
buf.append("}\n"); |
1277 |
String expected1= buf.toString(); |
1278 |
|
1279 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1280 |
} |
1281 |
|
1282 |
// Bug 421479 |
1283 |
public void testConvertToLambda24() throws Exception { |
1284 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1285 |
StringBuffer buf= new StringBuffer(); |
1286 |
buf.append("package test1;\n"); |
1287 |
buf.append("@FunctionalInterface\n"); |
1288 |
buf.append("interface Func2 {\n"); |
1289 |
buf.append(" enum En {\n"); |
1290 |
buf.append(" A, B\n"); |
1291 |
buf.append(" }\n"); |
1292 |
buf.append("\n"); |
1293 |
buf.append(" void foo();\n"); |
1294 |
buf.append("\n"); |
1295 |
buf.append(" String NAME = \"\";\n"); |
1296 |
buf.append("\n"); |
1297 |
buf.append(" static String staticName() {\n"); |
1298 |
buf.append(" return NAME;\n"); |
1299 |
buf.append(" }\n"); |
1300 |
buf.append("}\n"); |
1301 |
buf.append("\n"); |
1302 |
buf.append("class Test2 {\n"); |
1303 |
buf.append(" void bar() {\n"); |
1304 |
buf.append(" Func2 f = new Func2() {\n"); |
1305 |
buf.append(" @Override\n"); |
1306 |
buf.append(" public void foo() {\n"); |
1307 |
buf.append(" foo();\n"); |
1308 |
buf.append(" }\n"); |
1309 |
buf.append(" };\n"); |
1310 |
buf.append(" }\n"); |
1311 |
buf.append("}\n"); |
1312 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
1313 |
|
1314 |
int offset= buf.toString().indexOf("public void"); |
1315 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1316 |
assertNoErrors(context); |
1317 |
List proposals= collectAssists(context, false); |
1318 |
|
1319 |
assertNumberOfProposals(proposals, 0); |
1320 |
} |
1321 |
|
1322 |
// Bug 421479 |
1323 |
public void testConvertToLambda25() throws Exception { |
1324 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1325 |
StringBuffer buf= new StringBuffer(); |
1326 |
buf.append("package test1;\n"); |
1327 |
buf.append("import java.util.function.Consumer;\n"); |
1328 |
buf.append("\n"); |
1329 |
buf.append("public class Test {\n"); |
1330 |
buf.append(" static void run(Consumer<Integer> consumer) {\n"); |
1331 |
buf.append(" System.out.println(\"consumer\");\n"); |
1332 |
buf.append(" }\n"); |
1333 |
buf.append(" static {\n"); |
1334 |
buf.append(" run(new Consumer<Integer>() {\n"); |
1335 |
buf.append(" @Override\n"); |
1336 |
buf.append(" public void accept(Integer integer) {\n"); |
1337 |
buf.append(" System.out.println(andThen(null));\n"); |
1338 |
buf.append(" }\n"); |
1339 |
buf.append(" });\n"); |
1340 |
buf.append(" }\n"); |
1341 |
buf.append("}\n"); |
1342 |
ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); |
1343 |
|
1344 |
int offset= buf.toString().indexOf("public void"); |
1345 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1346 |
assertNoErrors(context); |
1347 |
List proposals= collectAssists(context, false); |
1348 |
|
1349 |
assertNumberOfProposals(proposals, 0); |
1350 |
} |
1351 |
|
933 |
public void testConvertToLambdaAmbiguousOverridden() throws Exception { |
1352 |
public void testConvertToLambdaAmbiguousOverridden() throws Exception { |
934 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1353 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
935 |
StringBuffer buf= new StringBuffer(); |
1354 |
StringBuffer buf= new StringBuffer(); |