| Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #947666] |
Wed, 17 October 2012 05:45  |
Thomas Schindl Messages: 4462 Registered: July 2009 |
Senior Member |
|
|
Hi,
When trying to get informations about problems happening while modifying
a working copy of the ICompilationUnit I only managed find a way to do
this using the deprecated
ICompilationUnit#becomeWorkingCopy(IProblemRequestor, ProgressMonitor)
My current code looks something like this (please note I'm a JDT-Dummy
more or less so maybe what I do makes not really sense)
-----------8<---------------
class MyJDTEditor {
MyJDTEditor(IEditorInput input) {
IResourceFileInput fsInput = (IResourceFileInput) input;
unit = (ICompilationUnit) JavaCore.create(fsInput.getFile());
unit.becomeWorkingCopy(new IProblemRequestor() {
// ...
public void acceptProblem(IProblem problem) {
int linenumber = problem.getSourceLineNumber();
int srcStart = problem.getSourceStart();
int srcEnd = problem.getSourceEnd();
});
}
public void insert(int start, String data) {
try {
unit.getBuffer().replace(start, 0, data);
unit.reconcile(ICompilationUnit.NO_AST, true, null, null);
} catch (JavaModelException e) {}
}
public void set(String data) {
try {
unit.getBuffer().setContents(data);
unit.reconcile(ICompilationUnit.NO_AST, true, null, null);
} catch (JavaModelException e) {}
}
public void save() {
unit.commitWorkingCopy(true, null);
}
}
-----------8<---------------
So what is the none deprecated way to get access to the compilation
errors/warnings? Pointers to JDT-UI code to see how things are dealt are
probably even better ;-)
Thanks
Tom
|
|
|