Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #947666] |
Wed, 17 October 2012 09:45 |
Thomas Schindl Messages: 6651 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
|
|
|
Re: Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #947691 is a reply to message #947666] |
Wed, 17 October 2012 10:16 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
On 17.10.2012 11:45, Tom Schindl wrote:
> 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)
The safest way (to shield yourself from the primary working copy model
owned/used by JDT) would be to implement your own WorkingCopyOwner and
use it in the JDT Core APIs. To create a working copy you'd call
org.eclipse.jdt.core.ITypeRoot.getWorkingCopy(WorkingCopyOwner,
IProgressMonitor).
Dani
>
> 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
>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03382 seconds