Language API and formatting: getChildAttributes never called?

It looks like my getChildAttributes method is never being called! I have
a basic formatting model implementation done, and many parts of
formatting work, but when I press Enter, Block.getChildAttributes is not
called for any object. Is this possible? Am I doing something wrong?

3 comments
Comment actions Permalink

I see that an exception is thrown whenever I press Enter - what am I doing wrong?

This trace is from 3436 IDEA 5.0:

-2
java.lang.ArrayIndexOutOfBoundsException: -2
at java.util.ArrayList.get(ArrayList.java:324)
at com.intellij.formatting.FormatProcessor.a(FormatProcessor.java:198)
at com.intellij.formatting.FormatProcessor.a(FormatProcessor.java:233)
at com.intellij.formatting.FormatProcessor.getIndentAt(FormatProcessor.java:133)
at com.intellij.formatting.FormatterImpl.adjustLineIndent(FormatterImpl.java:200)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.adjustLineIndent(CodeStyleManagerImpl.java:359)
at com.intellij.codeInsight.editorActions.EnterHandler$DoEnterAction.run(EnterHandler.java:19)
at com.intellij.codeInsight.editorActions.EnterHandler.executeWriteAction(EnterHandler.java:174)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:52)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:438)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(EditorWriteActionHandler.java:36)
at com.intellij.codeInsight.template.impl.TemplateManagerActions$EnterHandler.executeWriteAction(TemplateManagerActions.java:7)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:52)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:438)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(EditorWriteActionHandler.java:36)
at com.intellij.openapi.editor.actionSystem.EditorAction$1.run(EditorAction.java:51)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:30)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:84)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:57)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:42)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:29)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:189)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:38)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:79)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:160)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

0
Comment actions Permalink

Hello Keith,

KL> I see that an exception is thrown whenever I press Enter - what am I
KL> doing wrong?
KL>
KL> This trace is from 3436 IDEA 5.0:
KL>
KL> -2
KL> java.lang.ArrayIndexOutOfBoundsException: -2
KL> at java.util.ArrayList.get(ArrayList.java:324)
KL> at
KL> com.intellij.formatting.FormatProcessor.a(FormatProcessor.java:198)

This exception happens because some block cannot be found in the list returned
by getSubBlocks() of its parent block. In the current version of IDEA, you
must return the same list of child blocks when getSubBlocks() is repeatedly
called on a particular Block instance. (This requirement wasn't documented
- I'll add it to the documentation for the next build.)

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Dmitry Jemerov (JetBrains) wrote:

Hello Keith,

KL> I see that an exception is thrown whenever I press Enter - what am I
KL> doing wrong?
KL> KL> This trace is from 3436 IDEA 5.0:
KL> KL> -2
KL> java.lang.ArrayIndexOutOfBoundsException: -2
KL> at java.util.ArrayList.get(ArrayList.java:324)
KL> at
KL> com.intellij.formatting.FormatProcessor.a(FormatProcessor.java:198)

This exception happens because some block cannot be found in the list
returned by getSubBlocks() of its parent block. In the current version
of IDEA, you must return the same list of child blocks when
getSubBlocks() is repeatedly called on a particular Block instance.
(This requirement wasn't documented - I'll add it to the documentation
for the next build.)


Thank you! It works great now.

0

Please sign in to leave a comment.