org.eclipse.lsp4j.DiagnosticTag Java Examples

The following examples show how to use org.eclipse.lsp4j.DiagnosticTag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiagnosticHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDeprecated() throws Exception {
	IJavaProject javaProject = newEmptyProject();
	IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	StringBuilder buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("import java.security.Certificate;\n");
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

	CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, monitor);
	IProblem[] problems = astRoot.getProblems();
	List<Diagnostic> diagnostics = DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems), true);
	assertEquals(2, diagnostics.size());
	List<DiagnosticTag> tags = diagnostics.get(0).getTags();
	assertEquals(1, tags.size());
	assertEquals(DiagnosticTag.Deprecated, tags.get(0));
}
 
Example #2
Source File: DiagnosticHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnnecessary() throws Exception {
	IJavaProject javaProject = newEmptyProject();
	IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	StringBuilder buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("import java.security.*;\n");
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

	CompilationUnit asRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, monitor);
	IProblem[] problems = asRoot.getProblems();
	List<Diagnostic> diagnostics = DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems), true);
	assertEquals(1, diagnostics.size());
	List<DiagnosticTag> tags = diagnostics.get(0).getTags();
	assertEquals(1, tags.size());
	assertEquals(DiagnosticTag.Unnecessary, tags.get(0));
}
 
Example #3
Source File: BaseDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static List<DiagnosticTag> getDiagnosticTag(int id) {
	switch (id) {
		case IProblem.UsingDeprecatedType:
		case IProblem.UsingDeprecatedField:
		case IProblem.UsingDeprecatedMethod:
		case IProblem.UsingDeprecatedConstructor:
		case IProblem.OverridingDeprecatedMethod:
		case IProblem.JavadocUsingDeprecatedField:
		case IProblem.JavadocUsingDeprecatedConstructor:
		case IProblem.JavadocUsingDeprecatedMethod:
		case IProblem.JavadocUsingDeprecatedType:
		case IProblem.UsingTerminallyDeprecatedType:
		case IProblem.UsingTerminallyDeprecatedMethod:
		case IProblem.UsingTerminallyDeprecatedConstructor:
		case IProblem.UsingTerminallyDeprecatedField:
		case IProblem.OverridingTerminallyDeprecatedMethod:
		case IProblem.UsingDeprecatedSinceVersionType:
		case IProblem.UsingDeprecatedSinceVersionMethod:
		case IProblem.UsingDeprecatedSinceVersionConstructor:
		case IProblem.UsingDeprecatedSinceVersionField:
		case IProblem.OverridingDeprecatedSinceVersionMethod:
		case IProblem.UsingTerminallyDeprecatedSinceVersionType:
		case IProblem.UsingTerminallyDeprecatedSinceVersionMethod:
		case IProblem.UsingTerminallyDeprecatedSinceVersionConstructor:
		case IProblem.UsingTerminallyDeprecatedSinceVersionField:
		case IProblem.OverridingTerminallyDeprecatedSinceVersionMethod:
		case IProblem.UsingDeprecatedPackage:
		case IProblem.UsingDeprecatedSinceVersionPackage:
		case IProblem.UsingTerminallyDeprecatedPackage:
		case IProblem.UsingTerminallyDeprecatedSinceVersionPackage:
		case IProblem.UsingDeprecatedModule:
		case IProblem.UsingDeprecatedSinceVersionModule:
		case IProblem.UsingTerminallyDeprecatedModule:
		case IProblem.UsingTerminallyDeprecatedSinceVersionModule:
			return Arrays.asList(DiagnosticTag.Deprecated);
		case IProblem.UnnecessaryCast:
		case IProblem.UnnecessaryInstanceof:
		case IProblem.UnnecessaryElse:
		case IProblem.UnnecessaryNLSTag:
		// Report *unused* cases as unnecessary
		case IProblem.UnusedPrivateType:
		case IProblem.UnusedPrivateField:
		case IProblem.UnusedPrivateMethod:
		case IProblem.UnusedPrivateConstructor:
		case IProblem.UnusedObjectAllocation:
		case IProblem.UnusedMethodDeclaredThrownException:
		case IProblem.UnusedConstructorDeclaredThrownException:
		case IProblem.UnusedLabel:
		case IProblem.UnusedImport:
		case IProblem.UnusedTypeArgumentsForMethodInvocation:
		case IProblem.UnusedWarningToken:
		case IProblem.UnusedTypeArgumentsForConstructorInvocation:
		case IProblem.UnusedTypeParameter:
		// Other unused cases
		case IProblem.LocalVariableIsNeverUsed:
		case IProblem.ArgumentIsNeverUsed:
		case IProblem.ExceptionParameterIsNeverUsed:
			return Arrays.asList(DiagnosticTag.Unnecessary);
	}

	return null;
}
 
Example #4
Source File: DiagnosticsTagSupport.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DiagnosticsTagSupport() {
  ArrayList<DiagnosticTag> _arrayList = new ArrayList<DiagnosticTag>();
  this.valueSet = _arrayList;
}
 
Example #5
Source File: DiagnosticsTagSupport.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DiagnosticsTagSupport(@NonNull final List<DiagnosticTag> valueSet) {
  this.valueSet = Preconditions.<List<DiagnosticTag>>checkNotNull(valueSet, "valueSet");
}
 
Example #6
Source File: DiagnosticsTagSupport.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The tags supported by the client.
 */
@Pure
@NonNull
public List<DiagnosticTag> getValueSet() {
  return this.valueSet;
}
 
Example #7
Source File: DiagnosticsTagSupport.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The tags supported by the client.
 */
public void setValueSet(@NonNull final List<DiagnosticTag> valueSet) {
  this.valueSet = Preconditions.checkNotNull(valueSet, "valueSet");
}
 
Example #8
Source File: Diagnostic.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Additional metadata about the diagnostic.
 * 
 * Since 3.15.0
 */
@Pure
public List<DiagnosticTag> getTags() {
  return this.tags;
}
 
Example #9
Source File: Diagnostic.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Additional metadata about the diagnostic.
 * 
 * Since 3.15.0
 */
public void setTags(final List<DiagnosticTag> tags) {
  this.tags = tags;
}