Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Tracking problems while modifying a ICompilationUnit (use none deprecated methods)
Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #947666] Wed, 17 October 2012 09:45 Go to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
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 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
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
>
>
>
Re: Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #948880 is a reply to message #947691] Thu, 18 October 2012 13:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
Am 17.10.12 12:16, schrieb Daniel Megert:
> 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

That worked like a charme. Is there anything I need to do when I close
my editor to clean up the ICompilationUnit?

Tom
Re: Tracking problems while modifying a ICompilationUnit (use none deprecated methods) [message #948953 is a reply to message #948880] Thu, 18 October 2012 14:43 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
On 18.10.2012 15:24, Tom Schindl wrote:
> Am 17.10.12 12:16, schrieb Daniel Megert:
>> 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
> That worked like a charme. Is there anything I need to do when I close
> my editor to clean up the ICompilationUnit?
See org.eclipse.jdt.core.ICompilationUnit.discardWorkingCopy()

Dani
>
> Tom
>
>
Previous Topic:Need Help getting Hello Program on screen
Next Topic:J2EE 4.2.1 from 4.2.0 update fail
Goto Forum:
  


Current Time: Fri Dec 19 21:12:26 GMT 2014

Powered by FUDForum. Page generated in 0.01719 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software