Search in sources :

Example 6 with DiagnosticsHandler

use of org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler in project eclipse.jdt.ls by eclipse.

the class DiagnosticsCommand method publishDiagnostics.

private static void publishDiagnostics(JavaClientConnection connection, ICompilationUnit unit, IProgressMonitor monitor) throws JavaModelException {
    final DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit);
    WorkingCopyOwner wcOwner = new WorkingCopyOwner() {

        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            ICompilationUnit original = workingCopy.getPrimary();
            IResource resource = original.getResource();
            if (resource instanceof IFile) {
                return new DocumentAdapter(workingCopy, (IFile) resource);
            }
            return DocumentAdapter.Null;
        }

        @Override
        public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
            return handler;
        }
    };
    int flags = ICompilationUnit.FORCE_PROBLEM_DETECTION | ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
    unit.reconcile(ICompilationUnit.NO_AST, flags, wcOwner, monitor);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) DocumentAdapter(org.eclipse.jdt.ls.core.internal.DocumentAdapter) DiagnosticsHandler(org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler) IResource(org.eclipse.core.resources.IResource)

Example 7 with DiagnosticsHandler

use of org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler in project eclipse.jdt.ls by eclipse.

the class MavenClasspathTest method testTest.

@Test
public void testTest() throws Exception {
    IProject project = importMavenProject("classpathtest");
    IJavaProject javaProject = JavaCore.create(project);
    IType type = javaProject.findType("test.AppTest");
    ICompilationUnit cu = type.getCompilationUnit();
    openDocument(cu, cu.getSource(), 1);
    final DiagnosticsHandler handler = new DiagnosticsHandler(javaClient, cu);
    WorkingCopyOwner wcOwner = getWorkingCopy(handler);
    cu.reconcile(ICompilationUnit.NO_AST, true, wcOwner, null);
    assertTrue("There is a problem", handler.getProblems().size() == 0);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaProject(org.eclipse.jdt.core.IJavaProject) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) DiagnosticsHandler(org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 DiagnosticsHandler (org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)6 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)6 Test (org.junit.Test)5 IProject (org.eclipse.core.resources.IProject)4 IType (org.eclipse.jdt.core.IType)3 IFile (org.eclipse.core.resources.IFile)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 IProblem (org.eclipse.jdt.core.compiler.IProblem)2 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)2 CodeAction (org.eclipse.lsp4j.CodeAction)2 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)2 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1