Lines 59-64
Link Here
|
59 |
return new Java18ProjectTestSetup(test); |
59 |
return new Java18ProjectTestSetup(test); |
60 |
} |
60 |
} |
61 |
|
61 |
|
|
|
62 |
@Override |
62 |
protected void setUp() throws Exception { |
63 |
protected void setUp() throws Exception { |
63 |
Hashtable options= TestOptions.getDefaultOptions(); |
64 |
Hashtable options= TestOptions.getDefaultOptions(); |
64 |
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); |
65 |
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); |
Lines 74-79
Link Here
|
74 |
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); |
75 |
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); |
75 |
} |
76 |
} |
76 |
|
77 |
|
|
|
78 |
@Override |
77 |
protected void tearDown() throws Exception { |
79 |
protected void tearDown() throws Exception { |
78 |
JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); |
80 |
JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); |
79 |
} |
81 |
} |
Lines 930-935
Link Here
|
930 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
932 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
931 |
} |
933 |
} |
932 |
|
934 |
|
|
|
935 |
// Bug 421479 |
936 |
public void testConvertToLambda19() throws Exception { |
937 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
938 |
StringBuffer buf= new StringBuffer(); |
939 |
buf.append("package test1;\n"); |
940 |
buf.append("@FunctionalInterface\n"); |
941 |
buf.append("interface Func2 {\n"); |
942 |
buf.append(" enum En {\n"); |
943 |
buf.append(" A, B;\n"); |
944 |
buf.append(" enum COLOR {\n"); |
945 |
buf.append(" D, E\n"); |
946 |
buf.append(" }\n"); |
947 |
buf.append(" }\n"); |
948 |
buf.append("\n"); |
949 |
buf.append(" void foo();\n"); |
950 |
buf.append("\n"); |
951 |
buf.append(" String NAME = \"\";\n"); |
952 |
buf.append("\n"); |
953 |
buf.append(" static String staticName() {\n"); |
954 |
buf.append(" return NAME;\n"); |
955 |
buf.append(" }\n"); |
956 |
buf.append("}\n"); |
957 |
buf.append("\n"); |
958 |
buf.append("class Test2 {\n"); |
959 |
buf.append(" void bar() {\n"); |
960 |
buf.append(" Func2 f = new Func2() {\n"); |
961 |
buf.append(" @Override\n"); |
962 |
buf.append(" public void foo() {\n"); |
963 |
buf.append(" System.out.println(NAME);\n"); |
964 |
buf.append(" System.out.println(Func2.NAME);\n"); |
965 |
buf.append(" System.out.println(En.A);\n"); |
966 |
buf.append(" System.out.println(Func2.En.A);\n"); |
967 |
buf.append(" System.out.println(En.COLOR.D);\n"); |
968 |
buf.append(" System.out.println(Func2.En.COLOR.D);\n"); |
969 |
buf.append(" System.out.println(Test2.this);\n"); |
970 |
buf.append(" bar();\n"); |
971 |
buf.append(" }\n"); |
972 |
buf.append(" };\n"); |
973 |
buf.append(" }\n"); |
974 |
buf.append("}\n"); |
975 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
976 |
|
977 |
int offset= buf.toString().indexOf("public void"); |
978 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
979 |
assertNoErrors(context); |
980 |
List proposals= collectAssists(context, false); |
981 |
|
982 |
assertNumberOfProposals(proposals, 1); |
983 |
assertCorrectLabels(proposals); |
984 |
|
985 |
buf= new StringBuffer(); |
986 |
buf.append("package test1;\n\n"); |
987 |
buf.append("import test1.Func2.En;\n\n"); |
988 |
buf.append("@FunctionalInterface\n"); |
989 |
buf.append("interface Func2 {\n"); |
990 |
buf.append(" enum En {\n"); |
991 |
buf.append(" A, B;\n"); |
992 |
buf.append(" enum COLOR {\n"); |
993 |
buf.append(" D, E\n"); |
994 |
buf.append(" }\n"); |
995 |
buf.append(" }\n"); |
996 |
buf.append("\n"); |
997 |
buf.append(" void foo();\n"); |
998 |
buf.append("\n"); |
999 |
buf.append(" String NAME = \"\";\n"); |
1000 |
buf.append("\n"); |
1001 |
buf.append(" static String staticName() {\n"); |
1002 |
buf.append(" return NAME;\n"); |
1003 |
buf.append(" }\n"); |
1004 |
buf.append("}\n"); |
1005 |
buf.append("\n"); |
1006 |
buf.append("class Test2 {\n"); |
1007 |
buf.append(" void bar() {\n"); |
1008 |
buf.append(" Func2 f = () -> {\n"); |
1009 |
buf.append(" System.out.println(Func2.NAME);\n"); |
1010 |
buf.append(" System.out.println(Func2.NAME);\n"); |
1011 |
buf.append(" System.out.println(Func2.En.A);\n"); |
1012 |
buf.append(" System.out.println(Func2.En.A);\n"); |
1013 |
buf.append(" System.out.println(En.COLOR.D);\n"); |
1014 |
buf.append(" System.out.println(Func2.En.COLOR.D);\n"); |
1015 |
buf.append(" System.out.println(Test2.this);\n"); |
1016 |
buf.append(" bar();\n"); |
1017 |
buf.append(" };\n"); |
1018 |
buf.append(" }\n"); |
1019 |
buf.append("}\n"); |
1020 |
String expected1= buf.toString(); |
1021 |
|
1022 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1023 |
} |
1024 |
|
1025 |
// Bug 421479 |
1026 |
public void testConvertToLambda20() throws Exception { |
1027 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1028 |
StringBuffer buf= new StringBuffer(); |
1029 |
buf.append("package test1;\n"); |
1030 |
buf.append("interface Func<T> {\n"); |
1031 |
buf.append(" void go();\n"); |
1032 |
buf.append(" String NAME = Func.class.getName();\n"); |
1033 |
buf.append("}\n"); |
1034 |
buf.append("\n"); |
1035 |
buf.append("public class Test {\n"); |
1036 |
buf.append(" void foo() {\n"); |
1037 |
buf.append(" Func<String> f= new Func<String>() {\n"); |
1038 |
buf.append(" @Override\n"); |
1039 |
buf.append(" public void go() {\n"); |
1040 |
buf.append(" System.out.println(NAME);\n"); |
1041 |
buf.append(" }\n"); |
1042 |
buf.append(" };\n"); |
1043 |
buf.append(" }\n"); |
1044 |
buf.append("}\n"); |
1045 |
ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); |
1046 |
|
1047 |
int offset= buf.toString().indexOf("public void"); |
1048 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1049 |
assertNoErrors(context); |
1050 |
List proposals= collectAssists(context, false); |
1051 |
|
1052 |
assertNumberOfProposals(proposals, 1); |
1053 |
assertCorrectLabels(proposals); |
1054 |
|
1055 |
buf= new StringBuffer(); |
1056 |
buf.append("package test1;\n"); |
1057 |
buf.append("interface Func<T> {\n"); |
1058 |
buf.append(" void go();\n"); |
1059 |
buf.append(" String NAME = Func.class.getName();\n"); |
1060 |
buf.append("}\n"); |
1061 |
buf.append("\n"); |
1062 |
buf.append("public class Test {\n"); |
1063 |
buf.append(" void foo() {\n"); |
1064 |
buf.append(" Func<String> f= () -> System.out.println(Func.NAME);\n"); |
1065 |
buf.append(" }\n"); |
1066 |
buf.append("}\n"); |
1067 |
String expected1= buf.toString(); |
1068 |
|
1069 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1070 |
} |
1071 |
|
1072 |
// Bug 421479 |
1073 |
public void testConvertToLambda21() throws Exception { |
1074 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1075 |
StringBuffer buf= new StringBuffer(); |
1076 |
buf.append("package test1;\n"); |
1077 |
buf.append("import test1.Func2.En.COLOR;\n"); |
1078 |
buf.append("@FunctionalInterface\n"); |
1079 |
buf.append("interface Func2 {\n"); |
1080 |
buf.append(" enum En {\n"); |
1081 |
buf.append(" A, B;\n"); |
1082 |
buf.append(" enum COLOR {\n"); |
1083 |
buf.append(" D, E\n"); |
1084 |
buf.append(" }\n"); |
1085 |
buf.append(" }\n"); |
1086 |
buf.append("\n"); |
1087 |
buf.append(" void foo();\n"); |
1088 |
buf.append("\n"); |
1089 |
buf.append(" String NAME = \"\";\n"); |
1090 |
buf.append("\n"); |
1091 |
buf.append(" static String staticName() {\n"); |
1092 |
buf.append(" return NAME;\n"); |
1093 |
buf.append(" }\n"); |
1094 |
buf.append("}\n"); |
1095 |
buf.append("\n"); |
1096 |
buf.append("class Test2 {\n"); |
1097 |
buf.append(" void bar() {\n"); |
1098 |
buf.append(" Func2 f = new Func2() {\n"); |
1099 |
buf.append(" @Override\n"); |
1100 |
buf.append(" public void foo() {\n"); |
1101 |
buf.append(" System.out.println(COLOR.D);\n"); |
1102 |
buf.append(" }\n"); |
1103 |
buf.append(" };\n"); |
1104 |
buf.append(" }\n"); |
1105 |
buf.append("}\n"); |
1106 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
1107 |
|
1108 |
int offset= buf.toString().indexOf("public void"); |
1109 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1110 |
assertNoErrors(context); |
1111 |
List proposals= collectAssists(context, false); |
1112 |
|
1113 |
assertNumberOfProposals(proposals, 1); |
1114 |
assertCorrectLabels(proposals); |
1115 |
|
1116 |
buf= new StringBuffer(); |
1117 |
buf.append("package test1;\n"); |
1118 |
buf.append("import test1.Func2.En.COLOR;\n"); |
1119 |
buf.append("@FunctionalInterface\n"); |
1120 |
buf.append("interface Func2 {\n"); |
1121 |
buf.append(" enum En {\n"); |
1122 |
buf.append(" A, B;\n"); |
1123 |
buf.append(" enum COLOR {\n"); |
1124 |
buf.append(" D, E\n"); |
1125 |
buf.append(" }\n"); |
1126 |
buf.append(" }\n"); |
1127 |
buf.append("\n"); |
1128 |
buf.append(" void foo();\n"); |
1129 |
buf.append("\n"); |
1130 |
buf.append(" String NAME = \"\";\n"); |
1131 |
buf.append("\n"); |
1132 |
buf.append(" static String staticName() {\n"); |
1133 |
buf.append(" return NAME;\n"); |
1134 |
buf.append(" }\n"); |
1135 |
buf.append("}\n"); |
1136 |
buf.append("\n"); |
1137 |
buf.append("class Test2 {\n"); |
1138 |
buf.append(" void bar() {\n"); |
1139 |
buf.append(" Func2 f = () -> System.out.println(COLOR.D);\n"); |
1140 |
buf.append(" }\n"); |
1141 |
buf.append("}\n"); |
1142 |
String expected1= buf.toString(); |
1143 |
|
1144 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1145 |
} |
1146 |
|
1147 |
// Bug 421479 |
1148 |
public void testConvertToLambda22() throws Exception { |
1149 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1150 |
StringBuffer buf= new StringBuffer(); |
1151 |
buf.append("package test1;\n"); |
1152 |
buf.append("import test1.Func2.En.*;\n"); |
1153 |
buf.append("@FunctionalInterface\n"); |
1154 |
buf.append("interface Func2 {\n"); |
1155 |
buf.append(" enum En {\n"); |
1156 |
buf.append(" A, B;\n"); |
1157 |
buf.append(" enum COLOR {\n"); |
1158 |
buf.append(" D, E\n"); |
1159 |
buf.append(" }\n"); |
1160 |
buf.append(" }\n"); |
1161 |
buf.append("\n"); |
1162 |
buf.append(" void foo();\n"); |
1163 |
buf.append("\n"); |
1164 |
buf.append(" String NAME = \"\";\n"); |
1165 |
buf.append("\n"); |
1166 |
buf.append(" static String staticName() {\n"); |
1167 |
buf.append(" return NAME;\n"); |
1168 |
buf.append(" }\n"); |
1169 |
buf.append("}\n"); |
1170 |
buf.append("\n"); |
1171 |
buf.append("class Test2 {\n"); |
1172 |
buf.append(" void bar() {\n"); |
1173 |
buf.append(" Func2 f = new Func2() {\n"); |
1174 |
buf.append(" @Override\n"); |
1175 |
buf.append(" public void foo() {\n"); |
1176 |
buf.append(" System.out.println(COLOR.D);\n"); |
1177 |
buf.append(" }\n"); |
1178 |
buf.append(" };\n"); |
1179 |
buf.append(" }\n"); |
1180 |
buf.append("}\n"); |
1181 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
1182 |
|
1183 |
int offset= buf.toString().indexOf("public void"); |
1184 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1185 |
assertNoErrors(context); |
1186 |
List proposals= collectAssists(context, false); |
1187 |
|
1188 |
assertNumberOfProposals(proposals, 1); |
1189 |
assertCorrectLabels(proposals); |
1190 |
|
1191 |
buf= new StringBuffer(); |
1192 |
buf.append("package test1;\n"); |
1193 |
buf.append("import test1.Func2.En.*;\n"); |
1194 |
buf.append("@FunctionalInterface\n"); |
1195 |
buf.append("interface Func2 {\n"); |
1196 |
buf.append(" enum En {\n"); |
1197 |
buf.append(" A, B;\n"); |
1198 |
buf.append(" enum COLOR {\n"); |
1199 |
buf.append(" D, E\n"); |
1200 |
buf.append(" }\n"); |
1201 |
buf.append(" }\n"); |
1202 |
buf.append("\n"); |
1203 |
buf.append(" void foo();\n"); |
1204 |
buf.append("\n"); |
1205 |
buf.append(" String NAME = \"\";\n"); |
1206 |
buf.append("\n"); |
1207 |
buf.append(" static String staticName() {\n"); |
1208 |
buf.append(" return NAME;\n"); |
1209 |
buf.append(" }\n"); |
1210 |
buf.append("}\n"); |
1211 |
buf.append("\n"); |
1212 |
buf.append("class Test2 {\n"); |
1213 |
buf.append(" void bar() {\n"); |
1214 |
buf.append(" Func2 f = () -> System.out.println(COLOR.D);\n"); |
1215 |
buf.append(" }\n"); |
1216 |
buf.append("}\n"); |
1217 |
String expected1= buf.toString(); |
1218 |
|
1219 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1220 |
} |
1221 |
|
1222 |
// Bug 421479 |
1223 |
public void testConvertToLambda23() throws Exception { |
1224 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1225 |
StringBuffer buf= new StringBuffer(); |
1226 |
buf.append("package test1;\n"); |
1227 |
buf.append("@FunctionalInterface\n"); |
1228 |
buf.append("interface Func {\n"); |
1229 |
buf.append(" class C {\n"); |
1230 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1231 |
buf.append(" static String NAME = \"\";\n"); |
1232 |
buf.append(" }\n"); |
1233 |
buf.append(" void foo();\n"); |
1234 |
buf.append("}\n"); |
1235 |
buf.append("\n"); |
1236 |
buf.append("class Test {\n"); |
1237 |
buf.append(" static class C {\n"); |
1238 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1239 |
buf.append(" static String NAME = \"\";\n"); |
1240 |
buf.append(" }\n"); |
1241 |
buf.append(" void bar() {\n"); |
1242 |
buf.append(" Func f = new Func() {\n"); |
1243 |
buf.append(" @Override\n"); |
1244 |
buf.append(" public void foo() {\n"); |
1245 |
buf.append(" System.out.println(C.CIn.i);\n"); |
1246 |
buf.append(" System.out.println(C.NAME);\n"); |
1247 |
buf.append(" }\n"); |
1248 |
buf.append(" };\n"); |
1249 |
buf.append(" }\n"); |
1250 |
buf.append("}\n"); |
1251 |
ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); |
1252 |
|
1253 |
int offset= buf.toString().indexOf("public void"); |
1254 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1255 |
assertNoErrors(context); |
1256 |
List proposals= collectAssists(context, false); |
1257 |
|
1258 |
assertNumberOfProposals(proposals, 1); |
1259 |
assertCorrectLabels(proposals); |
1260 |
|
1261 |
buf= new StringBuffer(); |
1262 |
buf.append("package test1;\n"); |
1263 |
buf.append("@FunctionalInterface\n"); |
1264 |
buf.append("interface Func {\n"); |
1265 |
buf.append(" class C {\n"); |
1266 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1267 |
buf.append(" static String NAME = \"\";\n"); |
1268 |
buf.append(" }\n"); |
1269 |
buf.append(" void foo();\n"); |
1270 |
buf.append("}\n"); |
1271 |
buf.append("\n"); |
1272 |
buf.append("class Test {\n"); |
1273 |
buf.append(" static class C {\n"); |
1274 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1275 |
buf.append(" static String NAME = \"\";\n"); |
1276 |
buf.append(" }\n"); |
1277 |
buf.append(" void bar() {\n"); |
1278 |
buf.append(" Func f = () -> {\n"); |
1279 |
buf.append(" System.out.println(test1.Func.C.CIn.i);\n"); |
1280 |
buf.append(" System.out.println(Func.C.NAME);\n"); |
1281 |
buf.append(" };\n"); |
1282 |
buf.append(" }\n"); |
1283 |
buf.append("}\n"); |
1284 |
String expected1= buf.toString(); |
1285 |
|
1286 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1287 |
} |
1288 |
|
1289 |
// Bug 421479 |
1290 |
public void testConvertToLambda24() throws Exception { |
1291 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1292 |
StringBuffer buf= new StringBuffer(); |
1293 |
buf.append("package test1;\n"); |
1294 |
buf.append("@FunctionalInterface\n"); |
1295 |
buf.append("interface Func {\n"); |
1296 |
buf.append(" class C {\n"); |
1297 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1298 |
buf.append(" }\n"); |
1299 |
buf.append(" void foo();\n"); |
1300 |
buf.append("}\n"); |
1301 |
buf.append("\n"); |
1302 |
buf.append("class Test extends TT {\n"); |
1303 |
buf.append(" static class C {\n"); |
1304 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1305 |
buf.append(" }\n"); |
1306 |
buf.append(" void bar() {\n"); |
1307 |
buf.append(" test1.Func f = new test1.Func() {\n"); |
1308 |
buf.append(" @Override\n"); |
1309 |
buf.append(" public void foo() {\n"); |
1310 |
buf.append(" System.out.println(C.CIn.i); // [1]\n"); |
1311 |
buf.append(" }\n"); |
1312 |
buf.append(" };\n"); |
1313 |
buf.append(" }\n"); |
1314 |
buf.append("}\n"); |
1315 |
buf.append("\n"); |
1316 |
buf.append("class TT {\n"); |
1317 |
buf.append(" class Func {\n"); |
1318 |
buf.append(" }\n"); |
1319 |
buf.append("}\n"); |
1320 |
ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); |
1321 |
|
1322 |
int offset= buf.toString().indexOf("public void"); |
1323 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1324 |
assertNoErrors(context); |
1325 |
List proposals= collectAssists(context, false); |
1326 |
|
1327 |
assertNumberOfProposals(proposals, 1); |
1328 |
assertCorrectLabels(proposals); |
1329 |
|
1330 |
buf= new StringBuffer(); |
1331 |
buf.append("package test1;\n"); |
1332 |
buf.append("@FunctionalInterface\n"); |
1333 |
buf.append("interface Func {\n"); |
1334 |
buf.append(" class C {\n"); |
1335 |
buf.append(" static class CIn { static int i= 0; } \n"); |
1336 |
buf.append(" }\n"); |
1337 |
buf.append(" void foo();\n"); |
1338 |
buf.append("}\n"); |
1339 |
buf.append("\n"); |
1340 |
buf.append("class Test extends TT {\n"); |
1341 |
buf.append(" static class C {\n"); |
1342 |
buf.append(" static class CIn { static int i= 1; } \n"); |
1343 |
buf.append(" }\n"); |
1344 |
buf.append(" void bar() {\n"); |
1345 |
buf.append(" test1.Func f = () -> System.out.println(test1.Func.C.CIn.i);\n"); |
1346 |
buf.append(" }\n"); |
1347 |
buf.append("}\n"); |
1348 |
buf.append("\n"); |
1349 |
buf.append("class TT {\n"); |
1350 |
buf.append(" class Func {\n"); |
1351 |
buf.append(" }\n"); |
1352 |
buf.append("}\n"); |
1353 |
String expected1= buf.toString(); |
1354 |
|
1355 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1356 |
} |
1357 |
|
1358 |
// Bug 421479 |
1359 |
public void testConvertToLambda25() throws Exception { |
1360 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1361 |
StringBuffer buf= new StringBuffer(); |
1362 |
buf.append("package test1;\n"); |
1363 |
buf.append("@FunctionalInterface\n"); |
1364 |
buf.append("interface FI extends FIS {\n"); |
1365 |
buf.append(" void run(int x);\n"); |
1366 |
buf.append(" public static void test(int e) {\n"); |
1367 |
buf.append(" FI fi = new FI() {\n"); |
1368 |
buf.append(" @Override\n"); |
1369 |
buf.append(" public void run(int x) {\n"); |
1370 |
buf.append(" System.out.println(e);\n"); |
1371 |
buf.append(" }\n"); |
1372 |
buf.append(" };\n"); |
1373 |
buf.append(" fi.run(e);\n"); |
1374 |
buf.append(" } \n"); |
1375 |
buf.append("}\n"); |
1376 |
buf.append("\n"); |
1377 |
buf.append("interface FIS {\n"); |
1378 |
buf.append(" int e= 0; \n"); |
1379 |
buf.append("}\n"); |
1380 |
ICompilationUnit cu= pack1.createCompilationUnit("FI.java", buf.toString(), false, null); |
1381 |
|
1382 |
int offset= buf.toString().indexOf("public void"); |
1383 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1384 |
assertNoErrors(context); |
1385 |
List proposals= collectAssists(context, false); |
1386 |
|
1387 |
assertNumberOfProposals(proposals, 1); |
1388 |
assertCorrectLabels(proposals); |
1389 |
|
1390 |
buf= new StringBuffer(); |
1391 |
buf.append("package test1;\n"); |
1392 |
buf.append("@FunctionalInterface\n"); |
1393 |
buf.append("interface FI extends FIS {\n"); |
1394 |
buf.append(" void run(int x);\n"); |
1395 |
buf.append(" public static void test(int e) {\n"); |
1396 |
buf.append(" FI fi = x -> System.out.println(FIS.e);\n"); |
1397 |
buf.append(" fi.run(e);\n"); |
1398 |
buf.append(" } \n"); |
1399 |
buf.append("}\n"); |
1400 |
buf.append("\n"); |
1401 |
buf.append("interface FIS {\n"); |
1402 |
buf.append(" int e= 0; \n"); |
1403 |
buf.append("}\n"); |
1404 |
String expected1= buf.toString(); |
1405 |
|
1406 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
1407 |
} |
1408 |
|
1409 |
// Bug 421479 |
1410 |
public void testConvertToLambda26() throws Exception { |
1411 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1412 |
StringBuffer buf= new StringBuffer(); |
1413 |
buf.append("package test1;\n"); |
1414 |
buf.append("@FunctionalInterface\n"); |
1415 |
buf.append("interface Func2 {\n"); |
1416 |
buf.append(" enum En {\n"); |
1417 |
buf.append(" A, B\n"); |
1418 |
buf.append(" }\n"); |
1419 |
buf.append("\n"); |
1420 |
buf.append(" void foo();\n"); |
1421 |
buf.append("\n"); |
1422 |
buf.append(" String NAME = \"\";\n"); |
1423 |
buf.append("\n"); |
1424 |
buf.append(" static String staticName() {\n"); |
1425 |
buf.append(" return NAME;\n"); |
1426 |
buf.append(" }\n"); |
1427 |
buf.append("}\n"); |
1428 |
buf.append("\n"); |
1429 |
buf.append("class Test2 {\n"); |
1430 |
buf.append(" void bar() {\n"); |
1431 |
buf.append(" Func2 f = new Func2() {\n"); |
1432 |
buf.append(" @Override\n"); |
1433 |
buf.append(" public void foo() {\n"); |
1434 |
buf.append(" foo();\n"); |
1435 |
buf.append(" }\n"); |
1436 |
buf.append(" };\n"); |
1437 |
buf.append(" }\n"); |
1438 |
buf.append("}\n"); |
1439 |
ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); |
1440 |
|
1441 |
int offset= buf.toString().indexOf("public void"); |
1442 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1443 |
assertNoErrors(context); |
1444 |
List proposals= collectAssists(context, false); |
1445 |
|
1446 |
assertNumberOfProposals(proposals, 0); |
1447 |
} |
1448 |
|
1449 |
// Bug 421479 |
1450 |
public void testConvertToLambda27() throws Exception { |
1451 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1452 |
StringBuffer buf= new StringBuffer(); |
1453 |
buf.append("package test1;\n"); |
1454 |
buf.append("import java.util.function.Consumer;\n"); |
1455 |
buf.append("\n"); |
1456 |
buf.append("public class Test {\n"); |
1457 |
buf.append(" static void run(Consumer<Integer> consumer) {\n"); |
1458 |
buf.append(" System.out.println(\"consumer\");\n"); |
1459 |
buf.append(" }\n"); |
1460 |
buf.append(" static {\n"); |
1461 |
buf.append(" run(new Consumer<Integer>() {\n"); |
1462 |
buf.append(" @Override\n"); |
1463 |
buf.append(" public void accept(Integer integer) {\n"); |
1464 |
buf.append(" System.out.println(andThen(null));\n"); |
1465 |
buf.append(" }\n"); |
1466 |
buf.append(" });\n"); |
1467 |
buf.append(" }\n"); |
1468 |
buf.append("}\n"); |
1469 |
ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); |
1470 |
|
1471 |
int offset= buf.toString().indexOf("public void"); |
1472 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
1473 |
assertNoErrors(context); |
1474 |
List proposals= collectAssists(context, false); |
1475 |
|
1476 |
assertNumberOfProposals(proposals, 0); |
1477 |
} |
1478 |
|
933 |
public void testConvertToLambdaAmbiguousOverridden() throws Exception { |
1479 |
public void testConvertToLambdaAmbiguousOverridden() throws Exception { |
934 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
1480 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
935 |
StringBuffer buf= new StringBuffer(); |
1481 |
StringBuffer buf= new StringBuffer(); |