Search in sources :

Example 1 with DiagnosticTag

use of org.eclipse.lsp4j.DiagnosticTag in project eclipse.jdt.ls by eclipse.

the class DiagnosticHandlerTest method testUnnecessary.

@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));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) Diagnostic(org.eclipse.lsp4j.Diagnostic) IProblem(org.eclipse.jdt.core.compiler.IProblem) DiagnosticTag(org.eclipse.lsp4j.DiagnosticTag) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 2 with DiagnosticTag

use of org.eclipse.lsp4j.DiagnosticTag in project eclipse.jdt.ls by eclipse.

the class DiagnosticHandlerTest method testDeprecated.

@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));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) Diagnostic(org.eclipse.lsp4j.Diagnostic) IProblem(org.eclipse.jdt.core.compiler.IProblem) DiagnosticTag(org.eclipse.lsp4j.DiagnosticTag) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 IProblem (org.eclipse.jdt.core.compiler.IProblem)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 DiagnosticTag (org.eclipse.lsp4j.DiagnosticTag)2 Test (org.junit.Test)2