Home » Language IDEs » Java Development Tools (JDT) » Increase visibility of a method via content assist
Increase visibility of a method via content assist [message #250624] |
Sat, 12 January 2008 06:37  |
Eclipse User |
|
|
|
Hi,
I am trying to add content assist to my plug-in, so that a user can
increase the visibility of a method in a type, if it's not yet visible.
Consider this example:
class A {
private a() {...}
public anotherMethod() {...}
}
class B {
private b() {
A a = new A();
a.a(); // causes a compiler error, since a is not visible.
}
}
What I would like to have now is that, when typing the B class, the user
can type a.a<ctrl+space> and the content assist would propose "Increase
the visibility of A.a from private to package default."
My problem is that so far, I have found the
"JavaCompletionProposalComputer" (which I am not allowed to use, yeah I
know ;)) which gives me a list of all methods for code completion. So, in
the above example, if I type "a.a<ctrl+space>", it will yield
"anotherMethod" -- but not a, since a is not visible...
I read through the code some more and found that ultimately, the content
assist is performed by the compilation unit, which creates a
CompletionEngine.
=> Is there any way for me to get _all_ declared methods in the compilation
unit that is proposed by the CompletionProposalComputer? [In other words: How
do I get the ICompilationUnit proposed by the ProposalComputer? -- If I have
the correct ICompilationUnit, I can look for the methods myself].
I guess it all boils down to: "If I type a.a<ctrl+space>, how do I get the
CompilationUnit, in which the Type of the variable a is defined?"
Thanks for your patience and your help!
Kind Regards,
Philipp Bouillon
|
|
|
Re: Increase visibility of a method via content assist [message #250631 is a reply to message #250624] |
Sat, 12 January 2008 07:25   |
Eclipse User |
|
|
|
Philipp Bouillon wrote:
> Hi,
>
> I am trying to add content assist to my plug-in, so that a user can
> increase the visibility of a method in a type, if it's not yet visible.
This is already provided by Eclipse itself: simply use the corresponding
quick fix (Ctrl+1).
Eclipse doesn't use code assist to fix errors and warning but quick fix.
In addition Ctrl+1 also gives you access to quick assists (e.g. local
rename).
HTH
Dani
>
> Consider this example:
>
> class A {
> private a() {...}
> public anotherMethod() {...}
> }
>
> class B {
> private b() {
> A a = new A();
> a.a(); // causes a compiler error, since a is not visible.
> }
> }
>
> What I would like to have now is that, when typing the B class, the
> user can type a.a<ctrl+space> and the content assist would propose
> "Increase the visibility of A.a from private to package default."
>
> My problem is that so far, I have found the
> "JavaCompletionProposalComputer" (which I am not allowed to use, yeah
> I know ;)) which gives me a list of all methods for code completion.
> So, in the above example, if I type "a.a<ctrl+space>", it will yield
> "anotherMethod" -- but not a, since a is not visible...
> I read through the code some more and found that ultimately, the
> content assist is performed by the compilation unit, which creates a
> CompletionEngine.
>
> => Is there any way for me to get _all_ declared methods in the
> compilation unit that is proposed by the CompletionProposalComputer?
> [In other words: How do I get the ICompilationUnit proposed by the
> ProposalComputer? -- If I have the correct ICompilationUnit, I can
> look for the methods myself].
>
> I guess it all boils down to: "If I type a.a<ctrl+space>, how do I get
> the CompilationUnit, in which the Type of the variable a is defined?"
>
> Thanks for your patience and your help!
> Kind Regards,
> Philipp Bouillon
>
|
|
|
Re: Increase visibility of a method via content assist [message #250635 is a reply to message #250631] |
Sat, 12 January 2008 07:29  |
Eclipse User |
|
|
|
Daniel Megert wrote:
> Philipp Bouillon wrote:
>> Hi,
>>
>> I am trying to add content assist to my plug-in, so that a user can
>> increase the visibility of a method in a type, if it's not yet visible.
> This is already provided by Eclipse itself: simply use the corresponding
> quick fix (Ctrl+1).
> Eclipse doesn't use code assist to fix errors and warning but quick fix.
> In addition Ctrl+1 also gives you access to quick assists (e.g. local
> rename).
> HTH
> Dani
Thanks for your help, Dani. I was aware of quick-fix, but we specifically
wanted to "cure the problem" before it occurs. Hence, the content assist
idea. However, personally I agree that quick fix would be the better
option (especially since that means no work for me :)). Thus, I will
propose to use that. Thanks again.
|
|
|
Goto Forum:
Current Time: Wed May 07 14:49:45 EDT 2025
Powered by FUDForum. Page generated in 0.03224 seconds
|