summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcheuoua2007-01-10 03:11:39 (EST)
committerjcheuoua2007-01-10 03:11:39 (EST)
commitdad421d5e61059ef3802c3635e4fa246f15f8c93 (patch)
treece714fbe16aba3ffeb6394c4e3413b8b6296751e
parent9f9617f88115522cb2ef53c0d86ad5137239da73 (diff)
downloadorg.eclipse.jet-dad421d5e61059ef3802c3635e4fa246f15f8c93.zip
org.eclipse.jet-dad421d5e61059ef3802c3635e4fa246f15f8c93.tar.gz
org.eclipse.jet-dad421d5e61059ef3802c3635e4fa246f15f8c93.tar.bz2
2nd wave of modifications for JET Editor
-rw-r--r--plugins/org.eclipse.jet.editor/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--plugins/org.eclipse.jet.editor/.settings/org.eclipse.jet.prefs4
-rw-r--r--plugins/org.eclipse.jet.editor/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.jet.editor/icons/full/ctool16/JETFileWizard.gifbin0 -> 1006 bytes
-rw-r--r--plugins/org.eclipse.jet.editor/icons/full/ctool16/JETProjectWizard.gifbin0 -> 597 bytes
-rw-r--r--plugins/org.eclipse.jet.editor/icons/full/obj16/JETTemplateFile.gifbin0 -> 968 bytes
-rw-r--r--plugins/org.eclipse.jet.editor/icons/full/wizban/JETProjectWizard.gifbin0 -> 597 bytes
-rw-r--r--plugins/org.eclipse.jet.editor/plugin.properties1
-rw-r--r--plugins/org.eclipse.jet.editor/plugin.xml51
-rw-r--r--plugins/org.eclipse.jet.editor/schema/defaultContentColorerDelegates.exsd (renamed from plugins/org.eclipse.jet.editor/schema/partitionConfigurationDelegates.exsd)8
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditor.java130
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditorHelper.java318
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETSourceViewer.java83
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextEditor.java393
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextPreviewViewer.java193
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/actions/SetContentColorerAction.java65
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationHover.java133
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationModel.java54
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETProblemAnnotation.java23
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/autoedit/JETTemplateAutoEditStrategy.java266
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/IJETColorConstants.java4
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETDocumentProvider.java45
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETEditorPreferenceConstants.java6
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETReconcilingStrategy.java80
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETSourceViewerConfiguration.java116
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/AbstractJETTextPartitionConfigurationDelegate.java38
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETDefaultTextColorerDelegate.java11
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETTextPartitionConfigurationDelegate.java24
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/JavaContentPartitionConfigurationDelegate.java249
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/java/JavaContentPartitionConfigurationDelegate.java113
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/xml/XMLContentPartitionConfigurationDelegate.java156
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/AbstractXMLTagsBasedAssistProcessor.java153
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETCustomTagAssistProcessor.java86
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETDirectiveAssistProcessor.java30
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaDeclarationAssistProcessor.java42
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaExpressionAssistProcessor.java83
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaScriptletAssistProcessor.java77
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/gen/JETEditorJET2JavaGenerator.java115
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineContentProvider.java79
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineLabelProvider.java84
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlinePage.java58
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/ITokenScannerProvider.java8
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/JETDocumentPartitionScanner.java493
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/PartitionScannerBasedDamagerRepairer.java141
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTElementScannerRule.java42
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCommentRule.java17
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCustomTagRule.java16
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETDirectiveRule.java17
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaDeclarationRule.java17
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaExpressionRule.java17
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaScriptletRule.java17
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETDocumentReader.java69
-rw-r--r--plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETEditorHelper.java422
53 files changed, 3122 insertions, 1532 deletions
diff --git a/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jdt.core.prefs
index e9571be..e302ef5 100644
--- a/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Fri Nov 03 16:29:20 PST 2006
+#Tue Jan 09 21:39:30 PST 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
diff --git a/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jet.prefs b/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jet.prefs
deleted file mode 100644
index 2767a7b..0000000
--- a/plugins/org.eclipse.jet.editor/.settings/org.eclipse.jet.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-#Sun Nov 12 18:00:04 PST 2006
-eclipse.preferences.version=1
-org.eclipse.jet.compiledTemplateSrcDir=src
-org.eclipse.jet.projectPrefs=true
diff --git a/plugins/org.eclipse.jet.editor/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet.editor/META-INF/MANIFEST.MF
index f434cc4..e336d52 100644
--- a/plugins/org.eclipse.jet.editor/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet.editor/META-INF/MANIFEST.MF
@@ -15,7 +15,10 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.views.properties.tabbed,
org.eclipse.jdt.core,
org.eclipse.jdt.ui,
- org.eclipse.jet
+ org.eclipse.jet,
+ org.eclipse.emf.codegen.ecore,
+ org.eclipse.emf.ecore,
+ org.eclipse.emf.codegen.ecore.ui
Eclipse-LazyStart: true
Export-Package: org.eclipse.jet.editor,
org.eclipse.jet.editor.configuration,
diff --git a/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETFileWizard.gif b/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETFileWizard.gif
new file mode 100644
index 0000000..b603b01
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETFileWizard.gif
Binary files differ
diff --git a/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETProjectWizard.gif b/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETProjectWizard.gif
new file mode 100644
index 0000000..8d97ee5
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/icons/full/ctool16/JETProjectWizard.gif
Binary files differ
diff --git a/plugins/org.eclipse.jet.editor/icons/full/obj16/JETTemplateFile.gif b/plugins/org.eclipse.jet.editor/icons/full/obj16/JETTemplateFile.gif
new file mode 100644
index 0000000..66f8c76
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/icons/full/obj16/JETTemplateFile.gif
Binary files differ
diff --git a/plugins/org.eclipse.jet.editor/icons/full/wizban/JETProjectWizard.gif b/plugins/org.eclipse.jet.editor/icons/full/wizban/JETProjectWizard.gif
new file mode 100644
index 0000000..8d97ee5
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/icons/full/wizban/JETProjectWizard.gif
Binary files differ
diff --git a/plugins/org.eclipse.jet.editor/plugin.properties b/plugins/org.eclipse.jet.editor/plugin.properties
new file mode 100644
index 0000000..a7418d1
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/plugin.properties
@@ -0,0 +1 @@
+_UI_SetContentColorerAction.label=Set Non-JET Text Content Colorer ... \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/plugin.xml b/plugins/org.eclipse.jet.editor/plugin.xml
index 6f27b6b..da412af 100644
--- a/plugins/org.eclipse.jet.editor/plugin.xml
+++ b/plugins/org.eclipse.jet.editor/plugin.xml
@@ -1,24 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
- <extension-point id="partitionConfigurationDelegates" name="Partition Configuration Delegates" schema="schema/partitionConfigurationDelegates.exsd"/>
+ <extension-point id="defaultContentColorerDelegates" name="Default JET Text Content Colorer Delegates" schema="schema/defaultContentColorerDelegates.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
- name="Java Emitter Templates Editor"
+ name="EMFT - Java Emitter Templates Editor"
extensions="jet"
- icon="icons/sample.gif"
+ icon="icons/full/obj16/JETTemplateFile.gif"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="org.eclipse.jet.editor.JETTextEditor"
- id="org.eclipse.jet.editor.editors.JETEditor">
+ id="org.eclipse.jet.editor.JETEditor">
</editor>
</extension>
<extension
- point="org.eclipse.jet.editor.partitionConfigurationDelegates">
- <partitionConfigurationDelegate
- delegateClass="org.eclipse.jet.editor.configuration.delegates.JavaContentPartitionConfigurationDelegate">
- </partitionConfigurationDelegate>
+ point="org.eclipse.jet.editor.defaultContentColorerDelegates">
+ <defaultContentColorerDelegate
+ delegateClass="org.eclipse.jet.editor.configuration.delegates.java.JavaContentPartitionConfigurationDelegate">
+ </defaultContentColorerDelegate>
+ <defaultContentColorerDelegate
+ delegateClass="org.eclipse.jet.editor.configuration.delegates.xml.XMLContentPartitionConfigurationDelegate">
+ </defaultContentColorerDelegate>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editorActions">
+ <editorContribution
+ id="org.eclipse.jet.editor.JETEditor.actionsContributor"
+ targetID="org.eclipse.jet.editor.JETEditor">
+ <action
+ actionID="setDelegateColorerActionID"
+ class="org.eclipse.jet.editor.actions.SetContentColorerAction"
+ id="org.eclipse.jet.editor.setDelegateColorerActionID"
+ label="%_UI_SetContentColorerAction.label"
+ style="push">
+ </action>
+ </editorContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editors.annotationTypes">
+ <type
+ markerSeverity="2"
+ name="org.eclipse.jet.editor.error"
+ super="org.eclipse.ui.workbench.texteditor.error">
+ </type>
+ <type
+ markerSeverity="1"
+ name="org.eclipse.jet.editor.warning"
+ super="org.eclipse.ui.workbench.texteditor.warning">
+ </type>
+ <type
+ markerSeverity="0"
+ name="org.eclipse.jet.editor.info"
+ super="org.eclipse.ui.workbench.texteditor.info">
+ </type>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.jet.editor/schema/partitionConfigurationDelegates.exsd b/plugins/org.eclipse.jet.editor/schema/defaultContentColorerDelegates.exsd
index e542633..5c74163 100644
--- a/plugins/org.eclipse.jet.editor/schema/partitionConfigurationDelegates.exsd
+++ b/plugins/org.eclipse.jet.editor/schema/defaultContentColorerDelegates.exsd
@@ -3,7 +3,7 @@
<schema targetNamespace="org.eclipse.jet.editor">
<annotation>
<appInfo>
- <meta.schema plugin="org.eclipse.jet.editor" id="partitionConfigurationDelegates" name="Partition Configuration Delegates"/>
+ <meta.schema plugin="org.eclipse.jet.editor" id="defaultContentColorerDelegates" name="Default Content Colorer Delegates"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
@@ -13,7 +13,7 @@
<element name="extension">
<complexType>
<sequence>
- <element ref="partitionConfigurationDelegate" minOccurs="1" maxOccurs="unbounded"/>
+ <element ref="defaultContentColorerDelegate" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@@ -42,7 +42,7 @@
</complexType>
</element>
- <element name="partitionConfigurationDelegate">
+ <element name="defaultContentColorerDelegate">
<complexType>
<attribute name="delegateClass" type="string" use="required">
<annotation>
@@ -50,7 +50,7 @@
</documentation>
<appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.jet.editor.configuration.delegates.AbstractJETTextPartitionConfigurationDelegate"/>
+ <meta.attribute kind="java" basedOn="org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate"/>
</appInfo>
</annotation>
</attribute>
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditor.java
new file mode 100644
index 0000000..9617cbe
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditor.java
@@ -0,0 +1,130 @@
+package org.eclipse.jet.editor;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.ui.*;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.part.MultiPageSelectionProvider;
+import org.eclipse.ui.texteditor.IStatusField;
+import org.eclipse.ui.texteditor.ITextEditorExtension;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+
+public class JETEditor extends FormEditor implements ITextEditorExtension, IMenuListener, IGotoMarker {
+
+ public static final String ID = "org.eclipse.jet.editor";
+ public static final String copyright = "(c) 2006 Joel Cheuoua & Contributors";
+ protected IStatusLineManager contentOutlineStatusLineManager;
+ protected TreeViewer contentOutlineViewer;
+ protected PropertySheetPage propertySheetPage;
+ protected ISelectionChangedListener selectionChangedListener;
+ protected JETTextEditor jetTextEditor;
+
+ public JETEditor() {
+ jetTextEditor = new JETTextEditor();
+ }
+
+ public JETTextEditor getJetTextEditor() {
+ return jetTextEditor;
+ }
+
+ public void addPages() {
+ try {
+ int pageIndex = addPage(jetTextEditor, getEditorInput());
+ setPageText(pageIndex, "Edition");
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ Viewer viewer = new JETTextPreviewViewer(getContainer());
+ viewer.setInput(getEditorInput());
+ int pageIndex = addPage(viewer.getControl());
+ setPageText(pageIndex, "Preview");
+ }
+
+ public Object getAdapter(Class key) {
+ if (key.equals(IContentOutlinePage.class))
+ return jetTextEditor.getAdapter(key);
+ if (key.equals(IPropertySheetPage.class))
+ return getPropertySheetPage();
+ if (key.equals(IGotoMarker.class))
+ return this;
+ else
+ return super.getAdapter(key);
+ }
+
+ public IPropertySheetPage getPropertySheetPage() {
+ return propertySheetPage;
+ }
+
+ public boolean isDirty() {
+ return jetTextEditor != null && jetTextEditor.isDirty();
+ }
+
+ public void doSave(IProgressMonitor progressMonitor) {
+ if (jetTextEditor != null)
+ jetTextEditor.doSave(progressMonitor);
+ }
+
+ public boolean isSaveAsAllowed() {
+ if (jetTextEditor != null)
+ return jetTextEditor.isSaveAsAllowed();
+ else
+ return true;
+ }
+
+ public void doSaveAs() {
+ if (jetTextEditor != null)
+ jetTextEditor.doSaveAs();
+ }
+
+ public void gotoMarker(IMarker marker) {
+ if (jetTextEditor != null) {
+ IGotoMarker gotoMarker = (IGotoMarker) jetTextEditor.getAdapter(IGotoMarker.class);
+ if (gotoMarker != null)
+ gotoMarker.gotoMarker(marker);
+ }
+ }
+
+ public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
+ setSite(site);
+ setInput(editorInput);
+ jetTextEditor.init(site, editorInput);
+ setPartName(editorInput.getName());
+ site.setSelectionProvider(new MultiPageSelectionProvider(this));
+ }
+
+ public void menuAboutToShow(IMenuManager menuManager) {
+ ((IMenuListener) getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
+ }
+
+ public void dispose() {
+ if (jetTextEditor != null)
+ jetTextEditor.dispose();
+ super.dispose();
+ }
+
+ public void setStatusField(IStatusField field, String category) {
+ if (jetTextEditor != null)
+ jetTextEditor.setStatusField(field, category);
+ }
+
+ public boolean isEditorInputReadOnly() {
+ if (jetTextEditor != null)
+ jetTextEditor.isEditorInputReadOnly();
+ return false;
+ }
+
+ public void addRulerContextMenuListener(IMenuListener listener) {
+ if (jetTextEditor != null)
+ jetTextEditor.addRulerContextMenuListener(listener);
+ }
+
+ public void removeRulerContextMenuListener(IMenuListener listener) {
+ if (jetTextEditor != null)
+ jetTextEditor.removeRulerContextMenuListener(listener);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditorHelper.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditorHelper.java
deleted file mode 100644
index 7701b82..0000000
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETEditorHelper.java
+++ /dev/null
@@ -1,318 +0,0 @@
-package org.eclipse.jet.editor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.eval.IEvaluationContext;
-import org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal;
-import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
-import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
-import org.eclipse.jet.BodyContentWriter;
-import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.JET2Template;
-import org.eclipse.jet.JET2TemplateLoader;
-import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.compiler.Comment;
-import org.eclipse.jet.compiler.DefaultJET2ASTVisitor;
-import org.eclipse.jet.compiler.JET2ASTElement;
-import org.eclipse.jet.compiler.JET2CompilationUnit;
-import org.eclipse.jet.compiler.JET2Declaration;
-import org.eclipse.jet.compiler.JET2Directive;
-import org.eclipse.jet.compiler.JET2Expression;
-import org.eclipse.jet.compiler.JET2Scriptlet;
-import org.eclipse.jet.compiler.TextElement;
-import org.eclipse.jet.compiler.XMLBodyElement;
-import org.eclipse.jet.compiler.XMLBodyElementEnd;
-import org.eclipse.jet.compiler.XMLEmptyElement;
-import org.eclipse.jet.internal.compiler.MethodBodyCreator;
-import org.eclipse.jet.internal.compiler.templates.CodeGenTemplateLoader;
-import org.eclipse.jet.transform.TransformContextExtender;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.swt.graphics.Point;
-
-public class JETEditorHelper {
-
- public static class JETEditorMethodBodyCreator extends MethodBodyCreator
- {
-
- private Map generatedBodyMappingPositions;
-
- public JETEditorMethodBodyCreator(JET2TemplateLoader templateLoader, Map mappingPositions) {
- super(templateLoader);
- this.generatedBodyMappingPositions = mappingPositions;
- }
-
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#visit(org.eclipse.jet.compiler.XMLBodyElement)
- */
- public void visit(XMLBodyElement element)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(element, position);
- super.visit(element);
- position.setLength(getBuffer().length() - position.offset);
- }
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#endVisit(org.eclipse.jet.compiler.XMLBodyElement)
- */
- public void endVisit(XMLBodyElement element)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(element, position);
- super.endVisit(element);
- position.setLength(getBuffer().length() - position.offset);
- }
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#visit(org.eclipse.jet.compiler.XMLEmptyElement)
- */
- public void visit(XMLEmptyElement element)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(element, position);
- super.visit(element);
- position.setLength(getBuffer().length() - position.offset);
- }
-
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#visit(org.eclipse.jet.compiler.JET2Expression)
- */
- public void visit(JET2Expression expression)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(expression, position);
- super.visit(expression);
- position.setLength(getBuffer().length() - position.offset);
- }
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#visit(org.eclipse.jet.compiler.JET2Scriptlet)
- */
- public void visit(JET2Scriptlet scriptlet)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(scriptlet, position);
- super.visit(scriptlet);
- position.setLength(getBuffer().length() - position.offset);
- }
-
- /**
- * @see org.eclipse.jet.compiler.DefaultJET2ASTVisitor#visit(org.eclipse.jet.compiler.TextElement)
- */
- public void visit(TextElement text)
- {
- Position position = new Position(getBuffer().length());
- generatedBodyMappingPositions.put(text, position);
- super.visit(text);
- position.setLength(getBuffer().length() - position.offset);
- }
-
- }
- private static class RelevantElementFoundExcetion extends RuntimeException {
- private static final long serialVersionUID = -7146049866718374643L;
- }
- private static class Detector extends DefaultJET2ASTVisitor {
- JET2ASTElement match;
- int documentOffset;
-
- public Detector(int offset) {
- documentOffset = offset;
- }
-
- public void visit(JET2Declaration declaration) {
- matchOffset(declaration);
- }
-
- public void visit(JET2Directive directive) {
- matchOffset(directive);
- }
-
- public void visit(JET2Expression expression) {
- matchOffset(expression);
- }
-
- public void visit(JET2Scriptlet scriptlet) {
- matchOffset(scriptlet);
- }
-
- public void visit(TextElement text) {
- matchOffset(text);
- }
-
- public void visit(XMLEmptyElement xmlEmptyElement) {
- matchOffset(xmlEmptyElement);
- }
-
- public void visit(XMLBodyElement xmlBodyElement) {
- matchOffset(xmlBodyElement);
- }
-
- public void visit(XMLBodyElementEnd xmlBodyElementEnd) {
- matchOffset(xmlBodyElementEnd);
- }
-
- public void visit(Comment comment) {
- matchOffset(comment);
- }
-
- public void matchOffset(JET2ASTElement element) {
- if (element.getStart() <= documentOffset && element.getEnd() > documentOffset) {
- match = element;
- throw new RelevantElementFoundExcetion();
- }
- }
- }
-
-
-// public static String computeJavaSource(JET2CompilationUnit cu, Map mappedPositions) {
-// Map variables = new HashMap();
-// variables.put("org.eclipse.jet.storeJavaMappingPositions", mappedPositions);
-// variables.put("cu", cu);
-// JET2Context context = new JET2Context(null, variables); //$NON-NLS-1$
-// JET2TemplateLoader templateLoader = new CodeGenTemplateLoader();
-// TransformContextExtender.getInstance(context).setLoader(templateLoader);
-// JET2Template template = new JETEditorJET2JavaGenerator(); //$NON-NLS-1$
-// JET2Writer out = new BodyContentWriter();
-// template.generate(context, out);
-// return out.getDocument().get();
-// }
-
- public static JET2ASTElement getASTElementAt(JET2CompilationUnit cu, int documentOffset) {
- Detector detector = new Detector(documentOffset);
- try {
- cu.accept(detector);
- } catch (RelevantElementFoundExcetion e) {
- // element found
- }
- return detector.match;
- }
-
- private static JET2Declaration[] getAllJavaDeclarations(JET2CompilationUnit cu) {
- final List result = new ArrayList();
- cu.accept(new DefaultJET2ASTVisitor() {
- public void visit(JET2Declaration declaration) {
- result.add(declaration);
- }
- });
- return (JET2Declaration[]) result.toArray(new JET2Declaration[result.size()]);
- }
-
- public static String getDeclarationsSourceCode(JET2CompilationUnit cu) {
- JET2Declaration[] declarations = getAllJavaDeclarations(cu);
- StringBuffer declarationsSource = new StringBuffer(declarations.length * 20);
- for (int i = 0; i < declarations.length; i++) {
- JET2Declaration declaration = declarations[i];
- declarationsSource.append(declaration.getJavaContent());
- }
- return declarationsSource.toString();
- }
-
- public static String getPreviousGeneratedJavaSource(IJavaProject javaProject, JET2CompilationUnit cu,
- JET2ASTElement bodyElement) {
- JET2TemplateLoader templateLoader = new CodeGenTemplateLoader();
- MethodBodyCreator generatedBody = new MethodBodyCreator(templateLoader);
-
- List sortedPrevElements = new ArrayList();
- JET2ASTElement prevASTElement = bodyElement.getPrevElement();
- while (prevASTElement != null) {
- sortedPrevElements.add(0, prevASTElement);
- prevASTElement = prevASTElement.getPrevElement();
- }
- for (Iterator iterator = sortedPrevElements.iterator(); iterator.hasNext();) {
- JET2ASTElement prevElement = (JET2ASTElement) iterator.next();
- prevElement.accept(generatedBody);
- }
- return generatedBody.getBuffer();
- }
-
- public static CompletionProposalCollector collect(IJavaProject javaProject, JET2CompilationUnit cu,
- String codeSnippet, int offset) {
- IEvaluationContext context = javaProject.newEvaluationContext();
- List importList = new ArrayList();
- importList.addAll(cu.getImports());
- importList.add("org.eclipse.jet.JET2Context");
- importList.add("org.eclipse.jet.JET2Template");
- importList.add("org.eclipse.jet.JET2Writer");
- importList.add("org.eclipse.jet.taglib.RuntimeTagElement");
- importList.add("org.eclipse.jet.taglib.TagInfo");
- String[] imports = new String[importList.size()];
- importList.toArray(imports);
- String packageName = cu.getOutputJavaPackage();
-
- context.setPackageName(packageName);
- context.setImports(imports);
-
- CompletionProposalCollector proposalCollector = new CompletionProposalCollector(javaProject);
- try {
- context.codeComplete(codeSnippet, offset, proposalCollector);
- return proposalCollector;
- } catch (JavaModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- public static IJavaCompletionProposal[] getJavaCompletionProposal(IJavaProject javaProject, JET2CompilationUnit cu,
- String codeSnippet, ITextViewer viewer, int offset) {
- CompletionProposalCollector proposalCollector = collect(javaProject, cu, codeSnippet, offset);
- if (proposalCollector != null) {
- Point selection = viewer.getSelectedRange();
- if (selection.y > 0)
- proposalCollector.setReplacementLength(selection.y);
- IJavaCompletionProposal[] javaProposals = proposalCollector.getJavaCompletionProposals();
- IJavaCompletionProposal[] keywordsProposals = proposalCollector.getKeywordCompletionProposals();
-
- IJavaCompletionProposal[] unsortedJavaProposals = new IJavaCompletionProposal[javaProposals.length
- + keywordsProposals.length];
- System.arraycopy(keywordsProposals, 0, unsortedJavaProposals, 0, keywordsProposals.length);
- System.arraycopy(javaProposals, 0, unsortedJavaProposals, keywordsProposals.length, javaProposals.length);
-
- // sort them by relevance (which is given, but they are unsorted)
- List sortedJavaProposals = new LinkedList();
- for (int i = 0; i < unsortedJavaProposals.length; i++) {
- IJavaCompletionProposal unsortedJavaProposal = unsortedJavaProposals[i];
- int index = 0;
- for (Iterator iterator = sortedJavaProposals.iterator(); iterator.hasNext();) {
- IJavaCompletionProposal proposal = (IJavaCompletionProposal) iterator.next();
- if (proposal.getRelevance() <= unsortedJavaProposal.getRelevance()) {
- index = sortedJavaProposals.indexOf(proposal);
- break;
- }
- }
- sortedJavaProposals.add(index, unsortedJavaProposal);
- }
- IJavaCompletionProposal[] results = new IJavaCompletionProposal[sortedJavaProposals.size()];
- sortedJavaProposals.toArray(results);
- return results;
- }
- return new IJavaCompletionProposal[0];
- }
-
- public static String getMethodBodySource(JET2CompilationUnit cu, Map generatedBodyMappingPositions) {
- JET2TemplateLoader templateLoader = new CodeGenTemplateLoader();
- JETEditorMethodBodyCreator generatedBody = new JETEditorMethodBodyCreator(templateLoader,
- generatedBodyMappingPositions);
- cu.accept(generatedBody);
- return generatedBody.getBuffer();
- }
-
- public static void adjustResults(IJavaCompletionProposal[] results, int offset) {
- for (int i = 0; i < results.length; i++) {
- if (results[i] instanceof AbstractJavaCompletionProposal) {
- AbstractJavaCompletionProposal proposal = (AbstractJavaCompletionProposal) results[i];
- proposal.setReplacementOffset(offset);
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETSourceViewer.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETSourceViewer.java
index d07b38b..6d9cd34 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETSourceViewer.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETSourceViewer.java
@@ -9,33 +9,27 @@ import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
-import org.eclipse.ui.texteditor.AbstractTextEditor;
public class JETSourceViewer extends ProjectionViewer implements IPropertyChangeListener {
-
+
private IPreferenceStore preferenceStore;
private Color foregroundColor;
private Color backgroundColor;
private Color selectionForegroundColor;
private Color selectionBackgroundColor;
-
+
public JETSourceViewer(Composite parent, IVerticalRuler ruler, IOverviewRuler overviewRuler,
boolean showsAnnotationOverview, int styles, IPreferenceStore store) {
super(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
setPreferenceStore(store);
- // TODO Auto-generated constructor stub
}
public void setPreferenceStore(IPreferenceStore store) {
if (preferenceStore != null)
preferenceStore.removePropertyChangeListener(this);
-
preferenceStore = store;
-
if (preferenceStore != null) {
preferenceStore.addPropertyChangeListener(this);
initializeViewerColors();
@@ -44,96 +38,59 @@ public class JETSourceViewer extends ProjectionViewer implements IPropertyChange
private void initializeViewerColors() {
if (preferenceStore != null) {
-
StyledText styledText = getTextWidget();
if (styledText == null)
return;
- // ----------- foreground color --------------------
- Color color = preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null
- : createColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
+ Color color = preferenceStore.getBoolean("AbstractTextEditor.Color.Foreground.SystemDefault") ? null
+ : createColor(preferenceStore, "AbstractTextEditor.Color.Foreground", styledText.getDisplay());
styledText.setForeground(color);
-
if (foregroundColor != null)
foregroundColor.dispose();
-
foregroundColor = color;
-
- // ---------- background color ----------------------
- color = preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
- : createColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
+ color = preferenceStore.getBoolean("AbstractTextEditor.Color.Background.SystemDefault") ? null : createColor(
+ preferenceStore, "AbstractTextEditor.Color.Background", styledText.getDisplay());
styledText.setBackground(color);
-
if (backgroundColor != null)
backgroundColor.dispose();
-
backgroundColor = color;
-
- // ----------- selection foreground color --------------------
- color = preferenceStore
- .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR) ? null
- : createColor(preferenceStore,
- AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, styledText.getDisplay());
+ color = preferenceStore.getBoolean("AbstractTextEditor.Color.SelectionForeground.SystemDefault") ? null
+ : createColor(preferenceStore, "AbstractTextEditor.Color.SelectionForeground", styledText.getDisplay());
styledText.setSelectionForeground(color);
-
if (selectionForegroundColor != null)
selectionForegroundColor.dispose();
-
selectionForegroundColor = color;
-
- // ---------- selection background color ----------------------
- color = preferenceStore
- .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR) ? null
- : createColor(preferenceStore,
- AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, styledText.getDisplay());
+ color = preferenceStore.getBoolean("AbstractTextEditor.Color.SelectionBackground.SystemDefault") ? null
+ : createColor(preferenceStore, "AbstractTextEditor.Color.SelectionBackground", styledText.getDisplay());
styledText.setSelectionBackground(color);
-
if (selectionBackgroundColor != null)
selectionBackgroundColor.dispose();
-
selectionBackgroundColor = color;
}
}
- /**
- * Creates a color from the information stored in the given preference store.
- * Returns <code>null</code> if there is no such information available.
- *
- * @param store the store to read from
- * @param key the key used for the lookup in the preference store
- * @param display the display used create the color
- * @return the created color according to the specification in the preference store
- * @since 3.0
- */
private Color createColor(IPreferenceStore store, String key, Display display) {
-
- RGB rgb = null;
-
+ org.eclipse.swt.graphics.RGB rgb = null;
if (store.contains(key)) {
-
if (store.isDefault(key))
rgb = PreferenceConverter.getDefaultColor(store, key);
else
rgb = PreferenceConverter.getColor(store, key);
-
if (rgb != null)
return new Color(display, rgb);
}
-
return null;
}
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
- if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property)
- || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property)
- || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property)
- || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
- || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR.equals(property)
- || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR.equals(property)
- || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR.equals(property)
- || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR.equals(property))
- {
+ if ("AbstractTextEditor.Color.Foreground".equals(property)
+ || "AbstractTextEditor.Color.Foreground.SystemDefault".equals(property)
+ || "AbstractTextEditor.Color.Background".equals(property)
+ || "AbstractTextEditor.Color.Background.SystemDefault".equals(property)
+ || "AbstractTextEditor.Color.SelectionForeground".equals(property)
+ || "AbstractTextEditor.Color.SelectionForeground.SystemDefault".equals(property)
+ || "AbstractTextEditor.Color.SelectionBackground".equals(property)
+ || "AbstractTextEditor.Color.SelectionBackground.SystemDefault".equals(property))
initializeViewerColors();
- }
}
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextEditor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextEditor.java
index 8e1cd3a..35ef46e 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextEditor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextEditor.java
@@ -1,15 +1,22 @@
package org.eclipse.jet.editor;
import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
+import org.eclipse.core.resources.IEncodedStorage;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jet.JET2Platform;
@@ -29,24 +36,23 @@ import org.eclipse.jet.editor.configuration.JETDocumentProvider;
import org.eclipse.jet.editor.configuration.JETEditorPreferenceConstants;
import org.eclipse.jet.editor.configuration.JETSourceViewerConfiguration;
import org.eclipse.jet.editor.configuration.JETTokenStyleManager;
+import org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate;
import org.eclipse.jet.editor.outline.JETOutlinePage;
import org.eclipse.jet.editor.partition.JETDocumentPartitionScanner;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
import org.eclipse.jet.taglib.TagLibrary;
import org.eclipse.jet.taglib.TagLibraryManager;
import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.eclipse.jet.transform.IJETBundleManager;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.internal.text.link.contentassist.HTMLTextPresenter;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ITextListener;
import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextEvent;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
@@ -56,314 +62,346 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.editors.text.IEncodingSupport;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.ContentAssistAction;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.osgi.framework.Bundle;
public class JETTextEditor extends TextEditor {
- private JETTokenStyleManager tokenStyleManager;
+ private JETTokenStyleManager tokenStyleManager;
+
private JETSourceViewer sourceViewer;
- private JETDocumentPartitionScanner partitionScanner;
+
+ private JETDocumentPartitionScanner partitionScanner;
+
private ProjectionSupport projectionSupport;
+
private IContentOutlinePage outlinePage;
-
+
private JET2CompilationUnit cUnit;
+
private IJavaProject javaProject;
- private Map positions = Collections.EMPTY_MAP;
+
+ private Map positions;
+
private Map registeredPrefixMap;
-
- public JETTextEditor() {
- super();
+
+ private boolean cUnitInvalidated;
+
+ private ArrayList defaultContentColorerDelegates;
+
+ private IJETDefaultTextColorerDelegate currentDelegate;
+
+ public JETTextEditor() {
+ positions = Collections.EMPTY_MAP;
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
JETEditorPreferenceConstants.initializeDefaultValues(preferenceStore);
setPreferenceStore(preferenceStore);
- tokenStyleManager = new JETTokenStyleManager(preferenceStore);
+ tokenStyleManager = new JETTokenStyleManager(preferenceStore);
partitionScanner = new JETDocumentPartitionScanner(this);
- setSourceViewerConfiguration(new JETSourceViewerConfiguration(this));
- setDocumentProvider(new JETDocumentProvider(this));
- }
-
+ setSourceViewerConfiguration(new JETSourceViewerConfiguration(this));
+ setDocumentProvider(new JETDocumentProvider(this));
+ }
+
public void dispose() {
- tokenStyleManager.dispose();
- super.dispose();
- }
-
+ tokenStyleManager.dispose();
+ super.dispose();
+ }
+
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
if (input instanceof IFileEditorInput) {
IFile jetTemplateFile = ((IFileEditorInput) input).getFile();
javaProject = JavaCore.create(jetTemplateFile.getProject());
}
+ initDefaultContentColorerDelegetes();
+ if (!defaultContentColorerDelegates.isEmpty())
+ currentDelegate = (IJETDefaultTextColorerDelegate) defaultContentColorerDelegates.get(0);
+ }
+
+ public void setCurrentColorerDelegate(IJETDefaultTextColorerDelegate delegate) {
+ currentDelegate = delegate;
+ partitionScanner.updateJETTextContentDamagerRepairer();
+ if (isDirty())
+ getSourceViewer().getDocument().set(getSourceViewer().getDocument().get());
+ else
+ setInput(getEditorInput());
+ }
+
+ public IJETDefaultTextColorerDelegate getCurrentColorerDelegate() {
+ return currentDelegate;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
- */
- protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
- fAnnotationAccess= getAnnotationAccess();
- fOverviewRuler= createOverviewRuler(getSharedColors());
- sourceViewer= new JETSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles, getPreferenceStore());
- // ensure decoration support has been created and configured.
+ public IJETDefaultTextColorerDelegate[] getColorerDelegates() {
+ IJETDefaultTextColorerDelegate results[] = new IJETDefaultTextColorerDelegate[defaultContentColorerDelegates.size()];
+ defaultContentColorerDelegates.toArray(results);
+ return results;
+ }
+
+ private void initDefaultContentColorerDelegetes() {
+ defaultContentColorerDelegates = new ArrayList();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement elements[] = registry.getConfigurationElementsFor("org.eclipse.jet.editor",
+ "defaultContentColorerDelegates");
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement element = elements[i];
+ Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
+ String delegateClass = element.getAttribute("delegateClass");
+ IJETDefaultTextColorerDelegate delegate = null;
+ try {
+ Class clazz = bundle.loadClass(delegateClass);
+ Class argTypes[] = { JETTextEditor.class };
+ Constructor ctorWithTextEditor = null;
+ try {
+ ctorWithTextEditor = clazz.getConstructor(argTypes);
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ if (ctorWithTextEditor != null)
+ delegate = (IJETDefaultTextColorerDelegate) ctorWithTextEditor.newInstance(new Object[] { this });
+ else
+ delegate = (IJETDefaultTextColorerDelegate) clazz.newInstance();
+ defaultContentColorerDelegates.add(delegate);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
+ fAnnotationAccess = getAnnotationAccess();
+ fOverviewRuler = createOverviewRuler(getSharedColors());
+ sourceViewer = new JETSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles,
+ getPreferenceStore());
getSourceViewerDecorationSupport(sourceViewer);
-
- projectionSupport= new ProjectionSupport(sourceViewer, getAnnotationAccess(), getSharedColors());
- projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
- projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
+ projectionSupport = new ProjectionSupport(sourceViewer, getAnnotationAccess(), getSharedColors());
+ projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error");
+ projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning");
projectionSupport.setHoverControlCreator(new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell shell) {
- return new DefaultInformationControl(shell, SWT.TOOL | SWT.NO_TRIM | getOrientation(), SWT.NONE, new HTMLTextPresenter());
+ return new DefaultInformationControl(shell, getOrientation(), 0, new HTMLTextPresenter());
}
});
projectionSupport.install();
- sourceViewer.addTextListener(new ITextListener() {
- public void textChanged(TextEvent event) {
- int changeOffset = event.getOffset();
-
- int replacedTextLength = event.getReplacedText() == null ? 0 : event.getReplacedText().length();
- int textLength = event.getText() == null ? 0 : event.getText().length();
-
- int shift = textLength - replacedTextLength; // can be negative
-
- JET2ASTElement elementAtChangeOffset = getCachedASTElement(changeOffset);
- JET2ASTElement elementAtEndOfChange = getCachedASTElement(changeOffset + replacedTextLength);
-
- if (elementAtChangeOffset != null) {
- int start = elementAtChangeOffset.getStart();
- int end = elementAtEndOfChange == null ?
- elementAtChangeOffset.getEnd() :
- elementAtEndOfChange.getEnd();
- try {
- String newText =
- sourceViewer.getDocument().get(start, end - start + shift);
- // reparse this portion of the document only
-// JET2CompilationUnit incrementalCUnit = new JET2CompilationUnit();
-// Map cUnitPredefLibs = new HashMap();
-// for (int i = 0; i < cUnit.getTagLibraryReferences().length; i++) {
-// TagLibraryReference tagLibRef = cUnit.getTagLibraryReferences()[i];
-// cUnitPredefLibs.put(tagLibRef.getPrefix(), tagLibRef.getTagLibraryId());
-// }
-// incrementalCUnit.setPredefinedTagLibraries(cUnitPredefLibs);
-// incrementalCUnit.parse(newText);
-// List parsedBodyElements = incrementalCUnit.getBodyElements();
-//
-// // remove previous body elements on the original cUnit
-// int index = cUnit.getBodyElements().indexOf(elementAtChangeOffset);
-// if (elementAtChangeOffset == elementAtEndOfChange || elementAtEndOfChange == null) {
-// cUnit.getBodyElements().remove(elementAtChangeOffset);
-// } else {
-// JET2ASTElement nextElement = elementAtChangeOffset.getNextElement();
-// while (nextElement != elementAtEndOfChange) {
-// cUnit.getBodyElements().remove(elementAtEndOfChange);
-// nextElement = nextElement.getNextElement();
-// }
-// cUnit.getBodyElements().remove(elementAtChangeOffset);
-// cUnit.getBodyElements().remove(elementAtEndOfChange);
-// }
-// cUnit.getBodyElements().addAll(index, parsedBodyElements);
-// if (outlinePage != null)
-// ((JETOutlinePage)outlinePage).setInput();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- //editorTextChanged();
- }
- });
- return sourceViewer;
+ return sourceViewer;
}
-
+
public ISourceViewer getEditorSourceViewer() {
return sourceViewer;
}
-
+
public IPreferenceStore getEditorPreferenceStore() {
return super.getPreferenceStore();
}
-
+
public JETDocumentPartitionScanner getPartitionScanner() {
return partitionScanner;
}
-
+
public JETTokenStyleManager getTokenStyleManager() {
return tokenStyleManager;
}
-
+
protected void handleEditorInputChanged() {
super.handleEditorInputChanged();
- editorTextChanged();
+ handleDocumentChange(null);
}
- private void editorTextChanged() {
- cUnit = null;
-// if (outlinePage != null && outlinePage.getControl().isVisible())
-// ((JETOutlinePage)outlinePage).setInput();
+ public void handleDocumentChange(DocumentEvent e) {
+ cUnitInvalidated = true;
+ if (outlinePage != null && outlinePage.getControl().isVisible())
+ ((JETOutlinePage) outlinePage).setInput();
}
-
+
+ public boolean isCUnitInvalidated() {
+ return cUnitInvalidated;
+ }
+
public JET2CompilationUnit requestCompilationUnit() {
- if (cUnit == null) {
- IEditorInput editorInput = getEditorInput();
+ if (cUnit == null || cUnitInvalidated) {
+ IEditorInput editorInput = getEditorInput();
String charset = "UTF-8";
- InputStream is = new ByteArrayInputStream(sourceViewer.getDocument().get().getBytes());
- cUnit = new JET2CompilationUnit();
- Map predefinedLibraryMap = getRegisteredPrefixMap();
- if (editorInput instanceof IFileEditorInput) {
- IFile jetTemplateFile = ((IFileEditorInput) editorInput).getFile();
- IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
- IJETBundleDescriptor descriptor = bundleManager.getDescriptorForProject(jetTemplateFile.getProject().getName());
- predefinedLibraryMap.putAll(descriptor != null ? getPredefinedPrefixMap(descriptor) : Collections.EMPTY_MAP);
+ java.io.InputStream is = null;
+ if (sourceViewer == null) {
+ if (editorInput instanceof IStorageEditorInput)
+ try {
+ IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
+ is = storage.getContents();
+ if (storage instanceof IEncodedStorage)
+ charset = ((IEncodedStorage) storage).getCharset();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ } else {
+ is = new ByteArrayInputStream(sourceViewer.getDocument().get().getBytes());
+ }
+ if (is == null)
+ is = new ByteArrayInputStream("".getBytes());
+ if (cUnit == null) {
+ cUnit = new JET2CompilationUnit();
+ Map predefinedLibraryMap = getRegisteredPrefixMap();
+ if (editorInput instanceof IFileEditorInput) {
+ IFile jetTemplateFile = ((IFileEditorInput) editorInput).getFile();
+ IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+ IJETBundleDescriptor descriptor = bundleManager.getDescriptorForProject(jetTemplateFile.getProject()
+ .getName());
+ predefinedLibraryMap.putAll(descriptor == null ? Collections.EMPTY_MAP : getPredefinedPrefixMap(descriptor));
+ }
+ cUnit.setPredefinedTagLibraries(predefinedLibraryMap);
}
- cUnit.setPredefinedTagLibraries(predefinedLibraryMap);
cUnit.parse(is, charset);
PositionsCollector collector = new PositionsCollector();
cUnit.accept(collector);
positions = collector.getPositions();
+ cUnitInvalidated = false;
}
return cUnit;
}
-
+
public JET2ASTElement getASTElement(int offset) {
- if (cUnit == null)
- requestCompilationUnit(); // recompute the positions if the compilation unit has been invalidated
+ requestCompilationUnit();
return getCachedASTElement(offset);
}
- private JET2ASTElement getCachedASTElement(int offset) {
+ public JET2ASTElement getCachedASTElement(int offset) {
for (Iterator iterator = positions.keySet().iterator(); iterator.hasNext();) {
Position pos = (Position) iterator.next();
- if (pos.offset <= offset && (pos.length + pos.offset) > offset)
+ if (pos.offset <= offset && pos.length + pos.offset > offset)
return (JET2ASTElement) positions.get(pos);
}
+
return null;
}
-
+
public IJavaProject getJETJavaProject() {
return javaProject;
}
-
+
private Map getRegisteredPrefixMap() {
if (registeredPrefixMap == null) {
- String[] tagLibIds = TagLibraryManager.getInstance().getKnownLibraryIds();
+ String tagLibIds[] = TagLibraryManager.getInstance().getKnownLibraryIds();
registeredPrefixMap = new HashMap(tagLibIds.length);
for (int i = 0; i < tagLibIds.length; i++) {
String id = tagLibIds[i];
TagLibrary tagLib = TagLibraryManager.getInstance().getTagLibrary(id, true);
registeredPrefixMap.put(tagLib.getDefaultPrefix(), tagLib.getLibraryId());
}
+
}
return registeredPrefixMap;
}
private Map getPredefinedPrefixMap(IJETBundleDescriptor descriptor) {
- final TagLibraryReference[] tlRefs = descriptor.getTagLibraryReferences();
- final Map result = new HashMap(tlRefs.length);
- for (int i = 0; i < tlRefs.length; i++) {
- if (tlRefs[i].isAutoImport()) {
+ TagLibraryReference tlRefs[] = descriptor.getTagLibraryReferences();
+ Map result = new HashMap(tlRefs.length);
+ for (int i = 0; i < tlRefs.length; i++)
+ if (tlRefs[i].isAutoImport())
result.put(tlRefs[i].getPrefix(), tlRefs[i].getTagLibraryId());
- }
- }
+
return result;
}
-
- /*
- * @see AbstractTextEditor#createActions()
- */
+
protected void createActions() {
super.createActions();
ResourceBundle resourceBundle = ResourceBundle.getBundle("org.eclipse.jet.editor.i18n.TextEditorMessages");
- Action action = new ContentAssistAction(resourceBundle,"ContentAssistProposal.", this); //$NON-NLS-1$
- action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
- setAction("ContentAssistProposal", action); //$NON-NLS-1$
- markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
+ Action action = new ContentAssistAction(resourceBundle, "ContentAssistProposal.", this);
+ action.setActionDefinitionId("org.eclipse.ui.edit.text.contentAssist.proposals");
+ setAction("ContentAssistProposal", action);
+ markAsStateDependentAction("ContentAssistProposal", true);
}
-
+
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
- // TODO Auto-generated method stub
super.handlePreferenceStoreChanged(event);
- if (event.getNewValue() instanceof RGB) {
+ if (event.getNewValue() instanceof RGB)
getTokenStyleManager().bindColor(event.getProperty(), (RGB) event.getNewValue());
- }
}
-
- /*
- * @see AbstractTextEditor#getAdapter(Class)
- */
- public Object getAdapter(Class required) {
+ public Object getAdapter(Class required) {
if (IContentOutlinePage.class.equals(required)) {
if (outlinePage == null)
- outlinePage= createOutlinePage();
+ outlinePage = createOutlinePage();
return outlinePage;
}
-
if (IEncodingSupport.class.equals(required))
return fEncodingSupport;
-
if (projectionSupport != null) {
- Object adapter= projectionSupport.getAdapter(getSourceViewer(), required);
+ Object adapter = projectionSupport.getAdapter(getSourceViewer(), required);
if (adapter != null)
return adapter;
}
-
return super.getAdapter(required);
}
+ public void editorContextMenuAboutToShow(IMenuManager menu) {
+ super.editorContextMenuAboutToShow(menu);
+ addAction(menu, "settings", "setDelegateColorerActionID");
+ }
+
protected IContentOutlinePage createOutlinePage() {
- JETOutlinePage page= new JETOutlinePage(this);
- // Listen to selection so that we can handle it is a special way.
- //
+ JETOutlinePage page = new JETOutlinePage(this);
page.addSelectionChangedListener(new ISelectionChangedListener() {
- // This ensures that we handle selections correctly.
- //
public void selectionChanged(SelectionChangedEvent event) {
handleContentOutlineSelection(event.getSelection());
}
- });
+ });
return page;
}
protected void handleContentOutlineSelection(ISelection selection) {
- // TODO Auto-generated method stub
IStructuredSelection ssel = (IStructuredSelection) selection;
Object firstElement = ssel.getFirstElement();
if (firstElement instanceof JET2ASTElement) {
JET2ASTElement astElement = (JET2ASTElement) firstElement;
int start = astElement.getStart();
int end = astElement.getEnd();
+ int length = end - start;
if (astElement instanceof TextElement) {
- if (astElement.getPrevElement()!= null)
+ if (astElement.getPrevElement() != null)
start = astElement.getPrevElement().getEnd();
else
start = 0;
- if (astElement.getNextElement() != null)
- end = astElement.getNextElement().getStart();
- else
- end = sourceViewer.getDocument().getLength();
+ length = ((TextElement) astElement).getText().length;
}
- sourceViewer.setSelectedRange(start, end - start);
- sourceViewer.revealRange(start, end - start);
+ sourceViewer.setSelectedRange(start, length);
+ sourceViewer.revealRange(start, length);
}
}
- public void createContextMenuFor(TreeViewer contentOutlineViewer) {
- // TODO Auto-generated method stub
-
+ public void createContextMenuFor(TreeViewer treeviewer) {
}
-
+
+ public boolean isActive(IJETDefaultTextColorerDelegate candidate) {
+ return true;
+ }
+
private static class PositionsCollector extends DefaultJET2ASTVisitor {
- private Map positions = new HashMap();
-
+ private Map positions;
+
+ private PositionsCollector() {
+ positions = new HashMap();
+ }
+
public Map getPositions() {
return positions;
}
@@ -384,10 +422,6 @@ public class JETTextEditor extends TextEditor {
matchOffset(scriptlet);
}
- public void visit(TextElement text) {
- matchOffset(text);
- }
-
public void visit(XMLEmptyElement xmlEmptyElement) {
matchOffset(xmlEmptyElement);
}
@@ -404,8 +438,11 @@ public class JETTextEditor extends TextEditor {
matchOffset(comment);
}
- public void matchOffset(JET2ASTElement element) {
- positions.put(new Position(element.getStart(), element.getEnd() - element.getStart()), element);
+ public void matchOffset(JET2ASTElement astElement) {
+ int start = astElement.getStart();
+ int end = astElement.getEnd();
+ int length = end - start;
+ positions.put(new Position(start, length), astElement);
}
}
}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextPreviewViewer.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextPreviewViewer.java
new file mode 100644
index 0000000..85ac0fc
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/JETTextPreviewViewer.java
@@ -0,0 +1,193 @@
+package org.eclipse.jet.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelItemProviderAdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.dialogs.ResourceSelectionDialog;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.forms.ManagedForm;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+
+public class JETTextPreviewViewer extends Viewer {
+
+ private SourceViewer sourceViewer;
+
+ private Object fInput;
+
+ private ScrolledForm sForm;
+
+ private Text inputResource;
+
+ private Button browseWorkspace;
+
+ private Tree tree;
+
+ private TreeViewer treeViewer;
+
+ private ISelection selection;
+
+ public JETTextPreviewViewer(Composite parent) {
+ inputResource = null;
+ browseWorkspace = null;
+ tree = null;
+ treeViewer = null;
+ org.eclipse.swt.widgets.Display display = parent.getDisplay();
+ FormToolkit formToolkit = new FormToolkit(display);
+ sForm = formToolkit.createScrolledForm(parent);
+ ManagedForm overviewForm = new ManagedForm(formToolkit, sForm);
+ Composite body = sForm.getBody();
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.marginWidth = 10;
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 10;
+ body.setLayout(layout);
+ createInputArgumentsSection(overviewForm, body, formToolkit);
+ createTextViewerSection(overviewForm, body, formToolkit);
+ overviewForm.initialize();
+ overviewForm.refresh();
+ }
+
+ private void createInputArgumentsSection(ManagedForm mForm, Composite body, FormToolkit formToolkit) {
+ final Section section = formToolkit.createSection(body, 256);
+ section.setText("Input Argument");
+ Composite client = formToolkit.createComposite(section);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = formToolkit.getBorderStyle() == 0 ? 2 : 0;
+ layout.numColumns = 2;
+ client.setLayout(layout);
+ inputResource = formToolkit.createText(client, "<Empty>");
+ inputResource.setEditable(false);
+ GridData gd = new GridData();
+ gd.horizontalSpan = 1;
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = 4;
+ gd.grabExcessVerticalSpace = false;
+ inputResource.setLayoutData(gd);
+ browseWorkspace = formToolkit.createButton(client, "Browse ...", 0);
+ browseWorkspace.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ResourceSelectionDialog resSelectionDialog = new ResourceSelectionDialog(section.getShell(),
+ ResourcesPlugin.getWorkspace().getRoot(), "Select a workspace resource");
+ if (resSelectionDialog.open() == 0) {
+ Object result[] = resSelectionDialog.getResult();
+ if (result.length == 1) {
+ String inputFile = ((IResource) result[0]).getFullPath().toString();
+ inputResource.setText(inputFile);
+ ResourceSet resourceSet = new ResourceSetImpl();
+ URI uri = URI.createPlatformResourceURI(inputFile, true);
+ org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(uri, true);
+ if (resource != null)
+ treeViewer.setInput(resourceSet);
+ }
+ }
+ }
+ });
+ tree = formToolkit.createTree(client, 2052);
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ gd.horizontalAlignment = 4;
+ gd.verticalAlignment = 4;
+ gd.grabExcessVerticalSpace = true;
+ tree.setLayoutData(gd);
+ treeViewer = new TreeViewer(tree);
+ List factories = new ArrayList();
+ factories.add(new ResourceItemProviderAdapterFactory());
+ factories.add(new GenModelItemProviderAdapterFactory());
+ factories.add(new ReflectiveItemProviderAdapterFactory());
+ org.eclipse.emf.common.notify.AdapterFactory adapterFactory = new ComposedAdapterFactory(factories);
+ treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
+ treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
+ Button button = formToolkit.createButton(client, "Apply", 0x800008);
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IFileEditorInput fileInput = (IFileEditorInput) getInput();
+ IFile file = fileInput.getFile();
+ JavaCore.create(file.getProject());
+ }
+ });
+ section.setClient(client);
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = 4;
+ gd.verticalAlignment = 1;
+ section.setLayoutData(gd);
+ SectionPart sectionPart = new SectionPart(section);
+ mForm.addPart(sectionPart);
+ }
+
+ private void createTextViewerSection(ManagedForm mForm, Composite body, FormToolkit formToolkit) {
+ Section section = formToolkit.createSection(body, 256);
+ section.setText("Preview");
+ org.eclipse.jface.preference.IPreferenceStore store = EditorsUI.getPreferenceStore();
+ sourceViewer = new SourceViewer(section, null, 768);
+ sourceViewer.configure(new TextSourceViewerConfiguration(store));
+ sourceViewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.jdt.ui.editors.textfont"));
+ sourceViewer.setEditable(false);
+ section.setClient(sourceViewer.getControl());
+ GridData gd = new GridData();
+ gd.horizontalAlignment = 4;
+ gd.verticalAlignment = 4;
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = true;
+ section.setLayoutData(gd);
+ SectionPart sectionPart = new SectionPart(section);
+ mForm.addPart(sectionPart);
+ }
+
+ public Control getControl() {
+ return sForm;
+ }
+
+ public void setInput(Object input) {
+ fInput = input;
+ }
+
+ public Object getInput() {
+ return fInput;
+ }
+
+ public ISelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(ISelection s, boolean reveal) {
+ selection = s;
+ }
+
+ public void refresh() {
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/actions/SetContentColorerAction.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/actions/SetContentColorerAction.java
new file mode 100644
index 0000000..1b28873
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/actions/SetContentColorerAction.java
@@ -0,0 +1,65 @@
+package org.eclipse.jet.editor.actions;
+
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.*;
+import org.eclipse.ui.dialogs.ListDialog;
+
+public class SetContentColorerAction implements IEditorActionDelegate {
+ private JETTextEditor editor;
+
+ public SetContentColorerAction() {
+ }
+
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ editor = (JETTextEditor) targetEditor;
+ action.setText("Set default content colorer ...");
+ }
+
+ public void run(IAction action) {
+ ListDialog dialog = new ListDialog(editor.getSite().getShell());
+ dialog.setLabelProvider(new LabelProvider() {
+ public String getText(Object element) {
+ if (element instanceof IJETDefaultTextColorerDelegate)
+ return ((IJETDefaultTextColorerDelegate) element).getName();
+ else
+ return super.getText(element);
+ }
+
+ public Image getImage(Object element) {
+ if (element instanceof IJETDefaultTextColorerDelegate)
+ return ((IJETDefaultTextColorerDelegate) element).getImage();
+ else
+ return super.getImage(element);
+ }
+ });
+ dialog.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return editor.getColorerDelegates();
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+ }
+ });
+ dialog.setTitle("JET default text content colorer");
+ dialog.setMessage("Select the content colorer to the default text embeded in the JET template");
+ dialog.setInitialSelections(editor.getColorerDelegates());
+ dialog.setInput(editor);
+ int result = dialog.open();
+ if (result == 0) {
+ IJETDefaultTextColorerDelegate delegate = (IJETDefaultTextColorerDelegate) dialog.getResult()[0];
+ editor.setCurrentColorerDelegate(delegate);
+ }
+ }
+
+ public void selectionChanged(IAction iaction, ISelection iselection) {
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationHover.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationHover.java
new file mode 100644
index 0000000..663fd29
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationHover.java
@@ -0,0 +1,133 @@
+package org.eclipse.jet.editor.annotations;
+
+import java.util.*;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.source.*;
+
+public class JETAnnotationHover implements IAnnotationHover {
+
+ public JETAnnotationHover() {
+ }
+
+ /**
+ * Returns the distance to the ruler line.
+ * @param position Position
+ * @param document IDocument
+ * @param line int
+ * @return int
+ */
+ protected int compareRulerLine(Position position, IDocument document, int line) {
+ if (position.getOffset() > -1 && position.getLength() > -1) {
+ try {
+ int javaAnnotationLine = document.getLineOfOffset(position.getOffset());
+ if (line == javaAnnotationLine)
+ return 1;
+ if (javaAnnotationLine <= line
+ && line <= document.getLineOfOffset(position.getOffset() + position.getLength()))
+ return 2;
+ } catch (BadLocationException x) {
+ }
+ }
+ return 0;
+ }
+ /**
+ * Selects a set of markers from the two lists. By default, it just returns the set of exact
+ * matches.
+ * @param exactMatch List
+ * @param including List
+ * @return List
+ */
+ protected List select(List exactMatch, List including) {
+ return exactMatch;
+ }
+ /**
+ * Returns one marker which includes the ruler's line of activity.
+ * @param viewer ISourceViewer
+ * @param line int
+ * @return List
+ */
+ protected List getAnnotationsForLine(ISourceViewer viewer, int line) {
+ IDocument document = viewer.getDocument();
+ IAnnotationModel model = viewer.getAnnotationModel();
+ if (model == null)
+ return null;
+ List exact = new ArrayList();
+ List including = new ArrayList();
+ Iterator e = model.getAnnotationIterator();
+ HashMap messagesAtPosition = new HashMap();
+ while (e.hasNext()) {
+ Object o = e.next();
+ if (o instanceof JETProblemAnnotation) {
+ JETProblemAnnotation a = (JETProblemAnnotation) o;
+ Position position = model.getPosition(a);
+ if (position != null && !isDuplicateAnnotation(messagesAtPosition, position, a.getText()))
+ switch (compareRulerLine(position, document, line)) {
+ case 1: // '\001'
+ exact.add(a);
+ break;
+
+ case 2: // '\002'
+ including.add(a);
+ break;
+ }
+ }
+ }
+ return select(exact, including);
+ }
+ /**
+ * Method isDuplicateAnnotation.
+ * @param messagesAtPosition Map
+ * @param position Position
+ * @param message String
+ * @return boolean
+ */
+ private boolean isDuplicateAnnotation(Map messagesAtPosition, Position position, String message) {
+ if (messagesAtPosition.containsKey(position)) {
+ Object value = messagesAtPosition.get(position);
+ if (message.equals(value))
+ return true;
+ if (value instanceof List) {
+ List messages = (List) value;
+ if (messages.contains(message))
+ return true;
+ messages.add(message);
+ } else {
+ ArrayList messages = new ArrayList();
+ messages.add(value);
+ messages.add(message);
+ messagesAtPosition.put(position, messages);
+ }
+ } else {
+ messagesAtPosition.put(position, message);
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int)
+ */
+ public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
+ List annotations = getAnnotationsForLine(sourceViewer, lineNumber);
+ if (annotations != null)
+ if (annotations.size() == 1) {
+ JETProblemAnnotation annotation = (JETProblemAnnotation) annotations.get(0);
+ String message = annotation.getText();
+ if (message != null && message.trim().length() > 0)
+ return message;
+ } else {
+ List messages = new ArrayList();
+ for (Iterator e = annotations.iterator(); e.hasNext();) {
+ JETProblemAnnotation javaAnnotation = (JETProblemAnnotation) e.next();
+ String message = javaAnnotation.getText();
+ if (message != null && message.trim().length() > 0)
+ messages.add(message.trim());
+ }
+
+ if (messages.size() == 1)
+ return (String) messages.get(0);
+ if (messages.size() > 1)
+ return messages.toString();
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationModel.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationModel.java
new file mode 100644
index 0000000..96e2fc0
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETAnnotationModel.java
@@ -0,0 +1,54 @@
+package org.eclipse.jet.editor.annotations;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
+
+public class JETAnnotationModel extends ResourceMarkerAnnotationModel {
+ private boolean fireChanges;
+
+ public JETAnnotationModel(IResource resource) {
+ super(resource);
+ fireChanges = true;
+ }
+
+ public synchronized boolean isFireChanges() {
+ return fireChanges;
+ }
+
+ public synchronized void setFireChanges(boolean b) {
+ fireChanges = b;
+ }
+
+ public synchronized void addAnnotation(Annotation annotation, Position position) {
+ try {
+ addAnnotation(annotation, position, fireChanges);
+ } catch (BadLocationException _ex) {
+ }
+ }
+
+ public synchronized void removeAllAnnotations() {
+ super.removeAllAnnotations(fireChanges);
+ }
+
+ public synchronized void removeAnnotation(Annotation annotation) {
+ super.removeAnnotation(annotation, fireChanges);
+ }
+
+ public MarkerAnnotation createMarkerAnnotation(IMarker marker) {
+ return super.createMarkerAnnotation(marker);
+ }
+
+ public Position createPositionFromMarker(IMarker marker) {
+ return super.createPositionFromMarker(marker);
+ }
+
+ public void fireAnnotationModelChanged() {
+ fireModelChanged();
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETProblemAnnotation.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETProblemAnnotation.java
new file mode 100644
index 0000000..549499c
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/annotations/JETProblemAnnotation.java
@@ -0,0 +1,23 @@
+package org.eclipse.jet.editor.annotations;
+
+import org.eclipse.jet.compiler.Problem;
+import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jface.text.source.Annotation;
+
+public class JETProblemAnnotation extends Annotation {
+
+ public static final String ERROR_ANNOTATION_TYPE = "org.eclipse.jet.editor.error";
+
+ public static final String WARNING_ANNOTATION_TYPE = "org.eclipse.jet.editor.warning";
+
+ public static final String INFO_ANNOTATION_TYPE = "org.eclipse.jet.editor.info";
+
+ public JETProblemAnnotation(Problem problem) {
+ if (problem.getSeverity() == ParseProblemSeverity.ERROR)
+ setType("org.eclipse.jet.editor.error");
+ else if (problem.getSeverity() == ParseProblemSeverity.WARNING)
+ setType("org.eclipse.jet.editor.warning");
+ setText(problem.getMessage());
+ }
+
+}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/autoedit/JETTemplateAutoEditStrategy.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/autoedit/JETTemplateAutoEditStrategy.java
new file mode 100644
index 0000000..01b07f4
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/autoedit/JETTemplateAutoEditStrategy.java
@@ -0,0 +1,266 @@
+package org.eclipse.jet.editor.autoedit;
+
+import org.eclipse.jface.text.*;
+
+public class JETTemplateAutoEditStrategy extends DefaultIndentLineAutoEditStrategy {
+
+ public JETTemplateAutoEditStrategy() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
+ */
+ public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
+ if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
+ smartIndentAfterNewLine(d, c);
+ else if ("%>".equals(c.text)) { //$NON-NLS-1$
+ smartInsertAfterBracket(d, c);
+ }
+ }
+
+ /**
+ * Returns whether or not the text ends with one of the given search strings.
+ * @param d IDocument
+ * @param txt String
+ * @return boolean
+ */
+ private boolean endsWithDelimiter(IDocument d, String txt) {
+ String[] delimiters = d.getLegalLineDelimiters();
+ for (int i = 0; i < delimiters.length; i++) {
+ if (txt.endsWith(delimiters[i]))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the line number of the next bracket after end.
+ * @param document - the document being parsed
+ * @param line - the line to start searching back from
+ * @param end - the end position to search back from
+ * @param closingBracketIncrease - the number of brackets to skip
+ * @return int
+ * @throws BadLocationException
+ */
+ protected int findMatchingOpenBracket(IDocument document, int line, int end, int closingBracketIncrease)
+ throws BadLocationException {
+
+ int start = document.getLineOffset(line);
+ int brackcount = getBracketCount(document, start, end, false) - closingBracketIncrease;
+
+ // sum up the brackets counts of each line (closing brackets count negative,
+ // opening positive) until we find a line the brings the count to zero
+ while (brackcount < 0) {
+ line--;
+ if (line < 0) {
+ return -1;
+ }
+ start = document.getLineOffset(line);
+ end = start + document.getLineLength(line) - 1;
+ brackcount += getBracketCount(document, start, end, false);
+ }
+ return line;
+ }
+
+ /**
+ * Returns the bracket value of a section of text. Closing brackets have a value of -1 and
+ * open brackets have a value of 1.
+ * @param document - the document being parsed
+ * @param start - the start position for the search
+ * @param end - the end position for the search
+ * @param ignoreCloseJspTags boolean
+ * @return int
+ * @throws BadLocationException
+ */
+ private int getBracketCount(IDocument document, int start, int end, boolean ignoreCloseJspTags)
+ throws BadLocationException {
+
+ int begin = start;
+ int jsptagcount = 0;
+ while (begin < end) {
+ char curr = document.getChar(begin);
+ begin++;
+ switch (curr) {
+ case '/':
+ begin = adjustBeginOnComment(document, end, begin);
+ break;
+ case '*':
+ if (begin < end) {
+ char next = document.getChar(begin);
+ if (next == '/') {
+ // we have been in a comment: forget what we read before
+ jsptagcount = 0;
+ begin++;
+ }
+ }
+ break;
+ case '<':
+ if ((begin + 1 < document.getLength()) && (document.getChar(begin + 1) == '%')) {
+ jsptagcount++;
+ ignoreCloseJspTags = false;
+ }
+ break;
+ case '>':
+ if (!ignoreCloseJspTags && (begin > 1) && (document.getChar(begin - 1) == '%')) {
+ jsptagcount--;
+ }
+ break;
+ case '"':
+ case '\'':
+ begin = getStringEnd(document, begin, end, curr);
+ break;
+ default:
+ }
+ }
+ return jsptagcount;
+ }
+
+ private int adjustBeginOnComment(IDocument document, int end, int begin) throws BadLocationException {
+ if (begin < end) {
+ char next = document.getChar(begin);
+ if (next == '*') {
+ // a comment starts, advance to the comment end
+ begin = getCommentEnd(document, begin + 1, end);
+ } else if (next == '/') {
+ // '//'-comment: nothing to do anymore on this line
+ begin = end;
+ }
+ }
+ return begin;
+ }
+
+ /**
+ * Returns the end position a comment starting at pos.
+ * @param document - the document being parsed
+ * @param position - the start position for the search
+ * @param end - the end position for the search
+ * @return int
+ * @throws BadLocationException
+ */
+ private int getCommentEnd(IDocument document, int position, int end) throws BadLocationException {
+ int currentPosition = position;
+ while (currentPosition < end) {
+ char curr = document.getChar(currentPosition);
+ currentPosition++;
+ if (curr == '*') {
+ if (currentPosition < end && document.getChar(currentPosition) == '/') {
+ return currentPosition + 1;
+ }
+ }
+ }
+ return end;
+ }
+
+ /**
+ * Returns the String at line with the leading whitespace removed.
+ * @param document - the document being parsed
+ * @param line - the line being searched
+ * @return String
+ * @throws BadLocationException
+ */
+ protected String getIndentOfLine(IDocument document, int line) throws BadLocationException {
+ if (line > -1) {
+ int start = document.getLineOffset(line);
+ int end = start + document.getLineLength(line) - 1;
+ int whiteend = findEndOfWhiteSpace(document, start, end);
+ return document.get(start, whiteend - start);
+ } else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns the position of the character in the document after position.
+ * @param document - the document being parsed
+ * @param position - the position to start searching from
+ * @param end - the end of the document
+ * @param character - the character you are trying to match
+ * @return int
+ * @throws BadLocationException
+ */
+ private int getStringEnd(IDocument document, int position, int end, char character) throws BadLocationException {
+ int currentPosition = position;
+ while (currentPosition < end) {
+ char currentCharacter = document.getChar(currentPosition);
+ currentPosition++;
+ if (currentCharacter == '\\') {
+ // ignore escaped characters
+ currentPosition++;
+ } else if (currentCharacter == character) {
+ return currentPosition;
+ }
+ }
+ return end;
+ }
+
+ /**
+ * Set the indent of a new line based on the command provided in the supplied document.
+ * @param document - the document being parsed
+ * @param command - the command being performed
+ */
+ protected void smartIndentAfterNewLine(IDocument document, DocumentCommand command) {
+
+ int docLength = document.getLength();
+ if (command.offset == -1 || docLength == 0)
+ return;
+
+ try {
+ int p = (command.offset == docLength ? command.offset - 1 : command.offset);
+ int line = document.getLineOfOffset(p);
+
+ StringBuffer buf = new StringBuffer(command.text);
+ if (command.offset < docLength && document.getChar(command.offset) == '}') {
+ int indLine = findMatchingOpenBracket(document, line, command.offset, 0);
+ if (indLine == -1) {
+ indLine = line;
+ }
+ buf.append(getIndentOfLine(document, indLine));
+ } else {
+ int start = document.getLineOffset(line);
+ int whiteend = findEndOfWhiteSpace(document, start, command.offset);
+ buf.append(document.get(start, whiteend - start));
+ if (getBracketCount(document, start, command.offset, true) > 0) {
+ buf.append('\t');
+ }
+ }
+ command.text = buf.toString();
+
+ } catch (BadLocationException excp) {
+ }
+ }
+
+ /**
+ * Set the indent of a bracket based on the command provided in the supplied document.
+ * @param document - the document being parsed
+ * @param command - the command being performed
+ */
+ protected void smartInsertAfterBracket(IDocument document, DocumentCommand command) {
+ if (command.offset == -1 || document.getLength() == 0)
+ return;
+
+ try {
+ int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
+ int line = document.getLineOfOffset(p);
+ int start = document.getLineOffset(line);
+ int whiteend = findEndOfWhiteSpace(document, start, command.offset);
+
+ // shift only when line does not contain any text up to the closing bracket
+ if (whiteend == command.offset) {
+ // evaluate the line with the opening bracket that matches out closing bracket
+ int indLine = findMatchingOpenBracket(document, line, command.offset, 1);
+ if (indLine != -1 && indLine != line) {
+ // take the indent of the found line
+ StringBuffer replaceText = new StringBuffer(getIndentOfLine(document, indLine));
+ // add the rest of the current line including the just added close bracket
+ replaceText.append(document.get(whiteend, command.offset - whiteend));
+ replaceText.append(command.text);
+ // modify document command
+ command.length = command.offset - start;
+ command.offset = start;
+ command.text = replaceText.toString();
+ }
+ }
+ } catch (BadLocationException excp) {
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/IJETColorConstants.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/IJETColorConstants.java
index f109ac0..c93b1a0 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/IJETColorConstants.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/IJETColorConstants.java
@@ -2,7 +2,7 @@ package org.eclipse.jet.editor.configuration;
import org.eclipse.swt.graphics.RGB;
-interface IJETColorConstants {
+public interface IJETColorConstants {
RGB JET_CUSTOM_TAG_FG = new RGB(180, 128, 0);
RGB JET_COMMENT_FG = new RGB(0, 155, 50);
RGB JET_DIRECTIVE_FG = new RGB(180, 128, 0);
@@ -14,4 +14,4 @@ interface IJETColorConstants {
RGB JET_JAVA_CODE = new RGB(128, 128, 128);
RGB PROC_INSTR = new RGB(128, 128, 128);
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETDocumentProvider.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETDocumentProvider.java
index 22b88eb..327396b 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETDocumentProvider.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETDocumentProvider.java
@@ -1,31 +1,50 @@
package org.eclipse.jet.editor.configuration;
import org.eclipse.core.runtime.CoreException;
+
import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.annotations.JETAnnotationModel;
import org.eclipse.jet.editor.partition.JETDocumentPartitionScanner;
+import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
public class JETDocumentProvider extends FileDocumentProvider {
-
- private JETTextEditor editor;
+
+ private JETTextEditor editor;
+
public JETDocumentProvider(JETTextEditor editor) {
this.editor = editor;
}
protected IDocument createDocument(Object element) throws CoreException {
- IDocument document = super.createDocument(element);
+ IDocument document = super.createDocument(element);
JETDocumentPartitionScanner partitionScanner = editor.getPartitionScanner();
- if (document != null) {
- IDocumentPartitioner partitioner =
- new FastPartitioner(
- partitionScanner,
- partitionScanner.getContentTypes(editor.getEditorSourceViewer()));
- partitioner.connect(document);
- document.setDocumentPartitioner(partitioner);
- }
- return document;
- }
+ if (document != null) {
+ IDocumentPartitioner partitioner = new FastPartitioner(partitionScanner, partitionScanner.getContentTypes()) {
+ public IRegion documentChanged2(DocumentEvent e) {
+ editor.handleDocumentChange(e);
+ return super.documentChanged2(e);
+ }
+ };
+ partitioner.connect(document);
+ document.setDocumentPartitioner(partitioner);
+ }
+ return document;
+ }
+
+ protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
+ if (element instanceof IFileEditorInput) {
+ IFileEditorInput input = (IFileEditorInput) element;
+ return new JETAnnotationModel(input.getFile());
+ } else {
+ return super.createAnnotationModel(element);
+ }
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETEditorPreferenceConstants.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETEditorPreferenceConstants.java
index 30f5ea5..56489b1 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETEditorPreferenceConstants.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETEditorPreferenceConstants.java
@@ -18,7 +18,7 @@ import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
/**
* Preference Constants used for the IRL Editor
* @author lmirguet
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class JETEditorPreferenceConstants {
public static final String JET_CUSTOM_TAG_FG_COLOR = "jet_custom_tag_foreground";
@@ -53,10 +53,6 @@ public class JETEditorPreferenceConstants {
public static final String AUTO_COMPLETE_ENABLED = "autoCompleteEnable";
public static final String AUTO_COMPLETE_DELAY = "autoCompleteDelay";
-
-
-
-
/**
* Should not be instanciated.
*
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETReconcilingStrategy.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETReconcilingStrategy.java
new file mode 100644
index 0000000..e7e9d5a
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETReconcilingStrategy.java
@@ -0,0 +1,80 @@
+package org.eclipse.jet.editor.configuration;
+
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.compiler.JET2CompilationUnit;
+import org.eclipse.jet.compiler.Problem;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.annotations.JETAnnotationModel;
+import org.eclipse.jet.editor.annotations.JETProblemAnnotation;
+import org.eclipse.jet.internal.editor.JETEditorHelper;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.reconciler.*;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
+
+public class JETReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
+
+ private JETTextEditor jetEditor;
+
+ private ISourceViewer sourceViewer;
+
+ public JETReconcilingStrategy(ISourceViewer sourceViewer, JETTextEditor jetEditor) {
+ this.jetEditor = jetEditor;
+ this.sourceViewer = sourceViewer;
+ }
+
+ public void setDocument(IDocument idocument) {
+ }
+
+ public void initialReconcile() {
+ internalReconcile();
+ }
+
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+ internalReconcile();
+ }
+
+ public void reconcile(IRegion partition) {
+ internalReconcile();
+ }
+
+ private void internalReconcile() {
+ JET2CompilationUnit cUnit = jetEditor.requestCompilationUnit();
+ List cUnitProblems = cUnit.getProblems();
+ List javaContentProblems = JETEditorHelper.evaluateProblems(jetEditor.getJETJavaProject(), cUnit, sourceViewer
+ .getDocument());
+ JETAnnotationModel annotationModel = (JETAnnotationModel) sourceViewer.getAnnotationModel();
+ if (annotationModel != null) {
+ annotationModel.setFireChanges(false);
+ for (Iterator it = annotationModel.getAnnotationIterator(); it.hasNext();) {
+ Annotation annotation = (Annotation) it.next();
+ if ((annotation instanceof JETProblemAnnotation) || (annotation instanceof MarkerAnnotation))
+ annotationModel.removeAnnotation(annotation);
+ }
+
+ for (Iterator iterator = cUnitProblems.iterator(); iterator.hasNext(); ) {
+ Problem problem = (Problem) iterator.next();
+ JETProblemAnnotation annotation = new JETProblemAnnotation(problem);
+ Position position = new Position(problem.getStart(), problem.getEnd() - problem.getStart());
+ annotationModel.addAnnotation(annotation, position);
+ }
+
+ for (Iterator iterator = javaContentProblems.iterator(); iterator.hasNext(); ) {
+ Problem problem = (Problem) iterator.next();
+ JETProblemAnnotation annotation = new JETProblemAnnotation(problem);
+ Position position = new Position(problem.getStart(), problem.getEnd() - problem.getStart());
+ annotationModel.addAnnotation(annotation, position);
+ }
+
+ annotationModel.setFireChanges(true);
+ annotationModel.fireAnnotationModelChanged();
+ }
+ }
+
+ public void setProgressMonitor(IProgressMonitor iprogressmonitor) {
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETSourceViewerConfiguration.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETSourceViewerConfiguration.java
index 6ae34ef..7af9980 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETSourceViewerConfiguration.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/JETSourceViewerConfiguration.java
@@ -1,94 +1,112 @@
package org.eclipse.jet.editor.configuration;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.annotations.JETAnnotationHover;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.formatter.IFormattingStrategy;
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
-import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.IPresentationRepairer;
import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.*;
public class JETSourceViewerConfiguration extends SourceViewerConfiguration {
- private DoubleClickStrategy doubleClickStrategy;
+
+ private DoubleClickStrategy doubleClickStrategy;
private JETTextEditor editor;
- public JETSourceViewerConfiguration(JETTextEditor editor) {
+ public JETSourceViewerConfiguration(JETTextEditor editor) {
this.editor = editor;
- }
-
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return editor.getPartitionScanner().getContentTypes(sourceViewer);
- }
-
- public ITextDoubleClickStrategy getDoubleClickStrategy(
- ISourceViewer sourceViewer,
- String contentType) {
- if (doubleClickStrategy == null)
- doubleClickStrategy = new DoubleClickStrategy();
- return doubleClickStrategy;
- }
-
-
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
- ContentAssistant assistant= new ContentAssistant();
- assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+ }
+
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return editor.getPartitionScanner().getContentTypes();
+ }
+
+ public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
+ if (doubleClickStrategy == null)
+ doubleClickStrategy = new DoubleClickStrategy();
+ return doubleClickStrategy;
+ }
+
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ JETReconcilingStrategy strategy = new JETReconcilingStrategy(sourceViewer, editor);
+ MonoReconciler reconciler = new MonoReconciler(strategy, false);
+ reconciler.setProgressMonitor(new NullProgressMonitor());
+ reconciler.setDelay(500);
+ return reconciler;
+ }
+
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return new JETAnnotationHover();
+ }
- //assistant.setRestoreCompletionProposalSize(getSettings("completion_proposal_size")); //$NON-NLS-1$
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ IAutoEditStrategy strategies[] = editor.getPartitionScanner().getAutoEditStrategies(contentType);
+ if (strategies == null)
+ strategies = super.getAutoEditStrategies(sourceViewer, contentType);
+ return strategies;
+ }
- String[] configuredContentTypes = getConfiguredContentTypes(sourceViewer);
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+ ContentAssistant assistant = new ContentAssistant();
+ assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+ String configuredContentTypes[] = getConfiguredContentTypes(sourceViewer);
for (int i = 0; i < configuredContentTypes.length; i++) {
String contentType = configuredContentTypes[i];
- IContentAssistProcessor processor = editor.getPartitionScanner().getCompletionProcessor(contentType, assistant);
+ org.eclipse.jface.text.contentassist.IContentAssistProcessor processor = editor.getPartitionScanner()
+ .getCompletionProcessor(contentType, assistant);
if (processor != null)
- assistant.setContentAssistProcessor(processor, contentType);
+ assistant.setContentAssistProcessor(processor, contentType);
}
-
- assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
+
+ assistant.setContextInformationPopupOrientation(20);
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
-
assistant.enableAutoInsert(false);
assistant.enableAutoActivation(true);
return assistant;
}
-
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
- String[] configuredContentTypes = getConfiguredContentTypes(sourceViewer);
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ MultiPassContentFormatter formatter = new MultiPassContentFormatter(
+ getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
+ String configuredContentTypes[] = getConfiguredContentTypes(sourceViewer);
for (int i = 0; i < configuredContentTypes.length; i++) {
String contentType = configuredContentTypes[i];
- IFormattingStrategy strategy = editor.getPartitionScanner().getFormattingStrategy(contentType);
- if (strategy != null) {
+ org.eclipse.jface.text.formatter.IFormattingStrategy strategy = editor.getPartitionScanner()
+ .getFormattingStrategy(contentType);
+ if (strategy != null)
if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
formatter.setMasterStrategy(strategy);
else
formatter.setSlaveStrategy(strategy, contentType);
- }
}
+
return formatter;
}
-
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- String[] configuredContentTypes = getConfiguredContentTypes(sourceViewer);
+
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+ String configuredContentTypes[] = getConfiguredContentTypes(sourceViewer);
for (int i = 0; i < configuredContentTypes.length; i++) {
String contentType = configuredContentTypes[i];
- IPresentationDamager damager = editor.getPartitionScanner().getDamager(contentType);
- IPresentationRepairer repairer = editor.getPartitionScanner().getRepairer(contentType);
+ org.eclipse.jface.text.presentation.IPresentationDamager damager = editor.getPartitionScanner().getDamager(
+ contentType);
+ org.eclipse.jface.text.presentation.IPresentationRepairer repairer = editor.getPartitionScanner().getRepairer(
+ contentType);
if (damager != null)
reconciler.setDamager(damager, contentType);
if (repairer != null)
- reconciler.setRepairer(repairer, contentType);
+ reconciler.setRepairer(repairer, contentType);
}
- return reconciler;
- }
+
+ return reconciler;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/AbstractJETTextPartitionConfigurationDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/AbstractJETTextPartitionConfigurationDelegate.java
deleted file mode 100644
index 2f8f058..0000000
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/AbstractJETTextPartitionConfigurationDelegate.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.eclipse.jet.editor.configuration.delegates;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.text.presentation.IPresentationDamager;
-import org.eclipse.jface.text.presentation.IPresentationRepairer;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.ui.IEditorInput;
-
-public abstract class AbstractJETTextPartitionConfigurationDelegate implements IJETTextPartitionConfigurationDelegate {
-
- private Map defaultDamagerRepairers = new HashMap();
-
- public IPresentationDamager getDamager(String contentType) {
- DefaultDamagerRepairer dr = (DefaultDamagerRepairer) defaultDamagerRepairers.get(contentType);
- ITokenScanner tokenScanner = getTokenScanner(contentType);
- if (dr == null && tokenScanner != null) {
- dr = new DefaultDamagerRepairer(tokenScanner);
- }
- return dr;
- }
-
- public IPresentationRepairer getRepairer(String contentType) {
- DefaultDamagerRepairer dr = (DefaultDamagerRepairer) defaultDamagerRepairers.get(contentType);
- ITokenScanner tokenScanner = getTokenScanner(contentType);
- if (dr == null && tokenScanner != null) {
- dr = new DefaultDamagerRepairer(tokenScanner);
- }
- return dr;
- }
-
- public boolean isActiveFor(IEditorInput editorInput) {
- return true;
- }
-
-}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETDefaultTextColorerDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETDefaultTextColorerDelegate.java
new file mode 100644
index 0000000..849cc1b
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETDefaultTextColorerDelegate.java
@@ -0,0 +1,11 @@
+package org.eclipse.jet.editor.configuration.delegates;
+
+import org.eclipse.jet.editor.partition.ITokenScannerProvider;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.swt.graphics.Image;
+
+public interface IJETDefaultTextColorerDelegate extends ITokenScannerProvider {
+ IPredicateRule[] getPartitioningRules();
+ String getName();
+ Image getImage();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETTextPartitionConfigurationDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETTextPartitionConfigurationDelegate.java
deleted file mode 100644
index 63e34e3..0000000
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/IJETTextPartitionConfigurationDelegate.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.eclipse.jet.editor.configuration.delegates;
-
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.formatter.IFormattingStrategy;
-import org.eclipse.jface.text.presentation.IPresentationDamager;
-import org.eclipse.jface.text.presentation.IPresentationRepairer;
-import org.eclipse.jface.text.rules.IPredicateRule;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.IEditorInput;
-
-public interface IJETTextPartitionConfigurationDelegate {
- boolean isActiveFor(IEditorInput editorInput);
-
- String[] getContentTypes(ISourceViewer sourceViewer);
- IPredicateRule[] getPartitioningRules();
-
- IPresentationDamager getDamager(String contentType);
- IPresentationRepairer getRepairer(String contentType);
- IContentAssistProcessor getContentAssistProcessor(String contentType, ContentAssistant assistant);
- IFormattingStrategy getFormattingStrategy(String contentType);
- ITokenScanner getTokenScanner(String contentType);
-}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/JavaContentPartitionConfigurationDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/JavaContentPartitionConfigurationDelegate.java
deleted file mode 100644
index fac5832..0000000
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/JavaContentPartitionConfigurationDelegate.java
+++ /dev/null
@@ -1,249 +0,0 @@
-package org.eclipse.jet.editor.configuration.delegates;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.internal.ui.text.comment.CommentFormattingStrategy;
-import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor;
-import org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy;
-import org.eclipse.jdt.internal.ui.text.javadoc.JavadocCompletionProcessor;
-import org.eclipse.jdt.ui.JavaUI;
-import org.eclipse.jdt.ui.text.IJavaPartitions;
-import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
-import org.eclipse.jet.editor.JETTextEditor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.formatter.IFormattingStrategy;
-import org.eclipse.jface.text.rules.EndOfLineRule;
-import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.text.rules.IPredicateRule;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.MultiLineRule;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jface.text.rules.SingleLineRule;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-public class JavaContentPartitionConfigurationDelegate extends AbstractJETTextPartitionConfigurationDelegate {
- private JETJavaSourceViewerConfiguration javaConfiguration;
-
- public JavaContentPartitionConfigurationDelegate(JETTextEditor editor) {
- javaConfiguration = new JETJavaSourceViewerConfiguration(editor);
- }
-
- public String[] getContentTypes(ISourceViewer sourceViewer) {
- return new String[] {
- IDocument.DEFAULT_CONTENT_TYPE,
- IJavaPartitions.JAVA_DOC,
- IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
- IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
- IJavaPartitions.JAVA_STRING,
- IJavaPartitions.JAVA_CHARACTER
- };
- }
-
- public IPredicateRule[] getPartitioningRules() {
- IToken string= new Token(IJavaPartitions.JAVA_STRING);
- IToken character= new Token(IJavaPartitions.JAVA_CHARACTER);
- IToken javaDoc= new Token(IJavaPartitions.JAVA_DOC);
- IToken multiLineComment= new Token(IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
- IToken singleLineComment= new Token(IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
-
- List rules= new ArrayList();
-
- // Add rule for single line comments.
- rules.add(new EndOfLineRule("//", singleLineComment)); //$NON-NLS-1$
-
- // Add rule for strings.
- rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add rule for character constants.
- rules.add(new SingleLineRule("'", "'", character, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add special case word rule.
- EmptyCommentRule wordRule= new EmptyCommentRule(multiLineComment);
- rules.add(wordRule);
-
- // Add rules for multi-line comments and javadoc.
- rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$
- rules.add(new MultiLineRule("/*", "*/", multiLineComment)); //$NON-NLS-1$ //$NON-NLS-2$
-
- IPredicateRule[] result= new IPredicateRule[rules.size()];
- rules.toArray(result);
- return result;
- }
-
- public ITokenScanner getTokenScanner(String contentType) {
- if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
- return javaConfiguration.getCodeScanner();
- if (IJavaPartitions.JAVA_DOC.equals(contentType))
- return javaConfiguration.getJavaDocScanner();
- if (IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getMultilineCommentScanner();
- if (IJavaPartitions.JAVA_SINGLE_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getSinglelineCommentScanner();
- if (IJavaPartitions.JAVA_STRING.equals(contentType))
- return javaConfiguration.getStringScanner();
- if (IJavaPartitions.JAVA_CHARACTER.equals(contentType))
- return javaConfiguration.getStringScanner();
- return javaConfiguration.getCodeScanner();
- }
-
- public IContentAssistProcessor getContentAssistProcessor(String contentType, ContentAssistant assistant) {
- if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
- return javaConfiguration.getCodeAssistProcessor(assistant);
- if (IJavaPartitions.JAVA_DOC.equals(contentType))
- return javaConfiguration.getJavaDocAssistProcessor(assistant);
- if (IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getMultilineCommentAssistProcessor(assistant);
- if (IJavaPartitions.JAVA_SINGLE_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getSinglelineCommentAssistProcessor(assistant);
- if (IJavaPartitions.JAVA_STRING.equals(contentType))
- return javaConfiguration.getStringAssistProcessor(assistant);
- if (IJavaPartitions.JAVA_CHARACTER.equals(contentType))
- return javaConfiguration.getStringAssistProcessor(assistant);
- return null;
- }
-
- public IFormattingStrategy getFormattingStrategy(String contentType) {
- if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
- return javaConfiguration.getCodeFormattingStrategy();
- if (IJavaPartitions.JAVA_DOC.equals(contentType))
- return javaConfiguration.getJavaDocFormattingStrategy();
- if (IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getMultilineCommentFormattingStrategy();
- if (IJavaPartitions.JAVA_SINGLE_LINE_COMMENT.equals(contentType))
- return javaConfiguration.getSinglelineCommentFormattingStrategy();
- return null;
- }
-
- private class JETJavaSourceViewerConfiguration extends JavaSourceViewerConfiguration {
- public JETJavaSourceViewerConfiguration(JETTextEditor editor) {
- super(JavaUI.getColorManager(), editor.getEditorPreferenceStore(), editor, null);
- }
-
- public IFormattingStrategy getSinglelineCommentFormattingStrategy() {
- IFormattingStrategy strategy = new CommentFormattingStrategy();
- return strategy;
- }
-
- public IFormattingStrategy getMultilineCommentFormattingStrategy() {
- IFormattingStrategy strategy = new CommentFormattingStrategy();
- return strategy;
- }
-
- public IFormattingStrategy getJavaDocFormattingStrategy() {
- IFormattingStrategy strategy = new CommentFormattingStrategy();
- return strategy;
- }
-
- public IFormattingStrategy getCodeFormattingStrategy() {
- IFormattingStrategy strategy = new JavaFormattingStrategy();
- return strategy;
- }
-
- public IContentAssistProcessor getStringAssistProcessor(ContentAssistant assistant) {
- IContentAssistProcessor stringProcessor= new JavaCompletionProcessor(getEditor(), assistant, IJavaPartitions.JAVA_STRING);
- return stringProcessor;
- }
-
- public IContentAssistProcessor getSinglelineCommentAssistProcessor(ContentAssistant assistant) {
- IContentAssistProcessor singleLineProcessor= new JavaCompletionProcessor(getEditor(), assistant, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
- return singleLineProcessor;
- }
-
- public IContentAssistProcessor getMultilineCommentAssistProcessor(ContentAssistant assistant) {
- IContentAssistProcessor multiLineProcessor= new JavaCompletionProcessor(getEditor(), assistant, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
- return multiLineProcessor;
- }
-
- public IContentAssistProcessor getJavaDocAssistProcessor(ContentAssistant assistant) {
- IContentAssistProcessor javadocProcessor= new JavadocCompletionProcessor(getEditor(), assistant);
- return javadocProcessor;
- }
-
- public IContentAssistProcessor getCodeAssistProcessor(ContentAssistant assistant) {
- IContentAssistProcessor javaProcessor= new JavaCompletionProcessor(getEditor(), assistant, IDocument.DEFAULT_CONTENT_TYPE);
- return javaProcessor;
- }
-
- public RuleBasedScanner getCodeScanner() {
- return super.getCodeScanner();
- };
-
- public RuleBasedScanner getMultilineCommentScanner() {
- return super.getMultilineCommentScanner();
- }
-
- public RuleBasedScanner getSinglelineCommentScanner() {
- return super.getSinglelineCommentScanner();
- }
-
- public RuleBasedScanner getStringScanner() {
- return super.getStringScanner();
- }
-
- public RuleBasedScanner getJavaDocScanner() {
- return super.getJavaDocScanner();
- }
- }
-
- /**
- * Detector for empty comments.
- */
- static class EmptyCommentDetector implements IWordDetector {
-
- /*
- * @see IWordDetector#isWordStart
- */
- public boolean isWordStart(char c) {
- return (c == '/');
- }
-
- /*
- * @see IWordDetector#isWordPart
- */
- public boolean isWordPart(char c) {
- return (c == '*' || c == '/');
- }
- }
-
-
- /**
- * Word rule for empty comments.
- */
- static class EmptyCommentRule extends WordRule implements IPredicateRule {
-
- private IToken fSuccessToken;
- /**
- * Constructor for EmptyCommentRule.
- * @param successToken
- */
- public EmptyCommentRule(IToken successToken) {
- super(new EmptyCommentDetector());
- fSuccessToken= successToken;
- addWord("/**/", fSuccessToken); //$NON-NLS-1$
- }
-
- /*
- * @see IPredicateRule#evaluate(ICharacterScanner, boolean)
- */
- public IToken evaluate(ICharacterScanner scanner, boolean resume) {
- return evaluate(scanner);
- }
-
- /*
- * @see IPredicateRule#getSuccessToken()
- */
- public IToken getSuccessToken() {
- return fSuccessToken;
- }
- }
-
-
-
-}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/java/JavaContentPartitionConfigurationDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/java/JavaContentPartitionConfigurationDelegate.java
new file mode 100644
index 0000000..8291231
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/java/JavaContentPartitionConfigurationDelegate.java
@@ -0,0 +1,113 @@
+package org.eclipse.jet.editor.configuration.delegates.java;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jdt.ui.ISharedImages;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.*;
+import org.eclipse.swt.graphics.Image;
+
+public class JavaContentPartitionConfigurationDelegate implements IJETDefaultTextColorerDelegate {
+ private JETJavaSourceViewerConfiguration javaConfiguration;
+
+ public JavaContentPartitionConfigurationDelegate(JETTextEditor editor) {
+ javaConfiguration = new JETJavaSourceViewerConfiguration(editor);
+ }
+
+ public String getName() {
+ return "Java Text Content Colorer";
+ }
+
+ public Image getImage() {
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CUNIT);
+ }
+
+ public IPredicateRule[] getPartitioningRules() {
+ org.eclipse.jface.text.rules.IToken string = new Token("__java_string");
+ org.eclipse.jface.text.rules.IToken character = new Token("__java_character");
+ org.eclipse.jface.text.rules.IToken javaDoc = new Token("__java_javadoc");
+ org.eclipse.jface.text.rules.IToken multiLineComment = new Token("__java_multiline_comment");
+ org.eclipse.jface.text.rules.IToken singleLineComment = new Token("__java_singleline_comment");
+ List rules = new ArrayList();
+ rules.add(new EndOfLineRule("//", singleLineComment));
+ rules.add(new SingleLineRule("\"", "\"", string, '\\'));
+ rules.add(new SingleLineRule("'", "'", character, '\\'));
+ EmptyCommentRule wordRule = new EmptyCommentRule(multiLineComment);
+ rules.add(wordRule);
+ rules.add(new MultiLineRule("/**", "*/", javaDoc));
+ rules.add(new MultiLineRule("/*", "*/", multiLineComment));
+ IPredicateRule result[] = new IPredicateRule[rules.size()];
+ rules.toArray(result);
+ return result;
+ }
+
+ public ITokenScanner getTokenScanner(String contentType) {
+ if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
+ return javaConfiguration.getCodeScanner();
+ if ("__java_javadoc".equals(contentType))
+ return javaConfiguration.getJavaDocScanner();
+ if ("__java_multiline_comment".equals(contentType))
+ return javaConfiguration.getMultilineCommentScanner();
+ if ("__java_singleline_comment".equals(contentType))
+ return javaConfiguration.getSinglelineCommentScanner();
+ if ("__java_string".equals(contentType))
+ return javaConfiguration.getStringScanner();
+ if ("__java_character".equals(contentType))
+ return javaConfiguration.getStringScanner();
+ else
+ return javaConfiguration.getCodeScanner();
+ }
+
+ private class JETJavaSourceViewerConfiguration extends JavaSourceViewerConfiguration {
+ public RuleBasedScanner getCodeScanner() {
+ return super.getCodeScanner();
+ }
+ public RuleBasedScanner getMultilineCommentScanner() {
+ return super.getMultilineCommentScanner();
+ }
+ public RuleBasedScanner getSinglelineCommentScanner() {
+ return super.getSinglelineCommentScanner();
+ }
+ public RuleBasedScanner getStringScanner() {
+ return super.getStringScanner();
+ }
+ public RuleBasedScanner getJavaDocScanner() {
+ return super.getJavaDocScanner();
+ }
+ public JETJavaSourceViewerConfiguration(JETTextEditor editor) {
+ super(JavaUI.getColorManager(), editor.getEditorPreferenceStore(), editor, null);
+ }
+ }
+
+ private class EmptyCommentDetector implements IWordDetector {
+ public boolean isWordStart(char c) {
+ return c == '/';
+ }
+
+ public boolean isWordPart(char c) {
+ return c == '*' || c == '/';
+ }
+ }
+
+ private class EmptyCommentRule extends WordRule implements IPredicateRule {
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ return evaluate(scanner);
+ }
+
+ public IToken getSuccessToken() {
+ return fSuccessToken;
+ }
+
+ private IToken fSuccessToken;
+
+ public EmptyCommentRule(IToken successToken) {
+ super(new EmptyCommentDetector());
+ fSuccessToken = successToken;
+ addWord("/**/", fSuccessToken);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/xml/XMLContentPartitionConfigurationDelegate.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/xml/XMLContentPartitionConfigurationDelegate.java
new file mode 100644
index 0000000..bdb0e23
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/configuration/delegates/xml/XMLContentPartitionConfigurationDelegate.java
@@ -0,0 +1,156 @@
+package org.eclipse.jet.editor.configuration.delegates.xml;
+
+import org.eclipse.jdt.ui.text.IColorManager;
+import org.eclipse.jet.editor.Activator;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+
+public class XMLContentPartitionConfigurationDelegate implements IJETDefaultTextColorerDelegate {
+ public static final String XML_COMMENT = "__xml_comment";
+ public static final String XML_TAG = "__xml_tag";
+
+ private XMLTagScanner tagScanner;
+ private XMLScanner scanner;
+ private XMLScanner commentScanner;
+ private IColorManager colorManager;
+
+ public static interface IXMLColorConstants {
+ RGB XML_COMMENT = new RGB(128, 0, 0);
+ RGB PROC_INSTR = new RGB(128, 128, 128);
+ RGB STRING = new RGB(0, 128, 0);
+ RGB DEFAULT = new RGB(0, 0, 0);
+ RGB TAG = new RGB(0, 0, 128);
+ }
+
+ public class TagRule extends MultiLineRule {
+
+ protected boolean sequenceDetected(ICharacterScanner scanner, char sequence[], boolean eofAllowed) {
+ int c = scanner.read();
+ if (sequence[0] == '<') {
+ if (c == 63) {
+ scanner.unread();
+ return false;
+ }
+ if (c == 33) {
+ scanner.unread();
+ return false;
+ }
+ } else if (sequence[0] == '>')
+ scanner.unread();
+ return super.sequenceDetected(scanner, sequence, eofAllowed);
+ }
+
+ public TagRule(IToken token) {
+ super("<", ">", token);
+ }
+ }
+
+ public class XMLWhitespaceDetector implements IWhitespaceDetector {
+ public boolean isWhitespace(char c) {
+ return c == ' ' || c == '\t' || c == '\n' || c == '\r';
+ }
+
+ public XMLWhitespaceDetector() {
+ super();
+ }
+ }
+
+ public class XMLScanner extends RuleBasedScanner {
+
+ public XMLScanner(IColorManager manager) {
+ super();
+ org.eclipse.jface.text.rules.IToken procInstr = new Token(new TextAttribute(manager
+ .getColor(IXMLColorConstants.PROC_INSTR)));
+ IRule rules[] = new IRule[2];
+ rules[0] = new SingleLineRule("<?", "?>", procInstr);
+ rules[1] = new WhitespaceRule(new XMLWhitespaceDetector());
+ setRules(rules);
+ }
+ }
+
+ public class XMLTagScanner extends RuleBasedScanner {
+
+ public XMLTagScanner(IColorManager manager) {
+ super();
+ org.eclipse.jface.text.rules.IToken string = new Token(new TextAttribute(manager
+ .getColor(IXMLColorConstants.STRING)));
+ IRule rules[] = new IRule[3];
+ rules[0] = new SingleLineRule("\"", "\"", string, '\\');
+ rules[1] = new SingleLineRule("'", "'", string, '\\');
+ rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
+ setRules(rules);
+ }
+ }
+
+ public XMLContentPartitionConfigurationDelegate(JETTextEditor editor) {
+ colorManager = editor.getTokenStyleManager();
+ }
+
+ public String getName() {
+ return "XML Text Content Colorer";
+ }
+
+ public Image getImage() {
+ return Activator.getDefault().getWorkbench().getSharedImages().getImage("IMG_OBJ_FILE");
+ }
+
+ public IPredicateRule[] getPartitioningRules() {
+ org.eclipse.jface.text.rules.IToken xmlComment = new Token(XML_COMMENT);
+ org.eclipse.jface.text.rules.IToken tag = new Token(XML_TAG);
+ IPredicateRule rules[] = new IPredicateRule[2];
+ rules[0] = new MultiLineRule("<!--", "-->", xmlComment);
+ rules[1] = new TagRule(tag);
+ return rules;
+ }
+
+ public ITokenScanner getTokenScanner(String contentType) {
+ if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
+ return getXMLScanner();
+ if (XML_TAG.equals(contentType))
+ return getXMLTagScanner();
+ if (XML_COMMENT.equals(contentType))
+ return getCommentScanner();
+ else
+ return getXMLScanner();
+ }
+
+ protected XMLScanner getCommentScanner() {
+ if (commentScanner == null) {
+ commentScanner = new XMLScanner(colorManager);
+ commentScanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager
+ .getColor(IXMLColorConstants.XML_COMMENT))));
+ }
+ return commentScanner;
+ }
+
+ protected XMLScanner getXMLScanner() {
+ if (scanner == null) {
+ scanner = new XMLScanner(colorManager);
+ scanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.DEFAULT))));
+ }
+ return scanner;
+ }
+
+ protected XMLTagScanner getXMLTagScanner() {
+ if (tagScanner == null) {
+ tagScanner = new XMLTagScanner(colorManager);
+ tagScanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.TAG))));
+ }
+ return tagScanner;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/AbstractXMLTagsBasedAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/AbstractXMLTagsBasedAssistProcessor.java
new file mode 100644
index 0000000..b861461
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/AbstractXMLTagsBasedAssistProcessor.java
@@ -0,0 +1,153 @@
+package org.eclipse.jet.editor.contentassist;
+
+import java.util.*;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.internal.editor.JETDocumentReader;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+
+public abstract class AbstractXMLTagsBasedAssistProcessor extends AbstractJETAssistProcessor {
+
+ private TreeSet keywordSet;
+ private TreeSet innerKeywordSet;
+ private TreeMap innerMap;
+
+ public AbstractXMLTagsBasedAssistProcessor(JETTextEditor editor) {
+ super(editor);
+ keywordSet = new TreeSet();
+ innerKeywordSet = new TreeSet();
+ innerMap = new TreeMap();
+ String tagAttrs[][] = getTagAttributes();
+ for (int i = 0; i < tagAttrs.length; i++)
+ keywordSet.add(tagAttrs[i][0]);
+
+ for (int i = 0; i < tagAttrs.length; i++) {
+ TreeSet innerSet = new TreeSet();
+ for (int j = 1; j < tagAttrs[i].length; j++) {
+ innerSet.add(tagAttrs[i][j]);
+ innerKeywordSet.add(tagAttrs[i][j]);
+ }
+
+ innerMap.put(tagAttrs[i][0], innerSet);
+ }
+
+ }
+
+ public abstract String[] getRootTags();
+
+ public abstract String[][] getTagAttributes();
+
+ public String[] getAllKeywords() {
+ return (String[]) keywordSet.toArray(new String[keywordSet.size()]);
+ }
+
+ public String[] getAllInnerKeywords() {
+ return (String[]) innerKeywordSet.toArray(new String[innerKeywordSet.size()]);
+ }
+
+ public String[] getInnerKeywordsFor(String key) {
+ TreeSet set = (TreeSet) (TreeSet) innerMap.get(key);
+ if (set == null && key.length() == 0)
+ return getRootTags();
+ else
+ return (String[]) set.toArray(new String[set.size()]);
+ }
+
+ private boolean prefixMatches(String prefix, String word) {
+ prefix = prefix.toLowerCase();
+ return word.startsWith(prefix);
+ }
+
+ public String[] getAllWordsWithPrefix(String prefix) {
+ String all[] = getAllKeywords();
+ return getMatched(prefix, all);
+ }
+
+ private String[] getMatched(String prefix, String all[]) {
+ ArrayList matched = new ArrayList(10);
+ for (int i = 0; i < all.length; i++)
+ if (prefixMatches(prefix, all[i]))
+ matched.add(all[i]);
+
+ return (String[]) matched.toArray(new String[matched.size()]);
+ }
+
+ public String[] getTagsWithPrefix(String prefix) {
+ return getMatched(prefix, getRootTags());
+ }
+
+ public String[] getNonTagsKeywordsWithPrefix(String key, String prefix) {
+ return getMatched(prefix, getInnerKeywordsFor(key));
+ }
+
+ protected String[] getAllWords(char c, JETDocumentReader reader) {
+ ArrayList all = new ArrayList(20);
+ char currChar = c;
+ currChar = trimBlanksBackward(reader, currChar);
+ for (boolean done = false; !done;) {
+ Stack stack = new Stack();
+ for (; currChar != '\uFFFF' && !Character.isWhitespace(currChar); currChar = reader.readBackward())
+ stack.push(new Character(currChar));
+
+ String s;
+ for (s = new String(); !stack.empty(); s = (new StringBuilder(String.valueOf(s))).append(
+ ((Character) stack.pop()).toString()).toString())
+ ;
+ int jspPt = s.indexOf("<%@");
+ if (jspPt >= 0) {
+ s = s.substring(jspPt + 3);
+ done = true;
+ }
+ all.add(s);
+ currChar = trimBlanksBackward(reader, currChar);
+ if (currChar == '\uFFFF' || currChar == '@')
+ done = true;
+ }
+
+ return (String[]) all.toArray(new String[all.size()]);
+ }
+
+ private char trimBlanksBackward(JETDocumentReader reader, char currChar) {
+ for (; currChar != '\uFFFF' && Character.isWhitespace(currChar); currChar = reader.readBackward())
+ ;
+ return currChar;
+ }
+
+ protected abstract char getRootTagPrevChar();
+
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ org.eclipse.jface.text.IDocument doc = viewer.getDocument();
+ JETDocumentReader reader = new JETDocumentReader(doc, offset);
+ char c = reader.readBackward();
+ ICompletionProposal result[] = (ICompletionProposal[]) null;
+ String allWords[] = getAllWords(c, reader);
+ if (Character.isSpaceChar(c)) {
+ String nonTagWords[] = getInnerKeywordsFor(allWords[allWords.length - 1]);
+ result = new ICompletionProposal[nonTagWords.length];
+ for (int i = 0; i < nonTagWords.length; i++)
+ result[i] = new CompletionProposal(nonTagWords[i], offset, 0, nonTagWords[i].length());
+
+ } else if (c == getRootTagPrevChar()) {
+ String words[] = getRootTags();
+ result = new ICompletionProposal[words.length];
+ for (int i = 0; i < words.length; i++)
+ result[i] = new CompletionProposal(words[i].substring(allWords[0].length()), offset, 0, words[i].length()
+ - allWords[0].length(), null, words[i], null, null);
+
+ } else if (Character.isLetter(c)) {
+ String words[];
+ if (allWords.length > 1)
+ words = getNonTagsKeywordsWithPrefix(allWords[allWords.length - 1], allWords[0]);
+ else
+ words = getTagsWithPrefix(allWords[0]);
+ result = new ICompletionProposal[words.length];
+ for (int i = 0; i < words.length; i++)
+ result[i] = new CompletionProposal(words[i].substring(allWords[0].length()), offset, 0, words[i].length()
+ - allWords[0].length(), null, words[i], null, null);
+
+ }
+ return result;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETCustomTagAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETCustomTagAssistProcessor.java
index ffb654b..f63ae54 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETCustomTagAssistProcessor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETCustomTagAssistProcessor.java
@@ -1,45 +1,99 @@
package org.eclipse.jet.editor.contentassist;
+import java.util.*;
import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.taglib.*;
import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-public class JETCustomTagAssistProcessor extends AbstractJETAssistProcessor {
+public class JETCustomTagAssistProcessor extends AbstractXMLTagsBasedAssistProcessor {
+
+ private String rootTags[];
+ private String tagAttributes[][];
public JETCustomTagAssistProcessor(JETTextEditor editor) {
super(editor);
}
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
- return null;
+ public String[] getRootTags() {
+ if (rootTags == null) {
+ Collection tagNames = new ArrayList();
+ String tagLibIds[] = TagLibraryManager.getInstance().getKnownLibraryIds();
+ for (int i = 0; i < tagLibIds.length; i++) {
+ String id = tagLibIds[i];
+ TagLibrary tagLib = TagLibraryManager.getInstance().getTagLibrary(id, true);
+ String names[] = tagLib.getTagNames();
+ for (int j = 0; j < names.length; j++) {
+ String name = names[j];
+ tagNames.add((new StringBuilder(String.valueOf(tagLib.getDefaultPrefix()))).append(":").append(name)
+ .toString());
+ }
+
+ }
+
+ rootTags = new String[tagNames.size()];
+ tagNames.toArray(rootTags);
+ }
+ return rootTags;
+ }
+
+ public String[][] getTagAttributes() {
+ if (tagAttributes == null) {
+ Map tagAttributesMap = new HashMap();
+ String tagLibIds[] = TagLibraryManager.getInstance().getKnownLibraryIds();
+ for (int i = 0; i < tagLibIds.length; i++) {
+ String id = tagLibIds[i];
+ TagLibrary tagLib = TagLibraryManager.getInstance().getTagLibrary(id, true);
+ String names[] = tagLib.getTagNames();
+ for (int j = 0; j < names.length; j++) {
+ String name = names[j];
+ TagDefinition tagDef = tagLib.getTagDefinition(name);
+ Collection tagAttributeDefinitions = tagDef.getAttributeDefinitions();
+ String attributeNames[] = new String[tagAttributeDefinitions.size() + 1];
+ attributeNames[0] = (new StringBuilder(String.valueOf(tagLib.getDefaultPrefix()))).append(":").append(name)
+ .toString();
+ int cpt = 1;
+ for (Iterator iterator = tagAttributeDefinitions.iterator(); iterator.hasNext();) {
+ TagAttributeDefinition tagAttributeDef = (TagAttributeDefinition) iterator.next();
+ attributeNames[cpt++] = tagAttributeDef.getName();
+ }
+
+ tagAttributesMap.put((new StringBuilder(String.valueOf(tagLib.getDefaultPrefix()))).append(":").append(name)
+ .toString(), attributeNames);
+ }
+
+ }
+
+ int cpt = 0;
+ tagAttributes = new String[tagAttributesMap.size()][];
+ for (Iterator iterator = tagAttributesMap.keySet().iterator(); iterator.hasNext();) {
+ String tagName = (String) iterator.next();
+ String attributeNames[] = (String[]) tagAttributesMap.get(tagName);
+ tagAttributes[cpt++] = attributeNames;
+ }
+
+ }
+ return tagAttributes;
+ }
+
+ protected char getRootTagPrevChar() {
+ return '<';
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
public char[] getCompletionProposalAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
return null;
}
-
- public String getErrorMessage() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETDirectiveAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETDirectiveAssistProcessor.java
index 642cbf7..e439464 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETDirectiveAssistProcessor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETDirectiveAssistProcessor.java
@@ -2,44 +2,44 @@ package org.eclipse.jet.editor.contentassist;
import org.eclipse.jet.editor.JETTextEditor;
import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-public class JETDirectiveAssistProcessor extends AbstractJETAssistProcessor {
+public class JETDirectiveAssistProcessor extends AbstractXMLTagsBasedAssistProcessor {
+ private static String rootTags[] = { "jet", "taglib", "include", "start", "end" };
+ private static String tagAttributes[][] = { { "jet", "package", "class", "imports", "startTag", "endTag" },
+ { "taglib", "id", "prefix" }, { "include", "file" }, { "start", "id" }, { "end", "id" } };
public JETDirectiveAssistProcessor(JETTextEditor editor) {
super(editor);
}
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
- return null;
+ public String[] getRootTags() {
+ return rootTags;
+ }
+
+ public String[][] getTagAttributes() {
+ return tagAttributes;
+ }
+
+ protected char getRootTagPrevChar() {
+ return '@';
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
public char[] getCompletionProposalAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getErrorMessage() {
- // TODO Auto-generated method stub
return null;
}
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaDeclarationAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaDeclarationAssistProcessor.java
index 8abf132..0811aa1 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaDeclarationAssistProcessor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaDeclarationAssistProcessor.java
@@ -1,43 +1,39 @@
package org.eclipse.jet.editor.contentassist;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.ui.PreferenceConstants;
-import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
-import org.eclipse.jet.compiler.JET2CompilationUnit;
import org.eclipse.jet.compiler.JET2Declaration;
-import org.eclipse.jet.editor.JETEditorHelper;
import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.internal.editor.JETEditorHelper;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jface.text.contentassist.*;
public class JETJavaDeclarationAssistProcessor extends AbstractJETAssistProcessor {
- private char[] completionProposalAutoActivationCharacters;
+ private char completionProposalAutoActivationCharacters[];
+
public JETJavaDeclarationAssistProcessor(JETTextEditor editor) {
super(editor);
- completionProposalAutoActivationCharacters = editor.getEditorPreferenceStore().getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA).toCharArray();
+ completionProposalAutoActivationCharacters = editor.getEditorPreferenceStore().getString(
+ "content_assist_autoactivation_triggers_java").toCharArray();
}
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- JET2CompilationUnit cu = editor.requestCompilationUnit();
- JET2Declaration declaration = (JET2Declaration) JETEditorHelper.getASTElementAt(cu, offset);
-
- int jetStart = declaration.getStart() + 3; // 3 = "<%!" length
-
- IJavaProject javaProject = editor.getJETJavaProject();
- if (javaProject != null && javaProject.isOpen()) {
+ org.eclipse.jet.compiler.JET2CompilationUnit cu = editor.requestCompilationUnit();
+ JET2Declaration declaration = (JET2Declaration) editor.getASTElement(offset);
+ int jetStart = declaration.getStart() + 3;
+ org.eclipse.jdt.core.IJavaProject javaProject = editor.getJETJavaProject();
+ if (javaProject != null) {
int javaOffset = offset - jetStart;
String javaContent = declaration.getJavaContent();
- IJavaCompletionProposal[] javaCompletionProposals = JETEditorHelper.getJavaCompletionProposal(javaProject, cu, javaContent, viewer, javaOffset);
+ org.eclipse.jdt.ui.text.java.IJavaCompletionProposal javaCompletionProposals[] = JETEditorHelper
+ .getJavaCompletionProposal(javaProject, cu, javaContent, viewer, javaOffset);
JETEditorHelper.adjustResults(javaCompletionProposals, offset);
return javaCompletionProposals;
+ } else {
+ return null;
}
- return null;
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
@@ -46,18 +42,14 @@ public class JETJavaDeclarationAssistProcessor extends AbstractJETAssistProcesso
}
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
return null;
}
public String getErrorMessage() {
- // TODO Auto-generated method stub
return null;
}
-
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaExpressionAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaExpressionAssistProcessor.java
index e91cdb4..36641c0 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaExpressionAssistProcessor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaExpressionAssistProcessor.java
@@ -1,81 +1,56 @@
package org.eclipse.jet.editor.contentassist;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.ui.PreferenceConstants;
-import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
-import org.eclipse.jet.compiler.JET2CompilationUnit;
import org.eclipse.jet.compiler.JET2Expression;
-import org.eclipse.jet.editor.JETEditorHelper;
import org.eclipse.jet.editor.JETTextEditor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jet.internal.editor.JETEditorHelper;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.contentassist.*;
public class JETJavaExpressionAssistProcessor extends AbstractJETAssistProcessor {
-
- private char[] completionProposalAutoActivationCharacters;
+ private char completionProposalAutoActivationCharacters[];
public JETJavaExpressionAssistProcessor(JETTextEditor editor) {
super(editor);
completionProposalAutoActivationCharacters = editor.getEditorPreferenceStore().getString(
- PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA).toCharArray();
+ "content_assist_autoactivation_triggers_java").toCharArray();
}
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- JET2CompilationUnit cu = editor.requestCompilationUnit();
- JET2Expression expression = (JET2Expression) JETEditorHelper.getASTElementAt(cu, offset);
-
- int jetStart = expression.getStart();// + 3; // 3 = "<%=" length
- // Look for the start of the first non null character
+ org.eclipse.jet.compiler.JET2CompilationUnit cu = editor.requestCompilationUnit();
+ JET2Expression expression = (JET2Expression) editor.getASTElement(offset);
+ int jetStart = expression.getStart();
try {
- while (viewer.getDocument().getChar(jetStart) == '<' ||
- viewer.getDocument().getChar(jetStart) == '%' ||
- viewer.getDocument().getChar(jetStart) == '=' ||
- viewer.getDocument().getChar(jetStart) == ' ' ||
- viewer.getDocument().getChar(jetStart) == '\t' ||
- viewer.getDocument().getChar(jetStart) == '\r' ||
- viewer.getDocument().getChar(jetStart) == '\n')
+ while (viewer.getDocument().getChar(jetStart) == '<' || viewer.getDocument().getChar(jetStart) == '%'
+ || viewer.getDocument().getChar(jetStart) == '=' || viewer.getDocument().getChar(jetStart) == ' '
+ || viewer.getDocument().getChar(jetStart) == '\t' || viewer.getDocument().getChar(jetStart) == '\r'
+ || viewer.getDocument().getChar(jetStart) == '\n')
jetStart++;
} catch (BadLocationException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
-// try {
-// System.out.println(" JET Text at offset : " + viewer.getDocument().get(offset, 50));
-// } catch (BadLocationException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// Map mappedPositions = new HashMap();
-// String javaSource = JETEditorHelper.computeJavaSource(cu, mappedPositions);
-
- IJavaProject javaProject = editor.getJETJavaProject();
- if (javaProject != null && javaProject.isOpen()) {
+ org.eclipse.jdt.core.IJavaProject javaProject = editor.getJETJavaProject();
+ if (javaProject != null) {
String declarationsSource = JETEditorHelper.getDeclarationsSourceCode(cu);
- String bodyMethodDecl = "public void generate(final JET2Context context, JET2Writer out) {\r\n" ;
+ String bodyMethodDecl = "public void generate(final JET2Context context, JET2Writer out) {\r\n";
String previousJavaBodyContent = JETEditorHelper.getPreviousGeneratedJavaSource(javaProject, cu, expression);
String writeStr = "out.write(";
- String expBody = "out.write(" + expression.getJavaContent().trim() + ");";
-
- String javaContent = declarationsSource + bodyMethodDecl + previousJavaBodyContent + expBody;
- int javaOffset = (offset - jetStart) + declarationsSource.length() + bodyMethodDecl.length() + previousJavaBodyContent.length() + writeStr.length();
-
- //System.out.println(" Java Text at offset : " + javaContent.substring(javaOffset, javaOffset + 50));
-
- IJavaCompletionProposal[] javaCompletionProposals = JETEditorHelper.getJavaCompletionProposal(javaProject, cu,
- javaContent, viewer, javaOffset);
+ String expBody = (new StringBuilder(String.valueOf(writeStr))).append(expression.getJavaContent().trim()).append(
+ ");").toString();
+ String javaContent = (new StringBuilder(String.valueOf(declarationsSource))).append(bodyMethodDecl).append(
+ previousJavaBodyContent).append(expBody).toString();
+ int javaOffset = (offset - jetStart) + declarationsSource.length() + bodyMethodDecl.length()
+ + previousJavaBodyContent.length() + writeStr.length();
+ org.eclipse.jdt.ui.text.java.IJavaCompletionProposal javaCompletionProposals[] = JETEditorHelper
+ .getJavaCompletionProposal(javaProject, cu, javaContent, viewer, javaOffset);
JETEditorHelper.adjustResults(javaCompletionProposals, offset);
return javaCompletionProposals;
+ } else {
+ return null;
}
- return null;
}
-
-
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
@@ -84,18 +59,14 @@ public class JETJavaExpressionAssistProcessor extends AbstractJETAssistProcessor
}
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
return null;
}
public String getErrorMessage() {
- // TODO Auto-generated method stub
return null;
}
-
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaScriptletAssistProcessor.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaScriptletAssistProcessor.java
index fee9b38..465572a 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaScriptletAssistProcessor.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/contentassist/JETJavaScriptletAssistProcessor.java
@@ -1,78 +1,53 @@
package org.eclipse.jet.editor.contentassist;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.ui.PreferenceConstants;
-import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
-import org.eclipse.jet.compiler.JET2CompilationUnit;
import org.eclipse.jet.compiler.JET2Scriptlet;
-import org.eclipse.jet.editor.JETEditorHelper;
import org.eclipse.jet.editor.JETTextEditor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jet.internal.editor.JETEditorHelper;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.contentassist.*;
public class JETJavaScriptletAssistProcessor extends AbstractJETAssistProcessor {
-
- private char[] completionProposalAutoActivationCharacters;
+ private char completionProposalAutoActivationCharacters[];
public JETJavaScriptletAssistProcessor(JETTextEditor editor) {
super(editor);
completionProposalAutoActivationCharacters = editor.getEditorPreferenceStore().getString(
- PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA).toCharArray();
+ "content_assist_autoactivation_triggers_java").toCharArray();
}
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- JET2CompilationUnit cu = editor.requestCompilationUnit();
- JET2Scriptlet scriptlet = (JET2Scriptlet) JETEditorHelper.getASTElementAt(cu, offset);
-
- int jetStart = scriptlet.getStart();// + 2; // 2 = "<%" length
- // Look for the start of the first non null character
+ org.eclipse.jet.compiler.JET2CompilationUnit cu = editor.requestCompilationUnit();
+ JET2Scriptlet scriptlet = (JET2Scriptlet) editor.getASTElement(offset);
+ int jetStart = scriptlet.getStart();
try {
- while (viewer.getDocument().getChar(jetStart) == '<' ||
- viewer.getDocument().getChar(jetStart) == '%' ||
- viewer.getDocument().getChar(jetStart) == ' ' ||
- viewer.getDocument().getChar(jetStart) == '\t' ||
- viewer.getDocument().getChar(jetStart) == '\r' ||
- viewer.getDocument().getChar(jetStart) == '\n')
+ while (viewer.getDocument().getChar(jetStart) == '<' || viewer.getDocument().getChar(jetStart) == '%'
+ || viewer.getDocument().getChar(jetStart) == ' ' || viewer.getDocument().getChar(jetStart) == '\t'
+ || viewer.getDocument().getChar(jetStart) == '\r' || viewer.getDocument().getChar(jetStart) == '\n')
jetStart++;
} catch (BadLocationException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
-// try {
-// System.out.println(" JET Text at offset : " + viewer.getDocument().get(offset, 50));
-// } catch (BadLocationException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// Map mappedPositions = new HashMap();
-// String javaSource = JETEditorHelper.computeJavaSource(cu, mappedPositions);
-
- IJavaProject javaProject = editor.getJETJavaProject();
- if (javaProject != null && javaProject.isOpen()) {
+ org.eclipse.jdt.core.IJavaProject javaProject = editor.getJETJavaProject();
+ if (javaProject != null) {
String declarationsSource = JETEditorHelper.getDeclarationsSourceCode(cu);
- String bodyMethodDecl = "public void generate(final JET2Context context, JET2Writer out) {\r\n" ;
+ String bodyMethodDecl = "public void generate(final JET2Context context, JET2Writer out) {\r\n";
String previousJavaBodyContent = JETEditorHelper.getPreviousGeneratedJavaSource(javaProject, cu, scriptlet);
-
String scriptletBody = scriptlet.getJavaContent().trim();
-
- String javaContent = declarationsSource + bodyMethodDecl + previousJavaBodyContent + scriptletBody;
- int javaOffset = (offset - jetStart) + declarationsSource.length() + bodyMethodDecl.length() + previousJavaBodyContent.length();
-
- //System.out.println(" Java Text at offset : " + javaContent.substring(javaOffset, javaOffset + 50));
-
- IJavaCompletionProposal[] javaCompletionProposals = JETEditorHelper.getJavaCompletionProposal(javaProject, cu,
- javaContent, viewer, javaOffset);
+ String javaContent = (new StringBuilder(String.valueOf(declarationsSource))).append(bodyMethodDecl).append(
+ previousJavaBodyContent).append(scriptletBody).toString();
+ int javaOffset = (offset - jetStart) + declarationsSource.length() + bodyMethodDecl.length()
+ + previousJavaBodyContent.length();
+ org.eclipse.jdt.ui.text.java.IJavaCompletionProposal javaCompletionProposals[] = JETEditorHelper
+ .getJavaCompletionProposal(javaProject, cu, javaContent, viewer, javaOffset);
JETEditorHelper.adjustResults(javaCompletionProposals, offset);
return javaCompletionProposals;
+ } else {
+ return null;
}
- return null;
}
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
@@ -81,18 +56,14 @@ public class JETJavaScriptletAssistProcessor extends AbstractJETAssistProcessor
}
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
return null;
}
public String getErrorMessage() {
- // TODO Auto-generated method stub
return null;
}
-
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/gen/JETEditorJET2JavaGenerator.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/gen/JETEditorJET2JavaGenerator.java
new file mode 100644
index 0000000..9199205
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/gen/JETEditorJET2JavaGenerator.java
@@ -0,0 +1,115 @@
+package org.eclipse.jet.editor.gen;
+
+import java.util.*;
+import org.eclipse.jet.*;
+import org.eclipse.jet.compiler.*;
+import org.eclipse.jet.taglib.*;
+import org.eclipse.jet.transform.TransformContextExtender;
+import org.eclipse.jface.text.Position;
+
+public class JETEditorJET2JavaGenerator implements JET2Template {
+
+ private XMLElement[] getAllXMLTags(JET2CompilationUnit cu) {
+ final List result = new ArrayList();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(XMLBodyElement element) {
+ result.add(element);
+ }
+ public void visit(XMLEmptyElement element) {
+ result.add(element);
+ }
+ });
+ return (XMLElement[]) result.toArray(new XMLElement[result.size()]);
+ }
+
+ private JET2Declaration[] getAllJavaDeclarations(JET2CompilationUnit cu) {
+ final List result = new ArrayList();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(JET2Declaration declaration) {
+ result.add(declaration);
+ }
+ });
+ return (JET2Declaration[]) result.toArray(new JET2Declaration[result.size()]);
+ }
+
+ private void adjustGeneratedBodyPositions(Map mappingPositions, int generatedBodyOffsetStart) {
+ for (Iterator iterator = mappingPositions.keySet().iterator(); iterator.hasNext();) {
+ Object element = iterator.next();
+ if (!(element instanceof JET2Declaration)) {
+ Position position = (Position) mappingPositions.get(element);
+ position.offset += generatedBodyOffsetStart;
+ }
+ }
+
+ }
+
+ public JETEditorJET2JavaGenerator() {
+ }
+
+ public void generate(JET2Context context, JET2Writer out) {
+ TagInfo _jettd_c_include_100_4 = new TagInfo("c:include", 100, 4, new String[] { "template" },
+ new String[] { "templates/tagDataDeclarations.jet" });
+ JET2CompilationUnit cu = (JET2CompilationUnit) context.getVariable("cu");
+ JET2Declaration allMemberDeclarations[] = getAllJavaDeclarations(cu);
+ XMLElement allXMLElements[] = getAllXMLTags(cu);
+ TagLibraryReference tlRefs[] = cu.getTagLibraryReferences();
+ Map generatedBodyMappingPositions = new HashMap();
+ Map mappingPositions = (Map) context.getVariable("org.eclipse.jet.storeJavaMappingPositions");
+ org.eclipse.jet.internal.editor.JETEditorHelper.JETEditorMethodBodyCreator generatedBody = new org.eclipse.jet.internal.editor.JETEditorHelper.JETEditorMethodBodyCreator(
+ TransformContextExtender.getInstance(context).getLoader(), generatedBodyMappingPositions);
+ cu.accept(generatedBody);
+ out.write("package ");
+ out.write(cu.getOutputJavaPackage());
+ out
+ .write(";\r\n\r\nimport org.eclipse.jet.JET2Context;\r\nimport org.eclipse.jet.JET2Template;\r\nimport org.eclipse.jet.JET2Writer;\r\n");
+ if (allXMLElements.length > 0)
+ out.write("import org.eclipse.jet.taglib.RuntimeTagElement;\r\nimport org.eclipse.jet.taglib.TagInfo;\r\n");
+ for (Iterator i = cu.getImports().iterator(); i.hasNext(); out.write(";\r\n")) {
+ String importName = (String) i.next();
+ out.write("import ");
+ out.write(importName);
+ }
+
+ out.write("\r\npublic class ");
+ out.write(cu.getOutputJavaClassName());
+ out.write(" implements JET2Template {\r\n");
+ if (allXMLElements.length > 0) {
+ for (int i = 0; i < tlRefs.length; i++) {
+ out.write(" public static final String _jetns_");
+ out.write(tlRefs[i].getPrefix());
+ out.write(" = \"");
+ out.write(tlRefs[i].getTagLibraryId());
+ out.write("\"; //$NON-NLS-1$\r\n");
+ }
+
+ }
+ for (int i = 0; i < allMemberDeclarations.length; i++) {
+ Position position = new Position(out.getLength());
+ mappingPositions.put(allMemberDeclarations[i], position);
+ out.write(allMemberDeclarations[i].getJavaContent());
+ out.write("\r\n");
+ position.setLength(out.getLength() - position.offset);
+ }
+
+ out.write("\r\n\tpublic ");
+ out.write(cu.getOutputJavaClassName());
+ out
+ .write("() {\r\n\t\tsuper();\r\n\t}\r\n\r\n\tpublic void generate(final JET2Context context, JET2Writer out) {\r\n");
+ for (int i = 0; i < allXMLElements.length; i++) {
+ context.setVariable("element", allXMLElements[i]);
+ RuntimeTagElement _jettag_c_include_100_4 = context.getTagFactory().createRuntimeTag(
+ "org.eclipse.jet.controlTags", "include", "c:include", _jettd_c_include_100_4);
+ _jettag_c_include_100_4.setRuntimeParent(null);
+ _jettag_c_include_100_4.setTagInfo(_jettd_c_include_100_4);
+ _jettag_c_include_100_4.doStart(context, out);
+ _jettag_c_include_100_4.doEnd();
+ }
+
+ adjustGeneratedBodyPositions(generatedBodyMappingPositions, out.getLength());
+ mappingPositions.putAll(generatedBodyMappingPositions);
+ out.write(generatedBody.getBuffer());
+ out.write("\r\n\t}\r\n\r\n}\r\n");
+ }
+
+ public static final String _jetns_c = "org.eclipse.jet.controlTags";
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineContentProvider.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineContentProvider.java
index a21a742..af625d9 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineContentProvider.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineContentProvider.java
@@ -9,61 +9,66 @@ import org.eclipse.jet.compiler.JET2ASTElement;
import org.eclipse.jet.compiler.JET2CompilationUnit;
import org.eclipse.jet.compiler.TextElement;
import org.eclipse.jet.compiler.XMLBodyElement;
+import org.eclipse.jet.editor.JETTextEditor;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
public class JETOutlineContentProvider implements ITreeContentProvider {
-
private ImportsContainerInput importContainerInput;
private CompilationUnitContainerInput astContainerInput;
private OutputPackageInput outputPackageInput;
-
private JET2CompilationUnit cu;
private OutputClassInput outputClassInput;
+ private JETTextEditor editor;
- public void dispose() {
- // TODO Auto-generated method stub
- }
-
public class OutputClassInput {
private JET2CompilationUnit compilationUnit;
+
public OutputClassInput(JET2CompilationUnit cu) {
this.compilationUnit = cu;
}
+
public JET2CompilationUnit getCompilationUnit() {
return compilationUnit;
}
}
-
+
public class OutputPackageInput {
private JET2CompilationUnit compilationUnit;
+
public OutputPackageInput(JET2CompilationUnit cu) {
this.compilationUnit = cu;
}
+
public JET2CompilationUnit getCompilationUnit() {
return compilationUnit;
}
}
-
+
public class ImportInput {
private ImportsContainerInput container;
+
private String imp;
-
+
public ImportInput(ImportsContainerInput container, String imp) {
this.container = container;
this.imp = imp;
}
+
public ImportsContainerInput getImportsContainerInput() {
return container;
}
+
public String toString() {
return imp;
}
}
-
+
public class ImportsContainerInput {
private JET2CompilationUnit compilationUnit;
- private Collection importInputs;
+
+ private Collection importInputs;
+
public ImportsContainerInput(JET2CompilationUnit cu) {
this.compilationUnit = cu;
importInputs = new ArrayList();
@@ -72,17 +77,21 @@ public class JETOutlineContentProvider implements ITreeContentProvider {
importInputs.add(new ImportInput(this, imp));
}
}
+
public JET2CompilationUnit getCompilationUnit() {
return compilationUnit;
}
+
public Collection getImportImputs() {
return importInputs;
}
}
-
+
public class CompilationUnitContainerInput {
- private Collection bodyElements;
+ private Collection bodyElements;
+
private JET2CompilationUnit compilationUnit;
+
public CompilationUnitContainerInput(JET2CompilationUnit cu) {
this.bodyElements = new ArrayList();
this.compilationUnit = cu;
@@ -93,30 +102,41 @@ public class JETOutlineContentProvider implements ITreeContentProvider {
bodyElements.add(elt);
}
}
+
public Collection getFilteredASTElements() {
return bodyElements;
}
+
public JET2CompilationUnit getCompilationUnit() {
return compilationUnit;
}
+
private boolean isFiltered(JET2ASTElement elt) {
if (elt instanceof TextElement) {
- String text = new String(((TextElement)elt).getText());
+ String text = new String(((TextElement) elt).getText());
text = text.replace('\r', ' ');
text = text.replace('\n', ' ');
text = text.replace('\t', ' ');
text = text.trim();
return text.length() == 0;
}
-// if (elt instanceof JET2Directive) {
-// JET2Directive directive = (JET2Directive) elt;
-// if ("import".equals(directive.getName()) ||
-// "package".equals(directive.getName()))
-// return true;
-// }
+ // if (elt instanceof JET2Directive) {
+ // JET2Directive directive = (JET2Directive) elt;
+ // if ("import".equals(directive.getName()) ||
+ // "package".equals(directive.getName()))
+ // return true;
+ // }
return false;
}
}
+
+ public JETOutlineContentProvider(JETTextEditor editor) {
+ this.editor = editor;
+ }
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+ }
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
cu = (JET2CompilationUnit) newInput;
@@ -136,7 +156,7 @@ public class JETOutlineContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
if (parentElement == outputPackageInput) {
- return new Object[] {outputClassInput = new OutputClassInput(cu)};
+ return new Object[] { outputClassInput = new OutputClassInput(cu) };
}
if (parentElement == importContainerInput) {
return importContainerInput.getImportImputs().toArray();
@@ -152,18 +172,16 @@ public class JETOutlineContentProvider implements ITreeContentProvider {
}
public Object getParent(Object element) {
- if (element == outputPackageInput ||
- element == importContainerInput ||
- element == astContainerInput)
+ if (element == outputPackageInput || element == importContainerInput || element == astContainerInput)
return cu;
if (element == outputClassInput)
return outputPackageInput;
if (element instanceof ImportInput)
- return ((ImportInput)element).getImportsContainerInput();
+ return ((ImportInput) element).getImportsContainerInput();
if (element instanceof JET2ASTElement) {
- if (((JET2ASTElement)element).getParent() == cu)
+ if (((JET2ASTElement) element).getParent() == cu)
return astContainerInput;
- return ((JET2ASTElement)element).getParent();
+ return ((JET2ASTElement) element).getParent();
}
if (importContainerInput.getCompilationUnit().getImports().contains(element))
return importContainerInput;
@@ -171,10 +189,7 @@ public class JETOutlineContentProvider implements ITreeContentProvider {
}
public boolean hasChildren(Object element) {
- return (element instanceof XMLBodyElement) ||
- (element == outputPackageInput) ||
- (element == importContainerInput) ||
- (element == astContainerInput);
+ return (element instanceof XMLBodyElement) || (element == outputPackageInput) || (element == importContainerInput)
+ || (element == astContainerInput);
}
-
}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineLabelProvider.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineLabelProvider.java
index 3adc7eb..8bfb91d 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineLabelProvider.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlineLabelProvider.java
@@ -3,8 +3,11 @@ package org.eclipse.jet.editor.outline;
import java.util.Iterator;
import java.util.Map;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jet.compiler.Comment;
+import org.eclipse.jet.compiler.CompileOptionsManager;
+import org.eclipse.jet.compiler.JET2Compiler;
import org.eclipse.jet.compiler.JET2Declaration;
import org.eclipse.jet.compiler.JET2Directive;
import org.eclipse.jet.compiler.JET2Expression;
@@ -12,13 +15,21 @@ import org.eclipse.jet.compiler.JET2Scriptlet;
import org.eclipse.jet.compiler.TextElement;
import org.eclipse.jet.compiler.XMLElement;
import org.eclipse.jet.editor.Activator;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.internal.editor.JETEditorHelper;
import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ISharedImages;
public class JETOutlineLabelProvider extends LabelProvider {
-
+ private JETTextEditor editor;
+
+ public JETOutlineLabelProvider(JETTextEditor editor) {
+ this.editor = editor;
+ }
+
public Image getImage(Object element) {
if (element instanceof Comment) {
return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_JAVADOCTAG);
@@ -49,34 +60,57 @@ public class JETOutlineLabelProvider extends LabelProvider {
}
return super.getImage(element);
}
-
+
public String getText(Object element) {
- if (element instanceof Comment) {
- return getShortText(((Comment)element).getCommentText());
- } else if (element instanceof JET2Declaration) {
- return "<%!" + getShortText(((JET2Declaration)element).getJavaContent()) + "%>";
- } else if (element instanceof JET2Expression) {
- return "<%=" + getShortText(((JET2Expression)element).getJavaContent()) + "%>";
- } else if (element instanceof JET2Scriptlet) {
- return "<%" + getShortText(((JET2Scriptlet)element).getJavaContent()) + "%>";
- } else if (element instanceof JET2Directive) {
- return "<%@" + ((JET2Directive)element).getName() + " " + getAttributesText(((JET2Directive)element)) + "%>";
- } else if (element instanceof TextElement) {
- return getShortText(new String(((TextElement)element).getText()));
- } else if (element instanceof XMLElement) {
- return "<" + ((XMLElement)element).getName() + " " + getAttributesText(((XMLElement)element)) + ">";
- } else if (element instanceof JETOutlineContentProvider.ImportsContainerInput) {
+ if (element instanceof Comment)
+ return getShortText(((Comment) element).getCommentText());
+ if (element instanceof JET2Declaration)
+ return (new StringBuilder("<%!")).append(getShortText(((JET2Declaration) element).getJavaContent())).append("%>")
+ .toString();
+ if (element instanceof JET2Expression)
+ return (new StringBuilder("<%=")).append(getShortText(((JET2Expression) element).getJavaContent())).append("%>")
+ .toString();
+ if (element instanceof JET2Scriptlet)
+ return (new StringBuilder("<%")).append(getShortText(((JET2Scriptlet) element).getJavaContent())).append("%>")
+ .toString();
+ if (element instanceof JET2Directive)
+ return (new StringBuilder("<%@")).append(((JET2Directive) element).getName()).append(" ").append(
+ getAttributesText((JET2Directive) element)).append("%>").toString();
+ if (element instanceof TextElement)
+ return getShortText(new String(((TextElement) element).getText()));
+ if (element instanceof XMLElement)
+ return (new StringBuilder("<")).append(((XMLElement) element).getName()).append(" ").append(
+ getAttributesText((XMLElement) element)).append(">").toString();
+ if (element instanceof JETOutlineContentProvider.ImportsContainerInput)
return "import declarations";
- } else if (element instanceof JETOutlineContentProvider.CompilationUnitContainerInput) {
+ if (element instanceof JETOutlineContentProvider.CompilationUnitContainerInput)
return "Template AST";
- } else if (element instanceof JETOutlineContentProvider.OutputPackageInput) {
- return ((JETOutlineContentProvider.OutputPackageInput)element).getCompilationUnit().getOutputJavaPackage();
- } else if (element instanceof JETOutlineContentProvider.OutputClassInput) {
- return ((JETOutlineContentProvider.OutputClassInput)element).getCompilationUnit().getOutputJavaClassName();
- } else if (element instanceof TagLibraryReference) {
- return ((TagLibraryReference)element).getTagLibraryId();
+ if (element instanceof JETOutlineContentProvider.OutputPackageInput) {
+ String packageName = ((JETOutlineContentProvider.OutputPackageInput) element).getCompilationUnit()
+ .getOutputJavaPackage();
+ if (packageName == null) {
+ Map options = CompileOptionsManager.getOptions(editor.getJETJavaProject().getProject());
+ if (options.isEmpty())
+ options = JET2Compiler.getDefaultCompilerOptions();
+ packageName = (String) options.get("org.eclipse.jet.compiledTemplatePackage");
+ }
+ return packageName;
+ }
+ if (element instanceof JETOutlineContentProvider.OutputClassInput) {
+ String className = ((JETOutlineContentProvider.OutputClassInput) element).getCompilationUnit()
+ .getOutputJavaClassName();
+ if (className == null && (editor.getEditorInput() instanceof IFileEditorInput)) {
+ IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
+ String inputName = file.getFullPath().removeFileExtension().lastSegment();
+ String baseClassName = JETEditorHelper.makeJavaClassName(inputName);
+ className = baseClassName;
+ }
+ return className;
}
- return super.getText(element);
+ if (element instanceof TagLibraryReference)
+ return ((TagLibraryReference) element).getTagLibraryId();
+ else
+ return super.getText(element);
}
private String getShortText(String text) {
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlinePage.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlinePage.java
index b2286da..b27c66e 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlinePage.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/outline/JETOutlinePage.java
@@ -12,46 +12,38 @@ import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
public class JETOutlinePage extends ContentOutlinePage implements IAdaptable , IPostSelectionProvider {
private JETTextEditor editor;
private TreeViewer contentOutlineViewer;
- public JETOutlinePage(JETTextEditor editor) {
- this.editor = editor;
+ public JETOutlinePage(JETTextEditor editor)
+ {
+ this.editor = editor;
}
- public void createControl(Composite parent) {
- // TODO Auto-generated method stub
- super.createControl(parent);
- contentOutlineViewer = getTreeViewer();
- contentOutlineViewer.addSelectionChangedListener(this);
-
- // Set up the tree viewer.
- //
- contentOutlineViewer.setContentProvider(new JETOutlineContentProvider());
- contentOutlineViewer.setLabelProvider(new JETOutlineLabelProvider());
-
- setInput();
-
- // Make sure our popups work.
- //
- editor.createContextMenuFor(contentOutlineViewer);
+ public void createControl(Composite parent)
+ {
+ super.createControl(parent);
+ contentOutlineViewer = getTreeViewer();
+ contentOutlineViewer.addSelectionChangedListener(this);
+ contentOutlineViewer.setContentProvider(new JETOutlineContentProvider(editor));
+ contentOutlineViewer.setLabelProvider(new JETOutlineLabelProvider(editor));
+ setInput();
+ editor.createContextMenuFor(contentOutlineViewer);
}
-
- public void setInput() {
- JET2CompilationUnit cu = editor.requestCompilationUnit();
- contentOutlineViewer.setInput(cu);
- }
-
- public Object getAdapter(Class adapter) {
- // TODO Auto-generated method stub
- return null;
+
+ public void setInput()
+ {
+ org.eclipse.jet.compiler.JET2CompilationUnit cu = editor.requestCompilationUnit();
+ contentOutlineViewer.setInput(cu);
}
- public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
- // TODO Auto-generated method stub
-
+ public Object getAdapter(Class adapter)
+ {
+ return null;
}
- public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
- // TODO Auto-generated method stub
-
+ public void addPostSelectionChangedListener(ISelectionChangedListener iselectionchangedlistener)
+ {
}
+ public void removePostSelectionChangedListener(ISelectionChangedListener iselectionchangedlistener)
+ {
+ }
}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/ITokenScannerProvider.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/ITokenScannerProvider.java
new file mode 100644
index 0000000..33a1b3b
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/ITokenScannerProvider.java
@@ -0,0 +1,8 @@
+package org.eclipse.jet.editor.partition;
+
+import org.eclipse.jface.text.rules.ITokenScanner;
+
+public interface ITokenScannerProvider {
+
+ public abstract ITokenScanner getTokenScanner(String s);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/JETDocumentPartitionScanner.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/JETDocumentPartitionScanner.java
index c53b865..fe27452 100644
--- a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/JETDocumentPartitionScanner.java
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/JETDocumentPartitionScanner.java
@@ -1,67 +1,31 @@
package org.eclipse.jet.editor.partition;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
+import java.util.*;
+import org.eclipse.jdt.internal.ui.text.java.JavaAutoIndentStrategy;
import org.eclipse.jet.editor.JETTextEditor;
-import org.eclipse.jet.editor.configuration.JETTokenStyleManager;
-import org.eclipse.jet.editor.configuration.delegates.IJETTextPartitionConfigurationDelegate;
-import org.eclipse.jet.editor.contentassist.JETCustomTagAssistProcessor;
-import org.eclipse.jet.editor.contentassist.JETDirectiveAssistProcessor;
-import org.eclipse.jet.editor.contentassist.JETJavaDeclarationAssistProcessor;
-import org.eclipse.jet.editor.contentassist.JETJavaExpressionAssistProcessor;
-import org.eclipse.jet.editor.contentassist.JETJavaScriptletAssistProcessor;
-import org.eclipse.jet.editor.formatter.JETCustomTagFormattingStrategy;
-import org.eclipse.jet.editor.formatter.JETDirectiveFormattingStrategy;
-import org.eclipse.jet.editor.formatter.JETJavaDeclarationFormattingStrategy;
-import org.eclipse.jet.editor.formatter.JETJavaExpressionFormattingStrategy;
-import org.eclipse.jet.editor.formatter.JETJavaScriptletFormattingStrategy;
-import org.eclipse.jet.editor.rules.JETCommentRule;
-import org.eclipse.jet.editor.rules.JETCustomTagRule;
-import org.eclipse.jet.editor.rules.JETDirectiveRule;
-import org.eclipse.jet.editor.rules.JETJavaDeclarationRule;
-import org.eclipse.jet.editor.rules.JETJavaExpressionRule;
-import org.eclipse.jet.editor.rules.JETJavaScriptletRule;
-import org.eclipse.jet.editor.scanners.JETCommentScanner;
-import org.eclipse.jet.editor.scanners.JETCustomTagScanner;
-import org.eclipse.jet.editor.scanners.JETDefaultContentScanner;
-import org.eclipse.jet.editor.scanners.JETDirectiveScanner;
-import org.eclipse.jet.editor.scanners.JETJavaDeclarationScanner;
-import org.eclipse.jet.editor.scanners.JETJavaExpressionScanner;
-import org.eclipse.jet.editor.scanners.JETJavaScriptletScanner;
-import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jet.editor.autoedit.JETTemplateAutoEditStrategy;
+import org.eclipse.jet.editor.configuration.delegates.IJETDefaultTextColorerDelegate;
+import org.eclipse.jet.editor.contentassist.*;
+import org.eclipse.jet.editor.formatter.*;
+import org.eclipse.jet.editor.rules.*;
+import org.eclipse.jet.editor.scanners.*;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.formatter.IFormattingStrategy;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.IPredicateRule;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.osgi.framework.Bundle;
+import org.eclipse.jface.text.rules.*;
public class JETDocumentPartitionScanner extends RuleBasedPartitionScanner {
-
- public final static String JET_COMMENT = "__jet_comment";
- public final static String JET_CUSTOM_TAG = "__jet_xml_tag";
- public final static String JET_DIRECTIVE = "__jet_directive";
- public final static String JET_JAVA_DECLARATION = "__jet_java_declaration";
- public final static String JET_JAVA_EXPRESSION = "__jet_java_expression";
- public final static String JET_JAVA_SCRIPTLET = "__jet_java_scriptlet";
+
+ public static final String JET_COMMENT = "__jet_comment";
+ public static final String JET_CUSTOM_TAG = "__jet_xml_tag";
+ public static final String JET_DIRECTIVE = "__jet_directive";
+ public static final String JET_JAVA_DECLARATION = "__jet_java_declaration";
+ public static final String JET_JAVA_EXPRESSION = "__jet_java_expression";
+ public static final String JET_JAVA_SCRIPTLET = "__jet_java_scriptlet";
private Map tokenScanners;
private Map damagerRepairers;
@@ -69,65 +33,46 @@ public class JETDocumentPartitionScanner extends RuleBasedPartitionScanner {
private Map repairersOnly;
private Map completionProcessors;
private Map formattingStrategies;
-
private JETTextEditor editor;
-
+
private List contentTypes;
- private Map delegatesContentTypes;
-
- private Collection partitionConfigurationDelegates;
-
- private JETDefaultContentScanner defaultContentScanner;
private JETCustomTagScanner tagScanner;
private JETDirectiveScanner directiveScanner;
private JETJavaDeclarationScanner declarationScanner;
private JETJavaExpressionScanner expressionScanner;
private JETJavaScriptletScanner scriptletScanner;
private JETCommentScanner commentScanner;
-
+
private IContentAssistProcessor tagAssistProcessor;
private IContentAssistProcessor scriptletAssistProcessor;
private IContentAssistProcessor expressionAssistProcessor;
private IContentAssistProcessor declarationAssistProcessor;
+
private IContentAssistProcessor directiveAssistProcessor;
-
private IFormattingStrategy tagFormattingStrategy;
private IFormattingStrategy scriptletFormattingStrategy;
private IFormattingStrategy expressionFormattingStrategy;
private IFormattingStrategy declarationFormattingStrategy;
private IFormattingStrategy directiveFormattingStrategy;
+ private PartitionScannerBasedDamagerRepairer jetTextContentDamagerRepairer;
+
public JETDocumentPartitionScanner(JETTextEditor editor) {
this.editor = editor;
- initPartitionScannerDelegetes();
List rules = new ArrayList();
-
- IToken jetComments = new Token(JET_COMMENT);
- IToken jetCustomTags = new Token(JET_CUSTOM_TAG);
- IToken jetDirective = new Token(JET_DIRECTIVE);
- IToken jetJavaDeclaration = new Token(JET_JAVA_DECLARATION);
- IToken jetJavaExpression = new Token(JET_JAVA_EXPRESSION);
- IToken jetJavaScriptlet = new Token(JET_JAVA_SCRIPTLET);
-
- rules.add(new JETCommentRule(jetComments));
- rules.add(new JETCustomTagRule(jetCustomTags));
- rules.add(new JETDirectiveRule(jetDirective));
- rules.add(new JETJavaDeclarationRule(jetJavaDeclaration));
- rules.add(new JETJavaExpressionRule(jetJavaExpression));
- rules.add(new JETJavaScriptletRule(jetJavaScriptlet));
-
- for (Iterator iterator = partitionConfigurationDelegates.iterator(); iterator.hasNext();) {
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) iterator.next();
- if (delegate.isActiveFor(editor.getEditorInput())) {
- IPredicateRule[] partitioningRules = delegate.getPartitioningRules();
- for (int i = 0; i < partitioningRules.length; i++) {
- IPredicateRule rule = partitioningRules[i];
- rules.add(rule);
- }
- }
- }
-
- IPredicateRule[] result = new IPredicateRule[rules.size()];
+ org.eclipse.jface.text.rules.IToken jetComments = new Token("__jet_comment");
+ org.eclipse.jface.text.rules.IToken jetCustomTags = new Token("__jet_xml_tag");
+ org.eclipse.jface.text.rules.IToken jetDirective = new Token("__jet_directive");
+ org.eclipse.jface.text.rules.IToken jetJavaDeclaration = new Token("__jet_java_declaration");
+ org.eclipse.jface.text.rules.IToken jetJavaExpression = new Token("__jet_java_expression");
+ org.eclipse.jface.text.rules.IToken jetJavaScriptlet = new Token("__jet_java_scriptlet");
+ rules.add(new ASTJETCommentRule(editor, jetComments));
+ rules.add(new ASTJETCustomTagRule(editor, jetCustomTags));
+ rules.add(new ASTJETDirectiveRule(editor, jetDirective));
+ rules.add(new ASTJETJavaDeclarationRule(editor, jetJavaDeclaration));
+ rules.add(new ASTJETJavaExpressionRule(editor, jetJavaExpression));
+ rules.add(new ASTJETJavaScriptletRule(editor, jetJavaScriptlet));
+ IPredicateRule result[] = new IPredicateRule[rules.size()];
result = (IPredicateRule[]) rules.toArray(result);
setPredicateRules(result);
}
@@ -135,327 +80,196 @@ public class JETDocumentPartitionScanner extends RuleBasedPartitionScanner {
public int getNextCharacterOffset() {
return fOffset;
}
- private void initPartitionScannerDelegetes() {
- partitionConfigurationDelegates = new ArrayList();
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.jet.editor", "partitionConfigurationDelegates");
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement element = elements[i];
- Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
- String delegateClass = element.getAttribute("delegateClass");
- IJETTextPartitionConfigurationDelegate delegate = null;
- try {
- Class clazz = bundle.loadClass(delegateClass);
- Class[] argTypes = new Class[] {JETTextEditor.class};
- Constructor ctorWithTextEditor = null;
- try {
- ctorWithTextEditor = clazz.getConstructor(argTypes);
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if (ctorWithTextEditor != null)
- delegate = (IJETTextPartitionConfigurationDelegate) ctorWithTextEditor.newInstance(new Object[] {editor});
- else
- delegate = (IJETTextPartitionConfigurationDelegate) clazz.newInstance();
- partitionConfigurationDelegates.add(delegate);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- }
- public String[] getContentTypes(ISourceViewer sourceViewer) {
+ public String[] getContentTypes() {
if (contentTypes == null) {
contentTypes = new ArrayList();
- delegatesContentTypes = new HashMap();
-
contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE);
- contentTypes.add(JET_COMMENT);
- contentTypes.add(JET_CUSTOM_TAG);
- contentTypes.add(JET_DIRECTIVE);
- contentTypes.add(JET_JAVA_DECLARATION);
- contentTypes.add(JET_JAVA_EXPRESSION);
- contentTypes.add(JET_JAVA_SCRIPTLET);
-
- for (Iterator iterator = partitionConfigurationDelegates.iterator(); iterator.hasNext();) {
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) iterator.next();
- if (delegate.isActiveFor(editor.getEditorInput())) {
- String[] delegateContentTypes = delegate.getContentTypes(sourceViewer);
- for (int i = 0; i < delegateContentTypes.length; i++) {
- String contentType = delegateContentTypes[i];
- contentTypes.add(contentType);
- delegatesContentTypes.put(contentType, delegate);
- }
- }
- }
+ contentTypes.add("__jet_comment");
+ contentTypes.add("__jet_xml_tag");
+ contentTypes.add("__jet_directive");
+ contentTypes.add("__jet_java_declaration");
+ contentTypes.add("__jet_java_expression");
+ contentTypes.add("__jet_java_scriptlet");
}
- String[] result = new String[contentTypes.size()];
+ String result[] = new String[contentTypes.size()];
result = (String[]) contentTypes.toArray(result);
return result;
}
-
+
private void initTokenScanners() {
tokenScanners = new HashMap();
- tokenScanners.put(IDocument.DEFAULT_CONTENT_TYPE, getDefaultContentScanner());
- tokenScanners.put(JET_COMMENT, getCommentScanner());
- tokenScanners.put(JET_CUSTOM_TAG, getCustomTagScanner());
- tokenScanners.put(JET_DIRECTIVE, getDirectiveScanner());
- tokenScanners.put(JET_JAVA_DECLARATION, getJavaDeclarationScanner());
- tokenScanners.put(JET_JAVA_EXPRESSION, getJavaExpressionScanner());
- tokenScanners.put(JET_JAVA_SCRIPTLET, getJavaScriptletScanner());
-
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- ITokenScanner tokenScanner = delegate.getTokenScanner(contentType);
- if (tokenScanner != null)
- tokenScanners.put(contentType, tokenScanner);
- }
+ tokenScanners.put("__jet_comment", getCommentScanner());
+ tokenScanners.put("__jet_xml_tag", getCustomTagScanner());
+ tokenScanners.put("__jet_directive", getDirectiveScanner());
+ tokenScanners.put("__jet_java_declaration", getJavaDeclarationScanner());
+ tokenScanners.put("__jet_java_expression", getJavaExpressionScanner());
+ tokenScanners.put("__jet_java_scriptlet", getJavaScriptletScanner());
}
-
+
private void initCompletionProcessors(ContentAssistant assistant) {
completionProcessors = new HashMap();
- completionProcessors.put(IDocument.DEFAULT_CONTENT_TYPE, getDefaultContentAssistProcessor(assistant));
- completionProcessors.put(JET_COMMENT, getCommentAssistProcessor(assistant));
- completionProcessors.put(JET_CUSTOM_TAG, getCustomTagAssistProcessor(assistant));
- completionProcessors.put(JET_DIRECTIVE, getDirectiveAssistProcessor(assistant));
- completionProcessors.put(JET_JAVA_DECLARATION, getJavaDeclarationAssistProcessor(assistant));
- completionProcessors.put(JET_JAVA_EXPRESSION, getJavaExpressionAssistProcessor(assistant));
- completionProcessors.put(JET_JAVA_SCRIPTLET, getJavaScriptletAssistProcessor(assistant));
-
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- IContentAssistProcessor processor = delegate.getContentAssistProcessor(contentType, assistant);
- if (processor != null)
- completionProcessors.put(contentType, processor);
- }
+ completionProcessors.put(IDocument.DEFAULT_CONTENT_TYPE, getTextElementAssistProcessor(assistant));
+ completionProcessors.put("__jet_comment", getCommentAssistProcessor(assistant));
+ completionProcessors.put("__jet_xml_tag", getCustomTagAssistProcessor(assistant));
+ completionProcessors.put("__jet_directive", getDirectiveAssistProcessor(assistant));
+ completionProcessors.put("__jet_java_declaration", getJavaDeclarationAssistProcessor(assistant));
+ completionProcessors.put("__jet_java_expression", getJavaExpressionAssistProcessor(assistant));
+ completionProcessors.put("__jet_java_scriptlet", getJavaScriptletAssistProcessor(assistant));
}
-
+
private void initFormattingStrategies() {
formattingStrategies = new HashMap();
- formattingStrategies.put(IDocument.DEFAULT_CONTENT_TYPE, getDefaultFormattingStrategy());
- formattingStrategies.put(JET_COMMENT, getCommentFormattingStrategy());
- formattingStrategies.put(JET_CUSTOM_TAG, getCustomTagFormattingStrategy());
- formattingStrategies.put(JET_DIRECTIVE, getDirectiveFormattingStrategy());
- formattingStrategies.put(JET_JAVA_DECLARATION, getJavaDeclarationFormattingStrategy());
- formattingStrategies.put(JET_JAVA_EXPRESSION, getJavaExpressionFormattingStrategy());
- formattingStrategies.put(JET_JAVA_SCRIPTLET, getJavaScriptletFormattingStrategy());
-
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- IFormattingStrategy strategy = delegate.getFormattingStrategy(contentType);
- if (strategy != null)
- formattingStrategies.put(contentType, strategy);
- }
+ formattingStrategies.put(IDocument.DEFAULT_CONTENT_TYPE, getTextElementFormattingStrategy());
+ formattingStrategies.put("__jet_comment", getCommentFormattingStrategy());
+ formattingStrategies.put("__jet_xml_tag", getCustomTagFormattingStrategy());
+ formattingStrategies.put("__jet_directive", getDirectiveFormattingStrategy());
+ formattingStrategies.put("__jet_java_declaration", getJavaDeclarationFormattingStrategy());
+ formattingStrategies.put("__jet_java_expression", getJavaExpressionFormattingStrategy());
+ formattingStrategies.put("__jet_java_scriptlet", getJavaScriptletFormattingStrategy());
}
private void initDamagerRepairers() {
damagerRepairers = new HashMap();
-
- damagerRepairers.put(JET_COMMENT, createDefaultDamagerRepairer(JET_COMMENT));
- damagerRepairers.put(JET_CUSTOM_TAG, createDefaultDamagerRepairer(JET_CUSTOM_TAG));
- damagerRepairers.put(JET_DIRECTIVE, createDefaultDamagerRepairer(JET_DIRECTIVE));
- damagerRepairers.put(JET_JAVA_DECLARATION, createDefaultDamagerRepairer(JET_JAVA_DECLARATION));
- damagerRepairers.put(JET_JAVA_EXPRESSION, createDefaultDamagerRepairer(JET_JAVA_EXPRESSION));
- damagerRepairers.put(JET_JAVA_SCRIPTLET, createDefaultDamagerRepairer(JET_JAVA_SCRIPTLET));
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- IPresentationDamager delegateDamager = delegate.getDamager(contentType);
- IPresentationRepairer delegateRepairer = delegate.getRepairer(contentType);
- if (delegateDamager != null && delegateDamager == delegateRepairer)
- damagerRepairers.put(contentType, delegateDamager);
- }
+ damagerRepairers.put("__jet_comment", createDefaultDamagerRepairer("__jet_comment"));
+ damagerRepairers.put("__jet_xml_tag", createDefaultDamagerRepairer("__jet_xml_tag"));
+ damagerRepairers.put("__jet_directive", createDefaultDamagerRepairer("__jet_directive"));
+ damagerRepairers.put("__jet_java_declaration", createDefaultDamagerRepairer("__jet_java_declaration"));
+ damagerRepairers.put("__jet_java_expression", createDefaultDamagerRepairer("__jet_java_expression"));
+ damagerRepairers.put("__jet_java_scriptlet", createDefaultDamagerRepairer("__jet_java_scriptlet"));
+ if (createJETTextContentDamagerRepairer() != null)
+ damagerRepairers.put(IDocument.DEFAULT_CONTENT_TYPE, jetTextContentDamagerRepairer);
}
private void initDamagersOnly() {
damagersOnly = new HashMap();
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- IPresentationDamager delegateDamager = delegate.getDamager(contentType);
- if (delegateDamager != null && !damagerRepairers.containsValue(delegateDamager))
- damagersOnly.put(contentType, delegateDamager);
- }
}
-
+
protected void initRepairersOnly() {
repairersOnly = new HashMap();
- for (Iterator iterator = delegatesContentTypes.keySet().iterator(); iterator.hasNext();) {
- String contentType = (String) iterator.next();
- IJETTextPartitionConfigurationDelegate delegate = (IJETTextPartitionConfigurationDelegate) delegatesContentTypes.get(contentType);
- IPresentationRepairer delegateRepairer = delegate.getRepairer(contentType);
- if (delegateRepairer != null && !damagerRepairers.containsValue(delegateRepairer))
- repairersOnly.put(contentType, delegateRepairer);
- }
}
-
- protected IFormattingStrategy getDefaultFormattingStrategy() {
+
+ protected IFormattingStrategy getTextElementFormattingStrategy() {
return null;
}
-
+
protected IFormattingStrategy getCommentFormattingStrategy() {
return null;
}
-
+
protected IFormattingStrategy getCustomTagFormattingStrategy() {
- if (tagFormattingStrategy == null) {
- tagFormattingStrategy = new JETCustomTagFormattingStrategy();
- }
+ if (tagFormattingStrategy == null)
+ tagFormattingStrategy = new JETCustomTagFormattingStrategy();
return tagFormattingStrategy;
}
-
+
protected IFormattingStrategy getJavaScriptletFormattingStrategy() {
- if (scriptletFormattingStrategy == null) {
- scriptletFormattingStrategy = new JETJavaScriptletFormattingStrategy();
- }
+ if (scriptletFormattingStrategy == null)
+ scriptletFormattingStrategy = new JETJavaScriptletFormattingStrategy();
return scriptletFormattingStrategy;
}
protected IFormattingStrategy getJavaExpressionFormattingStrategy() {
- if (expressionFormattingStrategy == null) {
- expressionFormattingStrategy = new JETJavaExpressionFormattingStrategy();
- }
+ if (expressionFormattingStrategy == null)
+ expressionFormattingStrategy = new JETJavaExpressionFormattingStrategy();
return expressionFormattingStrategy;
}
protected IFormattingStrategy getJavaDeclarationFormattingStrategy() {
- if (declarationFormattingStrategy == null) {
- declarationFormattingStrategy = new JETJavaDeclarationFormattingStrategy();
- }
+ if (declarationFormattingStrategy == null)
+ declarationFormattingStrategy = new JETJavaDeclarationFormattingStrategy();
return declarationFormattingStrategy;
}
protected IFormattingStrategy getDirectiveFormattingStrategy() {
- if (directiveFormattingStrategy == null) {
- directiveFormattingStrategy = new JETDirectiveFormattingStrategy();
- }
+ if (directiveFormattingStrategy == null)
+ directiveFormattingStrategy = new JETDirectiveFormattingStrategy();
return directiveFormattingStrategy;
}
-
- protected IContentAssistProcessor getDefaultContentAssistProcessor(ContentAssistant assistant) {
+
+ protected IContentAssistProcessor getTextElementAssistProcessor(ContentAssistant assistant) {
return null;
}
-
+
protected IContentAssistProcessor getCommentAssistProcessor(ContentAssistant assistant) {
return null;
}
-
+
protected IContentAssistProcessor getCustomTagAssistProcessor(ContentAssistant assistant) {
- if (tagAssistProcessor == null) {
- tagAssistProcessor = new JETCustomTagAssistProcessor(editor);
- }
+ if (tagAssistProcessor == null)
+ tagAssistProcessor = new JETCustomTagAssistProcessor(editor);
return tagAssistProcessor;
}
-
+
protected IContentAssistProcessor getJavaScriptletAssistProcessor(ContentAssistant assistant) {
- if (scriptletAssistProcessor == null) {
- scriptletAssistProcessor = new JETJavaScriptletAssistProcessor(editor);
- }
+ if (scriptletAssistProcessor == null)
+ scriptletAssistProcessor = new JETJavaScriptletAssistProcessor(editor);
return scriptletAssistProcessor;
}
protected IContentAssistProcessor getJavaExpressionAssistProcessor(ContentAssistant assistant) {
- if (expressionAssistProcessor == null) {
- expressionAssistProcessor = new JETJavaExpressionAssistProcessor(editor);
- }
+ if (expressionAssistProcessor == null)
+ expressionAssistProcessor = new JETJavaExpressionAssistProcessor(editor);
return expressionAssistProcessor;
}
protected IContentAssistProcessor getJavaDeclarationAssistProcessor(ContentAssistant assistant) {
- if (declarationAssistProcessor == null) {
- declarationAssistProcessor = new JETJavaDeclarationAssistProcessor(editor);
- }
+ if (declarationAssistProcessor == null)
+ declarationAssistProcessor = new JETJavaDeclarationAssistProcessor(editor);
return declarationAssistProcessor;
}
protected IContentAssistProcessor getDirectiveAssistProcessor(ContentAssistant assistant) {
- if (directiveAssistProcessor == null) {
- directiveAssistProcessor = new JETDirectiveAssistProcessor(editor);
- }
+ if (directiveAssistProcessor == null)
+ directiveAssistProcessor = new JETDirectiveAssistProcessor(editor);
return directiveAssistProcessor;
}
- protected ITokenScanner getDefaultContentScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (defaultContentScanner == null) {
- defaultContentScanner = new JETDefaultContentScanner(tokenStyleManager, preferenceStore);
- }
- return defaultContentScanner;
- }
-
protected ITokenScanner getCommentScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (commentScanner == null) {
- commentScanner = new JETCommentScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (commentScanner == null)
+ commentScanner = new JETCommentScanner(tokenStyleManager, preferenceStore);
return commentScanner;
}
-
+
protected ITokenScanner getCustomTagScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (tagScanner == null) {
- tagScanner = new JETCustomTagScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (tagScanner == null)
+ tagScanner = new JETCustomTagScanner(tokenStyleManager, preferenceStore);
return tagScanner;
}
-
+
protected ITokenScanner getJavaScriptletScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (scriptletScanner == null) {
- scriptletScanner = new JETJavaScriptletScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (scriptletScanner == null)
+ scriptletScanner = new JETJavaScriptletScanner(tokenStyleManager, preferenceStore);
return scriptletScanner;
}
protected ITokenScanner getJavaExpressionScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (expressionScanner == null) {
- expressionScanner = new JETJavaExpressionScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (expressionScanner == null)
+ expressionScanner = new JETJavaExpressionScanner(tokenStyleManager, preferenceStore);
return expressionScanner;
}
protected ITokenScanner getJavaDeclarationScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (declarationScanner == null) {
- declarationScanner = new JETJavaDeclarationScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (declarationScanner == null)
+ declarationScanner = new JETJavaDeclarationScanner(tokenStyleManager, preferenceStore);
return declarationScanner;
}
protected ITokenScanner getDirectiveScanner() {
- JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
- IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
- if (directiveScanner == null) {
- directiveScanner = new JETDirectiveScanner(tokenStyleManager, preferenceStore);
- }
+ org.eclipse.jet.editor.configuration.JETTokenStyleManager tokenStyleManager = editor.getTokenStyleManager();
+ org.eclipse.jface.preference.IPreferenceStore preferenceStore = editor.getEditorPreferenceStore();
+ if (directiveScanner == null)
+ directiveScanner = new JETDirectiveScanner(tokenStyleManager, preferenceStore);
return directiveScanner;
}
@@ -466,11 +280,35 @@ public class JETDocumentPartitionScanner extends RuleBasedPartitionScanner {
return scanner;
}
+ private PartitionScannerBasedDamagerRepairer createJETTextContentDamagerRepairer() {
+ if (jetTextContentDamagerRepairer == null) {
+ IJETDefaultTextColorerDelegate delegate = editor.getCurrentColorerDelegate();
+ if (delegate != null) {
+ RuleBasedPartitionScanner partitionScanner = new RuleBasedPartitionScanner();
+ partitionScanner.setPredicateRules(delegate.getPartitioningRules());
+ jetTextContentDamagerRepairer = new PartitionScannerBasedDamagerRepairer(partitionScanner, delegate);
+ }
+ }
+ return jetTextContentDamagerRepairer;
+ }
+
+ public void updateJETTextContentDamagerRepairer() {
+ if (jetTextContentDamagerRepairer != null) {
+ IJETDefaultTextColorerDelegate delegate = editor.getCurrentColorerDelegate();
+ if (delegate != null) {
+ RuleBasedPartitionScanner partitionScanner = new RuleBasedPartitionScanner();
+ partitionScanner.setPredicateRules(delegate.getPartitioningRules());
+ jetTextContentDamagerRepairer.setPartitionScanner(partitionScanner);
+ jetTextContentDamagerRepairer.setTokenScannerProvider(delegate);
+ }
+ }
+ }
+
private DefaultDamagerRepairer createDefaultDamagerRepairer(String contentType) {
ITokenScanner tokenScanner = getTokenScanner(contentType);
- return tokenScanner == null ? null : new DefaultDamagerRepairer(tokenScanner);
+ return tokenScanner != null ? new DefaultDamagerRepairer(tokenScanner) : null;
}
-
+
public IPresentationDamager getDamager(String contentType) {
if (damagerRepairers == null)
initDamagerRepairers();
@@ -509,4 +347,19 @@ public class JETDocumentPartitionScanner extends RuleBasedPartitionScanner {
return formatter;
}
-}
+ public IAutoEditStrategy[] getAutoEditStrategies(String contentType) {
+ IAutoEditStrategy result[] = (IAutoEditStrategy[]) null;
+ if ("__jet_directive".equals(contentType))
+ result = (new IAutoEditStrategy[] { new JETTemplateAutoEditStrategy() });
+ else if ("__jet_java_scriptlet".equals(contentType))
+ result = (new IAutoEditStrategy[] {
+ new JavaAutoIndentStrategy("__dftl_partitioning", editor.getJETJavaProject()),
+ new JETTemplateAutoEditStrategy() });
+ else if ("__jet_java_declaration".equals(contentType))
+ result = (new IAutoEditStrategy[] {
+ new JavaAutoIndentStrategy("__dftl_partitioning", editor.getJETJavaProject()),
+ new JETTemplateAutoEditStrategy() });
+ return result;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/PartitionScannerBasedDamagerRepairer.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/PartitionScannerBasedDamagerRepairer.java
new file mode 100644
index 0000000..2b3d29e
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/partition/PartitionScannerBasedDamagerRepairer.java
@@ -0,0 +1,141 @@
+package org.eclipse.jet.editor.partition;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.jface.text.rules.*;
+import org.eclipse.swt.custom.StyleRange;
+
+public class PartitionScannerBasedDamagerRepairer implements IPresentationDamager, IPresentationRepairer {
+
+ protected IDocument document;
+ protected IPartitionTokenScanner partitionScanner;
+ protected ITokenScannerProvider tokenScannerProvider;
+ protected TextAttribute defaultTextAttribute;
+
+ public PartitionScannerBasedDamagerRepairer(IPartitionTokenScanner scanner, ITokenScannerProvider provider) {
+ Assert.isNotNull(scanner);
+ Assert.isNotNull(provider);
+ partitionScanner = scanner;
+ tokenScannerProvider = provider;
+ defaultTextAttribute = new TextAttribute(null);
+ }
+
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+
+ public void setPartitionScanner(IPartitionTokenScanner partitionScanner) {
+ this.partitionScanner = partitionScanner;
+ }
+
+ public void setTokenScannerProvider(ITokenScannerProvider provider) {
+ tokenScannerProvider = provider;
+ }
+
+ public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {
+ if (!documentPartitioningChanged)
+ return new Region(partition.getOffset(), partition.getLength());
+ else
+ return partition;
+ }
+
+ public void createPresentation(TextPresentation presentation, ITypedRegion region) {
+ partitionScanner.setRange(document, region.getOffset(), region.getLength());
+ String lastContentType = null;
+ int partitionScannerTokenLength = 0;
+ int partitionScannerTokenOffset = region.getOffset();
+ do {
+ IToken partitionToken = partitionScanner.nextToken();
+ if (partitionToken.isEOF()) {
+ if (lastContentType != null) {
+ ITokenScanner tokenScanner = tokenScannerProvider.getTokenScanner(lastContentType);
+ if (tokenScanner == null)
+ addRange(presentation, partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(),
+ defaultTextAttribute);
+ else
+ applyTokenScanner(presentation, partitionScannerTokenLength, partitionScannerTokenOffset, tokenScanner);
+ }
+ break;
+ }
+ String contentType = getTokenContentType(partitionToken);
+ if (contentType == null)
+ contentType = IDocument.DEFAULT_CONTENT_TYPE;
+ if (contentType.equals(lastContentType)) {
+ partitionScannerTokenLength += partitionScanner.getTokenLength();
+ } else {
+ if (lastContentType != null) {
+ ITokenScanner tokenScanner = tokenScannerProvider.getTokenScanner(lastContentType);
+ if (tokenScanner == null)
+ addRange(presentation, partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(),
+ defaultTextAttribute);
+ else
+ applyTokenScanner(presentation, partitionScannerTokenLength, partitionScannerTokenOffset, tokenScanner);
+ }
+ lastContentType = contentType;
+ partitionScannerTokenOffset = partitionScanner.getTokenOffset();
+ partitionScannerTokenLength = partitionScanner.getTokenLength();
+ }
+ } while (true);
+ }
+
+ private void applyTokenScanner(TextPresentation presentation, int partitionScannerTokenLength,
+ int partitionScannerTokenOffset, ITokenScanner tokenScanner) {
+ int lastStart = partitionScannerTokenOffset;
+ int length = 0;
+ boolean firstToken = true;
+ IToken lastToken = Token.UNDEFINED;
+ TextAttribute lastAttribute = getTokenTextAttribute(lastToken);
+ tokenScanner.setRange(document, partitionScannerTokenOffset, partitionScannerTokenLength);
+ do {
+ IToken token = tokenScanner.nextToken();
+ if (!token.isEOF()) {
+ TextAttribute attribute = getTokenTextAttribute(token);
+ if (lastAttribute != null && lastAttribute.equals(attribute)) {
+ length += tokenScanner.getTokenLength();
+ firstToken = false;
+ } else {
+ if (!firstToken)
+ addRange(presentation, lastStart, length, lastAttribute);
+ firstToken = false;
+ lastToken = token;
+ lastAttribute = attribute;
+ lastStart = tokenScanner.getTokenOffset();
+ length = tokenScanner.getTokenLength();
+ }
+ } else {
+ addRange(presentation, lastStart, length, lastAttribute);
+ return;
+ }
+ } while (true);
+ }
+
+ protected String getTokenContentType(IToken token) {
+ Object data = token.getData();
+ if (data instanceof String)
+ return (String) data;
+ else
+ return null;
+ }
+
+ protected TextAttribute getTokenTextAttribute(IToken token) {
+ Object data = token.getData();
+ if (data instanceof TextAttribute)
+ return (TextAttribute) data;
+ else
+ return defaultTextAttribute;
+ }
+
+ protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) {
+ if (attr != null) {
+ int style = attr.getStyle();
+ int fontStyle = style & 3;
+ StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), fontStyle);
+ styleRange.strikeout = (style & 0x20000000) != 0;
+ styleRange.underline = (style & 0x40000000) != 0;
+ styleRange.font = attr.getFont();
+ presentation.addStyleRange(styleRange);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTElementScannerRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTElementScannerRule.java
new file mode 100644
index 0000000..63ec4f7
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTElementScannerRule.java
@@ -0,0 +1,42 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.partition.JETDocumentPartitionScanner;
+import org.eclipse.jface.text.rules.*;
+
+public abstract class ASTElementScannerRule implements IPredicateRule {
+ private JETTextEditor editor;
+
+ private IToken successToken;
+
+ public ASTElementScannerRule(JETTextEditor editor, IToken successToken) {
+ this.editor = editor;
+ this.successToken = successToken;
+ }
+
+ public IToken getSuccessToken() {
+ return successToken;
+ }
+
+ public IToken evaluate(ICharacterScanner scanner) {
+ return evaluate(scanner, false);
+ }
+
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ JETDocumentPartitionScanner jetScanner = (JETDocumentPartitionScanner) scanner;
+ int offset = jetScanner.getNextCharacterOffset();
+ JET2ASTElement element = editor.getASTElement(offset);
+ if (element != null && isAcceptedElement(element)) {
+ int length = element.getEnd() - offset;
+ for (int i = 0; i < length; i++)
+ scanner.read();
+
+ return successToken;
+ } else {
+ return Token.UNDEFINED;
+ }
+ }
+
+ protected abstract boolean isAcceptedElement(JET2ASTElement jet2astelement);
+}
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCommentRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCommentRule.java
new file mode 100644
index 0000000..18be930
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCommentRule.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.Comment;
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETCommentRule extends ASTElementScannerRule {
+
+ public ASTJETCommentRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return element instanceof Comment;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCustomTagRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCustomTagRule.java
new file mode 100644
index 0000000..cfa5d79
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETCustomTagRule.java
@@ -0,0 +1,16 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.*;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETCustomTagRule extends ASTElementScannerRule {
+
+ public ASTJETCustomTagRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return (element instanceof XMLElement) || (element instanceof XMLBodyElementEnd);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETDirectiveRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETDirectiveRule.java
new file mode 100644
index 0000000..4b66251
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETDirectiveRule.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.compiler.JET2Directive;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETDirectiveRule extends ASTElementScannerRule {
+
+ public ASTJETDirectiveRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return element instanceof JET2Directive;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaDeclarationRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaDeclarationRule.java
new file mode 100644
index 0000000..fdaf12d
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaDeclarationRule.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.compiler.JET2Declaration;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETJavaDeclarationRule extends ASTElementScannerRule {
+
+ public ASTJETJavaDeclarationRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return element instanceof JET2Declaration;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaExpressionRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaExpressionRule.java
new file mode 100644
index 0000000..07353fd
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaExpressionRule.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.compiler.JET2Expression;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETJavaExpressionRule extends ASTElementScannerRule {
+
+ public ASTJETJavaExpressionRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return element instanceof JET2Expression;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaScriptletRule.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaScriptletRule.java
new file mode 100644
index 0000000..619b918
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/editor/rules/ASTJETJavaScriptletRule.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.editor.rules;
+
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.compiler.JET2Scriptlet;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jface.text.rules.IToken;
+
+public class ASTJETJavaScriptletRule extends ASTElementScannerRule {
+
+ public ASTJETJavaScriptletRule(JETTextEditor editor, IToken token) {
+ super(editor, token);
+ }
+
+ protected boolean isAcceptedElement(JET2ASTElement element) {
+ return element instanceof JET2Scriptlet;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETDocumentReader.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETDocumentReader.java
new file mode 100644
index 0000000..8e66197
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETDocumentReader.java
@@ -0,0 +1,69 @@
+package org.eclipse.jet.internal.editor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * @author jcheuoua
+ *
+ * To change the template for this generated type comment go to Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code
+ * and Comments
+ * @version $Revision: 1.1 $
+ */
+public class JETDocumentReader {
+ public static final int EOF = -1;
+
+ private IDocument document;
+
+ private int offset;
+
+ /**
+ * Constructor for JETDocumentReader.
+ *
+ * @param document
+ * IDocument
+ * @param documentOffset
+ * int
+ */
+ public JETDocumentReader(IDocument document, int documentOffset) {
+ this.document = null;
+ offset = -1;
+ if (documentOffset > 0)
+ offset = documentOffset;
+ this.document = document;
+ }
+
+ /**
+ * Method readForward.
+ *
+ * @return char
+ */
+ public char readForward() {
+ try {
+ if (document.getChar(offset) == '\uFFFF') {
+ return '\uFFFF';
+ } else {
+ offset++;
+ return document.getChar(offset);
+ }
+ } catch (BadLocationException ex) {
+ return '\uFFFF';
+ }
+ }
+
+ /**
+ * Method readBackward.
+ *
+ * @return char
+ */
+ public char readBackward() {
+ if (offset <= 0)
+ return '\uFFFF';
+ try {
+ offset--;
+ return document.getChar(offset);
+ } catch (BadLocationException e) {
+ return '\uFFFF';
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETEditorHelper.java b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETEditorHelper.java
new file mode 100644
index 0000000..2f5773a
--- /dev/null
+++ b/plugins/org.eclipse.jet.editor/src/org/eclipse/jet/internal/editor/JETEditorHelper.java
@@ -0,0 +1,422 @@
+package org.eclipse.jet.internal.editor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IProblemRequestor;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.eval.IEvaluationContext;
+import org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal;
+import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.compiler.CompileOptionsManager;
+import org.eclipse.jet.compiler.DefaultJET2ASTVisitor;
+import org.eclipse.jet.compiler.JET2ASTElement;
+import org.eclipse.jet.compiler.JET2CompilationUnit;
+import org.eclipse.jet.compiler.JET2Compiler;
+import org.eclipse.jet.compiler.JET2Declaration;
+import org.eclipse.jet.compiler.JET2Expression;
+import org.eclipse.jet.compiler.JET2Scriptlet;
+import org.eclipse.jet.compiler.Problem;
+import org.eclipse.jet.editor.JETTextEditor;
+import org.eclipse.jet.editor.gen.JETEditorJET2JavaGenerator;
+import org.eclipse.jet.internal.compiler.MethodBodyCreator;
+import org.eclipse.jet.internal.compiler.templates.CodeGenTemplateLoader;
+import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jet.transform.TransformContextExtender;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IFileEditorInput;
+
+public class JETEditorHelper {
+ public static class JETEditorMethodBodyCreator extends MethodBodyCreator {
+
+ public void setStartOffset(int offset) {
+ startOffset = offset;
+ }
+
+ public void visit(JET2Expression expression) {
+ Position position = new Position(getBuffer().length());
+ generatedBodyMappingPositions.put(expression, position);
+ super.visit(expression);
+ String writtenContent = getBuffer().substring(position.offset);
+ int javaContentIndex = writtenContent.indexOf(expression.getJavaContent());
+ position.setLength(getBuffer().length() - position.offset);
+ position.setOffset(startOffset + position.offset + javaContentIndex);
+ }
+
+ public void visit(JET2Scriptlet scriptlet) {
+ Position position = new Position(getBuffer().length());
+ generatedBodyMappingPositions.put(scriptlet, position);
+ super.visit(scriptlet);
+ String writtenContent = getBuffer().substring(position.offset);
+ int javaContentIndex = writtenContent.indexOf(scriptlet.getJavaContent());
+ position.setLength(getBuffer().length() - position.offset);
+ position.setOffset(startOffset + position.offset + javaContentIndex);
+ }
+
+ private Map generatedBodyMappingPositions;
+
+ private int startOffset;
+
+ public JETEditorMethodBodyCreator(JET2TemplateLoader templateLoader, Map mappingPositions) {
+ super(templateLoader);
+ startOffset = 0;
+ generatedBodyMappingPositions = mappingPositions;
+ }
+ }
+
+ private static final class JETJavaContentProblemRequestor implements IProblemRequestor {
+
+ private List problems;
+
+ private List javaProblems;
+
+ private IDocument javaDocument;
+
+ private IDocument jetDocument;
+
+ private Map mappingPositions;
+
+ private JETJavaContentProblemRequestor(List problems, Map mappings, IDocument javaDocument, IDocument jetDocument) {
+ this.problems = problems;
+ mappingPositions = mappings;
+ javaProblems = new ArrayList();
+ this.javaDocument = javaDocument;
+ this.jetDocument = jetDocument;
+ }
+
+ public List getProblems() {
+ return problems;
+ }
+
+ public void acceptProblem(IProblem problem) {
+ javaProblems.add(problem);
+ }
+
+ public void beginReporting() {
+ javaProblems.clear();
+ }
+
+ public void endReporting() {
+ Problem problem;
+ for (Iterator iter = javaProblems.iterator(); iter.hasNext(); problems.add(problem)) {
+ IProblem javaProblem = (IProblem) iter.next();
+ int javaOffset = javaProblem.getSourceStart();
+ int problemLength = (javaProblem.getSourceEnd() - javaProblem.getSourceStart()) + 1;
+ JET2ASTElement astElement = getElementForJavaOffset(javaOffset);
+ Position pos = (Position) mappingPositions.get(astElement);
+ int javaStart = pos.getOffset();
+ int jetOffset = JETEditorHelper.getASTElementContentStart(astElement, jetDocument) + (javaOffset - javaStart);
+ problem = new Problem("", javaProblem.isWarning() ? ParseProblemSeverity.WARNING : ParseProblemSeverity.ERROR,
+ -1, javaProblem.getMessage(), javaProblem.getArguments(), jetOffset, jetOffset + problemLength, -1, -1);
+ }
+
+ }
+
+ public boolean isActive() {
+ return true;
+ }
+
+ private JET2ASTElement getElementForJavaOffset(int javaOffset) {
+ for (Iterator iterator = mappingPositions.keySet().iterator(); iterator.hasNext();) {
+ JET2ASTElement element = (JET2ASTElement) iterator.next();
+ Position pos = (Position) mappingPositions.get(element);
+ if (pos.getOffset() <= javaOffset && javaOffset < pos.getOffset() + pos.getLength())
+ return element;
+ }
+
+ return null;
+ }
+ }
+
+ public static int getASTElementContentStart(JET2ASTElement astElement, IDocument jetDocument) {
+ int jetStart = astElement.getStart();
+ if (astElement instanceof JET2Declaration)
+ jetStart += 3;
+ if ((astElement instanceof JET2Expression) || (astElement instanceof JET2Scriptlet))
+ try {
+ String jetSnippet = jetDocument.get(jetStart, astElement.getEnd() - jetStart);
+ String javaContent = (astElement instanceof JET2Expression) ? ((JET2Expression) astElement).getJavaContent()
+ : ((JET2Scriptlet) astElement).getJavaContent();
+ int idx = jetSnippet.indexOf(javaContent);
+ jetStart += idx;
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ return jetStart;
+ }
+
+ public static IDocument computeJavaSource(JET2CompilationUnit cu, Map mappingPositions) {
+ HashMap arguments = new HashMap();
+ arguments.put("cu", cu);
+ arguments.put("org.eclipse.jet.storeJavaMappingPositions", mappingPositions);
+ JET2Context context = new JET2Context(null, arguments);
+ org.eclipse.jet.JET2TemplateLoader templateLoader = new CodeGenTemplateLoader();
+ TransformContextExtender.getInstance(context).setLoader(templateLoader);
+ JETEditorJET2JavaGenerator generator = new JETEditorJET2JavaGenerator();
+ BodyContentWriter out = new BodyContentWriter();
+ generator.generate(context, out);
+ return out.getDocument();
+ }
+
+ private static JET2Declaration[] getAllJavaDeclarations(JET2CompilationUnit cu) {
+ final List result = new ArrayList();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(JET2Declaration declaration) {
+ result.add(declaration);
+ }
+ });
+ return (JET2Declaration[]) result.toArray(new JET2Declaration[result.size()]);
+ }
+
+ public static String getDeclarationsSourceCode(JET2CompilationUnit cu) {
+ JET2Declaration declarations[] = getAllJavaDeclarations(cu);
+ StringBuffer declarationsSource = new StringBuffer(declarations.length * 20);
+ for (int i = 0; i < declarations.length; i++) {
+ JET2Declaration declaration = declarations[i];
+ declarationsSource.append(declaration.getJavaContent());
+ }
+
+ return declarationsSource.toString();
+ }
+
+ public static String getPreviousGeneratedJavaSource(IJavaProject javaProject, JET2CompilationUnit cu,
+ JET2ASTElement bodyElement) {
+ org.eclipse.jet.JET2TemplateLoader templateLoader = new CodeGenTemplateLoader();
+ MethodBodyCreator generatedBody = new MethodBodyCreator(templateLoader);
+ List sortedPrevElements = new ArrayList();
+ for (JET2ASTElement prevASTElement = bodyElement.getPrevElement(); prevASTElement != null; prevASTElement = prevASTElement
+ .getPrevElement())
+ sortedPrevElements.add(0, prevASTElement);
+
+ JET2ASTElement prevElement;
+ for (Iterator iterator = sortedPrevElements.iterator(); iterator.hasNext(); prevElement.accept(generatedBody))
+ prevElement = (JET2ASTElement) iterator.next();
+
+ return generatedBody.getBuffer();
+ }
+
+ public static List evaluateProblems(IJavaProject javaProject, JET2CompilationUnit cu, IDocument jetDocument) {
+ String packageName = cu.getOutputJavaPackage();
+ String className = cu.getOutputJavaClassName();
+ List problems = new ArrayList();
+ if (packageName == null || className == null)
+ return problems;
+ Map mappingPositions = new HashMap();
+ IDocument javaDocument = computeJavaSource(cu, mappingPositions);
+ JETJavaContentProblemRequestor problemRequestor = new JETJavaContentProblemRequestor(problems, mappingPositions,
+ javaDocument, jetDocument);
+ try {
+ ICompilationUnit compilationUnit = null;
+ IPackageFragmentRoot roots[] = javaProject.getPackageFragmentRoots();
+ for (int i = 0; i < roots.length;) {
+ IPackageFragmentRoot root = roots[i];
+ IPackageFragment packageFragment = root.getPackageFragment(packageName);
+ if (packageFragment == null || !packageFragment.exists())
+ packageFragment = root.createPackageFragment(packageName, true, new NullProgressMonitor());
+ compilationUnit = packageFragment.createCompilationUnit((new StringBuilder(String.valueOf(className))).append(
+ ".java").toString(), javaDocument.get(), true, new NullProgressMonitor());
+ break;
+ }
+
+ org.eclipse.jdt.core.WorkingCopyOwner owner = new WorkingCopyOwner() {
+ };
+ ICompilationUnit copy = compilationUnit.getWorkingCopy(owner, problemRequestor, null);
+ copy.reconcile(0, true, owner, null);
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return problems;
+ }
+
+ public static CompletionProposalCollector collect(IJavaProject javaProject, JET2CompilationUnit cu,
+ String codeSnippet, int offset) {
+ IEvaluationContext context;
+ CompletionProposalCollector proposalCollector;
+ context = javaProject.newEvaluationContext();
+ List importList = new ArrayList();
+ importList.addAll(cu.getImports());
+ importList.add("org.eclipse.jet.JET2Context");
+ importList.add("org.eclipse.jet.JET2Template");
+ importList.add("org.eclipse.jet.JET2Writer");
+ importList.add("org.eclipse.jet.taglib.RuntimeTagElement");
+ importList.add("org.eclipse.jet.taglib.TagInfo");
+ String imports[] = new String[importList.size()];
+ importList.toArray(imports);
+ String packageName = cu.getOutputJavaPackage();
+ if (packageName == null) {
+ Map options = CompileOptionsManager.getOptions(javaProject.getProject());
+ if (options.isEmpty())
+ options = JET2Compiler.getDefaultCompilerOptions();
+ packageName = (String) options.get("org.eclipse.jet.compiledTemplatePackage");
+ }
+ context.setPackageName(packageName);
+ context.setImports(imports);
+ proposalCollector = new CompletionProposalCollector(javaProject);
+ try {
+ context.codeComplete(codeSnippet, offset, proposalCollector);
+ return proposalCollector;
+ } catch (JavaModelException e) {
+ // TODO : log this exception
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static IJavaCompletionProposal[] getJavaCompletionProposal(JETTextEditor editor, ITextViewer viewer,
+ int completionOffset) {
+ IJavaProject javaProject;
+ String packageName;
+ String className;
+ Map mappingPositions;
+ IDocument javaDocument;
+ JET2CompilationUnit cu = editor.requestCompilationUnit();
+ javaProject = editor.getJETJavaProject();
+ packageName = cu.getOutputJavaPackage();
+ className = cu.getOutputJavaClassName();
+ if (packageName == null) {
+ Map options = CompileOptionsManager.getOptions(javaProject.getProject());
+ if (options.isEmpty())
+ options = JET2Compiler.getDefaultCompilerOptions();
+ packageName = (String) options.get("org.eclipse.jet.compiledTemplatePackage");
+ }
+ if (className == null && (editor.getEditorInput() instanceof IFileEditorInput)) {
+ IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
+ String inputName = file.getFullPath().removeFileExtension().lastSegment();
+ String baseClassName = makeJavaClassName(inputName);
+ className = baseClassName;
+ }
+ if (packageName == null || className == null)
+ return new IJavaCompletionProposal[0];
+ mappingPositions = new HashMap();
+ javaDocument = computeJavaSource(cu, mappingPositions);
+ IJavaCompletionProposal results[];
+ ICompilationUnit compilationUnit = null;
+ try {
+ IPackageFragmentRoot roots[] = javaProject.getPackageFragmentRoots();
+ for (int i = 0; i < roots.length;) {
+ IPackageFragmentRoot root = roots[i];
+ IPackageFragment packageFragment = root.getPackageFragment(packageName);
+ if (packageFragment == null || !packageFragment.exists())
+ packageFragment = root.createPackageFragment(packageName, true, new NullProgressMonitor());
+ compilationUnit = packageFragment.createCompilationUnit((new StringBuilder(String.valueOf(className))).append(
+ ".java").toString(), javaDocument.get(), true, new NullProgressMonitor());
+ break;
+ }
+
+ CompletionProposalCollector proposalCollector = new CompletionProposalCollector(compilationUnit);
+ JET2ASTElement astElement = editor.getASTElement(completionOffset);
+ Position javaPosition = (Position) mappingPositions.get(astElement);
+ int jetStart = getASTElementContentStart(astElement, viewer.getDocument());
+ int javaStart = javaPosition.getOffset();
+ int javaCompletionOffset = javaStart + (completionOffset - jetStart);
+ compilationUnit.codeComplete(javaCompletionOffset, proposalCollector);
+ Point selection = viewer.getSelectedRange();
+ if (selection.y > 0)
+ proposalCollector.setReplacementLength(selection.y);
+ IJavaCompletionProposal javaProposals[] = proposalCollector.getJavaCompletionProposals();
+ IJavaCompletionProposal keywordsProposals[] = proposalCollector.getKeywordCompletionProposals();
+ IJavaCompletionProposal unsortedJavaProposals[] = new IJavaCompletionProposal[javaProposals.length
+ + keywordsProposals.length];
+ System.arraycopy(keywordsProposals, 0, unsortedJavaProposals, 0, keywordsProposals.length);
+ System.arraycopy(javaProposals, 0, unsortedJavaProposals, keywordsProposals.length, javaProposals.length);
+ List sortedJavaProposals = new LinkedList();
+ for (int i = 0; i < unsortedJavaProposals.length; i++) {
+ IJavaCompletionProposal unsortedJavaProposal = unsortedJavaProposals[i];
+ int index = 0;
+ for (Iterator iterator = sortedJavaProposals.iterator(); iterator.hasNext();) {
+ IJavaCompletionProposal proposal = (IJavaCompletionProposal) iterator.next();
+ if (proposal.getRelevance() <= unsortedJavaProposal.getRelevance()) {
+ index = sortedJavaProposals.indexOf(proposal);
+ break;
+ }
+ }
+
+ sortedJavaProposals.add(index, unsortedJavaProposal);
+ }
+
+ results = new IJavaCompletionProposal[sortedJavaProposals.size()];
+ sortedJavaProposals.toArray(results);
+ adjustResults(results, completionOffset);
+ return results;
+ } catch (JavaModelException e) {
+ // TODO log this exception
+ e.printStackTrace();
+ }
+ return new IJavaCompletionProposal[0];
+ }
+
+ public static IJavaCompletionProposal[] getJavaCompletionProposal(IJavaProject javaProject, JET2CompilationUnit cu,
+ String codeSnippet, ITextViewer viewer, int offset) {
+ CompletionProposalCollector proposalCollector = collect(javaProject, cu, codeSnippet, offset);
+ if (proposalCollector != null) {
+ Point selection = viewer.getSelectedRange();
+ if (selection.y > 0)
+ proposalCollector.setReplacementLength(selection.y);
+ IJavaCompletionProposal javaProposals[] = proposalCollector.getJavaCompletionProposals();
+ IJavaCompletionProposal keywordsProposals[] = proposalCollector.getKeywordCompletionProposals();
+ IJavaCompletionProposal unsortedJavaProposals[] = new IJavaCompletionProposal[javaProposals.length
+ + keywordsProposals.length];
+ System.arraycopy(keywordsProposals, 0, unsortedJavaProposals, 0, keywordsProposals.length);
+ System.arraycopy(javaProposals, 0, unsortedJavaProposals, keywordsProposals.length, javaProposals.length);
+ List sortedJavaProposals = new LinkedList();
+ for (int i = 0; i < unsortedJavaProposals.length; i++) {
+ IJavaCompletionProposal unsortedJavaProposal = unsortedJavaProposals[i];
+ int index = 0;
+ for (Iterator iterator = sortedJavaProposals.iterator(); iterator.hasNext();) {
+ IJavaCompletionProposal proposal = (IJavaCompletionProposal) iterator.next();
+ if (proposal.getRelevance() <= unsortedJavaProposal.getRelevance()) {
+ index = sortedJavaProposals.indexOf(proposal);
+ break;
+ }
+ }
+
+ sortedJavaProposals.add(index, unsortedJavaProposal);
+ }
+
+ IJavaCompletionProposal results[] = new IJavaCompletionProposal[sortedJavaProposals.size()];
+ sortedJavaProposals.toArray(results);
+ return results;
+ } else {
+ return new IJavaCompletionProposal[0];
+ }
+ }
+
+ public static void adjustResults(IJavaCompletionProposal results[], int offset) {
+ for (int i = 0; i < results.length; i++)
+ if (results[i] instanceof AbstractJavaCompletionProposal) {
+ AbstractJavaCompletionProposal proposal = (AbstractJavaCompletionProposal) results[i];
+ proposal.setReplacementOffset(offset);
+ }
+
+ }
+
+ public static String makeJavaClassName(String name) {
+ StringBuffer result = new StringBuffer("_jet_");
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ if (Character.isJavaIdentifierPart(c))
+ result.append(c);
+ }
+ return result.toString();
+ }
+} \ No newline at end of file