Devin R
Devin R

Reputation: 901

Is it possible to configure Eclipse to highlight Java syntax within XML?

I'm programming for a product that includes snippets of Java (actually BeanShell) code embedded in larger XML files. These are executed on the fly at runtime. There can be more than one of these code tags at various levels throughout the document.

<larger-xml-file>
 <java>
  // java code that I want to syntax highlight
 </java>
 <more-xml...>
</larger-xml-file>

It would be great to allow basic syntax highlighting of the code within specific XML tags. I know that vi can do this with <script> tags inside of HTML, for example. It would really help me catch silly bugs like missing end quotes.

If it could allow completion or basic syntax checking, that would be even better.

Is there a way to easily configure this in Eclipse?

Upvotes: 2

Views: 769

Answers (1)

howlger
howlger

Reputation: 34165

This should be possible via the Eclipse project TM4E for syntax highlighting via TextMate grammars.

Eclipse Wild Web Developer which uses Eclipse TM4E shows how embedded/included/injected grammars work for JavaScript in HTML:

<extension point="org.eclipse.core.contenttype.contentTypes">
   <content-type
      base-type="org.eclipse.core.runtime.text"
      file-extensions="html"
      id="contentType.html"
      name="HTML"
      priority="low"/>
</extension>
<extension point="org.eclipse.ui.genericeditor.presentationReconcilers">
   <presentationReconciler
      class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
      contentType="contentType.html"/>
</extension>
<extension point="org.eclipse.ui.editors">
   <editor
      name="HTML Editor"
      icon="icons/html_editor_icon.png"
      class="org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor"
      contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
      id="language-editor.html"
      default="true"
      extensions="html">
   <contentTypeBinding
      contentTypeId="contentType.html"/>
   </editor>
</extension>

Upvotes: 4

Related Questions