Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » How do I convert a tree selection to a ITreeTranslationUnit
How do I convert a tree selection to a ITreeTranslationUnit [message #231495] Wed, 11 March 2009 23:21 Go to next message
Eclipse UserFriend
Hello,

I am developing a CDT plugin that will traverse the AST of a Translation
Unit.

I figured out how to set up a popup menu that applies to Translation Units
but I have a casting problem.

The "run" function of the Action that I wrote needs to convert a
TreeSelection to an ITranslationUnit. I did this by casting the first
element of the treeeSelection into a TranslationUnit which I can assign to
the "translationUnit" variable. However, Java is giving me a warning on
this.

What is the accepted way to convert elements of a treee selection into
ITranslationUnit.

I included a snippet of my "run" function.

-David

public void run(IAction action)
{
if (selection instanceof TreeSelection)
{
TreeSelection treeSelection = (TreeSelection) selection;
Object firstElement = treeSelection.getFirstElement();
ITranslationUnit translationUnit = (TranslationUnit) firstElement;
...
}
}
Re: How do I convert a tree selection to a ITreeTranslationUnit [message #231503 is a reply to message #231495] Thu, 12 March 2009 03:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: subs._nospam_consertum.com

Looking at your code, you are casting a TranslationUnit to an
ITranslationUnit... perhaps if you cast to the same type, the warning
would go away?

David Glaser wrote:
> Hello,
>
> I am developing a CDT plugin that will traverse the AST of a Translation
> Unit.
>
> I figured out how to set up a popup menu that applies to Translation Units
> but I have a casting problem.
>
> The "run" function of the Action that I wrote needs to convert a
> TreeSelection to an ITranslationUnit. I did this by casting the first
> element of the treeeSelection into a TranslationUnit which I can assign to
> the "translationUnit" variable. However, Java is giving me a warning on
> this.
>
> What is the accepted way to convert elements of a treee selection into
> ITranslationUnit.
>
> I included a snippet of my "run" function.
>
> -David
>
> public void run(IAction action)
> {
> if (selection instanceof TreeSelection)
> {
> TreeSelection treeSelection = (TreeSelection) selection;
> Object firstElement = treeSelection.getFirstElement();
> ITranslationUnit translationUnit = (TranslationUnit) firstElement;
> ...
> }
> }
>
>


--
Derek
Re: How do I convert a tree selection to a ITreeTranslationUnit [message #231528 is a reply to message #231503] Thu, 12 March 2009 10:09 Go to previous messageGo to next message
Eclipse UserFriend
Hi Derek,

The error I get is

Discouraged access: The type TranslationUnit is not accessible due to
restriction on required library C:\Program
Files\eclipse\plugins\org.eclipse.cdt.core_5.0.2.20090213080 1.jar
NewAction.java CppAnalysisTool/src/cppanalysistool/popup/actions line 11
Java Problem

The above problem relates to the issue that I should not be looking at
something (TranslationUnit) that is defined in the package
"org.eclipse.cdt.internal.core.model" which should not be accessed by my
code.

-David
===============================================
"Derek" <subs@_nospam_consertum.com> wrote in message
news:gpafca$gdv$1@build.eclipse.org...
> Looking at your code, you are casting a TranslationUnit to an
> ITranslationUnit... perhaps if you cast to the same type, the warning
> would go away?
>
Re: How do I convert a tree selection to a ITreeTranslationUnit [message #231535 is a reply to message #231528] Thu, 12 March 2009 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: subs._nospam_consertum.com

David Glaser wrote:
> Hi Derek,
>
> The error I get is
>
> Discouraged access: The type TranslationUnit is not accessible due to
> restriction on required library C:\Program
> Files\eclipse\plugins\org.eclipse.cdt.core_5.0.2.20090213080 1.jar
> NewAction.java CppAnalysisTool/src/cppanalysistool/popup/actions line 11
> Java Problem
>
> The above problem relates to the issue that I should not be looking at
> something (TranslationUnit) that is defined in the package
> "org.eclipse.cdt.internal.core.model" which should not be accessed by my
> code.
>
> -David
> ===============================================
> "Derek" <subs@_nospam_consertum.com> wrote in message
> news:gpafca$gdv$1@build.eclipse.org...
>> Looking at your code, you are casting a TranslationUnit to an
>> ITranslationUnit... perhaps if you cast to the same type, the warning
>> would go away?
>>
>
>
But why are you not doing this:

ITranslationUnit translationUnit = (ITranslationUnit) firstElement;
^^^^^^^^^^^^^^^^
ITranslation unit IS api.

--
Derek
Re: How do I convert a tree selection to a ITreeTranslationUnit [message #231550 is a reply to message #231535] Thu, 12 March 2009 13:58 Go to previous message
Eclipse UserFriend
Oops, I see your point. I changed it as you suggested and things work just
fine.

-David
=======================
"Derek" <subs@_nospam_consertum.com> wrote in message
news:49B91B78.8080908@_nospam_consertum.com...
> David Glaser wrote:
>> Hi Derek,
>>
>> The error I get is
>>
>> Discouraged access: The type TranslationUnit is not accessible due to
>> restriction on required library C:\Program
>> Files\eclipse\plugins\org.eclipse.cdt.core_5.0.2.20090213080 1.jar
>> NewAction.java CppAnalysisTool/src/cppanalysistool/popup/actions line 11
>> Java Problem
>>
>> The above problem relates to the issue that I should not be looking at
>> something (TranslationUnit) that is defined in the package
>> "org.eclipse.cdt.internal.core.model" which should not be accessed by my
>> code.
>>
>> -David
>> ===============================================
>> "Derek" <subs@_nospam_consertum.com> wrote in message
>> news:gpafca$gdv$1@build.eclipse.org...
>>> Looking at your code, you are casting a TranslationUnit to an
>>> ITranslationUnit... perhaps if you cast to the same type, the warning
>>> would go away?
>>>
>>
>>
> But why are you not doing this:
>
> ITranslationUnit translationUnit = (ITranslationUnit) firstElement;
> ^^^^^^^^^^^^^^^^
> ITranslation unit IS api.
>
> --
> Derek
Previous Topic:Better way to take over changes of library to the related project?
Next Topic:exception while checking CDT 5.0.2
Goto Forum:
  


Current Time: Sun Jun 01 04:11:50 EDT 2025

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

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

Back to the top