|
14 | 14 | package org.eclipse.jdt.core.tests.model; |
15 | 15 |
|
16 | 16 | import junit.framework.Test; |
| 17 | +import org.eclipse.core.runtime.NullProgressMonitor; |
17 | 18 | import org.eclipse.jdt.core.ICompilationUnit; |
18 | 19 | import org.eclipse.jdt.core.IJavaProject; |
19 | 20 | import org.eclipse.jdt.core.JavaCore; |
@@ -1181,4 +1182,199 @@ public record R(String name, int age) { |
1181 | 1182 | requestor.getResults()); |
1182 | 1183 |
|
1183 | 1184 | } |
| 1185 | + |
| 1186 | + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4215 |
| 1187 | + // Content Assist doesn't work for record type names in some contexts |
| 1188 | + public void testIssue4215() throws JavaModelException { |
| 1189 | + this.workingCopies = new ICompilationUnit[2]; |
| 1190 | + |
| 1191 | + this.workingCopies[1] = getWorkingCopy( |
| 1192 | + "/Completion/src/p/Point.java", |
| 1193 | + """ |
| 1194 | + package p; |
| 1195 | + public record Point(int x, int y) { |
| 1196 | + void foo() { |
| 1197 | + System.out.println(this.x); |
| 1198 | + System.out.println(x()); |
| 1199 | + } |
| 1200 | + } |
| 1201 | +
|
| 1202 | + class X { |
| 1203 | + X x = new X(); |
| 1204 | + } |
| 1205 | + """ |
| 1206 | + ); |
| 1207 | + this.workingCopies[0] = getWorkingCopy( |
| 1208 | + "/Completion/src/X.java", |
| 1209 | + """ |
| 1210 | + public class X { |
| 1211 | + public static void main(String[] args) { |
| 1212 | + new Poi |
| 1213 | + } |
| 1214 | + } |
| 1215 | + """ |
| 1216 | + ); |
| 1217 | + this.workingCopies[0].getJavaProject(); //assuming single project for all working copies |
| 1218 | + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 1219 | + requestor.allowAllRequiredProposals(); |
| 1220 | + String str = this.workingCopies[0].getSource(); |
| 1221 | + String completeBehind = "new Poi"; |
| 1222 | + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 1223 | + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, new NullProgressMonitor()); |
| 1224 | + assertResults( |
| 1225 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, (II)V, Point, (x, y), 52}", |
| 1226 | + requestor.getResults()); |
| 1227 | + |
| 1228 | + } |
| 1229 | + |
| 1230 | + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4215 |
| 1231 | + // Content Assist doesn't work for record type names in some contexts |
| 1232 | + public void testIssue4215_2() throws JavaModelException { |
| 1233 | + this.workingCopies = new ICompilationUnit[2]; |
| 1234 | + |
| 1235 | + this.workingCopies[1] = getWorkingCopy( |
| 1236 | + "/Completion/src/p/Point.java", |
| 1237 | + """ |
| 1238 | + package p; |
| 1239 | + public record Point(int x, int y) { |
| 1240 | + public Point { |
| 1241 | + x = 0; |
| 1242 | + y = 0; |
| 1243 | + } |
| 1244 | +
|
| 1245 | + void foo() { |
| 1246 | + System.out.println(this.x); |
| 1247 | + System.out.println(x()); |
| 1248 | + } |
| 1249 | + } |
| 1250 | +
|
| 1251 | + class X { |
| 1252 | + X x = new X(); |
| 1253 | + } |
| 1254 | + """ |
| 1255 | + ); |
| 1256 | + this.workingCopies[0] = getWorkingCopy( |
| 1257 | + "/Completion/src/X.java", |
| 1258 | + """ |
| 1259 | + public class X { |
| 1260 | + public static void main(String[] args) { |
| 1261 | + new Poi |
| 1262 | + } |
| 1263 | + } |
| 1264 | + """ |
| 1265 | + ); |
| 1266 | + this.workingCopies[0].getJavaProject(); //assuming single project for all working copies |
| 1267 | + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 1268 | + requestor.allowAllRequiredProposals(); |
| 1269 | + String str = this.workingCopies[0].getSource(); |
| 1270 | + String completeBehind = "new Poi"; |
| 1271 | + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 1272 | + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, new NullProgressMonitor()); |
| 1273 | + assertResults( |
| 1274 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, (II)V, Point, (x, y), 52}", |
| 1275 | + requestor.getResults()); |
| 1276 | + |
| 1277 | + } |
| 1278 | + |
| 1279 | + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4215 |
| 1280 | + // Content Assist doesn't work for record type names in some contexts |
| 1281 | + public void testIssue4215_3() throws JavaModelException { |
| 1282 | + this.workingCopies = new ICompilationUnit[2]; |
| 1283 | + |
| 1284 | + this.workingCopies[1] = getWorkingCopy( |
| 1285 | + "/Completion/src/p/Point.java", |
| 1286 | + """ |
| 1287 | + package p; |
| 1288 | + public record Point(int x, int y) { |
| 1289 | + public Point() { |
| 1290 | + this(0, 0); |
| 1291 | + } |
| 1292 | +
|
| 1293 | + void foo() { |
| 1294 | + System.out.println(this.x); |
| 1295 | + System.out.println(x()); |
| 1296 | + } |
| 1297 | + } |
| 1298 | +
|
| 1299 | + class X { |
| 1300 | + X x = new X(); |
| 1301 | + } |
| 1302 | + """ |
| 1303 | + ); |
| 1304 | + this.workingCopies[0] = getWorkingCopy( |
| 1305 | + "/Completion/src/X.java", |
| 1306 | + """ |
| 1307 | + public class X { |
| 1308 | + public static void main(String[] args) { |
| 1309 | + new Poi |
| 1310 | + } |
| 1311 | + } |
| 1312 | + """ |
| 1313 | + ); |
| 1314 | + this.workingCopies[0].getJavaProject(); //assuming single project for all working copies |
| 1315 | + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 1316 | + requestor.allowAllRequiredProposals(); |
| 1317 | + String str = this.workingCopies[0].getSource(); |
| 1318 | + String completeBehind = "new Poi"; |
| 1319 | + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 1320 | + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, new NullProgressMonitor()); |
| 1321 | + assertResults( |
| 1322 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, ()V, Point, null, 52}\n" + |
| 1323 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, (II)V, Point, (x, y), 52}", |
| 1324 | + requestor.getResults()); |
| 1325 | + |
| 1326 | + } |
| 1327 | + |
| 1328 | + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4215 |
| 1329 | + // Content Assist doesn't work for record type names in some contexts |
| 1330 | + public void testIssue4215_4() throws JavaModelException { |
| 1331 | + this.workingCopies = new ICompilationUnit[2]; |
| 1332 | + |
| 1333 | + this.workingCopies[1] = getWorkingCopy( |
| 1334 | + "/Completion/src/p/Point.java", |
| 1335 | + """ |
| 1336 | + package p; |
| 1337 | + public record Point(int x, int y) { |
| 1338 | + public Point() { |
| 1339 | + this(0, 0); |
| 1340 | + } |
| 1341 | + public Point (int x, int y) { |
| 1342 | + this.x = x; |
| 1343 | + this.y = y; |
| 1344 | + } |
| 1345 | + void foo() { |
| 1346 | + System.out.println(this.x); |
| 1347 | + System.out.println(x()); |
| 1348 | + } |
| 1349 | + } |
| 1350 | +
|
| 1351 | + class X { |
| 1352 | + X x = new X(); |
| 1353 | + } |
| 1354 | + """ |
| 1355 | + ); |
| 1356 | + this.workingCopies[0] = getWorkingCopy( |
| 1357 | + "/Completion/src/X.java", |
| 1358 | + """ |
| 1359 | + public class X { |
| 1360 | + public static void main(String[] args) { |
| 1361 | + new Poi |
| 1362 | + } |
| 1363 | + } |
| 1364 | + """ |
| 1365 | + ); |
| 1366 | + this.workingCopies[0].getJavaProject(); //assuming single project for all working copies |
| 1367 | + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 1368 | + requestor.allowAllRequiredProposals(); |
| 1369 | + String str = this.workingCopies[0].getSource(); |
| 1370 | + String completeBehind = "new Poi"; |
| 1371 | + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 1372 | + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, new NullProgressMonitor()); |
| 1373 | + assertResults( |
| 1374 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, ()V, Point, null, 52}\n" + |
| 1375 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, (II)V, Point, (x, y), 52}\n" + |
| 1376 | + "Point[CONSTRUCTOR_INVOCATION]{(), Lp.Point;, (II)V, Point, (x, y), 52}", // duplicated: see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4222 |
| 1377 | + requestor.getResults()); |
| 1378 | + |
| 1379 | + } |
1184 | 1380 | } |
0 commit comments