use of org.eclipse.jdt.core.IProblemRequestor 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.jdt.core.IProblemRequestor in project che by eclipse.
the class ReconcileWorkingCopyOperation method executeOperation.
/**
* @throws org.eclipse.jdt.core.JavaModelException
* if setting the source
* of the original compilation unit fails
*/
protected void executeOperation() throws JavaModelException {
checkCanceled();
try {
beginTask(Messages.element_reconciling, 2);
CompilationUnit workingCopy = getWorkingCopy();
boolean wasConsistent = workingCopy.isConsistent();
// check is problem requestor is active
IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
if (problemRequestor != null)
problemRequestor = ((JavaModelManager.PerWorkingCopyInfo) problemRequestor).getProblemRequestor();
boolean defaultRequestorIsActive = problemRequestor != null && problemRequestor.isActive();
IProblemRequestor ownerProblemRequestor = this.workingCopyOwner.getProblemRequestor(workingCopy);
boolean ownerRequestorIsActive = ownerProblemRequestor != null && ownerProblemRequestor != problemRequestor && ownerProblemRequestor.isActive();
this.requestorIsActive = defaultRequestorIsActive || ownerRequestorIsActive;
// create the delta builder (this remembers the current content of the cu)
this.deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
// make working copy consistent if needed and compute AST if needed
makeConsistent(workingCopy);
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319)
if (!wasConsistent || ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)) {
notifyParticipants(workingCopy);
// recreate ast if one participant reset it
if (this.ast == null)
makeConsistent(workingCopy);
}
// report problems
if (this.problems != null && (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) || !wasConsistent)) {
if (defaultRequestorIsActive) {
reportProblems(workingCopy, problemRequestor);
}
if (ownerRequestorIsActive) {
reportProblems(workingCopy, ownerProblemRequestor);
}
}
// report delta
JavaElementDelta delta = this.deltaBuilder.delta;
if (delta != null) {
addReconcileDelta(workingCopy, delta);
}
} finally {
done();
}
}
use of org.eclipse.jdt.core.IProblemRequestor in project che by eclipse.
the class QuickFixTest method collectCorrections2.
protected static final ArrayList collectCorrections2(ICompilationUnit cu, int nProblems) throws CoreException {
final ArrayList problemsList = new ArrayList();
final IProblemRequestor requestor = new IProblemRequestor() {
public void acceptProblem(IProblem problem) {
problemsList.add(problem);
}
public void beginReporting() {
problemsList.clear();
}
public void endReporting() {
}
public boolean isActive() {
return true;
}
};
WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
return requestor;
}
};
ICompilationUnit wc = cu.getWorkingCopy(workingCopyOwner, null);
try {
wc.reconcile(ICompilationUnit.NO_AST, true, true, wc.getOwner(), null);
} finally {
wc.discardWorkingCopy();
}
IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
assertNumberOfProblems(nProblems, problems);
return collectCorrections(cu, problems[0], null);
}
Aggregations