|
44 | 44 | import org.eclipse.jdt.core.JavaCore;
|
45 | 45 | import org.eclipse.jdt.core.JavaModelException;
|
46 | 46 | import org.eclipse.jdt.core.compiler.IProblem;
|
| 47 | +import org.eclipse.jdt.ls.core.internal.EventNotification; |
| 48 | +import org.eclipse.jdt.ls.core.internal.EventType; |
47 | 49 | import org.eclipse.jdt.ls.core.internal.JDTUtils;
|
48 | 50 | import org.eclipse.jdt.ls.core.internal.JavaClientConnection;
|
49 | 51 | import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
|
|
62 | 64 | import org.eclipse.m2e.core.internal.IMavenConstants;
|
63 | 65 | import org.eclipse.m2e.core.internal.Messages;
|
64 | 66 |
|
| 67 | +import com.google.gson.JsonArray; |
| 68 | +import com.google.gson.JsonObject; |
| 69 | + |
65 | 70 | /**
|
66 | 71 | * Listens to the resource change events and converts {@link IMarker}s to {@link Diagnostic}s.
|
67 | 72 | *
|
@@ -342,6 +347,31 @@ private void publishDiagnostics(List<IMarker> markers) {
|
342 | 347 | connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
|
343 | 348 | }
|
344 | 349 | }
|
| 350 | + |
| 351 | + checkPreviewFeatureValidity(markers); |
| 352 | + } |
| 353 | + |
| 354 | + public static void checkPreviewFeatureValidity(List<IMarker> problemMarkers) { |
| 355 | + // Preview feature support enabled on incompatible release version |
| 356 | + List<IMarker> previewFeatureMarkers = problemMarkers.stream().filter(m -> m.getAttribute(IJavaModelMarker.ID, 0) == IProblem.PreviewFeaturesNotAllowed).collect(Collectors.toList()); |
| 357 | + JsonArray errorList = new JsonArray(); |
| 358 | + if (!previewFeatureMarkers.isEmpty()) { |
| 359 | + for (IMarker marker : previewFeatureMarkers) { |
| 360 | + // error message mentions invalid release level, and the supported level |
| 361 | + String errorMessage = ResourceUtils.getMessage(marker); |
| 362 | + String projectUri = JDTUtils.getFileURI(marker.getResource().getProject()); |
| 363 | + JsonObject entry = new JsonObject(); |
| 364 | + entry.addProperty("uri", projectUri); |
| 365 | + entry.addProperty("message", errorMessage); |
| 366 | + if (!errorList.contains(entry)) { |
| 367 | + errorList.add(entry); |
| 368 | + } |
| 369 | + } |
| 370 | + if (JavaLanguageServerPlugin.getProjectsManager().getConnection() != null) { |
| 371 | + EventNotification prevFeatNotAllowedNotification = new EventNotification().withType(EventType.PreviewFeaturesNotAllowed).withData(errorList); |
| 372 | + JavaLanguageServerPlugin.getProjectsManager().getConnection().sendEventNotification(prevFeatNotAllowedNotification); |
| 373 | + } |
| 374 | + } |
345 | 375 | }
|
346 | 376 |
|
347 | 377 | @Deprecated
|
|
0 commit comments