Search in sources :

Example 1 with HighlightedPosition

use of org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition 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)

Example 2 with HighlightedPosition

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

the class JavaReconcilerStrategyTest method shouldDoParseWhenResolvingProjectHasResolved.

@Test
public void shouldDoParseWhenResolvingProjectHasResolved() throws Exception {
    when(resolvingProjectStateHolder.getState()).thenReturn(RESOLVED);
    HighlightedPosition highlightedPosition = mock(HighlightedPosition.class);
    List<HighlightedPosition> positions = new ArrayList<>();
    positions.add(highlightedPosition);
    when(reconcileResult.getHighlightedPositions()).thenReturn(positions);
    javaReconcilerStrategy.parse();
    verify(client).reconcile(anyString(), anyString(), reconcileCallbackCaptor.capture());
    JavaReconcileClient.ReconcileCallback reconcileCallback = reconcileCallbackCaptor.getValue();
    reconcileCallback.onReconcile(reconcileResult);
    verify(reconcileResult).getProblems();
    verify(reconcileResult).getHighlightedPositions();
    verify(codeAssistProcessor).enableCodeAssistant();
    verify(codeAssistProcessor, never()).disableCodeAssistant(anyString());
    verify(highlighter).reconcile(eq(positions));
}
Also used : HighlightedPosition(org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with HighlightedPosition

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

the class ReconcileTest method testSemanticHighlight.

@Test
public void testSemanticHighlight() throws Exception {
    IType type = project.findType("java.lang.Object");
    ICompilationUnit copy = type.getClassFile().getWorkingCopy(DefaultWorkingCopyOwner.PRIMARY, null);
    CompilationUnit unit = copy.reconcile(AST.JLS8, true, DefaultWorkingCopyOwner.PRIMARY, null);
    SemanticHighlightingReconciler reconciler = new SemanticHighlightingReconciler();
    List<HighlightedPosition> positions = reconciler.reconcileSemanticHighlight(unit);
    assertThat(positions).isNotNull().isNotEmpty();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HighlightedPosition(org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition) SemanticHighlightingReconciler(org.eclipse.che.jdt.javaeditor.SemanticHighlightingReconciler) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 4 with HighlightedPosition

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

the class SemanticHighlightRenderer method reconcile.

public void reconcile(List<HighlightedPosition> positions) {
    for (HasTextMarkers.MarkerRegistration marker : markers) {
        marker.clearMark();
    }
    markers.clear();
    for (HighlightedPosition position : positions) {
        final TextPosition from = this.document.getPositionFromIndex(position.getOffset());
        final TextPosition to = this.document.getPositionFromIndex(position.getOffset() + position.getLength());
        HasTextMarkers.MarkerRegistration registration = editor.addMarker(new TextRange(from, to), styleMap.get(position.getType()));
        if (registration != null) {
            markers.add(registration);
        }
    }
}
Also used : HasTextMarkers(org.eclipse.che.ide.api.editor.texteditor.HasTextMarkers) HighlightedPosition(org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextRange(org.eclipse.che.ide.api.editor.text.TextRange)

Aggregations

HighlightedPosition (org.eclipse.che.ide.ext.java.shared.dto.HighlightedPosition)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)1 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)1 HasTextMarkers (org.eclipse.che.ide.api.editor.texteditor.HasTextMarkers)1 ReconcileResult (org.eclipse.che.ide.ext.java.shared.dto.ReconcileResult)1 SemanticHighlightingReconciler (org.eclipse.che.jdt.javaeditor.SemanticHighlightingReconciler)1 IProblemRequestor (org.eclipse.jdt.core.IProblemRequestor)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)1 ClassFileWorkingCopy (org.eclipse.jdt.internal.core.ClassFileWorkingCopy)1