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