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;
}
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));
}
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();
}
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);
}
}
}
Aggregations