Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How does the JDT editor do paren and bracket matching?
How does the JDT editor do paren and bracket matching? [message #254977] Fri, 11 July 2008 19:32 Go to next message
Eclipse UserFriend
Could someone please point me the code in the JDT and hopefully some
explanation?

I kind of get the idea on how to do it for my editor, but I want to make
sure I do it correctly for my editor. Basically it involves adding an
annotation to show the matching parenthesis or bracket.

Thank you.
Re: How does the JDT editor do paren and bracket matching? [message #254989 is a reply to message #254977] Mon, 14 July 2008 04:37 Go to previous messageGo to next message
Eclipse UserFriend
AL wrote:
> Could someone please point me the code in the JDT and hopefully some
> explanation?
>
> I kind of get the idea on how to do it for my editor, but I want to
> make sure I do it correctly for my editor. Basically it involves
> adding an annotation to show the matching parenthesis or bracket.
See
org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)

Dani
>
> Thank you.
Re: How does the JDT editor do paren and bracket matching? [message #255008 is a reply to message #254989] Mon, 14 July 2008 17:06 Go to previous messageGo to next message
Eclipse UserFriend
Daniel Megert wrote:
> AL wrote:
>> Could someone please point me the code in the JDT and hopefully some
>> explanation?
>>
>> I kind of get the idea on how to do it for my editor, but I want to
>> make sure I do it correctly for my editor. Basically it involves
>> adding an annotation to show the matching parenthesis or bracket.
> See
> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)

Hi,

I installed the DefaultCharacterPairMatcher with char[] = {'(', ')',
'{', '}', '[', ']'} and to the partition of interest. Nothing happens
:-( The installation is done in MyEditor.createPartControl(...); that
is, MyEditor.createPartControl(...) calls super.createPartControl(...)
then install the DefaultCharacterPairMatcher.

Am I missing something? Thanks for any tips!
Re: How does the JDT editor do paren and bracket matching? [message #255012 is a reply to message #255008] Mon, 14 July 2008 20:34 Go to previous messageGo to next message
Eclipse UserFriend
AL wrote:
> Daniel Megert wrote:
>> AL wrote:
>>> Could someone please point me the code in the JDT and hopefully some
>>> explanation?
>>>
>>> I kind of get the idea on how to do it for my editor, but I want to
>>> make sure I do it correctly for my editor. Basically it involves
>>> adding an annotation to show the matching parenthesis or bracket.
>> See
>> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)
>
>
> Hi,
>
> I installed the DefaultCharacterPairMatcher with char[] = {'(', ')',
> '{', '}', '[', ']'} and to the partition of interest. Nothing happens
> :-( The installation is done in MyEditor.createPartControl(...); that
> is, MyEditor.createPartControl(...) calls super.createPartControl(...)
> then install the DefaultCharacterPairMatcher.
>
> Am I missing something? Thanks for any tips!

Added MyEditor.configureSourceViewerDecorationSupport(support), where
'MyEditor' extends TextEditor and 'support' is
SourceViewerDecorationSupport object. Still not working...
Re: How does the JDT editor do paren and bracket matching? [message #255019 is a reply to message #255012] Tue, 15 July 2008 01:59 Go to previous messageGo to next message
Eclipse UserFriend
AL wrote:
> AL wrote:
>> Daniel Megert wrote:
>>> AL wrote:
>>>> Could someone please point me the code in the JDT and hopefully some
>>>> explanation?
>>>>
>>>> I kind of get the idea on how to do it for my editor, but I want to
>>>> make sure I do it correctly for my editor. Basically it involves
>>>> adding an annotation to show the matching parenthesis or bracket.
>>> See
>>> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)
>>
>>
>>
>> Hi,
>>
>> I installed the DefaultCharacterPairMatcher with char[] = {'(', ')',
>> '{', '}', '[', ']'} and to the partition of interest. Nothing happens
>> :-( The installation is done in MyEditor.createPartControl(...); that
>> is, MyEditor.createPartControl(...) calls super.createPartControl(...)
>> then install the DefaultCharacterPairMatcher.
>>
>> Am I missing something? Thanks for any tips!
>
> Added MyEditor.configureSourceViewerDecorationSupport(support), where
> 'MyEditor' extends TextEditor and 'support' is
> SourceViewerDecorationSupport object. Still not working...

Ok...Chased it down a bit more...This is quite frustrating, as much as I
really like Eclipse, but there is no example :-(

Using the Java editor as my guide...Finally I chased it down to
MatchingCharacterPainter.paint(int reason), where a point and click
causes the execution of the method.

With my editor, I point and click but not event generated to execute the
method MatchingCharacterPainter.pain(int reason). I know that
MatchingCharacterPainter is created for my editor.

Any tip?
Re: How does the JDT editor do paren and bracket matching? [message #255029 is a reply to message #255019] Tue, 15 July 2008 07:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asterite.esperanto.org.ar

AL a écrit :
> AL wrote:
>> AL wrote:
>>> Daniel Megert wrote:
>>>> AL wrote:
>>>>> Could someone please point me the code in the JDT and hopefully
>>>>> some explanation?
>>>>>
>>>>> I kind of get the idea on how to do it for my editor, but I want to
>>>>> make sure I do it correctly for my editor. Basically it involves
>>>>> adding an annotation to show the matching parenthesis or bracket.
>>>> See
>>>> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)
>>>
>>>
>>>
>>>
>>> Hi,
>>>
>>> I installed the DefaultCharacterPairMatcher with char[] = {'(', ')',
>>> '{', '}', '[', ']'} and to the partition of interest. Nothing
>>> happens :-( The installation is done in
>>> MyEditor.createPartControl(...); that is,
>>> MyEditor.createPartControl(...) calls super.createPartControl(...)
>>> then install the DefaultCharacterPairMatcher.
>>>
>>> Am I missing something? Thanks for any tips!
>>
>> Added MyEditor.configureSourceViewerDecorationSupport(support), where
>> 'MyEditor' extends TextEditor and 'support' is
>> SourceViewerDecorationSupport object. Still not working...
>
> Ok...Chased it down a bit more...This is quite frustrating, as much as I
> really like Eclipse, but there is no example :-(
>
> Using the Java editor as my guide...Finally I chased it down to
> MatchingCharacterPainter.paint(int reason), where a point and click
> causes the execution of the method.
>
> With my editor, I point and click but not event generated to execute the
> method MatchingCharacterPainter.pain(int reason). I know that
> MatchingCharacterPainter is created for my editor.
>
> Any tip?

Hi Al,

It seems the character painter matcher only works if there is an
associated preference for it, and it is enabled.

See this:
http://kickjava.com/src/org/eclipse/ui/texteditor/SourceView erDecorationSupport.java.htm
(method areMatchingCharactersShown())

And here it is how it is done in JDT:

@Override
protected void
configureSourceViewerDecorationSupport(SourceViewerDecoratio nSupport
support) {
fBracketMatcher.setSourceVersion(getPreferenceStore().getStr ing(JavaCore.COMPILER_SOURCE));
support.setCharacterPairMatcher(fBracketMatcher);
support.setMatchingCharacterPainterPreferenceKeys(MATCHING_B RACKETS,
MATCHING_BRACKETS_COLOR);
super.configureSourceViewerDecorationSupport(support);
}

Where MATCHING_BRACKETS and MATCHING_BRACKETS_COLOR are strings that
indicate preferences. The easiest thing you can do for this to work is
to make a preference initializer for your plugin that set those keys to
"enabled" and some color. See the "org.eclipse.core.runtime.preferences"
extension point.

Hope that helps.
Re: How does the JDT editor do paren and bracket matching? [message #255039 is a reply to message #255029] Tue, 15 July 2008 12:54 Go to previous messageGo to next message
Eclipse UserFriend
Ary Borenszweig wrote:
> AL a écrit :
>> AL wrote:
>>> AL wrote:
>>>> Daniel Megert wrote:
>>>>> AL wrote:
>>>>>> Could someone please point me the code in the JDT and hopefully
>>>>>> some explanation?
>>>>>>
>>>>>> I kind of get the idea on how to do it for my editor, but I want
>>>>>> to make sure I do it correctly for my editor. Basically it
>>>>>> involves adding an annotation to show the matching parenthesis or
>>>>>> bracket.
>>>>> See
>>>>> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Hi,
>>>>
>>>> I installed the DefaultCharacterPairMatcher with char[] = {'(', ')',
>>>> '{', '}', '[', ']'} and to the partition of interest. Nothing
>>>> happens :-( The installation is done in
>>>> MyEditor.createPartControl(...); that is,
>>>> MyEditor.createPartControl(...) calls super.createPartControl(...)
>>>> then install the DefaultCharacterPairMatcher.
>>>>
>>>> Am I missing something? Thanks for any tips!
>>>
>>> Added MyEditor.configureSourceViewerDecorationSupport(support), where
>>> 'MyEditor' extends TextEditor and 'support' is
>>> SourceViewerDecorationSupport object. Still not working...
>>
>> Ok...Chased it down a bit more...This is quite frustrating, as much as
>> I really like Eclipse, but there is no example :-(
>>
>> Using the Java editor as my guide...Finally I chased it down to
>> MatchingCharacterPainter.paint(int reason), where a point and click
>> causes the execution of the method.
>>
>> With my editor, I point and click but not event generated to execute
>> the method MatchingCharacterPainter.pain(int reason). I know that
>> MatchingCharacterPainter is created for my editor.
>>
>> Any tip?
>
> Hi Al,
>
> It seems the character painter matcher only works if there is an
> associated preference for it, and it is enabled.
>
> See this:
> http://kickjava.com/src/org/eclipse/ui/texteditor/SourceView erDecorationSupport.java.htm
> (method areMatchingCharactersShown())
>
> And here it is how it is done in JDT:
>
> @Override
> protected void
> configureSourceViewerDecorationSupport(SourceViewerDecoratio nSupport
> support) {
> fBracketMatcher.setSourceVersion(getPreferenceStore().getStr ing(JavaCore.COMPILER_SOURCE));
>
> support.setCharacterPairMatcher(fBracketMatcher);
> support.setMatchingCharacterPainterPreferenceKeys(MATCHING_B RACKETS,
> MATCHING_BRACKETS_COLOR);
> super.configureSourceViewerDecorationSupport(support);
> }
>
> Where MATCHING_BRACKETS and MATCHING_BRACKETS_COLOR are strings that
> indicate preferences. The easiest thing you can do for this to work is
> to make a preference initializer for your plugin that set those keys to
> "enabled" and some color. See the "org.eclipse.core.runtime.preferences"
> extension point.
>
> Hope that helps.

Thanks for your response...Yeah, I did the above, too. My editor
overrides the configureSourceViewerDecorationSupport(...) and call the
setMatchCharacterPainterPreferenceKeys(...) method with my own
preference keys that are from the preference store I set to the
decoration support object. I have stepped into the code and verify that
the preference values are correctly set and got. They are iniitalized
in my preference initializer.

But still not working--ca va pas :-(
Re: How does the JDT editor do paren and bracket matching? [message #255066 is a reply to message #255039] Wed, 16 July 2008 03:14 Go to previous message
Eclipse UserFriend
AL wrote:
> Ary Borenszweig wrote:
>> AL a écrit :
>>> AL wrote:
>>>> AL wrote:
>>>>> Daniel Megert wrote:
>>>>>> AL wrote:
>>>>>>> Could someone please point me the code in the JDT and hopefully
>>>>>>> some explanation?
>>>>>>>
>>>>>>> I kind of get the idea on how to do it for my editor, but I want
>>>>>>> to make sure I do it correctly for my editor. Basically it
>>>>>>> involves adding an annotation to show the matching parenthesis or
>>>>>>> bracket.
>>>>>> See
>>>>>> org.eclipse.ui.texteditor.SourceViewerDecorationSupport.setC haracterPairMatcher(ICharacterPairMatcher)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I installed the DefaultCharacterPairMatcher with char[] = {'(',
>>>>> ')', '{', '}', '[', ']'} and to the partition of interest. Nothing
>>>>> happens :-( The installation is done in
>>>>> MyEditor.createPartControl(...); that is,
>>>>> MyEditor.createPartControl(...) calls super.createPartControl(...)
>>>>> then install the DefaultCharacterPairMatcher.
>>>>>
>>>>> Am I missing something? Thanks for any tips!
>>>>
>>>> Added MyEditor.configureSourceViewerDecorationSupport(support),
>>>> where 'MyEditor' extends TextEditor and 'support' is
>>>> SourceViewerDecorationSupport object. Still not working...
>>>
>>> Ok...Chased it down a bit more...This is quite frustrating, as much
>>> as I really like Eclipse, but there is no example :-(
>>>
>>> Using the Java editor as my guide...Finally I chased it down to
>>> MatchingCharacterPainter.paint(int reason), where a point and click
>>> causes the execution of the method.
>>>
>>> With my editor, I point and click but not event generated to execute
>>> the method MatchingCharacterPainter.pain(int reason). I know that
>>> MatchingCharacterPainter is created for my editor.
>>>
>>> Any tip?
>>
>> Hi Al,
>>
>> It seems the character painter matcher only works if there is an
>> associated preference for it, and it is enabled.
>>
>> See this:
>> http://kickjava.com/src/org/eclipse/ui/texteditor/SourceView erDecorationSupport.java.htm
>> (method areMatchingCharactersShown())
>>
>> And here it is how it is done in JDT:
>>
>> @Override
>> protected void
>> configureSourceViewerDecorationSupport(SourceViewerDecoratio nSupport
>> support) {
>>
>> fBracketMatcher.setSourceVersion(getPreferenceStore().getStr ing(JavaCore.COMPILER_SOURCE));
>>
>> support.setCharacterPairMatcher(fBracketMatcher);
>>
>> support.setMatchingCharacterPainterPreferenceKeys(MATCHING_B RACKETS,
>> MATCHING_BRACKETS_COLOR);
>> super.configureSourceViewerDecorationSupport(support);
>> }
>>
>> Where MATCHING_BRACKETS and MATCHING_BRACKETS_COLOR are strings that
>> indicate preferences. The easiest thing you can do for this to work is
>> to make a preference initializer for your plugin that set those keys
>> to "enabled" and some color. See the
>> "org.eclipse.core.runtime.preferences" extension point.
>>
>> Hope that helps.
>
> Thanks for your response...Yeah, I did the above, too. My editor
> overrides the configureSourceViewerDecorationSupport(...) and call the
> setMatchCharacterPainterPreferenceKeys(...) method with my own
> preference keys that are from the preference store I set to the
> decoration support object. I have stepped into the code and verify that
> the preference values are correctly set and got. They are iniitalized
> in my preference initializer.
>
> But still not working--ca va pas :-(

Eureka! The problem was that I override the method
AbstractTextEditor.configureSourceViewerDecorationSupport(.. .), which
gets called before the TextEditor.createPartControl(...). There I set
everything up, but when createPartControl(..) gets called, it's
installed the TextEditor's preference to the
SourceViewerDecoratorSupport object, thus, disabling the
PairMatcherPainter that I previously set in the overriden
configureSourceViewerDecorationSupport(...) method. This is why no
painting was done.

The solution is to set things at the end of the overriden
MyEditor.createPartControl(...) method, after calling
super.createPartControl(...) method.
Previous Topic:Identiting Workbench in Title bar
Next Topic:How can I create a Java Project programatically when running textual Eclipse?
Goto Forum:
  


Current Time: Fri Jul 18 03:06:01 EDT 2025

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

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

Back to the top