Embedding Java fragments within a custom language

This question is related to the plugin article found at http://www.jetbrains.com/idea/plugins/developing_custom_language_plugins.html.

I am trying to get highlighting working correctly for a custom language (its a config language that generates Java code) that can have bits of Java embedded directly into it (by bits I mean anything at the class level, eg fields, methods, constructors). The article above makes it sound like having my lexer create a single instance of IChameleonElementType that holds all of the text is enough however I hit the following assertion:

'Assertion failed: ParserDefinition.createElement() may not return null '

The IChameleonElementType that I am using was created as:


private static final Language JAVA_LANGUAGE = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension( "java" )).getLanguage();
new IChameleonElementType( "embedded java", JAVA_LANGUAGE );

I then have the lexer return all of the java code as a single token of this type. As far as I can tell, it is the parser created by JAVA_LANGUAGE that is returning null which leads me to think that I should be using a different element type.. sadly this is where I've head a road block with my thinking.

Thanks in advance for any pointers,


- Chris.

9 comments
Comment actions Permalink

What version of IDEA do you test with? As far as I can tell lokking at the latest sources, this should not return null, though I recall it used to do so in the past.

0
Comment actions Permalink

It is v5.1, downloaded two or three days ago. I run on Windows XP, using JDK 1.5.

0
Comment actions Permalink

I see. As a workaround you could test your plugin against 6.0 EAP, it is the other way there, and if it works, then we should be able to port it to 5.1.2 branch.

0
Comment actions Permalink

Interesting, as you suspected 6.0 does not have the null pointer problem so now it gets as far as trying to create a lexer. What I am trying to do is very similar to JSP, has the custom language code for JSP been released?


java.lang.UnsupportedOperationException: Cannot create lexer
at com.intellij.lang.java.JavaParserDefinition.createLexer(JavaParserDefinition.java:5)
at com.intellij.lang.impl.PsiBuilderImpl.]]>(PsiBuilderImpl.java:40)
at com.intellij.peer.impl.PeerFactoryImpl.createBuilder(PeerFactoryImpl.java:3)
at com.intellij.psi.tree.IChameleonElementType.parseContents(IChameleonElementType.java:57)
at com.intellij.psi.impl.source.tree.ChameleonElement.transform(ChameleonElement.java:35)
at com.intellij.psi.impl.source.parsing.ChameleonTransforming.transform(ChameleonTransforming.java:20)
at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:112)
at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:85)
at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:85)
at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:85)
at com.intellij.psi.impl.source.text.BlockSupportImpl.a(BlockSupportImpl.java:99)
at com.intellij.psi.impl.source.text.BlockSupportImpl.reparseRange(BlockSupportImpl.java:94)
at com.intellij.psi.impl.PsiDocumentManagerImpl.commit(PsiDocumentManagerImpl.java:82)
at com.intellij.psi.impl.PsiDocumentManagerImpl$1.run(PsiDocumentManagerImpl.java:7)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:6)
at com.intellij.psi.impl.PsiDocumentManagerImpl.commitDocument(PsiDocumentManagerImpl.java:144)
at com.intellij.openapi.fileEditor.impl.text.TextEditorImpl.getStateImpl(TextEditorImpl.java:63)
at com.intellij.openapi.fileEditor.impl.text.TextEditorImpl.getState(TextEditorImpl.java:23)
at com.intellij.openapi.fileEditor.impl.EditorHistoryManager.a(EditorHistoryManager.java:53)
at com.intellij.openapi.fileEditor.impl.EditorHistoryManager.writeExternal(EditorHistoryManager.java:117)
at com.intellij.openapi.components.impl.ComponentManagerImpl.serializeComponent(ComponentManagerImpl.java:180)
at com.intellij.openapi.project.impl.BaseFileConfigurable.saveToXml(BaseFileConfigurable.java:41)
at com.intellij.openapi.project.impl.ProjectImpl.saveToXml(ProjectImpl.java:211)
at com.intellij.openapi.project.impl.BaseFileConfigurable._save(BaseFileConfigurable.java:105)
at com.intellij.openapi.project.impl.ProjectImpl$4.run(ProjectImpl.java:0)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:24)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:6)
at com.intellij.openapi.project.impl.ProjectImpl.save(ProjectImpl.java:27)
at com.intellij.ide.SaveAndSyncHandler.b(SaveAndSyncHandler.java:50)
at com.intellij.ide.SaveAndSyncHandler.access$200(SaveAndSyncHandler.java:28)
at com.intellij.ide.SaveAndSyncHandler$3.onFrameDeactivated(SaveAndSyncHandler.java:5)
at com.intellij.ide.FrameStateManagerImpl.a(FrameStateManagerImpl.java:9)
at com.intellij.ide.FrameStateManagerImpl.access$100(FrameStateManagerImpl.java:30)
at com.intellij.ide.FrameStateManagerImpl$1.run(FrameStateManagerImpl.java:1)
at com.intellij.util.Alarm$1.run(Alarm.java:86)
at com.intellij.util.Alarm$MyThread$1.run(Alarm.java:229)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:23)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:36)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:124)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:134)
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)
ERROR - ij.components.ComponentManager - IntelliJ IDEA (Demetra) #5245 Build #5245
ERROR - ij.components.ComponentManager - JDK: 1.5.0_06
ERROR - ij.components.ComponentManager - VM: Java HotSpot(TM) Client VM
ERROR - ij.components.ComponentManager - Vendor: Sun Microsystems Inc.
ERROR - ij.components.ComponentManager - OS: Windows XP
ERROR - ij.components.ComponentManager - Last Action: EditorEnter
ERROR - ij.components.ComponentManager - Current Command: Save settings

0
Comment actions Permalink

Chris, JSP is by far the most complex language supported in IDEA taking into account full level of java inside jsp support. This is not released publicly,and probably will never be. But it seems you don't need to go that far: if you just need syntax highlighting for your language, look at Language::getSyntaxHighlighter() method.

0
Comment actions Permalink

JSP being the most complex example makes it in several ways a very useful example to be able to reference, I hope that some day it is released.

Thanks for your help.

- Chris.

0
Comment actions Permalink

Chris Kirk wrote:

JSP being the most complex example makes it in several ways a very
useful example to be able to reference, I hope that some day it is
released.

Thanks for your help.

- Chris.


Yes, we need JSP-like functionality for a plugin as well.

0
Comment actions Permalink

And how to make resolving coorectly?
For instance, pageContext will resolved in JSP correctly. How to enable such behaviour?

Relative to JFlex Support plugin, for example.

0
Comment actions Permalink

I am running into this same problem on 5.1.2. Is there a workaround?

Thanks,
Brian

0

Please sign in to leave a comment.