use of org.eclipse.jdt.ls.core.internal.preferences.Preferences.Severity in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandler method handleOpen.
public void handleOpen(DidOpenTextDocumentParams params) {
String uri = params.getTextDocument().getUri();
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
if (unit == null || unit.getResource() == null) {
return;
}
try {
// checks if the underlying resource exists and refreshes to sync the newly created file.
if (!unit.getResource().isAccessible()) {
try {
unit.getResource().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
if (unit.getResource().exists()) {
IJavaElement parent = unit.getParent();
if (parent instanceof IPackageFragment) {
IPackageFragment pkg = (IPackageFragment) parent;
unit = pkg.createCompilationUnit(unit.getElementName(), unit.getSource(), true, new NullProgressMonitor());
}
}
} catch (CoreException e) {
// ignored
}
}
IProject project = unit.getResource().getProject();
// Resources belonging to the default project can only report syntax errors, because the project classpath is incomplete
boolean isDefaultProject = project.equals(JavaLanguageServerPlugin.getProjectsManager().getDefaultProject());
if (isDefaultProject || !JDTUtils.isOnClassPath(unit)) {
Severity severity = preferenceManager.getPreferences(project).getIncompleteClasspathSeverity();
String msg;
if (isDefaultProject) {
msg = "Classpath is incomplete. Only syntax errors will be reported";
} else {
msg = unit.getElementName() + " isn't on the classpath. Only syntax errors will be reported";
}
JavaLanguageServerPlugin.logInfo(msg + " for " + uri);
if (severity.compareTo(Preferences.Severity.ignore) > 0) {
ActionableNotification ignoreIncompleteClasspath = new ActionableNotification().withSeverity(severity.toMessageType()).withMessage(msg).withCommands(Arrays.asList(new Command("More Information", "java.ignoreIncompleteClasspath.help", null), new Command("Don't Show Again", "java.ignoreIncompleteClasspath", null)));
connection.sendActionableNotification(ignoreIncompleteClasspath);
}
}
// DiagnosticsHandler problemRequestor = new DiagnosticsHandler(connection, unit.getResource(), reportOnlySyntaxErrors);
unit.becomeWorkingCopy(new NullProgressMonitor());
IBuffer buffer = unit.getBuffer();
String newContent = params.getTextDocument().getText();
if (buffer != null && !buffer.getContents().equals(newContent)) {
buffer.setContents(newContent);
}
triggerValidation(unit);
// see https://github.com/redhat-developer/vscode-java/issues/274
checkPackageDeclaration(uri, unit);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Error while opening document", e);
}
}
Aggregations