Search in sources :

Example 1 with ReconcileResult

use of org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult in project che by eclipse.

the class ReconcileTest method testCompilationUnitReconcile.

@Test
public void testCompilationUnitReconcile() throws Exception {
    setWorkingCopyContents("package p1;\n" + "public class X {\n" + "  public void foo() {\n" + "  }\n" + "  public void foo() {\n" + "  }\n" + "}");
    ReconcileResult reconcile = reconciler.reconcile(project, "p1.X");
    assertThat(reconcile).isNotNull();
    assertThat(reconcile.getProblems()).hasSize(2);
    assertThat(reconcile.getProblems()).onProperty("message").containsSequence("Duplicate method foo() in type X");
    assertThat(reconcile.getProblems()).onProperty("error").containsSequence(true);
}
Also used : ReconcileResult(org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult) Test(org.junit.Test)

Example 2 with ReconcileResult

use of org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult in project che by eclipse.

the class ReconcileTest method testWarnings.

@Test
public void testWarnings() throws Exception {
    project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR);
    project.setOption(JavaCore.COMPILER_PB_UNUSED_PARAMETER, JavaCore.ERROR);
    setWorkingCopyContents("package p1;\n" + "public class X {\n" + "  public void foo() {\n" + "     int i = 0;\n" + "     String b = new String();\n" + "     System.out.println(b);\n" + "  }\n" + "}");
    ReconcileResult reconcile = reconciler.reconcile(project, "p1.X");
    assertThat(reconcile.getProblems()).onProperty("error").containsSequence(true);
}
Also used : ReconcileResult(org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult) Test(org.junit.Test)

Example 3 with ReconcileResult

use of org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult in project che by eclipse.

the class JavaReconciler method reconcile.

public ReconcileResult reconcile(IJavaProject javaProject, String fqn) throws JavaModelException {
    final ProblemRequestor requestor = new ProblemRequestor();
    WorkingCopyOwner wcOwner = new WorkingCopyOwner() {

        public IProblemRequestor getProblemRequestor(ICompilationUnit unit) {
            return requestor;
        }

        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            //                ?????
            return new org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter(workingCopy, (IFile) workingCopy.getResource());
        }
    };
    List<HighlightedPosition> positions = null;
    ICompilationUnit compilationUnit = null;
    try {
        IType type = javaProject.findType(fqn);
        if (type == null) {
            return null;
        }
        if (type.isBinary()) {
            throw new IllegalArgumentException("Can't reconcile binary type: " + fqn);
        } else {
            compilationUnit = type.getCompilationUnit().getWorkingCopy(wcOwner, null);
        }
        requestor.reset();
        CompilationUnit unit = compilationUnit.reconcile(AST.JLS8, true, wcOwner, null);
        positions = semanticHighlighting.reconcileSemanticHighlight(unit);
        if (compilationUnit instanceof ClassFileWorkingCopy) {
            //we don't wont to show any errors from ".class" files
            requestor.reset();
        }
    } catch (JavaModelException e) {
        LOG.error("Can't reconcile class: " + fqn + " in project:" + javaProject.getPath().toOSString(), e);
        throw e;
    } finally {
        if (compilationUnit != null && compilationUnit.isWorkingCopy()) {
            try {
                //todo close buffer
                compilationUnit.getBuffer().close();
                compilationUnit.discardWorkingCopy();
            } catch (JavaModelException e) {
            //ignore
            }
        }
    }
    ReconcileResult result = DtoFactory.getInstance().createDto(ReconcileResult.class);
    result.setProblems(convertProblems(requestor.problems));
    result.setHighlightedPositions(positions);
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IProblemRequestor(org.eclipse.jdt.core.IProblemRequestor) IType(org.eclipse.jdt.core.IType) ClassFileWorkingCopy(org.eclipse.jdt.internal.core.ClassFileWorkingCopy) HighlightedPosition(org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition) ReconcileResult(org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner)

Aggregations

ReconcileResult (org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult)3 Test (org.junit.Test)2 HighlightedPosition (org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IProblemRequestor (org.eclipse.jdt.core.IProblemRequestor)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 ClassFileWorkingCopy (org.eclipse.jdt.internal.core.ClassFileWorkingCopy)1