summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-04-04 10:59:40 (EDT)
committerpelder2007-04-04 10:59:40 (EDT)
commit115966a43c9f71738ba2e952e0f42ce2051cd24f (patch)
tree03b461c5daf4d26221a24e26796adfe791674fba
parent94732f3ff6590dd893f5a896ad34b804e012b928 (diff)
downloadorg.eclipse.jet-115966a43c9f71738ba2e952e0f42ce2051cd24f.zip
org.eclipse.jet-115966a43c9f71738ba2e952e0f42ce2051cd24f.tar.gz
org.eclipse.jet-115966a43c9f71738ba2e952e0f42ce2051cd24f.tar.bz2
[180962,131208] add JET1 compilation, move some elements to org.eclipse.jet.core
-rw-r--r--plugins/org.eclipse.jet-feature/feature.xml7
-rw-r--r--plugins/org.eclipse.jet.ui/.classpath2
-rw-r--r--plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--plugins/org.eclipse.jet.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/Messages.java24
-rw-r--r--plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/messages.properties16
-rw-r--r--plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/CompilePreferencePage.java186
-rw-r--r--plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/JETPreferencePage.java2
-rw-r--r--plugins/org.eclipse.jet/.classpath4
-rw-r--r--plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--plugins/org.eclipse.jet/.settings/org.eclipse.jdt.ui.prefs4
-rw-r--r--plugins/org.eclipse.jet/META-INF/MANIFEST.MF10
-rw-r--r--plugins/org.eclipse.jet/about.html114
-rw-r--r--plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java12
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/AbstractContextExtender.java64
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java90
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java43
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java50
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java486
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java174
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Template.java35
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoader.java36
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java38
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java206
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/WriterPositionException.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java677
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/BodyElements.java170
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Comment.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/CompileOptionsManager.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/DefaultJET2ASTVisitor.java1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/IJETCompilerState.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2AST.java197
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTElement.java115
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTVisitor.java6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java249
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java546
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Declaration.java23
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Directive.java45
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Expression.java24
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Scriptlet.java24
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JavaElement.java33
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java182
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java132
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagValidationVisitor.java163
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TemplatePathUtil.java70
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TextElement.java79
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElement.java76
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElementEnd.java38
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLElement.java63
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLEmptyElement.java27
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JETPreferenceInitializer.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java81
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/JET2Builder.java353
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java333
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java87
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java90
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerStateManager.java75
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java72
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java63
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/GenXMLElement.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java253
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SimplifiedCompiler.java540
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TagUsageVisitor.java79
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TemplateRunner.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TextTrimmingVisitor.java175
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java120
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java176
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java91
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java206
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TagLibraryImpl.java15
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETProcess.java5
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamMonitor.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamsProxy.java1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETCoreElement.java34
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETMark.java277
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java40
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java631
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java766
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/ParseProblemSeverity.java29
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateInput.java92
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateResolverHelper.java54
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverBuilder.java76
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverHelperFactory.java84
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/CustomTagFactory.java37
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2TemplateStatus.java86
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java107
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java77
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeContainerRuntimeTag.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeFunctionRuntimeTag.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TagFactoryImpl.java61
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java81
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/JETTemplateModelLoader.java28
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java8
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagDefinitionImpl.java139
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagLibraryImpl.java14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java96
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java72
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java30
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java13
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java102
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java42
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/CustomTagKind.java69
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/JET2TagException.java70
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java59
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/RuntimeTagElement.java96
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagAttributeDefinition.java76
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagDefinition.java130
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagFactory.java33
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagInfo.java152
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibrary.java82
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java48
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java99
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java40
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java23
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java5
-rw-r--r--plugins/org.eclipse.jet/templates/v1/jet2java.jet79
-rw-r--r--plugins/org.eclipse.jet/templates/v2/jet2java.jet160
-rw-r--r--tests/org.eclipse.jet.tests-feature/feature.xml7
-rw-r--r--tests/org.eclipse.jet.tests/.classpath2
-rw-r--r--tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF1
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/changedTemplates/simple.v2.input.jet11
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet10
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java125
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input2.jet10
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java80
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat1
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat21
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat31
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat41
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet3
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java23
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java43
-rw-r--r--tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.astdump.expected41
-rw-r--r--tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.expected.java114
-rw-r--r--tests/org.eclipse.jet.tests/data/taglibs.jet.expected.java6
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java66
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java49
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java428
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TextTrimmingTests.java111
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java6
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java6
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/UuidTagTests.java10
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java13
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java4
-rw-r--r--transforms/org.eclipse.jet.transforms.newproject/.classpath3
-rw-r--r--transforms/org.eclipse.jet.transforms.newproject/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--transforms/org.eclipse.jet.transforms.newproject/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--transforms/org.eclipse.jet.transforms.newproject/META-INF/MANIFEST.MF2
-rw-r--r--transforms/org.eclipse.jet.transforms.taglibdoc/.classpath3
-rw-r--r--transforms/org.eclipse.jet.transforms.taglibdoc/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--transforms/org.eclipse.jet.transforms.taglibdoc/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--transforms/org.eclipse.jet.transforms.taglibdoc/META-INF/MANIFEST.MF1
163 files changed, 5303 insertions, 7756 deletions
diff --git a/plugins/org.eclipse.jet-feature/feature.xml b/plugins/org.eclipse.jet-feature/feature.xml
index 88cb14f..b5bc234 100644
--- a/plugins/org.eclipse.jet-feature/feature.xml
+++ b/plugins/org.eclipse.jet-feature/feature.xml
@@ -54,4 +54,11 @@
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.eclipse.jet.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
diff --git a/plugins/org.eclipse.jet.ui/.classpath b/plugins/org.eclipse.jet.ui/.classpath
index 751c8f2..ce73933 100644
--- a/plugins/org.eclipse.jet.ui/.classpath
+++ b/plugins/org.eclipse.jet.ui/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..c946a8c
--- /dev/null
+++ b/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Tue Apr 03 15:25:50 EDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..ab97989
--- /dev/null
+++ b/plugins/org.eclipse.jet.ui/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Tue Apr 03 15:14:26 EDT 2007
+eclipse.preferences.version=1
+internal.default.compliance=user
diff --git a/plugins/org.eclipse.jet.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet.ui/META-INF/MANIFEST.MF
index 5e1a380..986dc3d 100644
--- a/plugins/org.eclipse.jet.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet.ui/META-INF/MANIFEST.MF
@@ -14,7 +14,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)"
-Eclipse-AutoStart: true
+Eclipse-LazyStart: true
Export-Package: org.eclipse.jet.internal.ui.filters;x-internal:=true,
org.eclipse.jet.internal.ui.l10n;x-internal:=true,
org.eclipse.jet.internal.ui.launch;x-internal:=true,
@@ -22,3 +22,4 @@ Export-Package: org.eclipse.jet.internal.ui.filters;x-internal:=true,
org.eclipse.jet.internal.ui.prefs;x-internal:=true,
org.eclipse.jet.ui,
org.eclipse.jet.ui.newproject
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/Messages.java b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/Messages.java
index 3560121..7e3b28f 100644
--- a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/Messages.java
+++ b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/Messages.java
@@ -13,6 +13,12 @@ public class Messages extends NLS {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
+ public static String CompilePreferencePage_BaseLocationsLabel;
+
+ public static String CompilePreferencePage_CompileBaseTemplates;
+
+ public static String CompilePreferencePage_DependenciesGroupLabel;
+
public static String CompilePreferencePage_DeriveJavaFiles;
public static String CompilePreferencePage_Description;
@@ -21,10 +27,28 @@ public class Messages extends NLS {
public static String CompilePreferencePage_FileExtensions;
+ public static String CompilePreferencePage_InvalidBaseLocations;
+
+ public static String CompilePreferencePage_JavaGenerationGroupLabel;
+
public static String CompilePreferencePage_JavaPackage;
+ public static String CompilePreferencePage_JET1_OPTION;
+
+ public static String CompilePreferencePage_JET1OptionsGroupLabel;
+
+ public static String CompilePreferencePage_JET2_Option;
+
+ public static String CompilePreferencePage_JET2_OPTIONS_GROUP_LABEL;
+
+ public static String CompilePreferencePage_JETComformanceGroupLabel;
+
+ public static String CompilePreferencePage_OverrideTemplatesOption;
+
public static String CompilePreferencePage_SourceFolder;
+ public static String CompilePreferencePage_TemplatesDirLabel;
+
public static String ExtensionListEditor_AddDialogErrorMsg;
public static String ExtensionListEditor_AddDialogPrompt;
diff --git a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/messages.properties b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/messages.properties
index 31e618b..8552f49 100644
--- a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/messages.properties
+++ b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/l10n/messages.properties
@@ -42,10 +42,22 @@ JETTransformMainTab_TraceSeverity=trace
JETTransformMainTab_BrowseButtonLabel=&Browse...
CompilePreferencePage_Description=JET Compiler options
CompilePreferencePage_EnableProjectSettings=&Enable Project specific settings
-CompilePreferencePage_JavaPackage=&Package for generated Java classes:
+CompilePreferencePage_JETComformanceGroupLabel=Generate Method Conformance
+CompilePreferencePage_JET2_OPTIONS_GROUP_LABEL=JET2 Options
+CompilePreferencePage_JET1OptionsGroupLabel=JET1 Options
+CompilePreferencePage_JavaGenerationGroupLabel=Java Generation Options
+CompilePreferencePage_InvalidBaseLocations=Base locations must be a comma seperated lists of URIs
+CompilePreferencePage_DependenciesGroupLabel=Dependencies (JET1 only)
+CompilePreferencePage_OverrideTemplatesOption=&Override templates from a base plug-in
+CompilePreferencePage_CompileBaseTemplates=&Compile all base templates to Java classes in this project
+CompilePreferencePage_JavaPackage=Default Java &Package:
+CompilePreferencePage_JET1_OPTION=JET&1 - String generate(Object argument)
+CompilePreferencePage_JET2_Option=JET&2 - void generate(JET2Context context, JET2Writer out)
CompilePreferencePage_FileExtensions=&File extensions for templates:
-CompilePreferencePage_SourceFolder=&Source folder for generated Java classes:
+CompilePreferencePage_SourceFolder=Java &Source folder:
CompilePreferencePage_DeriveJavaFiles=&Hide compiled Java from Team system (mark .java files derived)
+CompilePreferencePage_BaseLocationsLabel=&Base Location URIs (comma separated):
+CompilePreferencePage_TemplatesDirLabel=Templates directory
ExtensionListEditor_AddDialogTitle=Add extension
ExtensionListEditor_AddDialogPrompt=Enter an extension
ExtensionListEditor_AddDialogErrorMsg=Extension must be a sequence of letters and/or digits
diff --git a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/CompilePreferencePage.java b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/CompilePreferencePage.java
index 0bcecdf..3bc916c 100644
--- a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/CompilePreferencePage.java
+++ b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/CompilePreferencePage.java
@@ -17,6 +17,9 @@
package org.eclipse.jet.internal.ui.prefs;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ProjectScope;
@@ -25,14 +28,22 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.compiler.JET2Compiler;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.core.parser.ast.JETAST;
import org.eclipse.jet.internal.JETPreferences;
import org.eclipse.jet.internal.ui.l10n.Messages;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbenchPropertyPage;
@@ -49,15 +60,23 @@ public class CompilePreferencePage extends FieldEditorPreferencePage implements
private StringFieldEditor packageFieldEditor;
private ExtensionListEditor extFieldEditor;
private StringFieldEditor srcFolderFieldEditor;
+ private StringFieldEditor templatesFolderFieldEditor;
private BooleanFieldEditor derivedJavaFieldEditor;
private BooleanFieldEditor projectSpecificSettingsEditor = null;
+ private RadioGroupFieldEditor jetVersionFieldEditor;
+ private BooleanFieldEditor compileBaseTemplatesFieldEditor = null;
+ private StringFieldEditor baseTransformationFieldEditor = null;
+ private Composite javaGenerationGroup;
+ private Composite v1OptionsGroup;
+ private Composite v2OptionsGroup;
+ private boolean v1OptionsEnabled;
/**
* @param style
*/
public CompilePreferencePage() {
super(GRID);
- setDescription(Messages.CompilePreferencePage_Description);
+// setDescription(Messages.CompilePreferencePage_Description);
}
/* (non-Javadoc)
@@ -65,49 +84,165 @@ public class CompilePreferencePage extends FieldEditorPreferencePage implements
*/
protected void createFieldEditors() {
- if(element == null) {
- setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), JET2Platform.PLUGIN_ID));
- } else {
+ // determine whether the page is showing the workspace scope (Windows > Preferences)
+ // or in project scope (Project properties)
+ final boolean projectSettings = element != null;
+ if(projectSettings) {
setPreferenceStore(new ScopedPreferenceStore(new ProjectScope(element), JET2Platform.PLUGIN_ID));
+ } else {
+ setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), JET2Platform.PLUGIN_ID));
+ }
+
+ if(projectSettings) {
+ // add a check box to use project specific settings
projectSpecificSettingsEditor = new BooleanFieldEditor(JETPreferences.PROJECT_SPECIFIC_SETTINGS,
Messages.CompilePreferencePage_EnableProjectSettings, getFieldEditorParent());
addField(projectSpecificSettingsEditor);
+ Label horizontalLine= new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
+ horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
+ horizontalLine.setFont(getFieldEditorParent().getFont());
}
+ // create "global" option editors...
+ jetVersionFieldEditor = new RadioGroupFieldEditor(JETCompilerOptions.OPTION_JET_SPECIFICATION_VERSION, Messages.CompilePreferencePage_JETComformanceGroupLabel, 1,
+ new String[][] {
+ {Messages.CompilePreferencePage_JET1_OPTION, String.valueOf(JETAST.JET_SPEC_V1)},
+ {Messages.CompilePreferencePage_JET2_Option, String.valueOf(JETAST.JET_SPEC_V2)},
+ },
+ getFieldEditorParent(), true);
+ addField(jetVersionFieldEditor);
+
+ v1OptionsEnabled = getPreferenceStore().getInt(JETCompilerOptions.OPTION_JET_SPECIFICATION_VERSION) == JETAST.JET_SPEC_V1;
- packageFieldEditor = new StringFieldEditor(JET2Compiler.OPTION_COMPILED_TEMPLATE_PACKAGE,
- Messages.CompilePreferencePage_JavaPackage, getFieldEditorParent());
- addField(packageFieldEditor);
- extFieldEditor = new ExtensionListEditor(JET2Compiler.OPTION_TEMPLATE_EXT,
- Messages.CompilePreferencePage_FileExtensions, getFieldEditorParent());
- addField(extFieldEditor);
- srcFolderFieldEditor = new StringFieldEditor(JET2Compiler.OPTION_COMPILED_TEMPLATE_SRC_DIR,
- Messages.CompilePreferencePage_SourceFolder, getFieldEditorParent());
+ // common generation group
+ javaGenerationGroup = createGroup(Messages.CompilePreferencePage_JavaGenerationGroupLabel);
+
+ srcFolderFieldEditor = new StringFieldEditor(JETCompilerOptions.OPTION_COMPILED_TEMPLATE_SRC_DIR,
+ Messages.CompilePreferencePage_SourceFolder, javaGenerationGroup);
addField(srcFolderFieldEditor);
- derivedJavaFieldEditor = new BooleanFieldEditor(JET2Compiler.OPTION_SET_JAVA_FILES_AS_DERIVED,
- Messages.CompilePreferencePage_DeriveJavaFiles, getFieldEditorParent());
+ derivedJavaFieldEditor = new BooleanFieldEditor(JETCompilerOptions.OPTION_SET_JAVA_FILES_AS_DERIVED,
+ Messages.CompilePreferencePage_DeriveJavaFiles, javaGenerationGroup);
addField(derivedJavaFieldEditor);
+ // v1 options group
+ v1OptionsGroup = createGroup(Messages.CompilePreferencePage_JET1OptionsGroupLabel);
+ templatesFolderFieldEditor = new StringFieldEditor(JETCompilerOptions.OPTION_V1_TEMPLATES_DIR,
+ Messages.CompilePreferencePage_TemplatesDirLabel, v1OptionsGroup);
+ addField(templatesFolderFieldEditor);
+ if(projectSettings) {
+ baseTransformationFieldEditor = new StringFieldEditor(JETCompilerOptions.OPTION_V1_BASE_TRANSFORMATION,
+ Messages.CompilePreferencePage_BaseLocationsLabel,
+ StringFieldEditor.UNLIMITED,
+ StringFieldEditor.VALIDATE_ON_KEY_STROKE,
+ v1OptionsGroup) {
+ protected boolean doCheckState() {
+ String trimmedValue = getStringValue().trim();
+ return trimmedValue.length() == 0 || isValidURIList(trimmedValue);
+ }
+
+ };
+ baseTransformationFieldEditor.setErrorMessage(Messages.CompilePreferencePage_InvalidBaseLocations);
+ addField(baseTransformationFieldEditor);
+
+ compileBaseTemplatesFieldEditor = new BooleanFieldEditor(JETCompilerOptions.OPTION_V1_COMPILE_BASE_TEMPLATES, Messages.CompilePreferencePage_CompileBaseTemplates, v1OptionsGroup);
+ addField(compileBaseTemplatesFieldEditor);
+ }
+
+ // v2 options group
+ v2OptionsGroup = createGroup(Messages.CompilePreferencePage_JET2_OPTIONS_GROUP_LABEL);
+
+ extFieldEditor = new ExtensionListEditor(JETCompilerOptions.OPTION_TEMPLATE_EXT,
+ Messages.CompilePreferencePage_FileExtensions, v2OptionsGroup);
+ addField(extFieldEditor);
+
+ packageFieldEditor = new StringFieldEditor(JETCompilerOptions.OPTION_COMPILED_TEMPLATE_PACKAGE,
+ Messages.CompilePreferencePage_JavaPackage, v2OptionsGroup);
+ addField(packageFieldEditor);
+
+
+ }
+
+ private boolean isValidURIList(String uriList) {
+ String[] uriStrings = uriList.split(","); //$NON-NLS-1$
+ boolean ok = true;
+ for (int i = 0; i < uriStrings.length; i++) {
+ try {
+ new URI(uriStrings[i]);
+ } catch (URISyntaxException e) {
+ ok = false;
+ }
+ }
+ return ok;
+ }
+
+ /**
+ * @param groupTitle
+ * @return
+ */
+ private Composite createGroup(final String groupTitle) {
+
+ final Group group = new Group(getFieldEditorParent(), SWT.NONE);
+ group.setFont(getFieldEditorParent().getFont());
+ group.setText(groupTitle);
+ group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
+ setGroupLayout(group, 2);
+
+ return group;
+ }
+
+ /**
+ * @param group
+ * @param numColumns TODO
+ */
+ private void setGroupLayout(final Composite group, int numColumns) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = numColumns;
+ group.setLayout(layout);
}
/**
*
*/
private void updateControlEnablement() {
- boolean enabled = projectSpecificSettingsEditor.getBooleanValue();
- packageFieldEditor.setEnabled(enabled, getFieldEditorParent());
- extFieldEditor.setEnabled(enabled, getFieldEditorParent());
- srcFolderFieldEditor.setEnabled(enabled, getFieldEditorParent());
- derivedJavaFieldEditor.setEnabled(enabled, getFieldEditorParent());
- if(!enabled) {
- packageFieldEditor.loadDefault();
- extFieldEditor.loadDefault();
+ final boolean projectSettings = projectSpecificSettingsEditor != null;
+ // enable "global" options
+ boolean enabledGlobalSettings = !projectSettings || projectSpecificSettingsEditor.getBooleanValue();
+ jetVersionFieldEditor.setEnabled(enabledGlobalSettings, getFieldEditorParent());
+ srcFolderFieldEditor.setEnabled(enabledGlobalSettings, javaGenerationGroup);
+ derivedJavaFieldEditor.setEnabled(enabledGlobalSettings, javaGenerationGroup);
+ if(!enabledGlobalSettings) {
srcFolderFieldEditor.loadDefault();
derivedJavaFieldEditor.loadDefault();
+ jetVersionFieldEditor.loadDefault();
+ }
+
+ // Enable JET1 options
+ if(projectSettings) {
+ boolean enableV1Options = v1OptionsEnabled && enabledGlobalSettings;
+ baseTransformationFieldEditor.setEnabled(enableV1Options, v1OptionsGroup);
+ compileBaseTemplatesFieldEditor.setEnabled(enableV1Options, v1OptionsGroup);
+ templatesFolderFieldEditor.setEnabled(enableV1Options, v1OptionsGroup);
+ if(!enableV1Options) {
+ baseTransformationFieldEditor.loadDefault();
+ compileBaseTemplatesFieldEditor.loadDefault();
+ templatesFolderFieldEditor.loadDefault();
+ }
}
+
+ // Enable JET2 options
+ if(projectSettings) {
+ boolean enableV2Options = !v1OptionsEnabled && enabledGlobalSettings;
+ extFieldEditor.setEnabled(enableV2Options, v2OptionsGroup);
+ packageFieldEditor.setEnabled(enableV2Options, v2OptionsGroup);
+ if(!enableV2Options) {
+ extFieldEditor.loadDefault();
+ packageFieldEditor.loadDefault();
+ }
+ }
+
}
/* (non-Javadoc)
@@ -136,7 +271,10 @@ public class CompilePreferencePage extends FieldEditorPreferencePage implements
super.propertyChange(event);
if(event.getSource() == projectSpecificSettingsEditor && FieldEditor.VALUE.equals(event.getProperty())) {
updateControlEnablement();
- }
+ } else if(event.getSource() == jetVersionFieldEditor && FieldEditor.VALUE.equals(event.getProperty())) {
+ v1OptionsEnabled = String.valueOf(JETAST.JET_SPEC_V1).equals(event.getNewValue());
+ updateControlEnablement();
+ }
}
protected void performDefaults() {
diff --git a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/JETPreferencePage.java b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/JETPreferencePage.java
index c4b24cc..fc31f9e 100644
--- a/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/JETPreferencePage.java
+++ b/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/internal/ui/prefs/JETPreferencePage.java
@@ -46,7 +46,7 @@ public class JETPreferencePage extends FieldEditorPreferencePage implements
public JETPreferencePage() {
super(GRID);
- setDescription(Messages.JETPreferencePage_Description);
+// setDescription(Messages.JETPreferencePage_Description);
}
/* (non-Javadoc)
diff --git a/plugins/org.eclipse.jet/.classpath b/plugins/org.eclipse.jet/.classpath
index f5a1d79..bd5f894 100644
--- a/plugins/org.eclipse.jet/.classpath
+++ b/plugins/org.eclipse.jet/.classpath
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry output="antbin" kind="src" path="antsrc"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" output="antbin" path="antsrc"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs
index 4b4a80c..acdefad 100644
--- a/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,15 @@
-#Mon Apr 03 09:49:33 EDT 2006
+#Tue Apr 03 15:34:23 EDT 2007
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.4
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=52
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.ui.prefs
index b841e07..7009eef 100644
--- a/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.ui.prefs
@@ -1,6 +1,6 @@
-#Thu May 11 14:07:55 EDT 2006
+#Tue Apr 03 14:51:48 EDT 2007
eclipse.preferences.version=1
formatter_profile=_EMFCodeFormatter.profile
formatter_settings_version=10
-internal.default.compliance=default
+internal.default.compliance=user
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author ${user}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/**\r\n * &lt;copyright&gt;\r\n *\r\n * Copyright (c) ${year} IBM Corporation and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\: \r\n * IBM - Initial API and implementation\r\n *\r\n * &lt;/copyright&gt;\r\n *\r\n * $$Id$$\r\n */\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
diff --git a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
index b9cce3a..330838e 100644
--- a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
@@ -9,8 +9,8 @@ Require-Bundle: org.eclipse.ant.core;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)",
org.eclipse.emf.common;bundle-version="[2.2.0,3.0.0)";visibility:=reexport,
+ org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)",
org.eclipse.emf.ecore;bundle-version="[2.2.0,3.0.0)",
org.eclipse.emf.ecore.xmi;bundle-version="[2.2.0,3.0.0)",
org.eclipse.text;bundle-version="[3.2.0,4.0.0)";visibility:=reexport,
@@ -18,8 +18,9 @@ Require-Bundle: org.eclipse.ant.core;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.filebuffers;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)",
org.apache.ant;bundle-version="[1.6.5,2.0.0)",
- org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional
-Eclipse-AutoStart: true
+ org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
+ org.eclipse.jet.core;bundle-version="[1.0.0,2.0.0)";visibility:=reexport
+Eclipse-LazyStart: true
Export-Package: org.eclipse.jet,
org.eclipse.jet.compiler,
org.eclipse.jet.internal;x-friends:="org.eclipse.jet.tests,org.eclipse.jet.ui",
@@ -27,7 +28,7 @@ Export-Package: org.eclipse.jet,
org.eclipse.jet.internal.compiler;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.compiler.templates;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.exceptions;x-friends:="org.eclipse.jet.tests",
- org.eclipse.jet.internal.extensionpoints;x-internal:=true,
+ org.eclipse.jet.internal.extensionpoints;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.l10n;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.launch;x-friends:="org.eclipse.jet.tests,org.eclipse.jet.ui",
org.eclipse.jet.internal.parser;x-friends:="org.eclipse.jet.tests",
@@ -52,3 +53,4 @@ Export-Package: org.eclipse.jet,
org.eclipse.jet.xpath,
org.eclipse.jet.xpath.inspector
Bundle-Vendor: %providerName
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/plugins/org.eclipse.jet/about.html b/plugins/org.eclipse.jet/about.html
index cc95c66..12a49f1 100644
--- a/plugins/org.eclipse.jet/about.html
+++ b/plugins/org.eclipse.jet/about.html
@@ -1,86 +1,28 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
-<title>About</title>
-</head>
-<body lang="EN-US">
-<h2>About This Content</h2>
-
-<p>May 2, 2006</p>
-<h3>License</h3>
-
-<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
-indicated below, the Content is provided to you under the terms and conditions of the
-Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
-at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
-For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
-
-<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
-being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
-apply to your use of any object code in the Content. Check the Redistributor's license that was
-provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
-indicated below, the terms and conditions of the EPL still apply to any source code in the Content
-and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
-
-
- <h3>Third Party Content</h3>
- <p>The Content includes items that have been sourced from third parties as set out below. If you
- did not receive this Content directly from the Eclipse Foundation, the following is provided
- for informational purposes only, and you should look to the Redistributor's license for
- terms and conditions of use.</p>
-
-<p><b>Tomcat 3.2.4</b></p>
-<p>The plug-in is based on software developed by The Apache Software Foundation as part of the Jakarta project.</p>
-
-<p>The content in the org.eclipse.jet package (&quot;JET&quot;) is based on code in the org.apache.jasper.compiler package of Tomcat.</p>
-
-<p>The JET binary code can be found in the plug-in JAR in the org\eclipse\jet directory.</p>
-
-<p>The JET source code can be found in src.zip in the the org\eclipse\jet directory.</p>
-
-<p>JET is:</p>
-
-<blockquote>Copyright (c) 1999 The Apache Software Foundation. All rights reserved.</blockquote>
-
-<p>Your use of JET is subject to the terms and conditions of the
-<a href="http://jakarta.apache.org/ant/manual/LICENSE">Apache Software License 1.1</a>.
-More specifically:</p>
-<blockquote>
- 1. Redistributions of source code must retain the above copyright notice, this list of<br />
- conditions and the following disclaimer.<br />
-<br />
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of<br />
- conditions and the following disclaimer in the documentation and/or other materials<br />
- provided with the distribution.<br />
-<br />
- 3. The end-user documentation included with the redistribution, if any, must include the<br />
- following acknowledgment:<br />
- <blockquote>
- &quot;This product includes software developed by the Apache Software Foundation<br />
- (<a href="http://www.apache.org/">http://www.apache.org/</a>).&quot;
- </blockquote>
- Alternately, this acknowledgment may appear in the software itself, if and wherever such<br />
- third-party acknowledgments normally appear.<br />
-<br />
- 4. The names &quot;The Jarkara Project&quot;, &quot;Tomcat&quot; and &quot;Apache Software Foundation&quot; must not be used to endorse or<br />
- promote products derived from this software without prior written permission. For written<br />
- permission, please contact <a href="mailto:apache@apache.org">apache@apache.org</a>.<br />
-<br />
- 5. Products derived from this software may not be called &quot;Apache&quot;, nor may &quot;Apache&quot; appear<br />
- in their name, without prior written permission of the Apache Software Foundation.<br />
-<br />
- THIS SOFTWARE IS PROVIDED &quot;AS IS&quot; AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br />
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br />
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS<br />
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br />
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR<br />
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON<br />
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<br />
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF<br />
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-</blockquote>
-
-</body>
-</html> \ No newline at end of file
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>May 2, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java
index b212396..42ae0b1 100644
--- a/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java
+++ b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java
@@ -32,7 +32,9 @@ import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jet.compiler.JET2Compiler;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.internal.builder.WorkspaceCompiler;
+import org.eclipse.jet.internal.core.compiler.IJETCompiler;
/**
* Implement the jet.compile tag.
@@ -78,19 +80,19 @@ public class JETCompileTask extends Task {
validate();
IProgressMonitor monitor =
(IProgressMonitor) getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
- jetBuildProperties.put(JET2Compiler.OPTION_COMPILED_TEMPLATE_SRC_DIR, destdir);
+ jetBuildProperties.put(JETCompilerOptions.OPTION_COMPILED_TEMPLATE_SRC_DIR, destdir);
log("destdir: " + destdir);
- JET2Compiler compiler = new JET2Compiler(eclipseProject, monitor, jetBuildProperties);
+ IJETCompiler compiler = new WorkspaceCompiler(eclipseProject, null, monitor);
for (Iterator i = srcFilesets.iterator(); i.hasNext();) {
FileSet fileset = (FileSet) i.next();
final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
final String[] includedFiles = ds.getIncludedFiles();
for (int j = 0; j < includedFiles.length; j++) {
log("Compiling: " + includedFiles[j], Project.MSG_INFO);
- compiler.compile(eclipseProject.getFile(includedFiles[j]));
+ compiler.compile(includedFiles[j]);
}
}
- compiler.createTransformFiles();
+ compiler.finish();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/AbstractContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/AbstractContextExtender.java
deleted file mode 100644
index 8503284..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/AbstractContextExtender.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet;
-
-
-/**
- * A base class for extending the JET2 context.
- *
- */
-public abstract class AbstractContextExtender
-{
-
- private final JET2Context baseContext;
-
- /**
- *
- */
- protected AbstractContextExtender(JET2Context context)
- {
- super();
- this.baseContext = context;
- if (!context.hasContextExtender(this.getClass()))
- {
- context.registerContextExtender(this.getClass(), createExtendedData(context));
- }
- }
-
- /**
- * Called by the AbstractContextExtender constructor if the extender's data
- * has not yet been created in the context.
- * @param context the context in which the data will be created.
- * @return the extension data object.
- */
- protected abstract Object createExtendedData(JET2Context context);
-
- protected Object getExtendedData()
- {
- return baseContext.getContextExtenderData(this.getClass());
- }
-
- /**
- * Return the JET2Context that this extender instance is extending.
- * @return the hosting context.
- */
- public final JET2Context getContext()
- {
- return baseContext;
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
index 530be94..ea57f34 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
@@ -19,12 +19,10 @@ package org.eclipse.jet;
import java.util.Collections;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jface.text.AbstractDocument;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
@@ -36,10 +34,11 @@ import org.eclipse.jface.text.Position;
/**
- * Standard implementation of JET2Writer
+ * Standard implementation of BufferedJET2Writer that uses on {@link IDocument}
+ * as its buffer.
*
*/
-public class BodyContentWriter implements JET2Writer
+public class BodyContentWriter implements BufferedJET2Writer
{
/**
@@ -154,12 +153,16 @@ public class BodyContentWriter implements JET2Writer
*/
public final void write(JET2Writer bodyContent)
{
+ if(!(bodyContent instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)bodyContent;
int positionDelta = document.getLength();
- write(bodyContent.toString());
+ write(bufferedWriter.getContent());
try
{
// transfer position categories, position updaters and positions
- IDocument childDocument = bodyContent.getDocument();
+ IDocument childDocument = (IDocument)bufferedWriter.getAdapter(IDocument.class);
// Position updaters should not be copied, instead, they will be added as part of adding
// any new categories.
@@ -167,7 +170,7 @@ public class BodyContentWriter implements JET2Writer
for (int i = 0; i < categories.length; i++)
{
// ensure 'document' has the category - no harm in doing this if the category is already there
- addPositionCategory(categories[i]);
+ document.addPositionCategory(categories[i]);
Position[] positions = childDocument.getPositions(categories[i]);
for (int j = 0; j < positions.length; j++)
{
@@ -214,7 +217,7 @@ public class BodyContentWriter implements JET2Writer
public final int getLength()
{
- return document.getLength();
+ return getContentLength();
}
public final IDocument getDocument()
@@ -234,24 +237,6 @@ public class BodyContentWriter implements JET2Writer
}
}
- public final void finalizeContent(Object file) throws JET2TagException
- {
- for (Iterator i = listeners.values().iterator(); i.hasNext();)
- {
- IWriterListener listener = (IWriterListener)i.next();
- listener.finalizeContent(this, file);
- }
- }
-
- public final void contentCommitted(Object committedObject) throws JET2TagException
- {
- for (Iterator i = listeners.values().iterator(); i.hasNext();)
- {
- IWriterListener listener = (IWriterListener)i.next();
- listener.postCommitContent(this, committedObject);
- }
- }
-
public final void addPositionCategory(String category)
{
if (!document.containsPositionCategory(category))
@@ -342,4 +327,57 @@ public class BodyContentWriter implements JET2Writer
write(obj != null ? obj.toString() : ""); //$NON-NLS-1$
}
+
+ public String getContent()
+ {
+ return document.get();
+ }
+
+
+ public int getContentLength()
+ {
+ return getContent().length();
+ }
+
+
+ public IWriterListener[] getEventListeners()
+ {
+ return (IWriterListener[])listeners.values().toArray(new IWriterListener[listeners.size()]);
+ }
+
+ public void replaceContent(int offset, int length, String text)
+ {
+ try {
+ document.replace(offset, length, text);
+ }
+ catch (BadLocationException e) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public void setContent(String content)
+ {
+ document.set(content);
+ }
+
+ public String getContent(int offset, int length)
+ {
+ try
+ {
+ return document.get(offset, length);
+ }
+ catch (BadLocationException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public Object getAdapter(Class adapterClass)
+ {
+ if(adapterClass == IDocument.class) {
+ return document;
+ }
+ return null;
+ }
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java
index b772671..d187fc4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java
@@ -16,10 +16,8 @@
*/
package org.eclipse.jet;
-import org.eclipse.emf.common.util.Diagnostic;
-
/**
- * An exception that represents
+ * Represents an exception in the core JET engine
*/
public class CoreJETException extends Exception
{
@@ -27,22 +25,43 @@ public class CoreJETException extends Exception
/**
*
*/
+ public CoreJETException()
+ {
+ super();
+ }
+
+ /**
+ * Create an exception wrapping another exception
+ * @param cause the root cause of the exception
+ */
+ public CoreJETException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ *
+ */
private static final long serialVersionUID = -3547604779390116089L;
- private final Diagnostic diagnostic;
- public CoreJETException(Diagnostic diagnostic)
+ /**
+ * Create a CoreJETException
+ * @param msg the exception message
+ */
+ public CoreJETException(String msg)
{
- super(diagnostic.getMessage());
- this.diagnostic = diagnostic;
-
+ super(msg);
}
/**
- * @return Returns the diagnostic.
+ * Create a CoreJETException
+ * @param message the execution message
+ * @param cause the root cause of the exception
*/
- public final Diagnostic getDiagnostic()
+ public CoreJETException(String message, Throwable cause)
{
- return diagnostic;
+ super(message, cause);
}
-
+
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java
deleted file mode 100644
index acfba20..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet;
-
-import org.eclipse.jet.taglib.JET2TagException;
-
-
-/**
- * Callback interface allowing participation in the finalization of a {@link JET2Writer}'s content.
- *
- */
-public interface IWriterListener
-{
-
- /**
- * Perform any finalization of the content in the writer.
- * @param writer the writer in the process of being finalized
- * @param file a handle to object to which the content will ultimately be written. The standard
- * JET2 Workspace tags pass an org.eclipse.core.resources.IFile, but other tags may pass objects
- * of other types.
- * @throws JET2TagException if the method cannot complete normally
- */
- public abstract void finalizeContent(JET2Writer writer, Object file) throws JET2TagException;
-
- /**
- * Perform any post processing on the committed file based on content written.
- * @param writer the writer that provided the committed content.
- * @param file a handle to the object containing the comitted content. The standard
- * JET2 Workspace tags pass an org.eclipse.core.resources.IFile, but other tags may pass objects
- * of other types.
- * @throws JET2TagException if method cannot complete normally.
- */
- public abstract void postCommitContent(JET2Writer writer, Object file) throws JET2TagException;
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java
deleted file mode 100644
index 5a8eb3a..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet;
-
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.runtime.JET2TemplateStatus;
-import org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtender;
-import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jet.taglib.TagFactory;
-import org.eclipse.jet.taglib.TagInfo;
-
-
-/**
- * Define the execution context for a JET2 transform or template.
- *
- */
-public final class JET2Context
-{
-
- private Object source;
-
- private BasicDiagnostic stati = new BasicDiagnostic("", Diagnostic.OK, "", null); //$NON-NLS-1$//$NON-NLS-2$
-
- private final Map extendedContextData = new HashMap();
-
- private TagFactory tagFactory = null;
-
- private final Map globalVariables = new HashMap();
-
- private String templatePath = ""; //$NON-NLS-1$
-
- private String jetBundleId;
-
- /**
- * Create a JET2 context with the specified source argument and the specified variables.
- * @param source the source object
- * @param variables A map <String,Object> of variable names to the object values.
- */
- public JET2Context(Object source, Map variables)
- {
- this.source = source;
- globalVariables.putAll(variables);
- }
-
- /**
- * Create a JET2 context with the specified source argument and no variables.
- * <p>
- * This is exactly equivalent to:
- * <pre>
- * JET2Context(source, Collections.EMPTY_MAP)
- * </pre>
- * @param source the source object
- */
- public JET2Context(Object source)
- {
- this(source, Collections.EMPTY_MAP);
- }
-
- /**
- * Set the source object for the transformation
- *
- * @param source
- */
- public void setSource(Object source)
- {
- this.source = source;
- }
-
- /**
- * Return the source object for the transformation.
- *
- * @return the source object
- */
- public Object getSource()
- {
- return source;
- }
-
- /**
- * @param severity
- * @param templatePath TODO
- * @param tagInfo
- * @param throwable
- */
- private void log(int severity, String templatePath, TagInfo tagInfo, String message, Throwable throwable)
- {
- if ((message == null || message.length() == 0) && throwable != null)
- {
- message = throwable.getLocalizedMessage();
- if (message == null || message.length() == 0)
- {
- message = throwable.toString();
- }
- }
- JET2TemplateStatus status = new JET2TemplateStatus(severity,
- getJETBundleId() != null ? getJETBundleId() : JET2Platform.PLUGIN_ID,
- message == null ? "" : message, //$NON-NLS-1$
- templatePath,
- tagInfo,
- throwable);
- stati.add(status);
- RuntimeLoggerContextExtender.log(this, message, tagInfo, templatePath, getLevel(severity));
- }
-
- private int getLevel(int severity)
- {
- switch(severity)
- {
- case Diagnostic.ERROR:
- return RuntimeLoggerContextExtender.ERROR_LEVEL;
- case Diagnostic.WARNING:
- return RuntimeLoggerContextExtender.WARNING_LEVEL;
- case Diagnostic.INFO:
- return RuntimeLoggerContextExtender.INFO_LEVEL;
- }
- return Diagnostic.ERROR;
- }
-
- /**
- * Return the id of the JET Bundle defining the current template. Used in generating
- * error messages.
- * @return the JET Bundle id, or <code>null</code> if not defined.
- * @see #setJETBundleId(String)
- */
- public String getJETBundleId()
- {
- return jetBundleId;
- }
-
- /**
- * Set the id of the JET Bundle defining the current template. Used in generating
- * error messages. If not set, then the ID of the JET plugin is used.
- * @param jetBundleId the JET Bundle ide.
- */
- public void setJETBundleId(String jetBundleId)
- {
- this.jetBundleId = jetBundleId;
-
- }
-
- // private void log(ExecutionLogEntry entry) {
- // executionLog.add(entry);
- // }
-
- /**
- * Log an informational message
- *
- * @param message
- */
- // Used once: LogTag.doFunction()
- public void logInfo(String message)
- {
- log(Diagnostic.INFO, getTemplatePath(), null, message, (Throwable)null);
- }
-
- /**
- * Return the path for the executing template. This is used in creating error messages.
- * @return the template path or <code>null</code> if no templatePath is defined.
- * @see #setTemplatePath(String)
- */
- public String getTemplatePath()
- {
- return templatePath;
- }
-
- /**
- * Set the templatePath. The templatePath is used in generating error messages.
- * @param templatePath the template path or <code>null</code> to indicate no executing template.
- */
- public void setTemplatePath(String templatePath)
- {
- this.templatePath = templatePath;
- }
- /**
- * Log a warning message
- *
- * @param message
- */
- // Used once: LogTag.doFunction()
- public void logWarning(String message)
- {
- log(Diagnostic.WARNING, getTemplatePath(), null, message, (Throwable)null);
- }
-
- /**
- * Log an error message
- *
- * @param message
- */
- // Used once: LogTag.doFunction()
- public void logError(String message)
- {
- log(Diagnostic.ERROR, getTemplatePath(), null, message, null);
- }
-
- /**
- * Log an exeception that occurred during execution
- *
- * @param e
- */
- // Used once: TransformContextExtender.commit()
- public void logError(Throwable e)
- {
- log(Diagnostic.ERROR, getTemplatePath(), null, null, e);
- }
-
- /**
- * Log an exception that occured during execution, along with a message.
- *
- * @param message
- * @param e
- * @deprecated Please don't use, will be removed...
- */
- // Never used!
- public void logError(String message, Throwable e)
- {
- log(Diagnostic.ERROR, getTemplatePath(), null, message, e);
- }
-
- /**
- * Return all logged messages for the transformation as a multi-status
- * IStatus object.
- *
- * @return the transformation log, as an IStatus
- */
-// public IStatus getLogAsMultiStatus()
- public Diagnostic getLogAsMultiStatus()
- {
- String message = ""; //$NON-NLS-1$
-
- int worstSeverity = stati.recomputeSeverity();;
- if (worstSeverity == Diagnostic.OK)
- {
- message = JET2Messages.JET2Context_SuccessfulExecution;
- }
- else if (worstSeverity == Diagnostic.INFO)
- {
- message = JET2Messages.JET2Context_SuccessfulWithMessages;
- }
- else if (worstSeverity == Diagnostic.WARNING)
- {
- message = JET2Messages.JET2Context_SuccessfulWithWarnings;
- }
- else if (worstSeverity == Diagnostic.ERROR)
- {
- message = JET2Messages.JET2Context_ErrorsInExecution;
- }
- BasicDiagnostic summary = new BasicDiagnostic(JET2Platform.PLUGIN_ID, 0, stati.getChildren(), message, null);
- summary.recomputeSeverity();
-// return BasicDiagnostic.toIStatus(summary);
- return summary;
-
- }
-
- /**
- * Log an error from the specified tag.
- * @param tagInfo
- * @param message the error message to display, or <code>null</code>
- * @param exception
- */
- // Used 3 times: TagSafeRunnable.handleException() x 2, tagFactoryImpl.createTagElement(),
- public void logError(TagInfo tagInfo, String message, Throwable exception)
- {
- log(Diagnostic.ERROR, getTemplatePath(), tagInfo, message, exception);
- }
-
- private String getContextExtenderId(Class clazz)
- {
- return clazz.getName();
- }
-
- /**
- * Test whether the context has an extender of the pass class.
- * @param extenderClass the extender class
- * @return <code>true</code> if the context has a registered extender of the passed class.
- */
- public boolean hasContextExtender(Class extenderClass)
- {
- return extendedContextData.containsKey(getContextExtenderId(extenderClass));
- }
-
- /**
- * Register a context extender class and its data.
- * <P>
- * This method is not normally called by clients.
- * It is intended for use by {@link AbstractContextExtender#AbstractContextExtender(JET2Context)}.
- * </P>
- * @param extenderClass the extender class
- * @param extenderData the data to be associated with the class
- * @throws IllegalStateException if <code>extenderClass</code> has already been registered on this context.
- */
- void registerContextExtender(Class extenderClass, Object extenderData)
- {
- String extenderId = getContextExtenderId(extenderClass);
- if (extendedContextData.containsKey(extenderClass))
- {
- throw new IllegalStateException(extenderId + "already registered"); //$NON-NLS-1$
- }
-
- extendedContextData.put(extenderId, extenderData);
- }
-
- /**
- * Return the context extension data for the passed class, or null if the extender class
- * has no associated data, or if <code>extenderClass</code> is not registered on the context.
- * <P>
- * This method is not normally called by clients.
- * It is intended for use by {@link AbstractContextExtender#getExtendedData()}.
- * </P>
- * @param extenderClass the context extender class.
- * @return the associated data or <code>null</code>.
- */
- Object getContextExtenderData(Class extenderClass)
- {
- return extendedContextData.get(getContextExtenderId(extenderClass));
- }
-
- /**
- * Log an error on the pass template
- * @param templatePath
- * @param tagInfo
- * @param message
- * @param e
- */
- public void logError(String templatePath, TagInfo tagInfo, String message, Throwable e)
- {
- log(Diagnostic.ERROR, templatePath, tagInfo, message, e);
-
- }
-
- private static final Pattern validVariableNamePattern = Pattern.compile("(?:_|\\p{L})(?:_|-|\\.|\\p{L}|\\d)*"); //$NON-NLS-1$
- /**
- * Assigne or create a variable, and set its value.
- * @param var the variable name. Cannot be <code>null</code>.
- * @param value the variable value.
- */
- public void setVariable(String var, Object value) throws JET2TagException
- {
- if(!validVariableNamePattern.matcher(var).matches())
- {
- throw new JET2TagException(MessageFormat.format(JET2Messages.JET2Context_InvalidVariableName, new Object[] {var}));
- }
- globalVariables.put(var, value);
- }
-
- /**
- * Return the value of a context variable
- * @param var the variable name
- * @return the value of the variable
- * @throws JET2TagException if the variable does not exist.
- */
- public Object getVariable(String var) throws JET2TagException
- {
- if (!hasVariable(var))
- {
- String msg = JET2Messages.JET2Context_VariableNotFound;
- throw new JET2TagException(MessageFormat.format(msg, new Object []{ var }));
- }
- return globalVariables.get(var);
- }
-
- /**
- * Return a map of all variables currently defined in the context. The map is a copy
- * of the variables maintained by the context; changes to the map have no affect on
- * the context.
- * @return a Map of variables, where the key is a variable name, and the value is the variable value.
- */
- public Map getVariables()
- {
- return new HashMap(globalVariables);
- }
- /**
- * Remove a variable
- * @param var the variable name
- */
- public void removeVariable(String var) throws JET2TagException
- {
- globalVariables.remove(var);
- }
-
- /**
- * Test whether a variable is defined
- * @param var the variable name
- * @return <code>true</code> if defined, <code>false</code> otherwise.
- */
- public boolean hasVariable(String var)
- {
- return globalVariables.containsKey(var);
- }
-
- /**
- * @return the tagFactory
- */
- public final TagFactory getTagFactory()
- {
- return tagFactory;
- }
-
- /**
- * @param tagFactory the tagFactory to set
- */
- public final void setTagFactory(TagFactory tagFactory)
- {
- this.tagFactory = tagFactory;
- }
-
- /**
- * Extract a list of variables from the context
- * @param variableNames a comma separated list of variables. May be <code>null</code>.
- * @return a Map keyed by variable name. Will be <code>null</code> if <code>variableNames</code> is <code>null</code>.
- * @throws JET2TagException if <code>variableNames</code> contains an invalid variable name.
- */
- public Map extractVariables(String variableNames) throws JET2TagException
- {
- Map savedVariableValues = null;
- if (variableNames != null)
- {
- savedVariableValues = new HashMap();
- for (StringTokenizer tokenizer = new StringTokenizer(variableNames, ","); tokenizer.hasMoreTokens();) { //$NON-NLS-1$
- String varName = tokenizer.nextToken();
- varName = varName.trim();
- savedVariableValues.put(varName, getVariable(varName));
- }
- }
- return savedVariableValues;
- }
-
- /**
- * Restore variables in the passed map to the context.
- * @param savedVariableValues a Map keyed by variable name. If <code>null</code> the method does nothing.
- * @throws JET2TagException if a variable name is invalid
- */
- public void restoreVariables(Map savedVariableValues) throws JET2TagException
- {
- if (savedVariableValues != null)
- {
- for (Iterator i = savedVariableValues.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- setVariable((String)entry.getKey(), entry.getValue());
- }
- }
- }
-
- /**
- * Set the context variables to only the variables in variablesToPass
- * @param variablesToPass a non-null map keyed by variable name.
- * @throws JET2TagException if a variable name is invalid
- */
- public void setVariables(Map variablesToPass) throws JET2TagException
- {
- globalVariables.clear();
- for (Iterator i = variablesToPass.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String varName = (String)entry.getKey();
- setVariable(varName, entry.getValue());
- }
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index 363b923..46338f2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -38,17 +38,15 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.compiler.JET2Compiler;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.JETActivatorWrapper;
+import org.eclipse.jet.internal.builder.WorkspaceCompiler;
import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.runtime.JET2TemplateStatus;
import org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtender;
import org.eclipse.jet.internal.runtime.RuntimeTagLogger;
import org.eclipse.jet.runtime.model.ILoaderManager;
@@ -67,6 +65,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.osgi.framework.BundleException;
/**
@@ -132,81 +131,77 @@ public class JET2Platform
/**
* @param project
- * @param result
+ * @param contextLog
* @throws CoreException
*/
- private static void addRuntimeProblemMarkersToProject(IProject project, Diagnostic result) throws CoreException
+ private static void addRuntimeProblemMarkersToProject(IProject project, ContextLogEntry contextLog) throws CoreException
{
Set fileBuffers = new HashSet();
final ITextFileBufferManager tfbManager = FileBuffers.getTextFileBufferManager();
// clear off any runtime markers...
- project.deleteMarkers(JET2Compiler.RUNTIME_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
- Diagnostic[] problems = (Diagnostic[])result.getChildren().toArray(new Diagnostic[0]);
+ project.deleteMarkers(WorkspaceCompiler.RUNTIME_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
+ ContextLogEntry[] problems = contextLog.getChildren();
try
{
for (int i = 0; i < problems.length; i++)
{
- if (problems[i] instanceof JET2TemplateStatus)
+ String templatePath = problems[i].getTemplatePath();
+ if (templatePath == null)
{
- JET2TemplateStatus tStatus = (JET2TemplateStatus)problems[i];
-
- if(tStatus.getTagInfo() == null) continue;
-
- String templatePath = tStatus.getTemplatePath();
- IResource errorResource = templatePath != null ? project.findMember(templatePath) : project;
-
- final IPath location = errorResource.getFullPath();
- if(!fileBuffers.contains(location))
- {
- tfbManager.connect(location, new NullProgressMonitor());
- fileBuffers.add(location);
- }
+ continue;
+ }
+ IResource errorResource = templatePath != null ? project.findMember(templatePath) : project;
- final ITextFileBuffer textFileBuffer = tfbManager.getTextFileBuffer(location);
-
- IMarker marker = errorResource.createMarker(JET2Compiler.RUNTIME_PROBLEM_MARKER);
- if (tStatus.getSeverity() == IStatus.ERROR)
- {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
- }
- else if (tStatus.getSeverity() == IStatus.WARNING)
- {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- }
- else if (tStatus.getSeverity() == IStatus.INFO)
- {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
- }
- TagInfo td = tStatus.getTagInfo();
- if (td != null)
- {
- marker.setAttribute(IMarker.LINE_NUMBER, td.getLine());
- try
- {
- int start = textFileBuffer.getDocument().getLineOffset(td.getLine() - 1) + td.getCol() - 1;
- final IRegion region = new FindReplaceDocumentAdapter(textFileBuffer.getDocument()).find(start,
- "(?<!\\\\)>", // Finds > not preceded by \\ //$NON-NLS-1$
- true, true, false, true);
- int end = region.getOffset() + region.getLength();
- marker.setAttribute(IMarker.CHAR_START, start);
- marker.setAttribute(IMarker.CHAR_END, end);
- }
- catch (BadLocationException e)
- {
- // do nothing, just won't set the start & end offsets;
- }
- }
- if (tStatus.getMessage() != null)
+ final IPath location = errorResource.getFullPath();
+ if (!fileBuffers.contains(location))
+ {
+ tfbManager.connect(location, new NullProgressMonitor());
+ fileBuffers.add(location);
+ }
+
+ final ITextFileBuffer textFileBuffer = tfbManager.getTextFileBuffer(location);
+
+ IMarker marker = errorResource.createMarker(WorkspaceCompiler.RUNTIME_PROBLEM_MARKER);
+ switch (problems[i].getSeverity())
+ {
+ case ContextLogEntry.ERROR:
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ break;
+ case ContextLogEntry.WARNING:
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ break;
+ case ContextLogEntry.INFO:
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
+ break;
+ }
+ TagInfo td = problems[i].getTagInfo();
+ int line = problems[i].getLine();
+ int col = problems[i].getCol();
+ if (line > 0 && col > 0)
+ {
+ marker.setAttribute(IMarker.LINE_NUMBER, line);
+ try
{
- marker.setAttribute(IMarker.MESSAGE, tStatus.getMessage());
+ int start = textFileBuffer.getDocument().getLineOffset(td.getLine() - 1) + td.getCol() - 1;
+ final IRegion region = new FindReplaceDocumentAdapter(textFileBuffer.getDocument()).find(start, "(?<!\\\\)>", // Finds > not preceded by \\ //$NON-NLS-1$
+ true,
+ true,
+ false,
+ true);
+ int end = region.getOffset() + region.getLength();
+ marker.setAttribute(IMarker.CHAR_START, start);
+ marker.setAttribute(IMarker.CHAR_END, end);
}
- else if (tStatus.getException() != null)
+ catch (BadLocationException e)
{
- String message = tStatus.getException().getLocalizedMessage();
- marker.setAttribute(IMarker.MESSAGE, message != null && message.length() > 0 ? message : tStatus.getException().toString());
+ // do nothing, just won't set the start & end offsets;
}
}
+ if (problems[i].getMessage() != null)
+ {
+ marker.setAttribute(IMarker.MESSAGE, problems[i].getMessage());
+ }
}
}
finally
@@ -314,10 +309,10 @@ public class JET2Platform
/**
* @param id
- * @param result
+ * @param contextLog
* @throws CoreException
*/
- private static void processResults(final String id, final Diagnostic result)
+ private static void processResults(final String id, final ContextLogEntry contextLog)
{
final IJETBundleManager bundleManager = getJETBundleManager();
String projectName = bundleManager.getProjectForId(id);
@@ -333,26 +328,48 @@ public class JET2Platform
public void run(IProgressMonitor monitor1) throws CoreException
{
project.deleteMarkers(
- JET2Compiler.RUNTIME_PROBLEM_MARKER,
+ WorkspaceCompiler.RUNTIME_PROBLEM_MARKER,
true,
IResource.DEPTH_INFINITE);
- addRuntimeProblemMarkersToProject(project, result);
+ addRuntimeProblemMarkersToProject(project, contextLog);
}
}, null, IWorkspace.AVOID_UPDATE, null);
}
catch (CoreException e)
{
InternalJET2Platform.logError(JET2Messages.JET2Platform_ErrorMarkingProject, e);
- InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
+ InternalJET2Platform.log(toIStatus(contextLog));
}
}
else
{
- InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
+ InternalJET2Platform.log(toIStatus(contextLog));
}
}
/**
+ * Convert a Context log entry into an IStatus;
+ * @param logEntry a log entry
+ * @return an IStatus
+ */
+ public static IStatus toIStatus(ContextLogEntry logEntry)
+ {
+ int severity = logEntry.getSeverity();
+ final ContextLogEntry[] children = logEntry.getChildren();
+// for (int i = 0; i < children.length; i++)
+// {
+// severity = Math.max(severity, children[i].getSeverity());
+// }
+ MultiStatus result = new MultiStatus(JET2Platform.PLUGIN_ID, severity, logEntry.getMessage(), logEntry.getException());
+ for (int i = 0; i < children.length; i++)
+ {
+ result.add(toIStatus(children[i]));
+ }
+
+
+ return result;
+ }
+ /**
* Invoke a JET transform against the passed context
* @param id the JET Transform id
* @param context the JET2Context
@@ -377,10 +394,12 @@ public class JET2Platform
}
monitor.subTask(JET2Messages.JET2Platform_RetrievingBundle);
+ // install the runtime logger
+ RuntimeLoggerContextExtender.install(context);
if (DEBUG)
{
- RuntimeLoggerContextExtender rl = new RuntimeLoggerContextExtender(context);
+ RuntimeLoggerContextExtender rl = RuntimeLoggerContextExtender.getInstance(context);
rl.addListener(new RuntimeTagLogger()
{
@@ -447,16 +466,17 @@ public class JET2Platform
}
}}, new SubProgressMonitor(monitor, 90));
- Diagnostic diagnostic = context.getLogAsMultiStatus();
- if (diagnostic.getSeverity() != Diagnostic.OK)
+// Diagnostic diagnostic = context.getLogAsMultiStatus();
+ ContextLogEntry contextLog = context.getLogEntries();
+ if (contextLog.getSeverity() != ContextLogEntry.OK)
{
- processResults(id, diagnostic);
+ processResults(id, contextLog);
}
- result = BasicDiagnostic.toIStatus(diagnostic);
+ result = toIStatus(contextLog);
}
- catch (CoreJETException e)
+ catch (BundleException e)
{
- result = BasicDiagnostic.toIStatus(e.getDiagnostic());
+ result = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e);
}
finally
{
@@ -556,7 +576,7 @@ public class JET2Platform
}
catch (CoreJETException e)
{
- return BasicDiagnostic.toIStatus(e.getDiagnostic());
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
}
}
@@ -615,11 +635,11 @@ public class JET2Platform
}
catch (JET2TagException e)
{
- return new Status(IStatus.ERROR, id, IStatus.OK, e.getMessage(), e);
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
}
catch (CoreJETException e)
{
- result = BasicDiagnostic.toIStatus(e.getDiagnostic());
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
}
catch (IOException e)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Template.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Template.java
deleted file mode 100644
index 91a4001..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Template.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet;
-
-
-/**
- * Interface to compiled JET2 templates.
- *
- */
-public interface JET2Template
-{
-
- /**
- * Execute the template against the input contained in the {@link JET2Context},
- * and writing the result to the {@link JET2Writer}.
- * @param context the input context. Cannot be <code>null</code>.
- * @param out the output writer. Cannote be <code>null</code>.
- */
- public abstract void generate(JET2Context context, JET2Writer out);
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoader.java
deleted file mode 100644
index 9c623e8..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoader.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet;
-
-/**
- * A loader for templates within a transform.
- */
-public interface JET2TemplateLoader
-{
-
- /**
- * Return an instance of the specified template, or <code>null</code>.
- * <p>
- * This class is not typically implemented by clients. The JET2 compiler will
- * emit an instance of this class for each JET2 project.
- * </p>
- * @param templatePath a transform project relative path to the template.
- * @return the template instance or <code>null</code> if the template cannot be found
- */
- public JET2Template getTemplate(String templatePath);
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java
deleted file mode 100644
index 1965951..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet;
-
-/**
- * Extension interface for {@link JET2TemplateLoader} allowing
- * for delegation of template loading to other loaders
- */
-public interface JET2TemplateLoaderExtension
-{
- /**
- * Add a template loader to which this loader will delegate
- * when it cannot find a template
- * @param loader a template loader or <code>null</code> to remove the delegate loader.
- */
- public abstract void setDelegateLoader(JET2TemplateLoader loader);
-
- /**
- * Return the template loader to which this loader will delegate
- * when it cannot find a template. The initial delegate loader is <code>null</code>.
- * @return the delegate loader or <code>null</code>.
- */
- public abstract JET2TemplateLoader getDelegateLoader();
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java
deleted file mode 100644
index 493c96d..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet;
-
-
-import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-
-
-/**
- * Define a JET2 output writer
- *
- */
-public interface JET2Writer
-{
-
- /**
- * Write the passed string.
- * @param string a string value.
- */
- public abstract void write(String string);
-
- /**
- * Write the contents of the passed writer to this writer.
- * @param bodyContent a writer
- */
- public abstract void write(JET2Writer bodyContent);
-
- /**
- * Write the passed boolean by calling {@link String#valueOf(boolean)}.
- * @param b a boolean value
- */
- public abstract void write(boolean b);
-
- /**
- * Write the passed character by calling {@link String#valueOf(char)}.
- * @param c a char value
- */
- public abstract void write(char c);
-
- /**
- * Write the passed character array by calling {@link String#valueOf(char[])}.
- * @param data an array of characters
- */
- public abstract void write(char[] data);
-
- /**
- * Write the passed double value by calling {@link String#valueOf(double)}.
- * @param d a double value
- */
- public abstract void write(double d);
-
- /**
- * Write the passed float value by calling {@link String#valueOf(float)}.
- * @param f a float value
- */
- public abstract void write(float f);
-
- /**
- * Write the passed integer by calling {@link String#valueOf(int)}.
- * @param i an integer value
- */
- public abstract void write(int i);
-
- /**
- * Write the passed long value calling {@link String#valueOf(long)}.
- * @param l a long value.
- */
- public abstract void write(long l);
-
- /**
- * Write the pass object by calling {@link Object#toString()}.
- * @param obj an object.
- */
- public abstract void write(Object obj);
-
- /**
- * Create a writer for handling nested content. The new writer will have access
- * to all position handlers defined on the parent writer (and its parents)
- * @return the nested content writer
- */
- public abstract JET2Writer newNestedContentWriter();
-
- /**
- * Return the parent of this writer, if it was created via {@link #newNestedContentWriter()}.
- * @return the parent writer, or <code>null</code>.
- */
- public abstract JET2Writer getParentWriter();
-
- /**
- * Return the current length (in characters) of the output
- * @return the current length
- */
- public abstract int getLength();
-
- /**
- * Return the backing IDocument for this writer. Use this method to do advanced
- * writer processing, such as adding Positions for later re-writing of the document
- * contents.
- * @return the backing document
- */
- public abstract IDocument getDocument();
-
- /**
- * Finalize the writers contents. Once finalized, no more content may be written to the writer.
- * Calls {@link IWriterListener#finalizeContent(JET2Writer, Object)} on all registered listeners.
- * Listeners are called in the
- * order in which the listeners were registered via {@link #addEventListener(String, IWriterListener)}.
- * <p>
- * The type of <code>file</code> varies depending on the context in which the content
- * is finalized. The standard JET2 Workspace tags pass an org.eclipse.core.resources.IFile.
- * </p>
- * @param file the file object to which the finalized contents will be written.
- * @throws JET2TagException if an error occurs
- * @see #addEventListener(String, IWriterListener)
- */
- public abstract void finalizeContent(Object file) throws JET2TagException;
-
- /**
- * Inform listeners that the content has been committed to some permanent store.
- * Calls {@link IWriterListener#postCommitContent(JET2Writer, Object)} on all registered listeners.
- * Listeners are called in the
- * order in which the listeners were registered via {@link #addEventListener(String, IWriterListener)}.
- * <p>
- * The type of <code>committedObject</code> varies, depending on the context in which the content
- * is committed. The standard JET2 Workspace tags pass an org.eclipse.core.resources.IFile.
- * </p>
- * @param committedObject the committed object.
- * @throws JET2TagException if event handle cannot terminate correctly.
- */
- public abstract void contentCommitted(Object committedObject) throws JET2TagException;
-
- /**
- * Add a listener to the writer life cycle events. The writer records one listener per
- * category. Subsequent calls to this method with the same category value have no effect.
- * If the listener was created view {@link #newNestedContentWriter()}, then the listener is added
- * to the root writer, rather than the listener itself.
- * @param category the listener category
- * @param listener a listener
- * @throws NullPointerException if listener is <code>null</code>.
- */
- public abstract void addEventListener(String category, IWriterListener listener);
-
- /**
- * Convenience method wrapping getDocument().addPositionCategory(String).
- * @param category a Position Category
- * @throws IllegalArgumentException wrapping a {@link org.eclipse.jface.text.BadPositionCategoryException}
- * @see IDocument#addPositionCategory(java.lang.String)
- */
- public abstract void addPositionCategory(String category);
-
- /**
- * Convenience method wrapping getDocument().addPosition(String, Position).
- * Any
- * {@link org.eclipse.jface.text.BadPositionCategoryException} or
- * {@link org.eclipse.jface.text.BadLocationException} is wrapped in a
- * a runtime exception.
- * @param category a position category
- * @param position a position
- * @throws WriterPositionException wrapping a {@link org.eclipse.jface.text.BadPositionCategoryException}
- * or {@link org.eclipse.jface.text.BadLocationException}
- * @see IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
- */
- public abstract void addPosition(String category, Position position);
-
- /**
- * Convenience method wrapping getDocument().getPositions(String).
- * Any
- * {@link org.eclipse.jface.text.BadPositionCategoryException}
- * is wrapped in a runtime exception.
- * @param category a position category
- * @return an array of positions
- * @throws WriterPositionException wrapping a {@link org.eclipse.jface.text.BadPositionCategoryException}
- * @see IDocument#getPositions(java.lang.String)
- */
- public abstract Position[] getPositions(String category);
-
- /**
- * Convenience method wrapping getDocument().replace(int,int,String).
- * Any
- * {@link org.eclipse.jface.text.BadLocationException}
- * is wrapped in a runtime exception.
- * @param offset the offset of the text to replace
- * @param length the length of the text to replace
- * @param text the replacement text
- * @throws WriterPositionException wrapping a {@link org.eclipse.jface.text.BadLocationException}
- * @see IDocument#replace(int, int, java.lang.String)
- */
- public abstract void replace(int offset, int length, String text);
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/WriterPositionException.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/WriterPositionException.java
index 6fdd9d2..db00ce1 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/WriterPositionException.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/WriterPositionException.java
@@ -21,6 +21,8 @@ package org.eclipse.jet;
/**
* Runtime exception to wrap the rather inconvenient checked exception thrown by
* the org.eclipse.jface.text classes and methods.
+ *
+ * @deprecated No longer used
*
*/
public class WriterPositionException extends RuntimeException
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
deleted file mode 100644
index 96d516a..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
+++ /dev/null
@@ -1,677 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.compiler;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.internal.compiler.CommentElementDelegate;
-import org.eclipse.jet.internal.compiler.DeclarationElementDelegate;
-import org.eclipse.jet.internal.compiler.ErrorRedirectingCoreElementDelegate;
-import org.eclipse.jet.internal.compiler.XMLElementDelegate;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-import org.eclipse.jet.taglib.TagDefinition;
-import org.eclipse.jet.taglib.TagLibraryManager;
-import org.eclipse.jet.taglib.TagLibraryReference;
-
-
-/**
- * JET Parser Listener used by the JET2 Compiler
- *
- */
-class ASTCompilerParseListener implements JETParseEventListener2
-{
-
- private static final String ID__ATTR = "id"; //$NON-NLS-1$
-
- private static final String PREFIX__ATTR = "prefix"; //$NON-NLS-1$
-
- private static final String TAGLIB__DIRECTIVE = "taglib"; //$NON-NLS-1$
- private static final String JET__DIRECTIVE = "jet"; //$NON-NLS-1$
- private final static class ElementStack
- {
-
- private final List stack = new ArrayList();
-
- /**
- *
- */
- public ElementStack()
- {
- super();
- }
-
- /**
- * Push an XML element on the active element stack
- * @param element
- */
- public void push(XMLBodyElement element)
- {
- stack.add(element);
- }
-
- /**
- * Remove an XML element from the active element stack
- * @return the popped element
- * @throws IllegalStateException if the stack is empty
- */
- public XMLBodyElement pop()
- {
- if (stack.size() == 0)
- {
- throw new IllegalStateException("stack is empty"); //$NON-NLS-1$
- }
- return (XMLBodyElement)stack.remove(stack.size() - 1);
- }
-
- /**
- * Return the top element on the active element statkc
- * @return the top element
- * @throws IllegalStateException if the stack is empty
- */
- public XMLBodyElement peek()
- {
- if (stack.size() == 0)
- {
- throw new IllegalStateException("stack is empty"); //$NON-NLS-1$
- }
- return (XMLBodyElement)stack.get(stack.size() - 1);
-
- }
-
- /**
- * Test if the stack is empty
- * @return <code>true</code> if empty, <code>false</code> otherwise
- */
- public boolean isEmpty()
- {
- return stack.size() == 0;
- }
-
- /**
- * Find the index of the element with the specified name that is closest to the top of the stack.
- * @param name the element name to search for
- * @return the found element's index or -1 if not found
- */
- public int findElementIndex(String name)
- {
- for (int i = stack.size() - 1; i >= 0; i--)
- {
- XMLBodyElement element = get(i);
- if (element.getName().equalsIgnoreCase(name))
- {
- return i;
- }
- }
-
- return -1;
- }
-
- /**
- * Test if the passed index is that of the top-most element in the active element stack.
- * @param index the test index
- * @return <code>true</code> if the index represents the top-most element, <code>false</code> otherwise.
- * @throws IllegalArgumentException if the index is less than 0 or larger than the stack size.
- */
- public boolean isAtTop(int index)
- {
- if (index < 0 || index >= stack.size())
- {
- throw new IllegalArgumentException();
- }
- return index == stack.size() - 1;
- }
-
- /**
- * Return the element at the specified index
- * @param index
- * @return the element
- * @throws IllegalArgumentException if the index is less than 0 or larger than the stack size.
- *
- */
- public XMLBodyElement get(int index)
- {
- if (index < 0 || index >= stack.size())
- {
- throw new IllegalArgumentException();
- }
- return (XMLBodyElement)stack.get(index);
- }
- }
-
- /**
- * Stack of elements waiting for end tags.
- */
- private final ElementStack elementStack = new ElementStack();
-
- private JET2CompilationUnit compilationUnit;
-
- private JET2AST ast;
-
- private final TagLibraryUsageManager tagLibManager;
-
- private final JETReader reader;
-
- public ASTCompilerParseListener(JET2CompilationUnit unit, JETReader reader)
- {
- this(unit, reader, Collections.EMPTY_MAP);
- }
-
- public ASTCompilerParseListener(JET2CompilationUnit unit, JETReader reader, Map predefinedLibraryMap)
- {
- compilationUnit = unit;
- ast = compilationUnit.getAst();
- this.reader = reader;
- tagLibManager = new TagLibraryUsageManager(predefinedLibraryMap);
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#beginPageProcessing()
- */
- public void beginPageProcessing()
- {
- // nothing to do
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#handleDirective(java.lang.String, org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark, java.util.Map)
- */
- public void handleDirective(String directive, JETMark start, JETMark stop, Map attributes)
- {
- JET2Directive directiveImpl = ast.createDirective(start.getLine(), start.getCol(), start.getCursor(), stop.getCursor() + 1, directive, attributes);
-
- // although a directive may appear nested, it really isn't. Add it to the compilation unit.
- // TODO Does this work for @start and @end? Probably NOT.
- compilationUnit.getInternalBodyElements().addBodyElement(directiveImpl);
-
- if (TAGLIB__DIRECTIVE.equalsIgnoreCase(directive))
- {
- handleTagLibDirective(start, stop, attributes);
- }
- else if(JET__DIRECTIVE.equalsIgnoreCase(directive))
- {
- handleJetDirective(start, stop, attributes);
- } else {
- recordProblem(ParseProblemSeverity.WARNING, Problem.UnsupportedDirective,
- JET2Messages.ASTCompilerParseListener_UnsupportedDirective,
- new Object[] {directive}, start.getCursor(), stop.getCursor(), start.getLine(), start.getCol() );
- }
- }
-
-
- private static Set knownJETAttributes =
- new LinkedHashSet(Arrays.asList(new String[] {
- "skeleton", //$NON-NLS-1$
- "package", //$NON-NLS-1$
- "imports", //$NON-NLS-1$
- "class", //$NON-NLS-1$
- "nlString", //$NON-NLS-1$
- "startTag", //$NON-NLS-1$
- "endTag", //$NON-NLS-1$
- "version", //$NON-NLS-1$
- }));
- private static Set deprecatedJETAttributes =
- new LinkedHashSet(Arrays.asList(new String[] {
- "skeleton", //$NON-NLS-1$
- "nlString", //$NON-NLS-1$
- }));
-
- private JETParser parser;
- private void handleJetDirective(JETMark start, JETMark stop, Map attributes)
- {
- for (Iterator i = attributes.keySet().iterator(); i.hasNext();)
- {
- String attrName = (String)i.next();
- if(!knownJETAttributes.contains(attrName))
- {
- recordProblem(ParseProblemSeverity.ERROR, Problem.UnknownAttributeInTag,
- JET2Messages.JET2Compiler_UnknownAttribute, new Object[] {attrName},
- start.getCursor(), stop.getCursor(), start.getLine(), start.getCol());
- }
- if(deprecatedJETAttributes.contains(attrName))
- {
- recordProblem(ParseProblemSeverity.WARNING, Problem.DeprecatedAttribute,
- JET2Messages.JET2Compiler_DeprecatedAttribute, new Object[] {attrName},
- start.getCursor(), stop.getCursor(), start.getLine(), start.getCol());
- }
- }
-
- String pkg = (String)attributes.get("package"); //$NON-NLS-1$
- String cls = (String)attributes.get("class"); //$NON-NLS-1$
- String importStr = (String)attributes.get("imports"); //$NON-NLS-1$
- String startTag = (String)attributes.get("startTag"); //$NON-NLS-1$
- String endTag = (String)attributes.get("endTag"); //$NON-NLS-1$
-
- if(pkg != null)
- {
- compilationUnit.setOutputJavaPackage(pkg);
- }
- if(cls != null)
- {
- compilationUnit.setOutputJavaClassName(cls);
- }
- if(importStr != null)
- {
- String[] imports = importStr.split("\\s+"); //$NON-NLS-1$
- compilationUnit.addImports(Arrays.asList(imports));
- }
-
- if(startTag != null)
- {
- parser.setStartTag(startTag);
- }
- if(endTag != null)
- {
- parser.setEndTag(endTag);
- }
- }
-
- /**
- * @param start
- * @param stop
- * @param attributes
- */
- private void handleTagLibDirective(JETMark start, JETMark stop, Map attributes)
- {
- String prefix = ((String)attributes.get(PREFIX__ATTR)).trim().toLowerCase();
- String id = (String)attributes.get(ID__ATTR);
-
- if (id == null)
- {
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingRequiredAttribute,
- JET2Messages.JET2Compiler_MissingDirectiveAttribute,
- new Object []{ TAGLIB__DIRECTIVE, ID__ATTR },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- else if (prefix == null)
- {
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingRequiredAttribute,
- JET2Messages.JET2Compiler_MissingDirectiveAttribute,
- new Object []{ TAGLIB__DIRECTIVE, PREFIX__ATTR },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- else if (!tagLibManager.canDefinePrefix(prefix, id))
- {
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.DuplicateXMLNamespacePrefix,
- JET2Messages.JET2Compiler_PrefixAlreadyAssigned,
- new Object []{ prefix, tagLibManager.getLibraryIdFromPrefix(prefix) },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- else if (TagLibraryManager.getInstance().getTagLibrary(id) == null)
- {
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnknownTagLibrary,
- JET2Messages.JET2Compiler_UnknownTagLibrary,
- new Object []{ id },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- else
- {
- tagLibManager.add(prefix, id);
- }
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#handleExpression(org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark, java.util.Map)
- */
- public void handleExpression(JETMark start, JETMark stop, Map attributes)
- {
- JET2Expression expression = ast.createExpression(
- start.getLine(),
- start.getCol(),
- start.getCursor() - 3,
- stop.getCursor() + 2,
- start.getCursor(),
- stop.getCursor(), reader.getChars(start, stop));
-
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(expression);
- }
- else
- {
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(expression);
- }
-
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#handleCharData(char[])
- */
- public void handleCharData(char[] chars)
- {
- TextElement text = ast.createTextElement(chars);
-
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(text);
- }
- else
- {
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(text);
- }
-
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#endPageProcessing()
- */
- public void endPageProcessing()
- {
- while (!elementStack.isEmpty())
- {
- XMLBodyElement element = elementStack.pop();
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingXmlEndTag,
- JET2Messages.JET2Compiler_MissingEndTag,
- new Object []{ element.getName() },
- element.getStart(),
- element.getEnd(),
- element.getLine(), element.getColumn());
- }
-
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener#handleScriptlet(org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark, java.util.Map)
- */
- public void handleScriptlet(JETMark start, JETMark stop, Map attributes)
- {
- JET2Scriptlet scriplet = ast.createScriplet(
- start.getLine(),
- start.getCol(),
- start.getCursor() - 3,
- stop.getCursor() + 2,
- start.getCursor(),
- stop.getCursor(), reader.getChars(start, stop));
-
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(scriplet);
- }
- else
- {
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(scriplet);
- }
-
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#handleComment(org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark)
- */
- public void handleComment(JETMark start, JETMark stop)
- {
- Comment comment = ast.createComment(
- start.getLine(),
- start.getCol(),
- start.getCursor() - 4,
- stop.getCursor() + 4,
- start.getCursor(),
- stop.getCursor(), reader.getChars(start, stop));
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(comment);
- }
- else
- {
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(comment);
- }
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#handleDeclaration(org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark)
- */
- public void handleDeclaration(JETMark start, JETMark stop)
- {
- JET2Declaration decl = ast.createDeclaration(
- start.getLine(),
- start.getCol(),
- start.getCursor() - 3,
- stop.getCursor() + 2,
- start.getCursor(),
- stop.getCursor(), reader.getChars(start, stop));
-
- compilationUnit.getInternalBodyElements().addBodyElement(decl);
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#handleXMLEndTag(java.lang.String, org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark)
- */
- public void handleXMLEndTag(String tagName, JETMark start, JETMark stop)
- {
- int tagIndex = elementStack.findElementIndex(tagName);
- XMLBodyElementEnd endTag = ast.createXMLBodyElementEnd(start.getLine(), start.getCol(),
- start.getCursor(), stop.getCursor(), tagName);
- if (tagIndex == -1)
- {
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingXmlStartTag,
- JET2Messages.JET2Compiler_MissingStartTag,
- new Object []{ tagName },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- else
- {
- while (!elementStack.isAtTop(tagIndex))
- {
- XMLBodyElement top = elementStack.pop();
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingXmlEndTag,
- JET2Messages.JET2Compiler_MissingEndTag,
- new Object []{ top.getName() },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- }
- XMLBodyElement topElement = elementStack.pop();
- endTag.setStartTag(topElement);
- topElement.setEndTag(endTag);
- }
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(endTag);
- }
- else
- {
- XMLBodyElement topElement = (XMLBodyElement)elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(endTag);
- }
-
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#handleXMLEmptyTag(java.lang.String, org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark, java.util.Map)
- */
- public void handleXMLEmptyTag(String tagName, JETMark start, JETMark stop, Map attributeMap)
- {
- TagDefinition td = tagLibManager.getTagDefinition(tagName);
-
- XMLEmptyElement decl = ast.createXMLEmptyElement(
- start.getLine(),
- start.getCol(),
- start.getCursor(),
- stop.getCursor(),
- tagName,
- attributeMap,
- td);
-
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(decl);
- }
- else
- {
- XMLBodyElement topElement = (XMLBodyElement)elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(decl);
- }
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#handleXMLStartTag(java.lang.String, org.eclipse.jet.internal.parser.JETMark, org.eclipse.jet.internal.parser.JETMark, java.util.Map)
- */
- public void handleXMLStartTag(String tagName, JETMark start, JETMark stop, Map attributeMap)
- {
-
- TagDefinition td = tagLibManager.getTagDefinition(tagName);
-
- if(!td.isContentAllowed() && tagName.indexOf(':') == -1)
- {
- // bug 147714: for DPTK compatibility, allow empty tags to appear as <tagname ...> instead of <tagname .../>
- // We only allow this for tags that have no namespace (as DPTK did not support namespaces).
- recordProblem(ParseProblemSeverity.WARNING, Problem.TagInterpretedAsEmptyTag,
- JET2Messages.JET2Compiler_TagShouldBeEmptyFormat,
- new Object [] {"<" + tagName + "/>"}, //$NON-NLS-1$ //$NON-NLS-2$
- start.getCursor(), stop.getCursor(), start.getLine(), start.getCol());
- handleXMLEmptyTag(tagName, start, stop, attributeMap);
- }
- else
- {
- XMLBodyElement decl = ast.createXMLBodyElement(
- start.getLine(),
- start.getCol(),
- start.getCursor(),
- stop.getCursor(),
- tagName,
- attributeMap,
- td);
-
- if (elementStack.isEmpty())
- {
- compilationUnit.getInternalBodyElements().addBodyElement(decl);
- }
- else
- {
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(decl);
- }
-
- elementStack.push(decl);
- }
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#isKnownTag(java.lang.String)
- */
- public boolean isKnownTag(String tagName)
- {
- return tagLibManager.isKnownTag(tagName);
- }
-
- /**
- * Return the compilation unit created as a result of handling the JET2 parser events.
- * @return compilation unit
- */
- public JET2CompilationUnit getCompilationUnit()
- {
- return compilationUnit;
- }
-
- /**
- * @see org.eclipse.jet.internal.parser.JETParseEventListener2#recordProblem(org.eclipse.jet.compiler.Problem.ParseProblemSeverity, int, java.lang.String, java.lang.Object[], int, int, int, int)
- */
- public void recordProblem(ParseProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line, int colOffset)
- {
- compilationUnit.createProblem(severity, problemId, message, msgArgs, start, end, line, colOffset);
- }
-
- public TagLibraryReference[] getTagLibraryReferences()
- {
- TagLibraryReference[] result = tagLibManager.getTagLibraryReferences();
-
- return result;
- }
-
- public void parse(JETReader reader) {
- JETParser.Directive directive = new JETParser.Directive();
- directive.getDirectives().add("jet"); //$NON-NLS-1$
- directive.getDirectives().add("taglib"); //$NON-NLS-1$
- directive.getDirectives().add("include"); //$NON-NLS-1$
- directive.getDirectives().add("start"); //$NON-NLS-1$
- directive.getDirectives().add("end"); //$NON-NLS-1$
- JETCoreElement[] coreElements = new JETCoreElement []{
- new ErrorRedirectingCoreElementDelegate(directive),
- new ErrorRedirectingCoreElementDelegate(new JETParser.Expression()),
- new ErrorRedirectingCoreElementDelegate(new CommentElementDelegate()),
- new ErrorRedirectingCoreElementDelegate(new DeclarationElementDelegate()),
- new ErrorRedirectingCoreElementDelegate(new JETParser.Scriptlet()),
- new ErrorRedirectingCoreElementDelegate(new XMLElementDelegate()), };
- parser = new JETParser(reader, this, coreElements);
- this.beginPageProcessing();
- try
- {
- parser.parse();
- }
- catch (JETException e)
- {
- // create a minimal compilation unit with the exeception recorded as the error.
- recordProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), null, 0, 0, 1, 1);
- }
- this.endPageProcessing();
-
- }
-
- public boolean isKnownInvalidTagName(String tagName)
- {
- return tagLibManager.isKnownInvalidTagName(tagName);
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/BodyElements.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/BodyElements.java
deleted file mode 100644
index 5dbe5da..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/BodyElements.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.compiler;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-
-/**
- * Container class core JET2 AST elements contained in another AST elements in their body.
- *
- */
-class BodyElements
-{
-
- private List bodyElements = new ArrayList();
-
- private final JET2ASTElement owner;
-
- /**
- * Create a new instance
- * @param owner The owner of the body elements
- */
- public BodyElements(JET2ASTElement owner)
- {
- super();
- this.owner = owner;
- }
-
- /**
- * Return a list of elements in the body
- * @return a {@link List} of elements, the empty list if there are no elements.
- */
- public List getBodyElements()
- {
- return Collections.unmodifiableList(bodyElements);
- }
-
- /**
- * Add a text element to the body
- * @param text the text to add
- */
- public void addBodyElement(TextElement text)
- {
- bodyElements.add(text);
- text.setParent(owner);
- }
-
- /**
- * Add an XML element to the body
- * @param xmlElement the xml element
- */
- public void addBodyElement(XMLElement xmlElement)
- {
- bodyElements.add(xmlElement);
- xmlElement.setParent(owner);
- }
-
- /**
- * Add a Java element to the body
- * @param javaElement the Java element
- */
- public void addBodyElement(JavaElement javaElement)
- {
- bodyElements.add(javaElement);
- javaElement.setParent(owner);
- }
-
- /**
- * Add a JET2 Directive to the body
- * @param directive the directive
- */
- public void addBodyElement(JET2Directive directive)
- {
- bodyElements.add(directive);
- directive.setParent(owner);
- }
-
- /**
- * Add a comment to the body.
- * @param comment the comment.
- */
- public void addBodyElement(Comment comment)
- {
- bodyElements.add(comment);
- comment.setParent(owner);
- }
-
- /**
- * @return Returns the owner.
- */
- public final JET2ASTElement getOwner()
- {
- return owner;
- }
-
- /**
- * Return the element after the passed element
- * @param element an element in the list
- * @return the next element or <code>null</code>
- * @throws IllegalArgumentException if element is not in the body
- */
- public JET2ASTElement elementAfter(JET2ASTElement element)
- {
- JET2ASTElement nextElement = null;
- if (bodyElements == null)
- {
- throw new IllegalArgumentException();
- }
- int index = bodyElements.indexOf(element);
- if (index == -1)
- {
- throw new IllegalArgumentException();
- }
-
- if (index + 1 < bodyElements.size())
- {
- nextElement = (JET2ASTElement)bodyElements.get(index + 1);
- }
- return nextElement;
- }
-
- public void addBodyElement(XMLBodyElementEnd endTag)
- {
- bodyElements.add(endTag);
- endTag.setParent(owner);
- }
-
- /**
- *
- * @param element
- * @return
- */
- public JET2ASTElement elementBefore(JET2ASTElement element)
- {
- JET2ASTElement prevElement = null;
- if (bodyElements == null)
- {
- throw new IllegalArgumentException();
- }
- int index = bodyElements.indexOf(element);
- if (index == -1)
- {
- throw new IllegalArgumentException();
- }
-
- if (index > 0)
- {
- prevElement = (JET2ASTElement)bodyElements.get(index - 1);
- }
- return prevElement;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Comment.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Comment.java
index c37920c..40adfda 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Comment.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Comment.java
@@ -16,37 +16,19 @@
*/
package org.eclipse.jet.compiler;
-
/**
* An JET2 AST element representing a comment
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.Comment}
*/
public class Comment extends JET2ASTElement
{
- private final int commentStart;
-
- private final int commentEnd;
-
- private final char[] comment;
-
- /**
- * Create a comment element
- * @param ast the root AST object to to which the comment will be long
- * @param line the start line of the comment
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset (doc relative) of the comment
- * @param end the end offset of the comment
- * @param commentStart the start offset of the comment text (doc relative)
- * @param commentEnd the end offset of the comment text (doc relative)
- * @param comment the comment text
- */
- Comment(JET2AST ast, int line, int colOffset, int start, int end, int commentStart, int commentEnd, char[] comment)
+ private final org.eclipse.jet.core.parser.ast.Comment delegate;
+
+ public Comment(JET2AST ast, org.eclipse.jet.core.parser.ast.Comment comment)
{
- super(ast, line, colOffset, start, end);
- this.commentStart = commentStart;
- this.commentEnd = commentEnd;
- this.comment = comment;
+ super(ast, comment);
+ delegate = comment;
}
/**
@@ -63,7 +45,7 @@ public class Comment extends JET2ASTElement
*/
public int getCommentEnd()
{
- return commentEnd;
+ return delegate.getCommentEnd();
}
/**
@@ -71,7 +53,7 @@ public class Comment extends JET2ASTElement
*/
public int getCommentStart()
{
- return commentStart;
+ return delegate.getCommentStart();
}
/**
@@ -80,12 +62,7 @@ public class Comment extends JET2ASTElement
*/
public String getCommentText()
{
- return new String(comment);
- }
-
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return true;
+ return delegate.getCommentText();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/CompileOptionsManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/CompileOptionsManager.java
index d24ea6b..67783cc 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/CompileOptionsManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/CompileOptionsManager.java
@@ -32,6 +32,7 @@ import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
/**
@@ -78,7 +79,7 @@ public class CompileOptionsManager
};
final IPreferencesService service = Platform.getPreferencesService();
- Set keys = JET2Compiler.getDefaultCompilerOptions().keySet();
+ Set keys = JETCompilerOptions.getDefaultCompilerOptions().keySet();
Map result = new HashMap(keys.size());
for (Iterator i = keys.iterator(); i.hasNext();)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/DefaultJET2ASTVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/DefaultJET2ASTVisitor.java
index 5d09420..6f81509 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/DefaultJET2ASTVisitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/DefaultJET2ASTVisitor.java
@@ -21,6 +21,7 @@ package org.eclipse.jet.compiler;
/**
* An implementation of the {@link org.eclipse.jet.compiler.JET2ASTVisitor} that does nothing.
* Override any of the visit or endVisit methods to create an operational visitor.
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.JETASTVisitor}
*
*/
public abstract class DefaultJET2ASTVisitor implements JET2ASTVisitor
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/IJETCompilerState.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/IJETCompilerState.java
index 2921981..483ea44 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/IJETCompilerState.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/IJETCompilerState.java
@@ -19,6 +19,7 @@ package org.eclipse.jet.compiler;
import java.util.Map;
+import org.eclipse.jet.core.parser.ast.JETASTParser;
import org.eclipse.jet.taglib.TagLibraryReference;
@@ -26,6 +27,7 @@ import org.eclipse.jet.taglib.TagLibraryReference;
* Provides access to the JET compiler state. Saving the compiler state, and then passing it
* to a new instances of {@link JET2Compiler} will allow the compiler to do a correct incremental
* compilation.
+ * @deprecated Use {@link JETASTParser}
*/
public interface IJETCompilerState
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2AST.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2AST.java
index 2a91973..785bfbe 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2AST.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2AST.java
@@ -17,160 +17,103 @@
package org.eclipse.jet.compiler;
+import java.util.HashMap;
import java.util.Map;
-import org.eclipse.jet.taglib.TagDefinition;
+import org.eclipse.jet.core.parser.ast.JETAST;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.core.parser.ast.JETDirective;
+import org.eclipse.jet.core.parser.ast.JavaDeclaration;
+import org.eclipse.jet.core.parser.ast.JavaExpression;
+import org.eclipse.jet.core.parser.ast.JavaScriptlet;
/**
- * The root AST object
+ * The root object of JET AST trees and a factory for JET nodes in that tree.
+ * @deprecated Since 0.8.0, use {@link JETAST}
*
*/
-class JET2AST
+final class JET2AST
{
+ private final JETAST delegateAST;
+ private final Map newToWrapped = new HashMap();
/**
* Create an instance
*/
public JET2AST()
{
- // do nothing
+ delegateAST = new JETAST();
}
-
- /**
- * Create a text element in the AST
- * @param chars the text
- * @return the new element
- */
- TextElement createTextElement(char[] chars)
- {
- return new TextElement(this, chars);
- }
-
- /**
- * Create a new Directive element in the AST
- * @param line the start line
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset (doc relative)
- * @param end the end offset (doc relative)
- * @param directiveName the directive name
- * @param attributes a map off attribute names and values
- * @return the new element
- */
- JET2Directive createDirective(int line, int colOffset, int start, int end, String directiveName, Map attributes)
- {
- return new JET2Directive(this, line, colOffset, start, end, directiveName, attributes);
- }
-
- /**
- * Create a new Java Expression element in the AST
- * @param line the start line
- * @param colOffset the offset within the line of the element's start.
- * @param start the offset of the expression element (doc relative)
- * @param end the end offset of the expression element (doc relative)
- * @param javaStart the offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code
- * @param javaContent the Java content
- * @return the new element
- */
- JET2Expression createExpression(int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
- {
- return new JET2Expression(this, line, colOffset, start, end, javaStart, javaEnd, javaContent);
- }
-
- /**
- * Create a new Java Scriptlet element in the AST
- * @param line the start line
- * @param colOffset the offset within the line of the element's start.
- * @param start the offset of the scriptlet element (doc relative)
- * @param end the end offset of the scriplet element (doc relative)
- * @param javaStart the offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code
- * @param javaContent the Java content
- * @return the new element
- */
- JET2Scriptlet createScriplet(int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
+
+ public JET2AST(JETAST delegateAST)
{
- return new JET2Scriptlet(this, line, colOffset, start, end, javaStart, javaEnd, javaContent);
+ this.delegateAST = delegateAST;
}
- /**
- * Create a new Java Declaration element in the AST
- * @param line the start line
- * @param colOffset the offset within the line of the element's start.
- * @param start the offset of the declaration element (doc relative)
- * @param end the end offset of the declaration element (doc relative)
- * @param javaStart the offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code
- * @param javaContent the Java content
- * @return the new element
- */
- JET2Declaration createDeclaration(int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
- {
- return new JET2Declaration(this, line, colOffset, start, end, javaStart, javaEnd, javaContent);
- }
- /**
- * Create a new empty XML element in the AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param tagName the QName of the element
- * @param attributeMap a Map off element attribute names and values
- * @param td the TagDefinition of the element
- * @return the new element
- */
- XMLEmptyElement createXMLEmptyElement(int line, int colOffset, int start, int end, String tagName, Map attributeMap, TagDefinition td)
+ JETAST getDelegateAST()
{
- return new XMLEmptyElement(this, line, colOffset, start, end, tagName, attributeMap, td);
+ return delegateAST;
}
- /**
- * Create a new XML element with body in the AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param tagName the QName of the element
- * @param attributeMap a Map off element attribute names and values
- * @param td the TagDefinition of the tag
- * @return the new element
- */
- XMLBodyElement createXMLBodyElement(int line, int colOffset, int start, int end, String tagName, Map attributeMap, TagDefinition td)
- {
- return new XMLBodyElement(this, line, colOffset, start, end, tagName, attributeMap, td);
- }
- /**
- * Create a new Comment element in the AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param commentStart the start offset of the comment text (doc relative)
- * @param commentEnd the end offset of the comment text (doc relative)
- * @param comment the comment text
- * @return the new element
- */
- Comment createComment(int line, int colOffset, int start, int end, int commentStart, int commentEnd, char[] comment)
+ public JET2ASTElement wrap(org.eclipse.jet.core.parser.ast.JETASTElement bodyElement)
{
- return new Comment(this, line, colOffset, start, end, commentStart, commentEnd, comment);
+ JET2ASTElement wrapper = (JET2ASTElement)newToWrapped.get(bodyElement);
+ if(wrapper != null) {
+ return wrapper;
+ }
+ if (bodyElement instanceof org.eclipse.jet.core.parser.ast.Comment)
+ {
+ wrapper = new Comment(this, (org.eclipse.jet.core.parser.ast.Comment)bodyElement);
+ }
+ else if (bodyElement instanceof JavaDeclaration)
+ {
+ wrapper = new JET2Declaration(this, (JavaDeclaration)bodyElement);
+ }
+ else if (bodyElement instanceof JavaExpression)
+ {
+ wrapper = new JET2Expression(this, (JavaExpression)bodyElement);
+ }
+ else if (bodyElement instanceof JavaScriptlet)
+ {
+ wrapper = new JET2Scriptlet(this, (JavaScriptlet)bodyElement);
+ }
+ else if (bodyElement instanceof JETDirective)
+ {
+ wrapper = new JET2Directive(this, (JETDirective)bodyElement);
+ }
+ else if (bodyElement instanceof org.eclipse.jet.core.parser.ast.TextElement)
+ {
+ wrapper = new TextElement(this, (org.eclipse.jet.core.parser.ast.TextElement)bodyElement);
+ }
+ else if (bodyElement instanceof org.eclipse.jet.core.parser.ast.XMLBodyElementEnd)
+ {
+ wrapper = new XMLBodyElementEnd(this, (org.eclipse.jet.core.parser.ast.XMLBodyElementEnd)bodyElement);
+ }
+ else if (bodyElement instanceof org.eclipse.jet.core.parser.ast.XMLBodyElement)
+ {
+ wrapper = new XMLBodyElement(this, (org.eclipse.jet.core.parser.ast.XMLBodyElement)bodyElement);
+ }
+ else if (bodyElement instanceof org.eclipse.jet.core.parser.ast.XMLEmptyElement)
+ {
+ wrapper = new XMLEmptyElement(this, (org.eclipse.jet.core.parser.ast.XMLEmptyElement)bodyElement);
+ } else if(bodyElement instanceof org.eclipse.jet.core.parser.ast.JETCompilationUnit) {
+ wrapper = new JET2CompilationUnit(this, (JETCompilationUnit)bodyElement);
+ }
+ newToWrapped.put(bodyElement, wrapper);
+ return wrapper;
}
- /**
- * Create a new XML end element corresponding to the end of a XMLBodyElement.
- * @param line
- * @param col
- * @param start
- * @param end
- * @param tagName
- * @param startTag
- * @return
- */
- XMLBodyElementEnd createXMLBodyElementEnd(int line, int col, int start, int end, String tagName)
+ public Problem wrap(org.eclipse.jet.core.parser.ast.Problem problem)
{
- return new XMLBodyElementEnd(this, line, col, start, end);
+ Problem wrapped = (Problem)newToWrapped.get(problem);
+ if(wrapped == null) {
+ wrapped = new Problem(problem);
+ newToWrapped.put(problem, wrapped);
+ }
+ return wrapped;
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTElement.java
index 8219928..f8cfdc8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTElement.java
@@ -16,60 +16,29 @@
*/
package org.eclipse.jet.compiler;
-
/**
* An abstract class representing common aspects of all JET2 AST elements.
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.JETASTElement}
*/
public abstract class JET2ASTElement
{
- private final int start;
-
- private final int end;
-
- private final JET2AST ast;
+ private JET2AST ast;
- private final int line;
-
- private JET2ASTElement parent = null;
-
- private final int column;
+ private org.eclipse.jet.core.parser.ast.JETASTElement delegate;
/**
* @return Returns the parent.
*/
public final JET2ASTElement getParent()
{
- return parent;
+ return ast.wrap(delegate.getParent());
}
- /**
- * Set the parent element
- * @param parent The parent to set.
- */
- final void setParent(JET2ASTElement parent)
- {
- this.parent = parent;
- }
-
- /**
- * Construct a new AST element
- * @param ast the AST root
- * @param line the line of the element
- * @param column the one-based offset within the line of the element's start.
- * @param start the start offset of the element
- * @param end the end offset of the element
- *
- */
- JET2ASTElement(JET2AST ast, int line, int column, int start, int end)
+ public JET2ASTElement(JET2AST ast, org.eclipse.jet.core.parser.ast.JETASTElement delegate)
{
- super();
this.ast = ast;
- this.column = column;
- this.line = line;
- this.start = start;
- this.end = end;
+ this.delegate = delegate;
}
/**
@@ -78,7 +47,7 @@ public abstract class JET2ASTElement
*/
public final int getStart()
{
- return start;
+ return delegate.getStart();
}
/**
@@ -87,7 +56,7 @@ public abstract class JET2ASTElement
*/
public final int getEnd()
{
- return end;
+ return delegate.getEnd();
}
/**
@@ -99,8 +68,9 @@ public abstract class JET2ASTElement
/**
* Return the AST root object
* @return the AST root object
+ * @since 0.8.0
*/
- JET2AST getAst()
+ public JET2AST getAst()
{
return ast;
}
@@ -111,63 +81,17 @@ public abstract class JET2ASTElement
*/
public final int getLine()
{
- return line;
- }
-
- /**
- * @param element The element for which body elements are sought
- * @return the body elements object
- */
- private BodyElements getBodyElements(JET2ASTElement element)
- {
- BodyElements bodyElements = null;
- if (parent instanceof JET2CompilationUnit)
- {
- bodyElements = ((JET2CompilationUnit)parent).getInternalBodyElements();
- }
- else if (parent instanceof XMLBodyElement)
- {
- bodyElements = ((XMLBodyElement)parent).getInternalBodyElements();
- }
- return bodyElements;
+ return delegate.getLine();
}
public JET2ASTElement getNextElement()
{
- JET2ASTElement next = null;
- if(parent != null)
- {
- BodyElements bodyElements = getBodyElements(parent);
- if (bodyElements != null)
- {
- next = bodyElements.elementAfter(this);
- }
- else
- {
- next = parent.getNextElement();
- }
-
- }
- return next;
+ return ast.wrap(delegate.getNextElement());
}
public JET2ASTElement getPrevElement()
{
- JET2ASTElement prev = null;
- if(parent != null)
- {
- BodyElements bodyElements = getBodyElements(parent);
- if (bodyElements != null)
- {
- prev = bodyElements.elementBefore(this);
- }
- else
- {
- prev = parent.getPrevElement();
- }
-
- }
- return prev;
+ return ast.wrap(delegate.getPrevElement());
}
/**
* Return the column number (one-based) at which the element starts.
@@ -175,7 +99,7 @@ public abstract class JET2ASTElement
*/
public final int getColumn()
{
- return column;
+ return delegate.getColumn();
}
/**
@@ -185,5 +109,14 @@ public abstract class JET2ASTElement
* while element that do should should return <code>true</code>.
* @return <code>true</code> if the containing line should be removed if otherwise empty.
*/
- public abstract boolean removeLineWhenOtherwiseEmpty();
+ public final boolean removeLineWhenOtherwiseEmpty()
+ {
+ return delegate.removeLineWhenOtherwiseEmpty();
+ }
+
+ protected void setDelegate(org.eclipse.jet.core.parser.ast.JETCompilationUnit delegate)
+ {
+ this.delegate = delegate;
+ this.ast = new JET2AST(delegate.getAst());
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTVisitor.java
index f99d5af..96b41b2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTVisitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2ASTVisitor.java
@@ -20,19 +20,19 @@ package org.eclipse.jet.compiler;
/**
* Define a visitor to the JET2 AST tree.
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.JETASTVisitor}
*/
public interface JET2ASTVisitor
{
/**
- * Visit a JET2CompilationUnit element, prior to visiting its body elements.
+ * Visit a JETCompilationUnit element, prior to visiting its body elements.
* @param compilationUnit
*/
public abstract void visit(JET2CompilationUnit compilationUnit);
/**
- * Visit a JET2CompilationUnit element, after visiting its body elements.
+ * Visit a JETCompilationUnit element, after visiting its body elements.
* @param compilationUnit
*/
public abstract void endVisit(JET2CompilationUnit compilationUnit);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
index 48c44e7..62d8469 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
@@ -21,64 +21,104 @@ package org.eclipse.jet.compiler;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jet.core.parser.IProblem;
+import org.eclipse.jet.core.parser.ITagLibraryResolver;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+import org.eclipse.jet.core.parser.ProblemSeverity;
+import org.eclipse.jet.core.parser.ast.BodyElement;
+import org.eclipse.jet.core.parser.ast.JETAST;
+import org.eclipse.jet.core.parser.ast.JETASTParser;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.core.parser.ast.JETASTParser.Builder;
+import org.eclipse.jet.internal.core.parser.jasper.JETReader;
+import org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder;
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryManager;
import org.eclipse.jet.taglib.TagLibraryReference;
/**
* Represent a compilation unit (a template) in the JET2 AST.
+ * @deprecated Since 0.8.0, use {@link JETCompilationUnit}
*
*/
public final class JET2CompilationUnit extends JET2ASTElement
{
+ private JETCompilationUnit delegate;
+
+ private List wrappedBodyElements = null;
- private BodyElements bodyElements = null;
-
- private final List problems = new ArrayList();
-
- private final String fileName;
-
- private String outputJavaPackage = null; //"org.eclipse.jet.compiled";
-
- private String outputJavaClassName;
-
- private boolean errors = false;
-
- private boolean warnings = false;
-
- private final IFile file;
+ private List wrappedProblems = null;
+
private Map predefinedLibraryMap = Collections.EMPTY_MAP;
- private TagLibraryReference[] tagLibraryReferences;
+ private final URI baseLocation;
+
+ private final String templatePath;
+
+ private final ITemplateResolver templateResolver;
- private Set imports = new LinkedHashSet();
+ private final String encoding;
+ /**
+ * @deprecated Use {@link JETAST#newJETCompilationUnit()} instead.
+ *
+ */
public JET2CompilationUnit()
{
- super(new JET2AST(), -1, -1, -1, -1);
- this.fileName = ""; //$NON-NLS-1$
- this.file = null;
+ super(new JET2AST(), null);
+ this.baseLocation = null;
+ this.templatePath = ""; //$NON-NLS-1$
+ templateResolver = null;
+ this.encoding = null;
+
+ this.delegate = getAst().getDelegateAST().newJETCompilationUnit(baseLocation, templatePath, encoding);
+ setDelegate(delegate);
}
+ /**
+ * @param file
+ * @deprecated Use {@link JETAST#newJETCompilationUnit(URI, String)} instead.
+ */
public JET2CompilationUnit(IFile file)
{
- super(new JET2AST(), -1, -1, -1, -1);
- this.file = file;
- this.fileName = file.getFullPath().toString();
+ super(new JET2AST(), null);
+ this.baseLocation = TemplatePathUtil.baseLocationURI(file);
+ this.templatePath = TemplatePathUtil.templatePath(file);
+ templateResolver = new WorkspaceTemplateResolverBuilder(file.getProject()).build();
+ try
+ {
+ this.encoding = file.getCharset();
+ }
+ catch (CoreException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.delegate = getAst().getDelegateAST().newJETCompilationUnit(baseLocation, templatePath, encoding);
+ super.setDelegate(delegate);
+ }
+
+ public JET2CompilationUnit(JET2AST jet2ast, JETCompilationUnit unit)
+ {
+ super(jet2ast, unit);
+ delegate = unit;
+ this.baseLocation = null;
+ this.templatePath = ""; //$NON-NLS-1$
+ this.templateResolver = null;
+ this.encoding = null;
}
/**
@@ -91,6 +131,10 @@ public final class JET2CompilationUnit extends JET2ASTElement
this.predefinedLibraryMap = predefinedLibraryMap;
}
+ /**
+ * @deprecated
+ * @param document
+ */
public void parse(String document)
{
final String ENCODING = "UTF-8"; //$NON-NLS-1$
@@ -107,19 +151,29 @@ public final class JET2CompilationUnit extends JET2ASTElement
}
+ /**
+ * @deprecated
+ * @throws CoreException
+ */
public void parse() throws CoreException
{
- if (file == null)
+ if (templateResolver == null)
{
throw new IllegalStateException();
}
+ IFile file = TemplatePathUtil.workspaceFile(baseLocation, templatePath);
final InputStream contents = file.getContents();
final String charset = file.getCharset();
internalParse(contents, charset);
}
+ /**
+ * @deprecated
+ * @param contents
+ * @param charset
+ */
public void parse(InputStream contents, String charset)
{
internalParse(contents, charset);
@@ -132,29 +186,46 @@ public final class JET2CompilationUnit extends JET2ASTElement
private void internalParse(final InputStream contents, final String charset)
{
// reset parse state...
- problems.clear();
- errors = false;
- warnings = false;
- bodyElements = null;
- outputJavaPackage = null; // "org.eclipse.jet.compiled";
- outputJavaClassName = null;
+ wrappedProblems = null;
+ wrappedBodyElements = null;
+
try
{
- JETReader reader = new JETReader(fileName, contents, charset);
+ InputStreamReader isr = new InputStreamReader(contents, charset);
+
+ JETReader reader = new JETReader(baseLocation == null ? null : baseLocation.toString(), templatePath, isr);
- ASTCompilerParseListener listener = new ASTCompilerParseListener(this, reader,
- predefinedLibraryMap != null ? predefinedLibraryMap : Collections.EMPTY_MAP);
- listener.parse(reader);
+ final Builder builder = new JETASTParser.Builder(JETAST.JET_SPEC_V2)
+ .predefinedTagLibraries(predefinedLibraryMap != null ? predefinedLibraryMap : Collections.EMPTY_MAP)
+ .tagLibraryResolver(new ITagLibraryResolver() {
+
+ public TagLibrary getLibrary(String tagLibraryID)
+ {
+ return TagLibraryManager.getInstance().getTagLibrary(tagLibraryID);
+ }});
+ if(templateResolver != null)
+ {
+ builder.templateResolver(templateResolver);
+ }
+
+ final JETASTParser parser = builder.build();
+
+ delegate = (JETCompilationUnit)parser.parse(reader.getChars());
+ setDelegate(delegate);
- tagLibraryReferences = listener.getTagLibraryReferences();
return;
}
- catch (JETException e)
+ catch (org.eclipse.jet.internal.core.parser.jasper.JETException e)
+ {
+ // create a minimal compilation unit with the exeception recorded as the error.
+ this.createProblem(ProblemSeverity.ERROR, IProblem.JETException, e.getLocalizedMessage(), null, 0, 0, 1, 1);
+ }
+ catch (UnsupportedEncodingException e)
{
// create a minimal compilation unit with the exeception recorded as the error.
- this.createProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), null, 0, 0, 1, 1);
+ this.createProblem(ProblemSeverity.ERROR, IProblem.JETException, e.getLocalizedMessage(), null, 0, 0, 1, 1);
}
finally
{
@@ -170,33 +241,26 @@ public final class JET2CompilationUnit extends JET2ASTElement
}
/**
- * Return the internal BodyElements object that gives access to an updateable
- * list of AST elements the the compilation unit contains
- * @return a BodyElements object
- */
- BodyElements getInternalBodyElements()
- {
- if (bodyElements == null)
- {
- bodyElements = new BodyElements(this);
- }
- return bodyElements;
- }
-
- /**
- * Return a {@link List} of JET2 AST element (@link JET2ASTElement} instances.
+ * Return a {@link List} of JET2 AST element (@link JETASTElement} instances.
* @return a List. The empty list of there are no body elements.
*/
public final List getBodyElements()
{
- if (bodyElements == null)
- {
- return Collections.EMPTY_LIST;
- }
- else
+ if (wrappedBodyElements == null)
{
- return bodyElements.getBodyElements();
+ List delegateBodyElements = delegate.getBodyElements();
+ if(delegateBodyElements.size() == 0) {
+ wrappedBodyElements = Collections.EMPTY_LIST;
+ } else {
+ wrappedBodyElements = new ArrayList(delegateBodyElements.size());
+ for (Iterator i = delegateBodyElements.iterator(); i.hasNext();)
+ {
+ BodyElement bodyElement = (BodyElement)i.next();
+ wrappedBodyElements.add(getAst().wrap(bodyElement));
+ }
+ }
}
+ return wrappedBodyElements;
}
/**
@@ -219,7 +283,21 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public List getProblems()
{
- return Collections.unmodifiableList(problems);
+ if (wrappedProblems == null)
+ {
+ List delegateProblems = delegate.getProblems();
+ if(delegateProblems.size() == 0) {
+ wrappedProblems = Collections.EMPTY_LIST;
+ } else {
+ wrappedProblems = new ArrayList(delegateProblems.size());
+ for (Iterator i = delegateProblems.iterator(); i.hasNext();)
+ {
+ org.eclipse.jet.core.parser.ast.Problem problem = (org.eclipse.jet.core.parser.ast.Problem)i.next();
+ wrappedProblems.add(getAst().wrap(problem));
+ }
+ }
+ }
+ return wrappedProblems;
}
/**
@@ -228,7 +306,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public boolean hasErrors()
{
- return errors;
+ return delegate.hasErrors();
}
/**
@@ -237,7 +315,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public boolean hasWarnings()
{
- return warnings;
+ return delegate.hasWarnings();
}
/**
@@ -251,17 +329,9 @@ public final class JET2CompilationUnit extends JET2ASTElement
* @param line the line number of the problem (1 based)
* @param colOffset TODO
*/
- public void createProblem(ParseProblemSeverity error, int problemId, String message, Object[] messageArgs, int start, int end, int line, int colOffset)
+ public void createProblem(ProblemSeverity error, int problemId, String message, Object[] messageArgs, int start, int end, int line, int colOffset)
{
- if (error == ParseProblemSeverity.ERROR)
- {
- errors = true;
- }
- else if (error == ParseProblemSeverity.WARNING)
- {
- warnings = true;
- }
- problems.add(new Problem(fileName, error, problemId, message, messageArgs, start, end, line, colOffset));
+ delegate.createProblem(error, problemId, message, messageArgs, start, end, line, colOffset);
}
/**
@@ -270,7 +340,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public String getOutputJavaPackage()
{
- return outputJavaPackage;
+ return delegate.getOutputJavaPackage();
}
/**
@@ -279,7 +349,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public String getOutputJavaClassName()
{
- return outputJavaClassName;
+ return delegate.getOutputJavaClassName();
}
/**
@@ -288,7 +358,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public void setOutputJavaClassName(String outputJavaClassName)
{
- this.outputJavaClassName = outputJavaClassName;
+ delegate.setOutputJavaClassName(outputJavaClassName);
}
/**
@@ -297,30 +367,35 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public void setOutputJavaPackage(String outputJavaPackage)
{
- this.outputJavaPackage = outputJavaPackage;
+ delegate.setOutputJavaPackage(outputJavaPackage);
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return false;
- }
-
/**
* Return an array of tag libraries referenced by this template.
* @return a possibly empty array of tag library references.
*/
public TagLibraryReference[] getTagLibraryReferences()
{
- return tagLibraryReferences;
+ return delegate.getTagLibraryReferences();
}
public void addImports(List list)
{
- imports .addAll(list);
+ delegate.addImports(list);
}
public Set getImports()
{
- return Collections.unmodifiableSet(imports);
+ return delegate.getImports();
+ }
+
+ /**
+ * Return the underlying {@link JETCompilationUnit} to which this instance delegates.
+ * Useful for calling mashing only 0.7.x code with later code.
+ * @return the underlying {@link JETCompilationUnit}
+ * @since 0.8.0
+ */
+ public JETCompilationUnit getDelegateCU() {
+ return delegate;
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
index 875ad3c..780334a 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
@@ -18,44 +18,24 @@
package org.eclipse.jet.compiler;
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.JETActivatorWrapper;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.internal.builder.WorkspaceCompiler;
import org.eclipse.jet.internal.compiler.JETCompilerState;
-import org.eclipse.jet.internal.compiler.LoaderGenerationParameters;
-import org.eclipse.jet.internal.compiler.TemplateRunner;
-import org.eclipse.jet.internal.compiler.TextTrimmingVisitor;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-import org.eclipse.jet.taglib.TagLibraryReference;
-import org.eclipse.jet.transform.IJETBundleDescriptor;
-import org.eclipse.jet.transform.IJETBundleManager;
/**
* The compiler that turns a JET2 sources files Java files in the Eclipse workspace.
- *
+ * @deprecated Since 0.8.0, use {@link WorkspaceCompiler} or {@link JETCompilerOptions} for options
*/
public class JET2Compiler
{
@@ -69,81 +49,66 @@ public class JET2Compiler
/**
* The default value of the {@link #OPTION_COMPILED_TEMPLATE_PACKAGE} option; value: "org.eclipse.jet2.internal.compiled".
+ * @deprecated Use {@link JETCompilerOptions#DEFAULT_COMPILED_TEMPLATE_PACKAGE} instead
*/
- public static final String DEFAULT_COMPILED_TEMPLATE_PACKAGE = "org.eclipse.jet.compiled"; //$NON-NLS-1$
+ public static final String DEFAULT_COMPILED_TEMPLATE_PACKAGE = JETCompilerOptions.DEFAULT_COMPILED_TEMPLATE_PACKAGE;
/**
* The default value of the {@link #OPTION_COMPILED_TEMPLATE_SRC_DIR} option; value: "jet2java".
+ * @deprecated Use {@link JETCompilerOptions#DEFAULT_COMPILED_TEMPLATE_SRC_DIR} instead
*/
- public static final String DEFAULT_COMPILED_TEMPLATE_SRC_DIR = "jet2java"; //$NON-NLS-1$
+ public static final String DEFAULT_COMPILED_TEMPLATE_SRC_DIR = JETCompilerOptions.DEFAULT_COMPILED_TEMPLATE_SRC_DIR;
/**
* The default value of the {@link #OPTION_TEMPLATE_EXT} option; value: "jet".
+ * @deprecated Use {@link JETCompilerOptions#DEFAULT_TEMPLATE_EXT} instead
*/
- public static final String DEFAULT_TEMPLATE_EXT = "jet"; //$NON-NLS-1$
+ public static final String DEFAULT_TEMPLATE_EXT = JETCompilerOptions.DEFAULT_TEMPLATE_EXT;
- public static final Boolean DEFAULT_SET_JAVA_FILES_AS_DERIVED = Boolean.TRUE;
-
- private static final String NS = "org.eclipse.jet."; //$NON-NLS-1$
+ /**
+ * @deprecated Use {@link JETCompilerOptions#DEFAULT_SET_JAVA_FILES_AS_DERIVED} instead
+ */
+ public static final Boolean DEFAULT_SET_JAVA_FILES_AS_DERIVED = JETCompilerOptions.DEFAULT_SET_JAVA_FILES_AS_DERIVED;
/**
* Compiler option specifying the package to which compiled templates are written; value: "compiledTemplatePackage".
+ * @deprecated Use {@link JETCompilerOptions#OPTION_COMPILED_TEMPLATE_PACKAGE} instead
*/
- public static final String OPTION_COMPILED_TEMPLATE_PACKAGE = NS + "compiledTemplatePackage"; //$NON-NLS-1$
+ public static final String OPTION_COMPILED_TEMPLATE_PACKAGE = JETCompilerOptions.OPTION_COMPILED_TEMPLATE_PACKAGE;
/**
* Compiler option specifying the Java project source directory to which compiled templates are written; value: "compiledTemplateSrcDir".
+ * @deprecated Use {@link JETCompilerOptions#OPTION_COMPILED_TEMPLATE_SRC_DIR} instead
*/
- public static final String OPTION_COMPILED_TEMPLATE_SRC_DIR = NS + "compiledTemplateSrcDir"; //$NON-NLS-1$
+ public static final String OPTION_COMPILED_TEMPLATE_SRC_DIR = JETCompilerOptions.OPTION_COMPILED_TEMPLATE_SRC_DIR;
/**
* Compiler option specifying which extensions are recognized as extensions; value: "templateExt".
+ * @deprecated Use {@link JETCompilerOptions#OPTION_TEMPLATE_EXT} instead
*/
- public static final String OPTION_TEMPLATE_EXT = NS + "templateExt"; //$NON-NLS-1$
+ public static final String OPTION_TEMPLATE_EXT = JETCompilerOptions.OPTION_TEMPLATE_EXT;
- public static final String OPTION_SET_JAVA_FILES_AS_DERIVED = NS + "setJavaDerived"; //$NON-NLS-1$
+ /**
+ * @deprecated Use {@link JETCompilerOptions#OPTION_SET_JAVA_FILES_AS_DERIVED} instead
+ */
+ public static final String OPTION_SET_JAVA_FILES_AS_DERIVED = JETCompilerOptions.OPTION_SET_JAVA_FILES_AS_DERIVED;
- private static Map defaultCompileOptions = null;
- private static final Object defaultCompileOptionsLock = new Object();
-
// Return the default compile options...
+ /**
+ * @deprecated Use {@link JETCompilerOptions#getDefaultCompilerOptions()} instead
+ */
public static Map getDefaultCompilerOptions()
{
- if(defaultCompileOptions == null)
- {
- Map map = new HashMap();
- map.put(OPTION_COMPILED_TEMPLATE_PACKAGE, DEFAULT_COMPILED_TEMPLATE_PACKAGE);
- map.put(OPTION_COMPILED_TEMPLATE_SRC_DIR, DEFAULT_COMPILED_TEMPLATE_SRC_DIR);
- map.put(OPTION_TEMPLATE_EXT, DEFAULT_TEMPLATE_EXT);
- map.put(OPTION_SET_JAVA_FILES_AS_DERIVED, DEFAULT_SET_JAVA_FILES_AS_DERIVED);
-
- synchronized(defaultCompileOptionsLock)
- {
- defaultCompileOptions = Collections.unmodifiableMap(map);
- }
- }
- return defaultCompileOptions;
+ return JETCompilerOptions.getDefaultCompilerOptions();
}
- private final IProgressMonitor monitor;
-
- private final IProject project;
-
- private IJETCompilerState compilerState;
-
private int noCompiles;
private final Map options;
- private final Map predefinedLibraryMap;
-
- private final String templateLoaderPackage;
-
- private final String templateLoaderClassName;
-
private Set sourceExtensions = null;
- private final TemplateRunner templateRunner;
+ private final WorkspaceCompiler workspaceCompiler;
/**
* Create an instance of the JET compiler capable of incremental compilation from a saved state.
@@ -154,31 +119,10 @@ public class JET2Compiler
*/
public JET2Compiler(IProject project, Map options, IJETCompilerState compilerState, IProgressMonitor monitor)
{
- super();
- this.project = project;
- this.monitor = monitor == null ? new NullProgressMonitor() : monitor;
- this.options = options == null ? getDefaultCompilerOptions() : options;
- this.compilerState = compilerState;
+ this.workspaceCompiler = new WorkspaceCompiler(project, null, monitor);
+ this.options = options == null ? JETCompilerOptions.getDefaultCompilerOptions() : options;
this.noCompiles = 0;
-
- final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
-
- final IJETBundleDescriptor descriptor = bundleManager.getDescriptorForProject(project.getName());
- predefinedLibraryMap = descriptor != null ? getPredefinedPrefixMap(descriptor) : Collections.EMPTY_MAP;
-
- if (descriptor != null && descriptor.getTemplateLoaderClass() != null)
- {
- final String templateLoaderClass = descriptor.getTemplateLoaderClass();
- int index = templateLoaderClass.lastIndexOf('.');
- templateLoaderPackage = index >= 0 ? templateLoaderClass.substring(0, index) : ""; //$NON-NLS-1$
- templateLoaderClassName = index >= 0 ? templateLoaderClass.substring(index + 1) : templateLoaderClass;
- }
- else
- {
- templateLoaderPackage = templateLoaderClassName = null;
- }
- templateRunner = new TemplateRunner();
}
/**
* Create an instance
@@ -192,89 +136,20 @@ public class JET2Compiler
this(project, options, new JETCompilerState(), monitor);
}
- 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())
- {
- result.put(tlRefs[i].getPrefix(), tlRefs[i].getTagLibraryId());
- }
- }
- return result;
- }
-
/**
* Create the Template Loader class for the project
*/
public void createTransformFiles()
{
- if(noCompiles > 0)
- {
- createTemplateLoaderClass();
- }
- }
-
- /**
- * Create the Class that loads compiled templates.
- */
- private void createTemplateLoaderClass()
- {
- if(templateLoaderClassName == null) return;
-
- final LoaderGenerationParameters args = new LoaderGenerationParameters(templateLoaderPackage,
- templateLoaderClassName, compilerState.getTemplateMap());
-
- String src = templateRunner.generate("templates/jet2transform.jet", //$NON-NLS-1$
- Collections.singletonMap("args", args)); //$NON-NLS-1$
-
- IPath targetPath = new Path(getSourceDirOption()).append(
- templateLoaderPackage.replace('.', '/')).append(templateLoaderClassName).addFileExtension("java"); //$NON-NLS-1$
-
- try
- {
- final IFile file = project.getFile(targetPath);
- writeFile(src, file, file.getCharset());
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
- }
- catch (UnsupportedEncodingException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
- }
- }
-
- /**
- * @return
- */
- private String getSourceDirOption()
- {
- return getOption(JET2Compiler.OPTION_COMPILED_TEMPLATE_SRC_DIR, JET2Compiler.DEFAULT_COMPILED_TEMPLATE_SRC_DIR);
+ workspaceCompiler.finish();
}
- private String getOption(String key, String defaultValue)
- {
- Object value = options.get(key);
- return value == null ? defaultValue : value.toString();
- }
-
- private boolean getBooleanOption(String key, boolean defaultValue)
- {
- Object value = options.get(key);
- return value == null ? defaultValue :
- value instanceof Boolean ? ((Boolean)value).booleanValue() :
- Boolean.valueOf(value.toString()).booleanValue();
- }
-
private boolean isJETSource(IPath path)
{
if(sourceExtensions == null) {
sourceExtensions = new HashSet();
- final String[] extensions = getOption(OPTION_TEMPLATE_EXT, DEFAULT_TEMPLATE_EXT).split(","); //$NON-NLS-1$
+ final String[] extensions = JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_TEMPLATE_EXT)
+ .split(","); //$NON-NLS-1$
for (int i = 0; i < extensions.length; i++)
{
sourceExtensions.add(extensions[i]);
@@ -299,280 +174,8 @@ public class JET2Compiler
*/
public void compile(IResource resource)
{
- if (!isJET2SourceFile(resource))
- {
- return; // ignore
- }
-
- ++noCompiles;
-
- IFile file = (IFile)resource;
-
- clean(resource.getProjectRelativePath().toString());
-
- removeMarkers(resource);
-
- JET2CompilationUnit cu = new JET2CompilationUnit(file);
- cu.setPredefinedTagLibraries(predefinedLibraryMap);
- try
- {
- cu.parse();
-
- cu.accept(new TagValidationVisitor(cu));
-
- markProblems(resource, cu);
-
- if (!cu.hasErrors())
- {
- cu.accept(new TextTrimmingVisitor());
- writeCompiledOutput(file, cu);
- }
- }
- catch (CoreException e)
- {
- // core exceptions represent problems reading the source file
- createParseExceptionMarker(resource, e);
- }
-
- }
- /**
- * @param resource
- */
- private void removeMarkers(IResource resource)
- {
- try
- {
- resource.deleteMarkers(COMPILE_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
- resource.deleteMarkers(RUNTIME_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorRemovingMarkers, e);
- }
- }
-
- private void createParseExceptionMarker(IResource resource, CoreException e)
- {
- try
- {
- IMarker marker = resource.createMarker(COMPILE_PROBLEM_MARKER);
- marker.setAttribute(IMarker.MESSAGE, e.getStatus().getMessage());
- marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
- }
- catch (CoreException ex)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorCreatingMarkers, e);
- }
- }
-
- /**
- * Place problem markers on the passed resource for each problem recorded in the compilation unit.
- * @param resource the resource to mark
- * @param cu the compilation unit corresponding to the resource
- */
- private void markProblems(IResource resource, JET2CompilationUnit cu)
- {
- try
- {
- for (Iterator i = cu.getProblems().iterator(); i.hasNext();)
- {
- Problem problem = (Problem)i.next();
- IMarker marker = resource.createMarker(COMPILE_PROBLEM_MARKER);
- marker.setAttribute(IMarker.LINE_NUMBER, problem.getLineNumber());
- marker.setAttribute(IMarker.CHAR_START, problem.getStart());
- marker.setAttribute(IMarker.CHAR_END, problem.getEnd());
- marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
- marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
- if (problem.getSeverity() == ParseProblemSeverity.ERROR)
- {
- marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
- }
- else if (problem.getSeverity() == ParseProblemSeverity.WARNING)
- {
- marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- }
- else
- {
- marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
- }
- }
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
- }
- }
-
- /**
- * @param file
- * @param cu
- */
- private void writeCompiledOutput(IFile file, JET2CompilationUnit cu)
- {
-
- ensureJavaOutputSet(file, cu);
-
- final String templatePath = file.getProjectRelativePath().toString();
- final String qualifiedClassName = makeFullyQualifiedJavaName(cu.getOutputJavaPackage(), cu.getOutputJavaClassName());
-
- if (templatePath.equals(compilerState.getTemplateFromClass(qualifiedClassName)))
- {
- cu.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MultipleTemplatesWithSameJavaClass,
- JET2Messages.JET2Compiler_SameJavaClassAsOther,
- new Object []{ qualifiedClassName, compilerState.getTemplateFromClass(qualifiedClassName), },
- -1,
- -1,
- -1,
- -1);
- }
-
- String javaSrc = templateRunner.generate("templates/jet2java.jet", //$NON-NLS-1$
- Collections.singletonMap("cu", cu)); //$NON-NLS-1$
-
- IFile targetFile = file.getProject().getFile(javaClassProjectPath(qualifiedClassName));
- try
- {
- writeFile(javaSrc, targetFile, file.getCharset());
- compilerState.addTemplate(templatePath, qualifiedClassName);
- compilerState.addTemplateTagLibraryReferences(templatePath, cu.getTagLibraryReferences());
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
- }
- catch (UnsupportedEncodingException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
- }
- }
-
- /**
- * Ensure the the compilation unit has Java output package and class
- * set. If not, generate names for these, taking into account that
- * a name may have been generated for them already.
- * @param file
- * @param cu
- */
- private boolean ensureJavaOutputSet(IFile file, JET2CompilationUnit cu)
- {
- boolean inferedJavaPackage = false;
- final String templatePath = file.getProjectRelativePath().toString();
-
- // See if we already have a name for this...
- final String existingQualifiedClass = (String)compilerState.getTemplateMap().get(templatePath);
-
- if (existingQualifiedClass == null)
- {
- // we haven't generated a name before, do it now...
-
- if (cu.getOutputJavaPackage() == null)
- {
- cu.setOutputJavaPackage(getOption(JET2Compiler.OPTION_COMPILED_TEMPLATE_PACKAGE, JET2Compiler.DEFAULT_COMPILED_TEMPLATE_PACKAGE));
- inferedJavaPackage = true;
- }
- if (cu.getOutputJavaClassName() == null)
- {
- // check for conflicts because we have name mangled
- // or for identically named files in different directories.
- String baseClassName = makeJavaClassName(file.getFullPath().removeFileExtension().lastSegment());
-
- String className = baseClassName;
- String potentialQualifiedName = makeFullyQualifiedJavaName(cu.getOutputJavaPackage(), className);
-
- for (int i = 0; compilerState.getTemplateFromClass(potentialQualifiedName) != null; i++)
- {
- className = baseClassName + "_" + i; //$NON-NLS-1$
- potentialQualifiedName = makeFullyQualifiedJavaName(cu.getOutputJavaPackage(), className);
- }
-
- cu.setOutputJavaClassName(className);
- }
- }
- else
- {
- int index = existingQualifiedClass.lastIndexOf('.');
- String existingPackage = index == -1 ? "" : existingQualifiedClass.substring(0, index); //$NON-NLS-1$
- String existingClass = index == -1 ? existingQualifiedClass : existingQualifiedClass.substring(index + 1);
-
- if (cu.getOutputJavaPackage() == null)
- {
- cu.setOutputJavaPackage(existingPackage);
- }
- if (cu.getOutputJavaClassName() == null)
- {
- cu.setOutputJavaClassName(existingClass);
- }
- }
- return inferedJavaPackage;
- }
-
- /**
- * @param javaClassName
- * @return the project relative path of the generated java file
- */
- private IPath javaClassProjectPath(String javaClassName)
- {
- IPath targetPath = new Path(getSourceDirOption()).append(javaClassName.replace('.', '/')).addFileExtension("java"); //$NON-NLS-1$
- return targetPath;
- }
-
- private String makeFullyQualifiedJavaName(String javaPackage, String javaClassName)
- {
- return javaPackage == null || javaPackage.trim().length() == 0 ? javaClassName : javaPackage + '.' + javaClassName;
- }
-
- /**
- * @param javaSrc
- * @param targetFile
- * @param charset the character encoding of the .jet source file
- * @throws CoreException
- * @throws UnsupportedEncodingException
- */
- private void writeFile(String javaSrc, IFile targetFile, String charset) throws CoreException, UnsupportedEncodingException
- {
- ensureDirsExist(targetFile.getParent());
-
- if (!targetFile.exists())
- {
- targetFile.create(new ByteArrayInputStream(new byte []{}), true, new SubProgressMonitor(monitor, 1));
- }
-
- if (!targetFile.getCharset().equals(charset))
- {
- targetFile.setCharset(charset, new SubProgressMonitor(monitor, 1));
- }
-
- targetFile.setContents(new ByteArrayInputStream(javaSrc.getBytes(charset)), true, false, new SubProgressMonitor(monitor, 1));
- targetFile.setDerived(getBooleanOption(OPTION_SET_JAVA_FILES_AS_DERIVED, DEFAULT_SET_JAVA_FILES_AS_DERIVED.booleanValue()));
- }
-
- private void ensureDirsExist(IContainer container) throws CoreException
- {
- if (container != null && !container.exists() && container.getType() == IResource.FOLDER)
- {
- ensureDirsExist(container.getParent());
- ((IFolder)container).create(false, true, monitor);
- }
- }
-
- private String makeJavaClassName(String name)
- {
- StringBuffer result = new StringBuffer("_jet_"); //$NON-NLS-1$
- for (int i = 0; i < name.length(); i++)
- {
- char c = name.charAt(i);
- if (Character.isJavaIdentifierPart(c))
- {
- result.append(c);
- }
- }
- return result.toString();
+ ++ noCompiles;
+ workspaceCompiler.compile(resource.getProjectRelativePath().toString());
}
/**
@@ -598,35 +201,9 @@ public class JET2Compiler
*/
public void removeDerivedResources(IResource resource, boolean derivedOnly) throws CoreException
{
- if (!isJET2SourceFile(resource))
- {
- return; // ignore
- }
-
- String javaClassName = (String)compilerState.getTemplateMap().get(resource.getProjectRelativePath().toString());
- if (javaClassName != null)
- {
- ++noCompiles;
- removeJavaClass(javaClassName, derivedOnly);
- }
-
- }
- /**
- * @param javaClassName
- * @param derivedOnly
- * @throws CoreException
- */
- private void removeJavaClass(String javaClassName, boolean derivedOnly) throws CoreException
- {
- IPath javaSrcFile = javaClassProjectPath(javaClassName);
-
- IFile file = project.getFile(javaSrcFile);
- if (file.exists() && (file.isDerived() || !derivedOnly))
- {
- file.delete(true, new SubProgressMonitor(monitor, 1));
- }
+ workspaceCompiler.removeTemplate(resource.getProjectRelativePath().toString());
}
-
+
/**
* @return Returns the noCompiles.
*/
@@ -637,54 +214,7 @@ public class JET2Compiler
public void clean()
{
- // make a safe copy of the keyset, as we will be modifying the template map by cleaning...
- final Set templatePathSet = new HashSet(compilerState.getTemplateMap().keySet());
- monitor.beginTask("", templatePathSet.size() + 2); //$NON-NLS-1$
- for (Iterator i = templatePathSet.iterator(); i.hasNext();)
- {
- String templatePath = (String)i.next();
- clean(templatePath);
- }
-
- if(templateLoaderClassName != null)
- {
- try
- {
- removeJavaClass(templateLoaderPackage + "." + templateLoaderClassName, true); //$NON-NLS-1$
- }
- catch (CoreException e)
- {
- JETActivatorWrapper.INSTANCE.log(e);
- }
- }
-
- removeMarkers(project);
- monitor.done();
- }
- /**
- * @param templatePath
- */
- private void clean(String templatePath)
- {
- IFile templateResource = project.getFile(templatePath);
- try
- {
- removeDerivedResources(templateResource, true);
- compilerState.removeTemplate(templatePath);
- }
- catch (CoreException e)
- {
- JETActivatorWrapper.INSTANCE.log(e);
- }
- }
-
- /**
- * Returns the current compiler state
- * @return the current compiler state
- */
- public final IJETCompilerState getCompilerState()
- {
- return compilerState;
+ workspaceCompiler.clean();
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Declaration.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Declaration.java
index 5edb5ae..6325558 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Declaration.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Declaration.java
@@ -17,28 +17,20 @@
package org.eclipse.jet.compiler;
+import org.eclipse.jet.core.parser.ast.JavaDeclaration;
+
/**
* Define a Java Declaration Element in the JET2 AST
+ * @deprecated Since 0.8.0, use {@link JavaDeclaration}
*
*/
public final class JET2Declaration extends JavaElement
{
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param javaStart the start offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code (doc relative)
- * @param javaContent the Java code
- */
- JET2Declaration(JET2AST ast, int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
+ public JET2Declaration(JET2AST jet2ast, JavaDeclaration declaration)
{
- super(ast, line, colOffset, start, end, javaStart, javaEnd, javaContent);
+ super(jet2ast, declaration);
}
/**
@@ -49,9 +41,4 @@ public final class JET2Declaration extends JavaElement
visitor.visit(this);
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return true;
- }
-
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Directive.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Directive.java
index dc60ce8..943cdb8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Directive.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Directive.java
@@ -18,55 +18,42 @@
package org.eclipse.jet.compiler;
-import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.Map;
+import org.eclipse.jet.core.parser.ast.JETDirective;
+
/**
* Define a Directive Element in the JET2 AST
- *
+ * @deprecated Since 0.8.0, use {@link JETDirective}
*/
public final class JET2Directive extends JET2ASTElement
{
- private final String name;
-
- private final Map attributes;
+ private final JETDirective delegate;
- /**
- * Create an instance
- * @param ast the owning JET2 AST
- * @param line the start line of the directive
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the directive (doc relative)
- * @param end the end offset of the directive (doc relative)
- * @param name the directive name
- * @param attributes a Map of attribute names to attribute values for the directive
- */
- JET2Directive(JET2AST ast, int line, int colOffset, int start, int end, String name, Map attributes)
+ public JET2Directive(JET2AST jet2ast, JETDirective directive)
{
- super(ast, line, colOffset, start, end);
- this.name = name;
- this.attributes = Collections.unmodifiableMap(new LinkedHashMap(attributes));
+ super(jet2ast, directive);
+ this.delegate = directive;
}
/**
- * Return the directive name
- * @return the directive name
+ * Return the delegate name
+ * @return the delegate name
*/
public final String getName()
{
- return name;
+ return delegate.getName();
}
/**
- * Return a Map the directive attribute names to values
- * @return a Map of the directive attributes (unmodifiable)
+ * Return a Map the delegate attribute names to values
+ * @return a Map of the delegate attributes (unmodifiable)
*/
public final Map getAttributes()
{
- return attributes;
+ return delegate.getAttributes();
}
/**
@@ -76,10 +63,4 @@ public final class JET2Directive extends JET2ASTElement
{
visitor.visit(this);
}
-
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return true;
- }
-
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Expression.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Expression.java
index 084369b..0b12001 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Expression.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Expression.java
@@ -17,29 +17,20 @@
package org.eclipse.jet.compiler;
+import org.eclipse.jet.core.parser.ast.JavaExpression;
+
/**
* Define a Java Expression Element in the JET2 AST
- *
+ * @deprecated Since 0.8.0, use {@link JavaExpression}
*/
public final class JET2Expression extends JavaElement
{
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param javaStart the start offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code (doc relative)
- * @param javaContent the Java code
- */
- JET2Expression(JET2AST ast, int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
+ public JET2Expression(JET2AST ast, JavaExpression expression)
{
- super(ast, line, colOffset, start, end, javaStart, javaEnd, javaContent);
+ super(ast, expression);
}
/**
@@ -50,9 +41,4 @@ public final class JET2Expression extends JavaElement
visitor.visit(this);
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return false;
- }
-
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Scriptlet.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Scriptlet.java
index 4461503..949d15e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Scriptlet.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Scriptlet.java
@@ -17,28 +17,19 @@
package org.eclipse.jet.compiler;
+import org.eclipse.jet.core.parser.ast.JavaScriptlet;
+
/**
* Define a Java Scriptlet Element in the JET2 AST
- *
+ * @deprecated Since 0.8.0, use {@link JavaScriptlet}
*/
public final class JET2Scriptlet extends JavaElement
{
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param javaStart the start offset of the Java code (doc relative)
- * @param javaEnd the end offset of the Java code (doc relative)
- * @param javaContent the Java code
- */
- JET2Scriptlet(JET2AST ast, int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
+ public JET2Scriptlet(JET2AST ast, JavaScriptlet scriptlet)
{
- super(ast, line, colOffset, start, end, javaStart, javaEnd, javaContent);
+ super(ast, scriptlet);
}
/**
@@ -49,9 +40,4 @@ public final class JET2Scriptlet extends JavaElement
visitor.visit(this);
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return true;
- }
-
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JavaElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JavaElement.java
index 89c7ae3..d8971ab 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JavaElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JavaElement.java
@@ -17,37 +17,20 @@
package org.eclipse.jet.compiler;
-
/**
* Abstract representation of JET2 AST elements that contain Java code
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.JavaElement}
*/
public abstract class JavaElement extends JET2ASTElement
{
- private final int javaStart;
-
- private final int javaEnd;
+ private final org.eclipse.jet.core.parser.ast.JavaElement delegate;
- private final char[] javaContent;
- /**
- * Create a new instance
- * @param ast the root AST to which the element belongs
- * @param line the line in which the element begins
- * @param colOffset the offset within the line of the element's start.
- * @param start the offset at which the element starts (doc relative)
- * @param end the offset at which the element ends (doc relative)
- * @param javaStart the offset at which the Java code starts (doc relative)
- * @param javaEnd the offset at which the Java code ends (doc relative)
- * @param javaContent the java code
- */
- JavaElement(JET2AST ast, int line, int colOffset, int start, int end, int javaStart, int javaEnd, char[] javaContent)
+ public JavaElement(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.JavaElement delegate)
{
- super(ast, line, colOffset, start, end);
- this.javaStart = javaStart;
- this.javaEnd = javaEnd;
- this.javaContent = javaContent;
+ super(jet2ast, delegate);
+ this.delegate = delegate;
}
/**
@@ -56,7 +39,7 @@ public abstract class JavaElement extends JET2ASTElement
*/
public final int getJavaStart()
{
- return javaStart;
+ return delegate.getJavaStart();
}
/**
@@ -65,7 +48,7 @@ public abstract class JavaElement extends JET2ASTElement
*/
public final int getJavaEnd()
{
- return javaEnd;
+ return delegate.getJavaEnd();
}
/**
@@ -74,6 +57,6 @@ public abstract class JavaElement extends JET2ASTElement
*/
public String getJavaContent()
{
- return new String(javaContent);
+ return delegate.getJavaContent();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
index 4a87d6d..e99b8cf 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
@@ -18,127 +18,134 @@
package org.eclipse.jet.compiler;
+import java.net.URI;
import java.text.MessageFormat;
+import org.eclipse.jet.core.parser.IProblem;
+import org.eclipse.jet.core.parser.ProblemSeverity;
import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-
/**
* Represent a compilation problem on a JET2 tempalte.
- *
+ * <p>
+ * This class is not intended to be extended by clients
+ * </p>
+ * @since 0.7.0
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.Problem}
*/
-public class Problem
+public final class Problem
{
/**
* Error Id for an XML end tag that has no corresponding start tag.
* @see #getId()
+ * @deprecated Use {@link IProblem#MissingXmlStartTag}
*/
- public static final int MissingXmlStartTag = 1;
+ public static final int MissingXmlStartTag = IProblem.MissingXmlStartTag;
/**
* Error Id for an XML start tag that has no corresponding end tag.
* @see #getId()
+ * @deprecated Use {@link IProblem#MissingXmlEndTag}
*/
- public static final int MissingXmlEndTag = 2;
+ public static final int MissingXmlEndTag = IProblem.MissingXmlEndTag;
/**
* Error Id for an XML tag or JET directive that is missing a required attribute
* @see #getId()
+ * @deprecated Use {@link IProblem#MissingRequiredAttribute}
*/
- public static final int MissingRequiredAttribute = 3;
+ public static final int MissingRequiredAttribute = IProblem.MissingRequiredAttribute;
/**
* Error Id for taglib directive that defines a prefix defined by a preceding taglib directive
* @see #getId()
+ * @deprecated Use {@link IProblem#DuplicateXMLNamespacePrefix}
*/
- public static final int DuplicateXMLNamespacePrefix = 4;
+ public static final int DuplicateXMLNamespacePrefix = IProblem.DuplicateXMLNamespacePrefix;
/**
* Error Id for taglib directive that defines references an unknown tag library id
* @see #getId()
+ * @deprecated Use {@link IProblem#UnknownTagLibrary}
*/
- public static final int UnknownTagLibrary = 5;
+ public static final int UnknownTagLibrary = IProblem.UnknownTagLibrary;
/**
* Error Id for an attribute that is not defined in the tag definition
+ * @deprecated Use {@link IProblem#UnknownAttributeInTag}
*/
- public static final int UnknownAttributeInTag = 6;
+ public static final int UnknownAttributeInTag = IProblem.UnknownAttributeInTag;
/**
* Represent an unterminated XML Tag
+ * @deprecated Use {@link IProblem#UnterminatedXMLTag}
*/
- public static final int UnterminatedXMLTag = 7;
+ public static final int UnterminatedXMLTag = IProblem.UnterminatedXMLTag;
/**
* Represent a duplicate attribute in an XML Tag;
+ * @deprecated Use {@link IProblem#DuplicateAttribute}
*/
- public static final int DuplicateAttribute = 8;
+ public static final int DuplicateAttribute = IProblem.DuplicateAttribute;
/**
* An underlying JETException was thrown by the JET parser
+ * @deprecated Use {@link IProblem#JETException}
*/
- public static final int JETException = 9;
+ public static final int JETException = IProblem.JETException;
/**
* Two templates specify that they compile to the same Java Class
+ * @deprecated Use {@link IProblem#MultipleTemplatesWithSameJavaClass}
*/
- public static final int MultipleTemplatesWithSameJavaClass = 10;
+ public static final int MultipleTemplatesWithSameJavaClass = IProblem.MultipleTemplatesWithSameJavaClass;
/**
* Use of an attribute that has been deprecated.
+ * @deprecated Use {@link IProblem#DeprecatedAttribute}
*/
- public static final int DeprecatedAttribute = 11;
+ public static final int DeprecatedAttribute = IProblem.DeprecatedAttribute;
/**
* Tag may not have a body - the tag must be of the form &lt;tagName/&gt;.
+ * @deprecated Use {@link IProblem#TagCannotHaveContent}
*/
- public static final int TagCannotHaveContent = 12;
+ public static final int TagCannotHaveContent = IProblem.TagCannotHaveContent;
/**
* Tag must have content - the tag must be of the form &lt;tagName&gt;xxx&lt;/tagName&gt;.
+ * @deprecated Use {@link IProblem#TagCannotBeEmpty}
*/
- public static final int TagCannotBeEmpty = 13;
+ public static final int TagCannotBeEmpty = IProblem.TagCannotBeEmpty;
/**
* Use of the tag has been deprecated.
+ * @deprecated Use {@link IProblem#DeprecatedTag}
*/
- public static final int DeprecatedTag = 14;
+ public static final int DeprecatedTag = IProblem.DeprecatedTag;
/**
* Unsupported Directive.
+ * @deprecated Use {@link IProblem#UnsupportedDirective}
*/
- public static final int UnsupportedDirective = 15;
+ public static final int UnsupportedDirective = IProblem.UnsupportedDirective;
/**
* A tag that has a known tag library prefix, but is not a recognized name. Usually
* indicates a typographical error.
+ * @deprecated Use {@link IProblem#UnknownXMLTag}
*/
- public static final int UnknownXMLTag = 16;
+ public static final int UnknownXMLTag = IProblem.UnknownXMLTag;
/**
* A tag this is declared as an 'emptyTag' occured as &lt;tag ...&gt;, and has been
* interpreted as the equivalent empty tag &lt;tag .../&gt;.
+ * @deprecated Use {@link IProblem#TagInterpretedAsEmptyTag}
*/
- public static final int TagInterpretedAsEmptyTag = 17;
-
- private final String originatingFileName;
-
- private final int id;
-
- private final String message;
-
- private final Object[] messageArgs;
-
- private final int start;
-
- private final int end;
-
- private final int lineNumber;
-
- private final ParseProblemSeverity severity;
+ public static final int TagInterpretedAsEmptyTag = IProblem.TagInterpretedAsEmptyTag;
- private final int colOffset;
+ private final org.eclipse.jet.core.parser.ast.Problem delegate;
/**
* Create an new instance
@@ -151,6 +158,7 @@ public class Problem
* @param end the end offset of the problem (doc relative)
* @param lineNumber the start line of the problem
* @param colOffset TODO
+ * @deprecated Use {@link #Problem(URI,String,ProblemSeverity,int,String,Object[],int,int,int,int)} instead
*/
public Problem(
String originatingFileName,
@@ -163,16 +171,50 @@ public class Problem
int lineNumber,
int colOffset)
{
- super();
- this.originatingFileName = originatingFileName;
- this.severity = severity;
- this.id = id;
- this.colOffset = colOffset;
- this.message = messageArgs != null && messageArgs.length > 0 ? MessageFormat.format(message, messageArgs) : message;
- this.messageArgs = messageArgs;
- this.start = start;
- this.end = end;
- this.lineNumber = lineNumber;
+ this(
+ TemplatePathUtil.baseLocationURI(originatingFileName),
+ TemplatePathUtil.templatePath(originatingFileName),
+ severity == ParseProblemSeverity.ERROR ? ProblemSeverity.ERROR : ProblemSeverity.WARNING,
+ id,
+ message,
+ messageArgs,
+ start,
+ end,
+ lineNumber,
+ colOffset);
+ }
+
+ /**
+ * Create an new instance
+ * @param baseLocation the base location from which the template path is resolved.
+ * @param templatePath the file name from which the problem originates
+ * @param problemSeverity the problemSeverity
+ * @param id the problem id. See static constants declared on this class
+ * @param message the error message in {@link MessageFormat} style
+ * @param messageArgs the error message arguments
+ * @param start the start offset of the problem (doc relative)
+ * @param end the end offset of the problem (doc relative)
+ * @param lineNumber the start line of the problem
+ * @param colOffset TODO
+ */
+ public Problem(
+ URI baseLocation,
+ String templatePath,
+ ProblemSeverity severity,
+ int id,
+ String message,
+ Object[] messageArgs,
+ int start,
+ int end,
+ int lineNumber, int colOffset)
+ {
+ this(new org.eclipse.jet.core.parser.ast.Problem(baseLocation, templatePath, severity, id, message, messageArgs, start, end, lineNumber, colOffset));
+ }
+
+ Problem(org.eclipse.jet.core.parser.ast.Problem problem)
+ {
+ this.delegate = problem;
+
}
/**
@@ -180,7 +222,7 @@ public class Problem
*/
public int getEnd()
{
- return end;
+ return delegate.getEnd();
}
/**
@@ -188,7 +230,7 @@ public class Problem
*/
public int getId()
{
- return id;
+ return delegate.getId();
}
/**
@@ -196,7 +238,7 @@ public class Problem
*/
public int getLineNumber()
{
- return lineNumber;
+ return delegate.getLineNumber();
}
/**
@@ -204,7 +246,7 @@ public class Problem
*/
public String getMessage()
{
- return message;
+ return delegate.getMessage();
}
/**
@@ -212,7 +254,7 @@ public class Problem
*/
public Object[] getMessageArgs()
{
- return messageArgs;
+ return delegate.getMessageArgs();
}
/**
@@ -220,23 +262,38 @@ public class Problem
*/
public String getOriginatingFileName()
{
- return originatingFileName;
+ return delegate.getOriginatingFileName();
}
/**
- * @return Returns the severity.
+ * @return Returns the problemSeverity.
+ * @deprecated Use @link {@link #getProblemSeverity()} instead.
*/
public ParseProblemSeverity getSeverity()
{
- return severity;
+ ProblemSeverity problemSeverity = delegate.getProblemSeverity();
+ if(problemSeverity == ProblemSeverity.ERROR)
+ {
+ return ParseProblemSeverity.ERROR;
+ }
+ else if(problemSeverity == ProblemSeverity.WARNING)
+ {
+ return ParseProblemSeverity.WARNING;
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
}
+
+
/**
* @return Returns the start.
*/
public int getStart()
{
- return start;
+ return delegate.getStart();
}
/**
@@ -244,7 +301,18 @@ public class Problem
*/
public final int getColOffset()
{
- return colOffset;
+ return delegate.getColOffset();
+ }
+
+
+ /**
+ * Return the problem severity
+ * @return the problem severity
+ * @since 0.8.0
+ */
+ public ProblemSeverity getProblemSeverity()
+ {
+ return delegate.getProblemSeverity();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
index dc68b15..b361169 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
@@ -4,13 +4,9 @@
package org.eclipse.jet.compiler;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
+import org.eclipse.jet.core.parser.ITagLibraryResolver;
import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagLibrary;
import org.eclipse.jet.taglib.TagLibraryManager;
@@ -19,16 +15,12 @@ import org.eclipse.jet.taglib.TagLibraryReference;
/**
* A class to manage usage of tag libraries in a JET2 template.
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.TagLibraryUsageManager}
*/
public class TagLibraryUsageManager
{
- private final Map tagLibraries = new HashMap();
-
- private final Map predefinedLibraryMap;
-
- private List tags = null;
+ private final org.eclipse.jet.core.parser.ast.TagLibraryUsageManager delegate;
/**
* @param predefinedLibraryMap a map of predefined prefixes and their tag libary ids.
@@ -36,8 +28,13 @@ public class TagLibraryUsageManager
*/
public TagLibraryUsageManager(Map predefinedLibraryMap)
{
- // make a defensive copy, we may change it...
- this.predefinedLibraryMap = new HashMap(predefinedLibraryMap);
+ delegate = new org.eclipse.jet.core.parser.ast.TagLibraryUsageManager(predefinedLibraryMap,
+ new ITagLibraryResolver() {
+ public TagLibrary getLibrary(String tagLibraryID)
+ {
+ return TagLibraryManager.getInstance().getTagLibrary(tagLibraryID);
+ }
+ });
}
/**
@@ -55,35 +52,17 @@ public class TagLibraryUsageManager
public boolean canDefinePrefix(String prefix, String id)
{
- if (!tagLibraries.containsKey(prefix) && !predefinedLibraryMap.containsKey(prefix))
- {
- return true;
- }
-
- // check for duplicate definitions of predefined libraries, this is ok, too.
- if (id.equals(predefinedLibraryMap.get(prefix)))
- {
- return true;
- }
- else
- {
- return false;
- }
+ return delegate.canDefinePrefix(prefix, id);
}
public boolean isLibraryDefined(String libaryId)
{
- return tagLibraries.containsValue(libaryId);
+ return delegate.isLibraryDefined(libaryId);
}
public String getLibraryIdFromPrefix(String prefix)
{
- String id = (String)tagLibraries.get(prefix);
- if (id == null)
- {
- id = (String)predefinedLibraryMap.get(prefix);
- }
- return id;
+ return delegate.getLibraryIdFromPrefix(prefix);
}
/**
@@ -94,18 +73,7 @@ public class TagLibraryUsageManager
*/
public void add(String prefix, String libraryId)
{
- tagLibraries.put(prefix, libraryId);
-
- for (Iterator i = predefinedLibraryMap.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- if (libraryId.equals(entry.getValue()))
- {
- i.remove();
- }
- }
-
- tags = null; // clear the tags list cache
+ delegate.add(prefix, libraryId);
}
/**
@@ -115,12 +83,7 @@ public class TagLibraryUsageManager
*/
public TagDefinition getTagDefinition(String tagName)
{
- int sepIndex = tagName.indexOf(':');
- String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
- String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
- String id = getLibraryIdFromPrefix(prefix.toLowerCase());
- TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
- return tagLibrary.getTagDefinition(tagNCName);
+ return delegate.getTagDefinition(tagName);
}
/**
@@ -129,21 +92,7 @@ public class TagLibraryUsageManager
*/
public boolean isKnownTag(String tagName)
{
- boolean knownTag = false;
-
- int sepIndex = tagName.indexOf(':');
- String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
- String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
- String id = getLibraryIdFromPrefix(prefix.toLowerCase());
- if (id != null)
- {
- TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
- if (tagLibrary != null)
- {
- knownTag = tagLibrary.hasTag(tagNCName);
- }
- }
- return knownTag;
+ return delegate.isKnownTag(tagName);
}
/**
@@ -152,60 +101,17 @@ public class TagLibraryUsageManager
* @return <code>true</code> if the tag matches one of the libraries, <code>false</code> otherwise.
*/
public boolean isKnownInvalidTagName(String tagName) {
- boolean knownInvalidTagName = false;
-
- int sepIndex = tagName.indexOf(':');
- String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
- String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
- String id = getLibraryIdFromPrefix(prefix.toLowerCase());
- if (id != null)
- {
- TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
- if (tagLibrary != null && prefix.length() > 0)
- {
- knownInvalidTagName = !tagLibrary.hasTag(tagNCName);
- }
- }
- return knownInvalidTagName;
+ return delegate.isKnownInvalidTagName(tagName);
}
public TagLibraryReference[] getTagLibraryReferences()
{
- List result = new ArrayList(predefinedLibraryMap.size() + tagLibraries.size());
- for (Iterator i = predefinedLibraryMap.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- result.add(new TagLibraryReferenceImpl((String)entry.getKey(), (String)entry.getValue(), true));
- }
- for (Iterator i = tagLibraries.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- result.add(new TagLibraryReferenceImpl((String)entry.getKey(), (String)entry.getValue(), false));
- }
- return (TagLibraryReference[])result.toArray(new TagLibraryReference [result.size()]);
+ return delegate.getTagLibraryReferences();
}
public String[] getKnownTagNames()
{
- List localTags = tags; // protect against concurrent access
- if (localTags == null)
- {
- localTags = new ArrayList();
- for (Iterator i = tagLibraries.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String prefix = (String)entry.getKey();
- String id = (String)entry.getValue();
- TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
- final String[] tagNames = tagLibrary.getTagNames();
-
- for (int j = 0; j < tagNames.length; j++)
- {
- localTags.add(prefix + "." + tagNames[j]); //$NON-NLS-1$
- }
- }
- }
- return (String[])localTags.toArray(new String [localTags.size()]);
+ return delegate.getKnownTagNames();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagValidationVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagValidationVisitor.java
deleted file mode 100644
index 98bfe1c..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagValidationVisitor.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.compiler;
-
-
-import java.util.Iterator;
-
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-import org.eclipse.jet.taglib.TagAttributeDefinition;
-import org.eclipse.jet.taglib.TagDefinition;
-
-
-/**
- * Validate tags and attributes found on tag declarations.
- * <p>
- * Types of attribute validation:
- * <bl>
- * <li>that required attributes are in the tag declaration.</li>
- * <li>that all attributes correspond to a declared attribute.</li>
- * <li>that warnings are generated for deprecated attribute access.</li>
- * </bl>
- * <p>
- * Types of tag validation:
- * <bl>
- * <li>whether tag or tag library is deprecated</li>
- * <li>whether the tag is permitted to be used as an empty tag</li>
- * <li>whether the tag is permitted to be used as a content tag</li>
- * </bl>
- * </p>
- */
-final class TagValidationVisitor extends DefaultJET2ASTVisitor implements JET2ASTVisitor
-{
-
- private final JET2CompilationUnit cu;
-
- /**
- * @param cu
- *
- */
- public TagValidationVisitor(JET2CompilationUnit cu)
- {
- super();
- this.cu = cu;
- }
-
- public void visit(XMLBodyElement xmlBodyElement)
- {
- if (!xmlBodyElement.getTagDefinition().isContentAllowed())
- {
- cu.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.TagCannotHaveContent,
- JET2Messages.JET2Compiler_TagCannotHaveContent,
- new Object [0],
- xmlBodyElement.getStart(),
- xmlBodyElement.getEnd(),
- xmlBodyElement.getLine(),
- xmlBodyElement.getColumn());
- }
- validateAttributes(xmlBodyElement);
- }
-
- private void validateAttributes(XMLElement xmlElement)
- {
- TagDefinition tagDefinition = xmlElement.getTagDefinition();
-
- if (tagDefinition.isDeprecated() || tagDefinition.getTagLibrary().isDeprecated())
- {
- cu.createProblem(
- ParseProblemSeverity.WARNING,
- Problem.DeprecatedTag,
- JET2Messages.JET2Compiler_DeprecatedTag,
- new Object [0],
- xmlElement.getStart(),
- xmlElement.getEnd(),
- xmlElement.getLine(),
- xmlElement.getColumn());
- }
-
- // Validate that every supplied attribute is in the tag definition
- for (Iterator i = xmlElement.getAttributes().keySet().iterator(); i.hasNext();)
- {
- String attrName = (String)i.next();
- if (tagDefinition.getAttributeDefinition(attrName) == null)
- {
- cu.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnknownAttributeInTag,
- JET2Messages.JET2Compiler_UnknownAttribute,
- new Object []{ attrName },
- xmlElement.getStart(),
- xmlElement.getEnd(),
- xmlElement.getLine(),
- xmlElement.getColumn());
- }
- }
-
- // Validate that every required attribute is in the supplied attributes
- for (Iterator i = tagDefinition.getAttributeDefinitions().iterator(); i.hasNext();)
- {
- TagAttributeDefinition tad = (TagAttributeDefinition)i.next();
- final String attributeName = tad.getName();
- if (tad.isRequired() && !xmlElement.getAttributes().containsKey(attributeName))
- {
- cu.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.MissingRequiredAttribute,
- JET2Messages.JET2Compiler_MissingRequiredAttribute,
- new Object []{ attributeName },
- xmlElement.getStart(),
- xmlElement.getEnd(),
- xmlElement.getLine(),
- xmlElement.getColumn());
- }
- if (tad.isDeprecated() && xmlElement.getAttributes().containsKey(attributeName))
- {
- cu.createProblem(
- ParseProblemSeverity.WARNING,
- Problem.DeprecatedAttribute,
- JET2Messages.JET2Compiler_DeprecatedAttribute,
- new Object []{ attributeName },
- xmlElement.getStart(),
- xmlElement.getEnd(),
- xmlElement.getLine(),
- xmlElement.getColumn());
- }
- }
- }
-
- public void visit(XMLEmptyElement xmlEmptyElement)
- {
- if (!xmlEmptyElement.getTagDefinition().isEmptyTagAllowed())
- {
- cu.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.TagCannotBeEmpty,
- JET2Messages.JET2Compiler_TagRequiresContent,
- new Object [0],
- xmlEmptyElement.getStart(),
- xmlEmptyElement.getEnd(),
- xmlEmptyElement.getLine(),
- xmlEmptyElement.getColumn());
- }
- validateAttributes(xmlEmptyElement);
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TemplatePathUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TemplatePathUtil.java
new file mode 100644
index 0000000..37d0fcc
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TemplatePathUtil.java
@@ -0,0 +1,70 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: TemplatePathUtil.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.compiler;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Utility class for mapping between Eclipse Workspace files and template paths
+ */
+class TemplatePathUtil
+{
+
+ private TemplatePathUtil() {
+ // prevent instantiation
+ }
+
+ public static URI baseLocationURI(String workspaceFullPath)
+ {
+ final String projectName = new Path(workspaceFullPath).segment(0);
+ return projectName == null ? null : ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).getLocationURI();
+ }
+
+ public static URI baseLocationURI(IFile templateFile)
+ {
+ return templateFile.getProject().getLocationURI();
+ }
+
+ public static String templatePath(String workspaceFullPath)
+ {
+ final Path wsPath = new Path(workspaceFullPath);
+ return wsPath.segmentCount() == 0 ? "" : wsPath.removeFirstSegments(1).makeRelative().toString(); //$NON-NLS-1$
+ }
+
+ public static String templatePath(IFile templateFile)
+ {
+ return templateFile.getProjectRelativePath().toString();
+ }
+
+ public static IFile workspaceFile(URI baseLocation, String templatePath)
+ {
+ final IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(baseLocation);
+ if(containers.length > 0) {
+ assert containers[0].getType() == IResource.PROJECT;
+ return ((IProject)containers[0]).getFile(templatePath);
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TextElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TextElement.java
index 2dce261..7e7aff3 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TextElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TextElement.java
@@ -21,52 +21,20 @@ import org.eclipse.jet.internal.parser.LineInfo;
/**
* Define a Text Element in the JET2 AST
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.TextElement}
*/
public final class TextElement extends JET2ASTElement
{
- private static final String ESCAPED_JET_ELEMENT_START = "<\\%"; //$NON-NLS-1$
-
- private char[] text;
-
- private boolean trimLastLine = false;
- private boolean trimFirstLine = false;
+ private final org.eclipse.jet.core.parser.ast.TextElement delegate;
- private final LineInfo[] lines;
-
- /**
- * Create an instance
- * @param jet2ast the AST
- * @param text the text
- */
- TextElement(JET2AST jet2ast, char[] text)
+ public TextElement(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.TextElement element)
{
- super(jet2ast, -1, -1, 0, 0);
- this.text = handleEscapes(text);
- this.lines = LineInfo.calculateLines(this.text);
+ super(jet2ast, element);
+ this.delegate = element;
}
- /**
- * Remove any escape sequences in the raw text.
- * The only escaped sequences handled are:
- * <bl>
- * <li>&lt;\% to &lt;%</li>
- * </bl>
- * @param originalText
- * @return
- */
- private char[] handleEscapes(char[] originalText)
- {
- StringBuffer buffer = new StringBuffer(originalText.length);
- buffer.append(originalText);
- for (int i = buffer.indexOf(ESCAPED_JET_ELEMENT_START); i != -1; i = buffer.indexOf(ESCAPED_JET_ELEMENT_START, i))
- {
- buffer.replace(i, i + ESCAPED_JET_ELEMENT_START.length(), "<%"); //$NON-NLS-1$
- }
- return buffer.toString().toCharArray();
- }
/**
* @see org.eclipse.jet.compiler.JET2ASTElement#accept(org.eclipse.jet.compiler.JET2ASTVisitor)
@@ -82,41 +50,18 @@ public final class TextElement extends JET2ASTElement
*/
public char[] getText()
{
- char[] result = text;
- if(lines.length > 0)
- {
- int start = isTrimFirstLine() && lines[0].hasDelimiter()
- ? lines[0].getEnd() + lines[0].getDelimiter().length() : 0;
- int end = isTrimLastLine() && !lines[lines.length -1].hasDelimiter()
- ? lines[lines.length - 1].getStart() : text.length;
- result = new String(text, start, end - start).toCharArray();
- }
- return result;
+ return delegate.getText();
}
public char[] getRawText()
{
- return text;
- }
-
- /**
- *
- * @param newText
- * @deprecated
- */
- void setText(char[] newText)
- {
- text = newText;
+ return delegate.getRawText();
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return false;
- }
public void setTrimLastLine(boolean trim)
{
- this.trimLastLine = trim;
+ delegate.setTrimLastLine(trim);
}
/**
@@ -124,12 +69,12 @@ public final class TextElement extends JET2ASTElement
*/
public final boolean isTrimLastLine()
{
- return trimLastLine;
+ return delegate.isTrimLastLine();
}
public void setTrimFirstLine(boolean trim)
{
- this.trimFirstLine = trim;
+ delegate.setTrimFirstLine(trim);
}
/**
@@ -137,7 +82,7 @@ public final class TextElement extends JET2ASTElement
*/
public final boolean isTrimFirstLine()
{
- return trimFirstLine;
+ return delegate.isTrimFirstLine();
}
/**
@@ -145,7 +90,7 @@ public final class TextElement extends JET2ASTElement
*/
public final LineInfo[] getLines()
{
- return lines;
+ return LineInfo.calculateLines(getText());
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElement.java
index 2088364..a89d73c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElement.java
@@ -18,68 +18,51 @@
package org.eclipse.jet.compiler;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jet.taglib.TagDefinition;
+import org.eclipse.jet.core.parser.ast.BodyElement;
/**
* Define a JET2 XML Element that has a begin-tag and end-tag, and zero or more body elements.
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.XMLBodyElement}
*/
public final class XMLBodyElement extends XMLElement
{
- private BodyElements bodyElements = null;
+ private List wrappedBodyElements = null;
- private XMLBodyElementEnd endTag = null;
+ private final org.eclipse.jet.core.parser.ast.XMLBodyElement delegate;
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param name the QName of the element
- * @param attributes a Map of attribute names to their values of the element
- * @param td the TagDefinition
- */
- XMLBodyElement(JET2AST ast, int line, int colOffset, int start, int end, String name, Map attributes, TagDefinition td)
+ public XMLBodyElement(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.XMLBodyElement element)
{
- super(ast, line, colOffset, start, end, name, attributes, td);
- }
-
- /**
- * Return a object that allows writable access to the JET2 elements contained by this element.
- * @return a BodyElements instance
- */
- BodyElements getInternalBodyElements()
- {
- if (bodyElements == null)
- {
- bodyElements = new BodyElements(this);
- }
- return bodyElements;
+ super(jet2ast, (org.eclipse.jet.core.parser.ast.XMLElement)element);
+ this.delegate = element;
}
/**
* Return a read-only list of JET2 elements contained by this element.
- * @return a List of {@link JET2ASTElement} instances. The empty list is returned if there are no elements.
+ * @return a List of {@link JETASTElement} instances. The empty list is returned if there are no elements.
*/
public final List getBodyElements()
{
- if (bodyElements == null)
- {
- return Collections.EMPTY_LIST;
- }
- else
+ if (wrappedBodyElements == null)
{
- return bodyElements.getBodyElements();
+ List delegateBodyElements = delegate.getBodyElements();
+ if(delegateBodyElements.size() == 0) {
+ wrappedBodyElements = Collections.EMPTY_LIST;
+ } else {
+ wrappedBodyElements = new ArrayList(delegateBodyElements.size());
+ for (Iterator i = delegateBodyElements.iterator(); i.hasNext();)
+ {
+ BodyElement bodyElement = (BodyElement)i.next();
+ wrappedBodyElements.add(getAst().wrap(bodyElement));
+ }
+ }
}
+ return wrappedBodyElements;
}
/**
@@ -99,7 +82,7 @@ public final class XMLBodyElement extends XMLElement
void setEndTag(XMLBodyElementEnd endTag)
{
- this.endTag = endTag;
+ throw new UnsupportedOperationException();
}
/**
@@ -107,24 +90,17 @@ public final class XMLBodyElement extends XMLElement
*/
public final XMLBodyElementEnd getEndTag()
{
- return endTag;
+ return (XMLBodyElementEnd)getAst().wrap(delegate.getEndTag());
}
public String toString()
{
- return "Line " + getLine() + ": <" + getName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return delegate.toString();
}
public JET2ASTElement getNextElement()
{
- if(getBodyElements().size() > 0)
- {
- return (JET2ASTElement)getBodyElements().get(0);
- }
- else
- {
- return super.getNextElement();
- }
+ return getAst().wrap(delegate.getNextElement());
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElementEnd.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElementEnd.java
index d940d39..91e5290 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElementEnd.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLBodyElementEnd.java
@@ -16,29 +16,22 @@
*/
package org.eclipse.jet.compiler;
-import java.util.List;
-
/**
* Represent the closing tag of an XML Tag with a body.
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.XMLBodyElementEnd}
*/
public class XMLBodyElementEnd extends JET2ASTElement
{
private XMLBodyElement startTag;
+ private final org.eclipse.jet.core.parser.ast.XMLBodyElementEnd delegate;
- /**
- *
- * @param ast
- * @param line
- * @param colOffset
- * @param start
- * @param end
- * @param startTag
- */
- XMLBodyElementEnd(JET2AST ast, int line, int colOffset, int start, int end)
+
+ public XMLBodyElementEnd(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.XMLBodyElementEnd end)
{
- super(ast, line, colOffset, start, end);
+ super(jet2ast, end);
+ this.delegate = end;
}
/* (non-Javadoc)
@@ -57,34 +50,21 @@ public class XMLBodyElementEnd extends JET2ASTElement
return startTag;
}
- public boolean removeLineWhenOtherwiseEmpty()
- {
- return startTag.removeLineWhenOtherwiseEmpty();
- }
-
/**
* @param startTag The startTag to set.
*/
public final void setStartTag(XMLBodyElement startTag)
{
- this.startTag = startTag;
+ throw new UnsupportedOperationException();
}
public JET2ASTElement getPrevElement()
{
- final List bodyElements = startTag.getBodyElements();
- if(bodyElements.size() > 0)
- {
- return (JET2ASTElement)bodyElements.get(bodyElements.size() - 1);
- }
- else
- {
- return startTag;
- }
+ return getAst().wrap(delegate.getPrevElement());
}
public String toString()
{
- return "Line " + getLine() + ": </" + getStartTag().getName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return delegate.toString();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLElement.java
index 67c8a16..52ada02 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLElement.java
@@ -18,53 +18,33 @@
package org.eclipse.jet.compiler;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import org.eclipse.jet.taglib.TagDefinition;
-
/**
* An abstract implementation representing all XML-based elements in the JET2 AST
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.XMLElement}
*
*/
public abstract class XMLElement extends JET2ASTElement
{
- private final String name;
-
- private final Map attributes;
-
- private final TagDefinition tagDefinition;
+ private final org.eclipse.jet.core.parser.ast.XMLElement delegate;
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param name the QName of the element
- * @param attributes a Map of attribute names to values for the element.
- * @param td the TagDefinition
- */
- XMLElement(JET2AST ast, int line, int colOffset, int start, int end, String name, Map attributes, TagDefinition td)
+ public XMLElement(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.XMLElement element)
{
- super(ast, line, colOffset, start, end);
- this.name = name;
- this.tagDefinition = td;
- this.attributes = Collections.unmodifiableMap(new HashMap(attributes)); // defensive copy
-
+ super(jet2ast, element);
+ this.delegate = element;
}
/**
- * Return the QName of the element
+ * Return the QName of the delegate
* @return a string
*/
public final String getName()
{
- return name;
+ return delegate.getName();
}
/**
@@ -73,29 +53,25 @@ public abstract class XMLElement extends JET2ASTElement
*/
public final Map getAttributes()
{
- return attributes;
+ return delegate.getAttributes();
}
/**
- * Return the NCName (unqualified name) of the element.
+ * Return the NCName (unqualified name) of the delegate.
* @return the name with any XML namespace prefix (<i>prefix</i>:) removed
*/
public String getTagNCName()
{
- String qName = getName();
- int sepIndex = qName.indexOf(':');
- return sepIndex >= 0 ? qName.substring(sepIndex + 1) : qName;
+ return delegate.getTagNCName();
}
/**
- * Return the XML Namespace prefixe of the element
+ * Return the XML Namespace prefixe of the delegate
* @return the namespace prefix or the empty string if there is no namespace prefix.
*/
public String getNSPrefix()
{
- String qName = getName();
- int sepIndex = qName.indexOf(':');
- return sepIndex >= 0 ? qName.substring(0, sepIndex) : ""; //$NON-NLS-1$
+ return delegate.getNSPrefix();
}
/**
@@ -103,11 +79,20 @@ public abstract class XMLElement extends JET2ASTElement
*/
public final TagDefinition getTagDefinition()
{
- return tagDefinition;
+ return delegate.getTagDefinition();
}
- public final boolean removeLineWhenOtherwiseEmpty()
+ /**
+ * Return the underlying new AST object to which this one delegates.
+ * Useful in mashing old AST code into new.
+ * <p>
+ * Intended for internal use only.
+ * </p>
+ * @return the underlying {@link org.eclipse.jet.core.parser.ast.XMLElement}
+ */
+ public org.eclipse.jet.core.parser.ast.XMLElement getDelegate()
{
- return tagDefinition.removeWhenContainingLineIsEmpty();
+ return delegate;
}
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLEmptyElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLEmptyElement.java
index b240a1c..e70e3fb 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLEmptyElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/XMLEmptyElement.java
@@ -18,32 +18,21 @@
package org.eclipse.jet.compiler;
-import java.util.Map;
-
-import org.eclipse.jet.taglib.TagDefinition;
-
/**
* Define an empty XML element in the JET2 AST.
- *
+ * @deprecated Since 0.8.0, use {@link org.eclipse.jet.core.parser.ast.XMLEmptyElement}
*/
public final class XMLEmptyElement extends XMLElement
{
- /**
- * Create an instance
- * @param ast the owning AST
- * @param line the start line of the element
- * @param colOffset the offset within the line of the element's start.
- * @param start the start offset of the element (doc relative)
- * @param end the end offset of the element (doc relative)
- * @param name the QName of the element
- * @param attributes a Map of attribute names to values for the element.
- * @param td the TagDefinition
- */
- XMLEmptyElement(JET2AST ast, int line, int colOffset, int start, int end, String name, Map attributes, TagDefinition td)
+
+ private final org.eclipse.jet.core.parser.ast.XMLEmptyElement delegate;
+
+ public XMLEmptyElement(JET2AST jet2ast, org.eclipse.jet.core.parser.ast.XMLEmptyElement element)
{
- super(ast, line, colOffset, start, end, name, attributes, td);
+ super(jet2ast, element);
+ this.delegate = element;
}
/**
@@ -56,7 +45,7 @@ public final class XMLEmptyElement extends XMLElement
public String toString()
{
- return "Line " + getLine() + ": <" + getName() + "/>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return delegate.toString();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JETPreferenceInitializer.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JETPreferenceInitializer.java
index 4aa78f2..beae989 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JETPreferenceInitializer.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JETPreferenceInitializer.java
@@ -23,7 +23,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.compiler.JET2Compiler;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
/**
* Preference initializer
@@ -47,7 +47,7 @@ public class JETPreferenceInitializer extends AbstractPreferenceInitializer
final IEclipsePreferences node = new DefaultScope().getNode(JET2Platform.PLUGIN_ID);
// save the compiler defaults...
- Map compilerOptions = JET2Compiler.getDefaultCompilerOptions();
+ Map compilerOptions = JETCompilerOptions.getDefaultCompilerOptions();
for (Iterator i = compilerOptions.entrySet().iterator(); i.hasNext();)
{
Map.Entry entry = (Map.Entry)i.next();
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
index 6c98473..641a1d9 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
@@ -16,6 +16,9 @@
*/
package org.eclipse.jet.internal;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Utility class for Java related code generation.
@@ -23,6 +26,8 @@ package org.eclipse.jet.internal;
public class JavaUtil
{
+ private static final String NL_PATTERN = "([\\n][\\r]?|[\\r][\\n]?)"; //$NON-NLS-1$
+
/**
*
*/
@@ -92,4 +97,80 @@ public class JavaUtil
return encoded.toString();
}
+ /**
+ * Return a Java String expression with + NL + in place of new line data
+ * @param text
+ * @return
+ */
+ public static String asJavaQuoteStringWithNLRemoved(char[] text)
+ {
+ String rawString = new String(text);
+ Matcher m = Pattern.compile(NL_PATTERN, Pattern.MULTILINE).matcher(rawString);
+ int nextStringStart = 0;
+ boolean nlFound = m.find();
+ if(nlFound) {
+ StringBuffer result = new StringBuffer(text.length);
+ boolean firstExprComponent = true;
+ for( ;nlFound; nlFound = m.find()) {
+ if(firstExprComponent) {
+ firstExprComponent = false;
+ } else {
+ result.append(" + "); //$NON-NLS-1$
+ }
+ if(m.start() > nextStringStart) {
+ result.append(asJavaQuotedString(rawString.substring(nextStringStart, m.start()).toCharArray()));
+ result.append(" + "); //$NON-NLS-1$
+ }
+ result.append("NL"); //$NON-NLS-1$
+ nextStringStart = m.end();
+ }
+ if(nextStringStart < rawString.length()) {
+ if(!firstExprComponent) {
+ result.append(" + "); //$NON-NLS-1$
+ result.append(asJavaQuotedString(rawString.substring(nextStringStart).toCharArray()));
+ }
+ }
+ return result.toString();
+ } else {
+ return asJavaQuotedString(text);
+ }
+ }
+
+ /**
+ * Return a Java String expression with + NL + in place of new line data
+ * @param text
+ * @return
+ */
+ public static String nlsCommentsForJavaQuoteStringWithNLRemoved(char[] text)
+ {
+ String rawString = new String(text);
+ Matcher nlMatch = Pattern.compile(NL_PATTERN, Pattern.MULTILINE).matcher(rawString);
+ int nextLiteralStart = 0;
+ int i = 0;
+
+ StringBuffer result = new StringBuffer(text.length);
+ for (boolean nlFound = nlMatch.find(); nlFound; nlFound = nlMatch.find())
+ {
+ if (nlMatch.start() > nextLiteralStart)
+ {
+ nlComment(result, ++i);
+ }
+ nextLiteralStart = nlMatch.end();
+ }
+ if (nextLiteralStart < rawString.length() || rawString.length() == 0)
+ {
+ nlComment(result, ++i);
+ }
+ return result.toString();
+ }
+
+ /**
+ * @param result
+ * @param i
+ * @return
+ */
+ private static StringBuffer nlComment(StringBuffer result, int i)
+ {
+ return result.append(" //$NON-NLS-").append(i).append("$"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/JET2Builder.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/JET2Builder.java
index b19aeff..115677b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/JET2Builder.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/JET2Builder.java
@@ -24,9 +24,14 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.jar.JarFile;
import org.eclipse.core.resources.IProject;
@@ -42,14 +47,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.compiler.CompileOptionsManager;
-import org.eclipse.jet.compiler.IJETCompilerState;
-import org.eclipse.jet.compiler.JET2Compiler;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.JETActivatorWrapper;
import org.eclipse.jet.internal.SavedStateManager;
-import org.eclipse.jet.internal.compiler.JETCompilerState;
+import org.eclipse.jet.internal.compiler.SimplifiedCompiler;
+import org.eclipse.jet.internal.core.compiler.IJETCompiler;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.osgi.util.NLS;
@@ -65,9 +67,7 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
static final String COMPILESTATE_PROJECT_DIR = "projects"; //$NON-NLS-1$
- private int filesToCompileCount;
-
- private JETCompilerState compilerState;
+ private Serializable savedState;
private final SavedStateManager savedStateManager;
@@ -82,13 +82,17 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
protected void clean(IProgressMonitor monitor) throws CoreException
{
- if(DEBUG) System.out.println("JET2Builder: cleaning " + getProject()); //$NON-NLS-1$
- final JET2Compiler compiler = getJETCompiler(new SubProgressMonitor(monitor, 1));
+ if(DEBUG) {
+ System.out.println("JET2Builder: cleaning " + getProject()); //$NON-NLS-1$
+ }
+
+ getCompiler(new SubProgressMonitor(monitor,1)).clean();
- compiler.clean();
+ savedState = null;
- compilerState.clear();
- if(DEBUG) System.out.println("*JET2Builder: done cleaning " + getProject()); //$NON-NLS-1$
+ if(DEBUG) {
+ System.out.println("*JET2Builder: done cleaning " + getProject()); //$NON-NLS-1$
+ }
}
/* (non-Javadoc)
@@ -96,34 +100,24 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException
{
+ IProject[] projectDependencies = null;
if (DEBUG)
System.out.println("JET2Builder: build(" + getProject() + ", " + kind + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
try
{
- if (kind == IncrementalProjectBuilder.CLEAN_BUILD)
- {
- compilerState.clear();
- }
- else if (kind == IncrementalProjectBuilder.FULL_BUILD)
+ IResourceDelta delta = getDelta(getProject());
+ if (kind == IncrementalProjectBuilder.FULL_BUILD || isReferencedProjectChanged() || delta == null )
{
+ monitor.beginTask(NLS.bind(JET2Messages.JET2Builder_CompilingAll, getProject().getName()), 2);
clean(new SubProgressMonitor(monitor, 1));
- fullBuild(new SubProgressMonitor(monitor, 1));
+ projectDependencies = fullBuild(new SubProgressMonitor(monitor, 1));
+ monitor.done();
}
- else
+ else // INCREMENTAL BUILD or AUTO BUILD -- treat as the same thing
{
-
- IResourceDelta delta = getDelta(getProject());
- if (isReferencedProjectChanged() || delta == null)
- {
- clean(new SubProgressMonitor(monitor, 1));
- fullBuild(new SubProgressMonitor(monitor, 1));
- }
- else
- {
- incrementalBuild(delta, monitor);
- }
+ projectDependencies = incrementalBuild(delta, monitor);
}
- return computeReferencedProjects(compilerState);
+ return projectDependencies;
}
finally
{
@@ -134,7 +128,7 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
private boolean isReferencedProjectChanged()
{
- final IProject[] projects = computeReferencedProjects(compilerState);
+ final IProject[] projects = computeReferencedProjects(getCompiler(null).getTagLibaryDependencies());
for (int i = 0; i < projects.length; i++)
{
final IResourceDelta delta = getDelta(projects[i]);
@@ -158,77 +152,72 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
* @param monitor
* @throws CoreException
*/
- private void incrementalBuild(IResourceDelta mainDelta, final IProgressMonitor monitor) throws CoreException
+ private IProject[] incrementalBuild(IResourceDelta mainDelta, final IProgressMonitor monitor) throws CoreException
{
- if(DEBUG) System.out.println("JET2Builder: incrementalBuild " + getProject()); //$NON-NLS-1$
- compilerState.setProjectTagLibraryReferences(JET2Platform.getProjectDescription(getProject().getName()).getTagLibraryReferences());
- final JET2Compiler compiler = getJETCompiler(monitor);
- filesToCompileCount = 0;
+ if(DEBUG) {
+ System.out.println("JET2Builder: incrementalBuild " + getProject()); //$NON-NLS-1$
+ }
+
+ final IJETCompiler compiler = getCompiler(monitor);
+
+ final Set templatesToRemove = new HashSet();
+ final Set templatesToCompile = new HashSet();
+
// figure out how much work we must do (for the progress monitor).
mainDelta.accept(new IResourceDeltaVisitor()
{
public boolean visit(IResourceDelta delta) throws CoreException
{
+ final String templatePath = delta.getResource().getProjectRelativePath().toString();
switch (delta.getKind())
{
case IResourceDelta.ADDED:
case IResourceDelta.CHANGED:
+ if (compiler.isTemplate(templatePath))
+ {
+ templatesToCompile.add(templatePath);
+ }
+ templatesToCompile.addAll(Arrays.asList(compiler.getAffectedTemplatePaths(templatePath)));
+ break;
case IResourceDelta.REMOVED:
- if (compiler.isJET2SourceFile(delta.getResource()))
+ if (compiler.isTemplate(templatePath))
{
- filesToCompileCount++;
+ templatesToRemove.add(templatePath);
}
+ templatesToCompile.addAll(Arrays.asList(compiler.getAffectedTemplatePaths(templatePath)));
break;
}
return true;
}
});
- monitor.beginTask(NLS.bind(JET2Messages.JET2Builder_CompilingChanged, getProject().getName()), filesToCompileCount);
+ monitor.beginTask(NLS.bind(JET2Messages.JET2Builder_CompilingChanged, getProject().getName()),
+ templatesToCompile.size() + templatesToRemove.size());
try
{
- mainDelta.accept(new IResourceDeltaVisitor()
- {
-
- public boolean visit(IResourceDelta delta) throws CoreException
- {
- final IResource resource = delta.getResource();
- switch (delta.getKind())
- {
- case IResourceDelta.ADDED:
- case IResourceDelta.CHANGED:
- if(DEBUG) System.out.println("JET2Builder: add/change " + resource); //$NON-NLS-1$
- if(resource.getType() == IResource.FILE && getProject().equals(resource.getProject())) {
- monitor.subTask(NLS.bind(JET2Messages.JET2Builder_Compiling, resource.getProjectRelativePath()));
- compiler.compile(resource);
- }
- monitor.worked(1);
- break;
- case IResourceDelta.REMOVED:
- if(DEBUG) System.out.println("JET2Builder remove " + resource); //$NON-NLS-1$
- monitor.subTask(NLS.bind(JET2Messages.JET2Builder_Cleaning, resource.getProjectRelativePath()));
- if(resource.getType() == IResource.FILE && getProject().equals(resource.getProject())) {
- compiler.removeDerivedResources(resource, false);
- compilerState.removeTemplate(resource.getProjectRelativePath().toString());
- }
- monitor.worked(1);
- break;
- }
- return true;
- }
- });
- compiler.createTransformFiles();
-
- }
- catch (CoreException e)
- {
- compilerState.clear();
- forgetLastBuiltState();
- throw e;
+ for (Iterator i = templatesToRemove.iterator(); i.hasNext();)
+ {
+ String templatePath = (String)i.next();
+ monitor.setTaskName(NLS.bind(JET2Messages.JET2Builder_Cleaning,templatePath));
+ compiler.removeTemplate(templatePath);
+ monitor.worked(1);
+ }
+ for (Iterator i = templatesToCompile.iterator(); i.hasNext();)
+ {
+ String templatePath = (String)i.next();
+ monitor.setTaskName(NLS.bind(JET2Messages.JET2Builder_Compiling,templatePath));
+ compiler.compile(templatePath);
+ monitor.worked(1);
+ }
+ compiler.finish();
+ savedState = compiler.getMemento();
+ return computeReferencedProjects(compiler.getTagLibaryDependencies());
}
finally
{
monitor.done();
- if(DEBUG) System.out.println("JET2Builder: done incrementalBuild " + getProject()); //$NON-NLS-1$
+ if(DEBUG) {
+ System.out.println("JET2Builder: done incrementalBuild " + getProject()); //$NON-NLS-1$
+ }
}
}
@@ -238,65 +227,49 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
* @param monitor
* @throws CoreException
*/
- private void fullBuild(final IProgressMonitor monitor) throws CoreException
+ private IProject[] fullBuild(final IProgressMonitor monitor) throws CoreException
{
- if(DEBUG) System.out.println("JET2Builder: fullBuild " + getProject()); //$NON-NLS-1$
- compilerState.setProjectTagLibraryReferences(JET2Platform.getProjectDescription(getProject().getName()).getTagLibraryReferences());
- final JET2Compiler compiler = getJETCompiler(monitor);
- filesToCompileCount = 0;
+ if(DEBUG) {
+ System.out.println("JET2Builder: fullBuild " + getProject()); //$NON-NLS-1$
+ }
+ final IJETCompiler compiler = getCompiler(monitor);
+ final Set templatesToCompile = new HashSet();
// figure out how much work we must do (for the progress monitor).
getProject().accept(new IResourceVisitor()
{
public boolean visit(IResource resource) throws CoreException
{
- if (compiler.isJET2SourceFile(resource))
+ String templatePath = resource.getProjectRelativePath().toString();
+ if (resource.getType() == IResource.FILE && compiler.isTemplate(templatePath))
{
- filesToCompileCount++;
+ templatesToCompile.add(templatePath);
}
return true;
}
});
- monitor.beginTask(NLS.bind(JET2Messages.JET2Builder_CompilingAll, getProject().getName()), filesToCompileCount);
- try
- {
- getProject().accept(new IResourceVisitor()
- {
-
- public boolean visit(IResource resource) throws CoreException
- {
- monitor.subTask(NLS.bind(JET2Messages.JET2Builder_Compiling, resource.getProjectRelativePath()));
- compiler.compile(resource);
- monitor.worked(1);
- return true;
- }
- });
- compiler.createTransformFiles();
- // TODO Save compilation state upon successful build
- }
- catch (CoreException e)
+ monitor.beginTask(NLS.bind(JET2Messages.JET2Builder_CompilingAll, getProject().getName()),
+ templatesToCompile.size());
+
+ for (Iterator i = templatesToCompile.iterator(); i.hasNext();)
{
- compilerState.clear();
- forgetLastBuiltState();
- throw e;
+ String templatePath = (String)i.next();
+ compiler.compile(templatePath);
}
- finally
- {
- monitor.done();
- if(DEBUG) System.out.println("JET2Builder: done fullBuild " + getProject()); //$NON-NLS-1$
+
+ compiler.finish();
+
+ savedState = compiler.getMemento();
+
+ monitor.done();
+ if(DEBUG) {
+ System.out.println("JET2Builder: done fullBuild " + getProject()); //$NON-NLS-1$
}
+ return computeReferencedProjects(compiler.getTagLibaryDependencies());
}
- /**
- * @param monitor
- * @return
- */
- private JET2Compiler getJETCompiler(final IProgressMonitor monitor)
+ private IJETCompiler getCompiler(final IProgressMonitor monitor)
{
- final JET2Compiler compiler = new JET2Compiler(getProject(),
- CompileOptionsManager.getOptions(getProject()),
- compilerState,
- monitor);
- return compiler;
+ return new WorkspaceCompiler(getProject(), savedState, monitor);
}
/*
@@ -306,73 +279,100 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
{
super.startupOnInitialize();
- compilerState = null;
+// compilerState = null;
if (DEBUG) System.out.println("JET2Builder: startupOnInitialize " + getProject()); //$NON-NLS-1$
try
{
IPath fileLocation = savedStateManager.addSaveSaver(this, getProject());
-
+
if (fileLocation != null)
{
File savedStateFile = fileLocation.toFile();
- try
- {
- ObjectInputStream ois = new ObjectInputStream(new java.io.FileInputStream(savedStateFile));
- compilerState = (JETCompilerState)ois.readObject();
- ois.close();
- if (DEBUG)
- {
- System.out.println(" loaded compilerState from saved state"); //$NON-NLS-1$
- System.out.print(" taglibs : ["); //$NON-NLS-1$
- String[] ids = compilerState.getAllReferencedTagLibraryIds();
- for (int i = 0; i < ids.length; i++)
- {
- if (i != 0)
- System.out.print(", "); //$NON-NLS-1$
- System.out.print(ids[i]);
- }
- System.out.println("]"); //$NON-NLS-1$
- System.out.println(" templates : " + compilerState.getTemplateMap()); //$NON-NLS-1$
- }
- }
- catch (FileNotFoundException e)
- {
- // nothing to do, the state was not saved for some reason.
- // NO NOT log this, this will happen whenever a new project occurs.
- }
- catch (IOException e)
- {
- // error reading the file, assume state is unrecoverable.
- // remove the state file.
- JETActivatorWrapper.INSTANCE.log(e);
- savedStateFile.delete();
- }
- catch (ClassNotFoundException e)
- {
- // error in deserializing the file. This should not happen. Log an error, for the record...
- InternalJET2Platform.logError("Could not deserialize JET2Builder State", e); //$NON-NLS-1$
- }
+ readSavedState(savedStateFile);
}
}
finally
{
- if (compilerState == null)
+ if (/*compilerState == null && */savedState == null)
{
- if(DEBUG) System.out.println(" compilerState not loaded from saved state"); //$NON-NLS-1$
+ if (DEBUG)
+ System.out.println(" compilerState not loaded from saved state"); //$NON-NLS-1$
// don't have the saved build state, force a full rebuild...
- compilerState = new JETCompilerState();
+// compilerState = new JETCompilerState();
forgetLastBuiltState();
}
if (DEBUG)
System.out.println("JET2Builder: done startupOnInitialize " + getProject()); //$NON-NLS-1$
}
}
+
+ /**
+ * @param savedStateFile
+ */
+ private void readSavedState(File savedStateFile)
+ {
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(new java.io.FileInputStream(savedStateFile));
+ final Object readObject = ois.readObject();
+// if (readObject instanceof JETCompilerState)
+// {
+// compilerState = (JETCompilerState)readObject;
+// ois.close();
+// if (DEBUG)
+// {
+// System.out.println(" loaded compilerState from saved state"); //$NON-NLS-1$
+// System.out.print(" taglibs : ["); //$NON-NLS-1$
+// String[] ids = compilerState.getAllReferencedTagLibraryIds();
+// for (int i = 0; i < ids.length; i++)
+// {
+// if (i != 0)
+// System.out.print(", "); //$NON-NLS-1$
+// System.out.print(ids[i]);
+// }
+// System.out.println("]"); //$NON-NLS-1$
+// System.out.println(" templates : " + compilerState.getTemplateMap()); //$NON-NLS-1$
+// }
+// }
+// else
+// {
+ if(readObject instanceof SimplifiedCompiler.SaveStateMemento) {
+ savedState = (Serializable)readObject;
+ }
+ if (DEBUG)
+ {
+ System.out.println(" loaded compilerState from saved state"); //$NON-NLS-1$
+ System.out.println(savedState.toString());
+ }
+// }
+ }
+ catch (FileNotFoundException e)
+ {
+ // nothing to do, the state was not saved for some reason.
+ // NO NOT log this, this will happen whenever a new project occurs.
+ }
+ catch (IOException e)
+ {
+ // error reading the file, assume state is unrecoverable.
+ // remove the state file.
+ JETActivatorWrapper.INSTANCE.log(e);
+ savedStateFile.delete();
+ }
+ catch (ClassNotFoundException e)
+ {
+ // error in deserializing the file. This should not happen. Log an error, for the record...
+ InternalJET2Platform.logError("Could not deserialize JET2Builder State", e); //$NON-NLS-1$
+ }
+ }
- private IProject[] computeReferencedProjects(IJETCompilerState compilerState)
+ /**
+ * @param allReferencedTagLibraryIds
+ * @return
+ */
+ private IProject[] computeReferencedProjects(final String[] allReferencedTagLibraryIds)
{
- final String[] allReferencedTagLibraryIds = compilerState.getAllReferencedTagLibraryIds();
List referencedProjects = new ArrayList(allReferencedTagLibraryIds.length);
for (int i = 0; i < allReferencedTagLibraryIds.length; i++)
{
@@ -383,26 +383,23 @@ public class JET2Builder extends IncrementalProjectBuilder implements SavedState
if(DEBUG) System.out.println(" depends on:" + refProject); //$NON-NLS-1$
}
}
- return (IProject[])referencedProjects.toArray(new IProject[referencedProjects.size()]);
+ final IProject[] projects = (IProject[])referencedProjects.toArray(new IProject[referencedProjects.size()]);
+ return projects;
}
- public IJETCompilerState getCompilerState()
- {
- return compilerState;
- }
-
public void doSave(IPath location) throws CoreException
{
FileOutputStream fileStream = null;
ObjectOutputStream objStream = null;
try
{
-
- File file = location.toFile();
- file.getParentFile().mkdirs();
- fileStream = new FileOutputStream(file);
- objStream = new ObjectOutputStream(fileStream);
- objStream.writeObject(compilerState);
+ if(savedState != null) {
+ File file = location.toFile();
+ file.getParentFile().mkdirs();
+ fileStream = new FileOutputStream(file);
+ objStream = new ObjectOutputStream(fileStream);
+ objStream.writeObject(savedState);
+ }
}
catch (IOException e)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java
new file mode 100644
index 0000000..da00516
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java
@@ -0,0 +1,333 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: WorkspaceCompiler.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.compiler.CompileOptionsManager;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.core.parser.ITagLibraryResolver;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+import org.eclipse.jet.core.parser.ProblemSeverity;
+import org.eclipse.jet.core.parser.ast.Problem;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.compiler.SimplifiedCompiler;
+import org.eclipse.jet.internal.compiler.SimplifiedCompiler.Builder;
+import org.eclipse.jet.internal.core.compiler.ICompilerOutput;
+import org.eclipse.jet.internal.core.compiler.IJETCompiler;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder;
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryManager;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+
+/**
+ * Workspace compiler that delegates to the simplified compiler and adds Eclipse workspace operations
+ */
+public class WorkspaceCompiler implements IJETCompiler, ICompilerOutput, ITagLibraryResolver
+{
+ public static final String RUNTIME_PROBLEM_MARKER = JET2Platform.PLUGIN_ID + ".runtimeProblem"; //$NON-NLS-1$
+
+ /**
+ * The Marker created by the compiler on all identified problems.
+ */
+ public static final String COMPILE_PROBLEM_MARKER = JET2Platform.PLUGIN_ID + ".compileProblem"; //$NON-NLS-1$
+
+
+ private final IJETCompiler simplifiedCompiler;
+ private final IProject project;
+ private final IContainer outputLocation;
+ private final boolean writeFilesAsDerived;
+ private final IProgressMonitor monitor;
+
+ public WorkspaceCompiler(IProject project, Serializable savedState, IProgressMonitor monitor)
+ {
+ this.project = project;
+ final Map options = CompileOptionsManager.getOptions(project);
+
+ final IJETBundleDescriptor descriptor = JET2Platform.getProjectDescription(project.getName());
+ final Builder builder = new SimplifiedCompiler.Builder(
+ JETCompilerOptions.getIntOption(options, JETCompilerOptions.OPTION_JET_SPECIFICATION_VERSION),
+ this)
+ .templateResolver(buildTemplateResolver(project, options))
+ .predefinedTagLibraries(getPredefinitionMap(descriptor.getTagLibraryReferences()))
+ .options(options)
+ .tagLibraryResolver(this);
+
+ final String templateLoaderClass = descriptor.getTemplateLoaderClass();
+ if(templateLoaderClass != null && templateLoaderClass.length() > 0) {
+ builder.templateLoaderFQN(templateLoaderClass);
+ }
+ if(savedState != null) {
+ builder.savedState(savedState);
+ }
+ this.simplifiedCompiler = builder.build();
+
+ final String javaSrcFolder = JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_COMPILED_TEMPLATE_SRC_DIR).trim();
+
+ this.outputLocation = javaSrcFolder.length() == 0 ? (IContainer)project : (IContainer)project.getFolder(javaSrcFolder);
+
+ this.writeFilesAsDerived = JETCompilerOptions.getBooleanOption(options, JETCompilerOptions.OPTION_SET_JAVA_FILES_AS_DERIVED);
+
+ this.monitor = monitor == null ? new NullProgressMonitor() : monitor;
+ }
+
+ /**
+ * @param project
+ * @param options
+ * @return
+ */
+ private ITemplateResolver buildTemplateResolver(IProject project, final Map options)
+ {
+ final WorkspaceTemplateResolverBuilder templateResolverWorkspaceTemplateResolverBuilder = new WorkspaceTemplateResolverBuilder(project);
+ URI altBaseLocations[] = getAltBaseLocations(options);
+ if(altBaseLocations.length > 0) {
+ templateResolverWorkspaceTemplateResolverBuilder.addAltBaseLocations(altBaseLocations);
+ }
+ final ITemplateResolver templateResolver = templateResolverWorkspaceTemplateResolverBuilder.build();
+ return templateResolver;
+ }
+
+ private URI[] getAltBaseLocations(Map options)
+ {
+ final String value = JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_V1_BASE_TRANSFORMATION);
+ if(value == null || value.trim().length() == 0) {
+ return new URI[0];
+ }
+ String[] uriStrings = value.split(","); //$NON-NLS-1$
+
+ List altLocations = new ArrayList(uriStrings.length);
+
+ for (int i = 0; i < uriStrings.length; i++)
+ {
+ String uriString = uriStrings[i].endsWith("/") ? uriStrings[i] : uriStrings[i] + "/"; //$NON-NLS-1$ //$NON-NLS-2$
+ try
+ {
+ URI uri = new URI(uriString);
+ altLocations.add(uri);
+ }
+ catch (URISyntaxException e)
+ {
+ InternalJET2Platform.logError(null, e);
+ }
+ }
+
+ return (URI[])altLocations.toArray(new URI[altLocations.size()]);
+ }
+
+ /**
+ * Create a map of tag library prefix to tag library id.
+ * @param tagLibraryReferences an array of tag library references
+ * @return a map
+ */
+ private Map getPredefinitionMap(TagLibraryReference[] tagLibraryReferences)
+ {
+ final Map predefinedMap = new HashMap(tagLibraryReferences.length);
+ for (int i = 0; i < tagLibraryReferences.length; i++)
+ {
+ if(tagLibraryReferences[i].isAutoImport())
+ {
+ predefinedMap.put(tagLibraryReferences[i].getPrefix(), tagLibraryReferences[i].getTagLibraryId());
+ }
+ }
+ return predefinedMap;
+ }
+
+ public void clean()
+ {
+ simplifiedCompiler.clean();
+ }
+
+ public CompileResult compile(String templatePath)
+ {
+ return simplifiedCompiler.compile(templatePath);
+ }
+
+ public void finish()
+ {
+ simplifiedCompiler.finish();
+ }
+
+ public Serializable getMemento()
+ {
+ return simplifiedCompiler.getMemento();
+ }
+
+ public String[] getTagLibaryDependencies()
+ {
+ return simplifiedCompiler.getTagLibaryDependencies();
+ }
+
+ public void removeTemplate(String templatePath)
+ {
+ simplifiedCompiler.removeTemplate(templatePath);
+ }
+
+ public boolean isTemplate(String templatePath)
+ {
+ return simplifiedCompiler.isTemplate(templatePath);
+ }
+
+ public void removeOutput(String outputFilePath)
+ {
+ final IFile file = outputLocation.getFile(new Path(outputFilePath));
+ if(file.exists() || file.isDerived()) {
+ try
+ {
+ file.delete(false, new SubProgressMonitor(monitor, 1));
+ }
+ catch (CoreException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
+ }
+ }
+ }
+
+ public void writeOutput(String outputFilePath, String contents, String encoding)
+ {
+ try
+ {
+ final IFile file = outputLocation.getFile(new Path(outputFilePath));
+ ensureDirsExist(file.getParent());
+
+ if (!file.exists())
+ {
+ file.create(new ByteArrayInputStream(new byte []{}), true, new SubProgressMonitor(monitor, 1));
+ }
+
+ if (encoding != null && !file.getCharset().equals(encoding))
+ {
+ file.setCharset(encoding, new SubProgressMonitor(monitor, 1));
+ }
+
+ file.setContents(new ByteArrayInputStream(contents.getBytes(file.getCharset())), true, false, new SubProgressMonitor(monitor, 1));
+ file.setDerived(writeFilesAsDerived);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
+ }
+ catch (CoreException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
+ }
+ }
+
+ /**
+ * Ensure the given container exists
+ * @param container
+ * @throws CoreException
+ */
+ private void ensureDirsExist(IContainer container) throws CoreException
+ {
+ if (container != null && !container.exists() && container.getType() == IResource.FOLDER)
+ {
+ ensureDirsExist(container.getParent());
+ ((IFolder)container).create(false, true, new SubProgressMonitor(monitor, 1));
+ }
+ }
+
+ public void recordProblems(String templatePath, List problems)
+ {
+ IFile file = project.getFile(templatePath);
+ if(file.exists()) {
+ try
+ {
+ for (Iterator i = problems.iterator(); i.hasNext();)
+ {
+ Problem problem = (Problem)i.next();
+ IMarker marker = file.createMarker(COMPILE_PROBLEM_MARKER);
+ marker.setAttribute(IMarker.LINE_NUMBER, problem.getLineNumber());
+ marker.setAttribute(IMarker.CHAR_START, problem.getStart());
+ marker.setAttribute(IMarker.CHAR_END, problem.getEnd());
+ marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
+ if (problem.getProblemSeverity() == ProblemSeverity.ERROR)
+ {
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ }
+ else if (problem.getProblemSeverity() == ProblemSeverity.WARNING)
+ {
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ }
+ else
+ {
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
+ }
+ }
+ }
+ catch (CoreException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
+ }
+ }
+ }
+
+ public void preCompile(String templatePath)
+ {
+ IFile file = project.getFile(templatePath);
+ try
+ {
+ if(file.exists()) {
+ file.deleteMarkers(COMPILE_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
+ file.deleteMarkers(RUNTIME_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
+ }
+ }
+ catch (CoreException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Compiler_ErrorWritingJava, e);
+ }
+ }
+
+ public TagLibrary getLibrary(String tagLibraryID)
+ {
+ return TagLibraryManager.getInstance().getTagLibrary(tagLibraryID);
+ }
+
+ public String[] getAffectedTemplatePaths(String changedFilePath)
+ {
+ return simplifiedCompiler.getAffectedTemplatePaths(changedFilePath);
+ }
+
+
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java
deleted file mode 100644
index 12ba899..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.compiler;
-
-
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-
-
-/**
- * A JET Compiler delegate for handling JET2 comments (&lt;%-- ... --%&gt;).
- *
- */
-public class CommentElementDelegate implements JETCoreElement
-{
-
- private static final String STD_COMMENT_CHARS = "--"; //$NON-NLS-1$
-
- /**
- * Create a new CommentElementDelegate
- */
- public CommentElementDelegate()
- {
- super();
- }
-
- /**
- * Given the parser state (reader, parser), determine if the parser is currently located at
- * a JET2 comment. If so, parse it, calling appropriate methods on <code>listener</code>.
- * @param listener the JET parser event listener, to which comment events are dispatched if a comment is recognized
- * @param reader the JET reader (lexer)
- * @param parser the JET parser instance
- * @return <code>true</code> a JET2 comment element was recognized, <code>false</code> otherwise
- * @throws JETException if an error occurs
- *
- */
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- if (!(listener instanceof JETParseEventListener2))
- {
- return false;
- }
- JETParseEventListener2 jet2Listener = (JETParseEventListener2)listener;
-
- String elementOpen = parser.getOpenScriptlet() + STD_COMMENT_CHARS;
- String elementClose = STD_COMMENT_CHARS + parser.getCloseScriptlet();
- if (!reader.matches(elementOpen))
- {
- return false;
- }
- JETMark elementStart = reader.mark();
- reader.advance(elementOpen.length());
-
- JETMark start = reader.mark();
- JETMark stop = reader.skipUntil(elementClose);
- if (stop == null)
- {
- CompilerErrorUtil.recordUnterminatedElement(jet2Listener, elementClose, elementStart, reader);
- }
- else
- {
- jet2Listener.handleComment(start, stop);
- }
- return true;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java
deleted file mode 100644
index a17858c..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.compiler;
-
-
-import java.text.MessageFormat;
-
-import org.eclipse.jet.compiler.Problem;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-
-
-/**
- * Utility class to aid in handling file errors
- */
-public class CompilerErrorUtil
-{
-
- /**
- *
- */
- private CompilerErrorUtil()
- {
- }
-
- /**
- * Record a parse error for a JET element whose close sequence is missing.
- * @param listener the JETParseEventLister2
- * @param expectedCloseSequence the expected close sequence
- * @param elementStart the JETMark for the start of the element
- * @param reader the current JETReader
- */
- public static void recordUnterminatedElement(
- JETParseEventListener2 listener,
- String expectedCloseSequence,
- JETMark elementStart,
- JETReader reader)
- {
- // FIXME: Note that we use XPath_Expected (text: Expected: {0}) because the message "jet.error.unterminated"
- // in the codegen plug-in is incorrect.
- listener.recordProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnterminatedXMLTag,
- JET2Messages.XPath_Expected,
- new Object []{ expectedCloseSequence },
- elementStart.getCursor(),
- reader.mark().getCursor(),
- elementStart.getLine(),
- elementStart.getCol());
-
- }
-
- /**
- * Return the formatted error message for an unterminated string.
- * @param openSequence
- * @param expectedCloseSequence
- * @param reader
- * @return
- */
- public static String getUnterminatedMessage(String openSequence, String expectedCloseSequence, JETReader reader) {
- // This method encapsulates the retrieval of the 'unterminated' error message. Because this message is part
- // of EMF Codegen, and it is incorect (it incorrectly uses the first argument twice), we centralize
- // access to it, and implement the 'fix' once.
- // This is the 'unfixed' code:
-// final String msg = CodeGenPlugin.getPlugin().getString(
-// "jet.error.unterminated", //$NON-NLS-1$
-// new Object []{ openSequence, reader.mark().toString() });
-
- // FIXME: Note that we use XPath_Expected (text: Expected: {0}) because the message "jet.error.unterminated"
- // in the codegen plug-in is incorrect.
- return MessageFormat.format(JET2Messages.XPath_Expected, new Object[] {expectedCloseSequence});
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerStateManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerStateManager.java
deleted file mode 100644
index 0d92ca2..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerStateManager.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.compiler;
-
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jet.compiler.IJETCompilerState;
-
-
-/**
- * Manager compiler state stored in the workspace meta data.
- * @deprecated Don't think we need this
- */
-public class CompilerStateManager
-{
-
- private final Map projectCache = Collections.synchronizedMap(new HashMap());
-
- /**
- *
- */
- public CompilerStateManager()
- {
- super();
- }
-
- /**
- * Return the cached compiler state for the identified project.
- * Create a compiler state if it does not exist.
- * @param project
- * @return the compiler state
- */
- public IJETCompilerState getCompilerState(IProject project)
- {
- IJETCompilerState compilerState = (IJETCompilerState)projectCache.get(project.getName());
-
- if (compilerState == null)
- {
- compilerState = new JETCompilerState();
- projectCache.put(project.getName(), compilerState);
- }
-
- return compilerState;
- }
-
- /**
- * Associate the compiler state with a JET2 project.
- * @param project an Eclipse workspace project (containing a JET2 builder).
- * @param compilerState the compiler state.
- */
- public void setCompilerState(IProject project, IJETCompilerState compilerState)
- {
- projectCache.put(project.getName(), compilerState);
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java
deleted file mode 100644
index ac83aac..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.compiler;
-
-
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-
-
-/**
- * Parser delegate for parsing a JET2 declaration &lt;%! ... %&gt;
- */
-public class DeclarationElementDelegate implements JETCoreElement
-{
-
- private static final String STD_DECL_CHARS = "!"; //$NON-NLS-1$
-
- public DeclarationElementDelegate()
- {
- super();
- }
-
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- if (!(listener instanceof JETParseEventListener2))
- {
- return false;
- }
- JETParseEventListener2 jet2Listener = (JETParseEventListener2)listener;
-
- String declOpen = parser.getOpenScriptlet() + STD_DECL_CHARS;
- String declClose = parser.getCloseScriptlet();
- if (!reader.matches(declOpen))
- {
- return false;
- }
- JETMark elementStart = reader.mark();
- reader.advance(declOpen.length());
-
- JETMark start = reader.mark();
- JETMark stop = reader.skipUntil(declClose);
- if (stop == null)
- {
- CompilerErrorUtil.recordUnterminatedElement(jet2Listener, declClose, elementStart, reader);
- }
- else
- {
- jet2Listener.handleDeclaration(start, stop);
- }
- return true;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java
deleted file mode 100644
index 6cf84fc..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.compiler;
-
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.compiler.Problem;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-
-/**
- * A JETCoreElement that delegates its accept the the passed core element, but records any JETException
- * as errors on a JETParseEventListener2.
- */
-public class ErrorRedirectingCoreElementDelegate implements JETCoreElement
-{
-
- private final JETCoreElement delegate;
-
- public ErrorRedirectingCoreElementDelegate(JETCoreElement delegate) {
- this.delegate = delegate;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.internal.parser.JETCoreElement#accept(org.eclipse.jet.internal.parser.JETParseEventListener, org.eclipse.jet.internal.parser.JETReader, org.eclipse.jet.internal.parser.JETParser)
- */
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser)
- {
- boolean isAccepted = true;
- JETMark start = reader.mark();
- try {
- isAccepted = delegate.accept(listener, reader, parser);
- }
- catch(JETException e) {
- if(listener instanceof JETParseEventListener2)
- {
- JETParseEventListener2 listener2 = (JETParseEventListener2)listener;
- listener2.recordProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), new Object[0],
- start.getCursor(), reader.mark().getCursor(), start.getLine(), start.getCol());
- }
- }
- return isAccepted;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/GenXMLElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/GenXMLElement.java
index 158109a..40b343e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/GenXMLElement.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/GenXMLElement.java
@@ -20,8 +20,8 @@ package org.eclipse.jet.internal.compiler;
import java.util.Map;
-import org.eclipse.jet.compiler.XMLBodyElement;
-import org.eclipse.jet.compiler.XMLElement;
+import org.eclipse.jet.core.parser.ast.XMLBodyElement;
+import org.eclipse.jet.core.parser.ast.XMLElement;
/**
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
index 3ea3c9c..246d3dc 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
@@ -132,7 +132,7 @@ public class MethodBodyCreator extends DefaultJET2ASTVisitor
{
String tagVarName = tagVariableName(element);
String parentTagVar = varStack.empty() ? NULL_KEYWORD : (String)varStack.peek();
- return new GenXMLElement(element, tagVarName, tagInfoVariableName(element), parentTagVar);
+ return new GenXMLElement(element.getDelegate(), tagVarName, tagInfoVariableName(element), parentTagVar);
}
/**
@@ -174,7 +174,7 @@ public class MethodBodyCreator extends DefaultJET2ASTVisitor
*/
public String getBuffer()
{
- return out.getDocument().get();
+ return out.toString();
}
private void generate(String templatePath, String indent, Object element) {
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
new file mode 100644
index 0000000..3943736
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
@@ -0,0 +1,253 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: SafeJETASTVisitor.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+import java.util.regex.Matcher;
+
+import org.eclipse.jet.BufferedJET2Writer;
+import org.eclipse.jet.IWriterListener;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.core.parser.ast.JETASTVisitor;
+import org.eclipse.jet.internal.core.NewLineUtil;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+
+/**
+ * A JETAST Visitor this doesn't case compile errors when used in JET templates
+ */
+public class SafeJETASTVisitor extends JETASTVisitor
+{
+
+ private final class IndentingWriter implements JET2Writer {
+
+ private final JET2Writer delegate;
+
+ private boolean atLineStart;
+
+ public IndentingWriter(JET2Writer delegate) {
+ this.delegate = delegate;
+ this.atLineStart = true;
+
+ }
+
+ public void addEventListener(String category, IWriterListener listener)
+ {
+ delegate.addEventListener(category, listener);
+ }
+
+ public void addPosition(String category, Position position)
+ {
+ IDocument document = getDocument();
+ if(document != null) {
+ try
+ {
+ document.addPosition(category, position);
+ }
+ catch (BadLocationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (BadPositionCategoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public void addPositionCategory(String category)
+ {
+ IDocument document = getDocument();
+ if(document != null) {
+ document.addPositionCategory(category);
+ }
+ }
+
+ public IDocument getDocument()
+ {
+ return delegate instanceof BufferedJET2Writer ?
+ (IDocument)((BufferedJET2Writer)delegate).getAdapter(IDocument.class)
+ : null;
+ }
+
+ public int getLength()
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ return ((BufferedJET2Writer)delegate).getContentLength();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public JET2Writer getParentWriter()
+ {
+ return delegate.getParentWriter();
+ }
+
+ public Position[] getPositions(String category)
+ {
+ final IDocument document = getDocument();
+ if(document != null) {
+ try
+ {
+ return document.getPositions(category);
+ }
+ catch (BadPositionCategoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return new Position[0];
+ }
+
+ public JET2Writer newNestedContentWriter()
+ {
+ return delegate.newNestedContentWriter();
+ }
+
+ public void replace(int offset, int length, String text)
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ ((BufferedJET2Writer)delegate).replaceContent(offset, length, text);
+ } else {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ public void write(boolean b)
+ {
+ write(Boolean.valueOf(b));
+ }
+
+ public void write(char c)
+ {
+ write(Character.toString(c));
+ }
+
+ public void write(char[] data)
+ {
+ write(data == null ? "" : new String(data)); //$NON-NLS-1$
+ }
+
+ public void write(double d)
+ {
+ write(Double.toString(d));
+ }
+
+ public void write(float f)
+ {
+ write(Float.toString(f));
+ }
+
+ public void write(int i)
+ {
+ write(Integer.toString(i));
+ }
+
+ public void write(JET2Writer bodyContent)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void write(long l)
+ {
+ write(Long.toString(l));
+ }
+
+ public void write(Object obj)
+ {
+ write(String.valueOf(obj));
+ }
+
+ public void write(String string)
+ {
+ if(string == null) {
+ string = ""; //$NON-NLS-1$
+ }
+ if(atLineStart && string.length() > 0) {
+ delegate.write(indent);
+ atLineStart = false;
+ }
+ int nextToWrite = 0;
+ for(final Matcher nlMatcher = NewLineUtil.NEW_LINE_PATTERN.matcher(string);
+ nlMatcher.find();) {
+ writeLineText(string, nextToWrite, nlMatcher.start());
+ delegate.write(string.substring(nlMatcher.start(), nlMatcher.end()));
+ nextToWrite = nlMatcher.end();
+ atLineStart = true;
+ }
+ writeLineText(string, nextToWrite, string.length());
+ // atLineStart is true if this string ended with a new line
+ atLineStart = nextToWrite > 0 && nextToWrite == string.length();
+ }
+
+ /**
+ * @param string
+ * @param start
+ * @param end
+ */
+ private void writeLineText(String string, int start, int end)
+ {
+ if(start < end) {
+ if(atLineStart) {
+ delegate.write(indent);
+ }
+ delegate.write(string.substring(start, end));
+ }
+ }
+
+ public IWriterListener[] getEventListeners()
+ {
+ return delegate.getEventListeners();
+ }
+ }
+ protected final JET2Context context;
+ protected final JET2Writer out;
+ private String indent;
+ private final String stdIndent;
+
+ public SafeJETASTVisitor(JET2Context context, JET2Writer out) {
+ this(context, out, " "); //$NON-NLS-1$
+ }
+
+ public SafeJETASTVisitor(JET2Context context, JET2Writer out, String stdIndent) {
+ this.context = context;
+ this.out = new IndentingWriter(out);
+ this.stdIndent = stdIndent;
+ this.indent = ""; //$NON-NLS-1$
+ }
+
+ public SafeJETASTVisitor in()
+ {
+ indent = indent + stdIndent;
+ return this;
+ }
+
+ public SafeJETASTVisitor out()
+ {
+ indent = indent.substring(0, indent.length() - stdIndent.length());
+ return this;
+ }
+
+ public String ident()
+ {
+ return indent;
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SimplifiedCompiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SimplifiedCompiler.java
new file mode 100644
index 0000000..847a5b4
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SimplifiedCompiler.java
@@ -0,0 +1,540 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: SimplifiedCompiler.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.core.parser.DefaultTemplateResolver;
+import org.eclipse.jet.core.parser.IProblem;
+import org.eclipse.jet.core.parser.ITagLibraryResolver;
+import org.eclipse.jet.core.parser.ITemplateInput;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+import org.eclipse.jet.core.parser.ProblemSeverity;
+import org.eclipse.jet.core.parser.RecursiveIncludeException;
+import org.eclipse.jet.core.parser.ast.JETAST;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.internal.core.NewLineUtil;
+import org.eclipse.jet.internal.core.compiler.DuplicateGeneratedClassException;
+import org.eclipse.jet.internal.core.compiler.ICompilerOutput;
+import org.eclipse.jet.internal.core.compiler.IJETCompiler;
+import org.eclipse.jet.internal.core.compiler.IncludeDependencies;
+import org.eclipse.jet.internal.core.compiler.IncludeDependenciesUtil;
+import org.eclipse.jet.internal.core.compiler.UniqueNameGenerator;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryReference;
+
+/**
+ * Implementation of IJETCompiler
+ */
+public final class SimplifiedCompiler implements IJETCompiler
+{
+
+ private static final class NullTemplateResolver implements ITemplateResolver
+ {
+ public URI[] getBaseLocations()
+ {
+ return new URI[0];
+ }
+
+ public ITemplateInput getIncludedInput(String templatePath, ITemplateInput[] activeInputs) throws RecursiveIncludeException
+ {
+ return null;
+ }
+
+ public ITemplateInput getInput(String templatePath)
+ {
+ return null;
+ }
+ }
+ private static final class JET1TemplateMatcher implements ITemplateMatcher
+ {
+ private final String templatesDir;
+
+ public JET1TemplateMatcher(String templatesDir)
+ {
+ if(templatesDir == null || templatesDir.length() == 0)
+ {
+ this.templatesDir = ""; //$NON-NLS-1$
+ }
+ else
+ {
+ this.templatesDir = templatesDir.endsWith("/") ? templatesDir : templatesDir + "/"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+ }
+
+ public boolean isTemplate(String templatePath)
+ {
+ return templatePath.startsWith(templatesDir) && templatePath.endsWith("jet"); //$NON-NLS-1$
+ }
+ }
+ public interface ITemplateMatcher
+ {
+ public abstract boolean isTemplate(String templatePath);
+ }
+
+ public static final class JET2TemplateMatcher implements ITemplateMatcher
+ {
+ private final Set sourceExtensions;
+
+ public JET2TemplateMatcher(Set sourceExtensions)
+ {
+ this.sourceExtensions = sourceExtensions;
+ }
+
+ public boolean isTemplate(String templatePath)
+ {
+ final int extensionIndex = templatePath.lastIndexOf("."); //$NON-NLS-1$
+ if(extensionIndex >= 0)
+ {
+ final String extension = templatePath.substring(extensionIndex + 1);
+ return sourceExtensions.contains(extension);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+
+ /**
+ * Memento for shared state
+ */
+ public static final class SaveStateMemento implements Serializable
+ {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5023383826047467196L;
+ private final Map fqnToPathMap;
+ private final Map pathToFQNMap;
+ private final Map pathToRefTagLibSet;
+ private final IncludeDependencies includeDependencies;
+
+ /**
+ * Create a SaveStateMemento for the specified compiler
+ * @param compiler a compiler instance
+ */
+ public SaveStateMemento(SimplifiedCompiler compiler)
+ {
+ this.fqnToPathMap = compiler.uniqueNameGenerator.getFQNToPathMap();
+ this.pathToFQNMap = compiler.uniqueNameGenerator.getPathToFQNMap();
+ this.pathToRefTagLibSet = new HashMap(compiler.pathToRefTagLibSet);
+ this.includeDependencies = compiler.includeDependencies;
+ }
+
+ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
+ s.defaultReadObject();
+
+ if(includeDependencies == null) {
+ throw new IOException("includeDependencies is null"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Builder for SimplifiedCompiler
+ */
+ public static final class Builder
+ {
+
+ private final int jetSpec;
+ private ITemplateResolver templateResolver;
+ private SaveStateMemento savedState;
+ private Map options;
+ private final ICompilerOutput compilerOutput;
+ private String templateLoaderFQN;
+ private Map predefinedTagLibraries;
+ public ITagLibraryResolver tagLibraryResolver;
+
+
+ public Builder(int jetSpec, URI baseLocation, ICompilerOutput compilerOutput)
+ {
+ this(jetSpec, compilerOutput);
+ templateResolver(new DefaultTemplateResolver.Builder(baseLocation).build());
+ }
+
+ public Builder(int jetSpec, ICompilerOutput compilerOutput)
+ {
+ this.jetSpec = jetSpec;
+ this.compilerOutput = compilerOutput;
+
+ }
+ public Builder templateResolver(ITemplateResolver templateResolver)
+ {
+ this.templateResolver = templateResolver;
+ return this;
+ }
+
+ /**
+ * Specify the saved state
+ * @param savedState
+ * @return
+ */
+ public Builder savedState(Serializable savedState)
+ {
+ if(!(savedState instanceof SaveStateMemento))
+ {
+ throw new IllegalArgumentException();
+ }
+ this.savedState = (SaveStateMemento)savedState;
+ return this;
+ }
+
+ public Builder options(Map options)
+ {
+ this.options = options;
+ return this;
+ }
+
+ /**
+ * Set the fully qualified Java class name of the template loader
+ * @param templateLoader the fully qualified Java class name of the template laoder
+ * @return the bulder
+ */
+ public Builder templateLoaderFQN(String templateLoaderFQN)
+ {
+ this.templateLoaderFQN = templateLoaderFQN;
+ return this;
+ }
+
+ /**
+ * Set the predefined tag libraries map (key = prefix, value = id).
+ * @param predefinedTagLibraries a map of tag library prefixes to tag library ids
+ * @return the builder
+ */
+ public Builder predefinedTagLibraries(Map predefinedTagLibraries)
+ {
+ this.predefinedTagLibraries = predefinedTagLibraries;
+ return this;
+ }
+
+ public Builder tagLibraryResolver(ITagLibraryResolver tagLibraryResolver) {
+ this.tagLibraryResolver = tagLibraryResolver;
+ return this;
+ }
+ /**
+ * Build the compiler instance
+ * @return
+ */
+ public SimplifiedCompiler build()
+ {
+ return new SimplifiedCompiler(this);
+ }
+ }
+
+ private final int jetSpec;
+ private final ITemplateResolver templateResolver;
+ private final Map predefinedTagLibraries;
+ private final Map options;
+ private final UniqueNameGenerator uniqueNameGenerator;
+ private final Map pathToRefTagLibSet; // Map<String,Set<String>>
+ private final ICompilerOutput compilerOutput;
+ private final ITemplateMatcher templateMatcher;
+ private final String templateLoaderClassName;
+ private final String templateLoaderPackage;
+ private final ITagLibraryResolver tagLibraryResolver;
+ private final IncludeDependencies includeDependencies;
+
+ private static final ITagLibraryResolver nullTagLibraryResolver = new ITagLibraryResolver() {
+
+ public TagLibrary getLibrary(String tagLibraryID)
+ {
+ return null;
+ }};
+
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ private SimplifiedCompiler(Builder builder)
+ {
+ this.jetSpec = builder.jetSpec;
+ this.templateResolver = builder.templateResolver == null ?
+ new NullTemplateResolver()
+ : builder.templateResolver;
+ // Make a defensive copy of the builder provided tag library maps
+ this.predefinedTagLibraries = builder.predefinedTagLibraries == null ? Collections.EMPTY_MAP : new HashMap(
+ builder.predefinedTagLibraries);
+
+ // Make a defensive copy of the options passed to the builder.
+ this.options = builder.options == null ? JETCompilerOptions.getDefaultCompilerOptions() : new HashMap(builder.options);
+
+ final Map pathToFQNMap = builder.savedState == null ? Collections.EMPTY_MAP : builder.savedState.pathToFQNMap;
+ final Map fqnToPathMap = builder.savedState == null ? Collections.EMPTY_MAP : builder.savedState.fqnToPathMap;
+ this.uniqueNameGenerator = new UniqueNameGenerator(pathToFQNMap, fqnToPathMap,
+ JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_COMPILED_TEMPLATE_PACKAGE));
+
+ this.compilerOutput = builder.compilerOutput;
+
+ if(builder.templateLoaderFQN == null)
+ {
+ this.templateLoaderPackage = null;
+ this.templateLoaderClassName = null;
+ }
+ else
+ {
+ int index = builder.templateLoaderFQN.lastIndexOf('.');
+ templateLoaderPackage = index >= 0 ? builder.templateLoaderFQN.substring(0, index) : ""; //$NON-NLS-1$
+ templateLoaderClassName = index >= 0 ? builder.templateLoaderFQN.substring(index + 1) : builder.templateLoaderFQN;
+ }
+
+ Set sourceExtensions = new HashSet();
+ final String[] extensions = JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_TEMPLATE_EXT).split(","); //$NON-NLS-1$
+ for (int i = 0; i < extensions.length; i++)
+ {
+ sourceExtensions.add(extensions[i].trim());
+ }
+
+ this.pathToRefTagLibSet = builder.savedState == null ? new HashMap() : new HashMap(builder.savedState.pathToRefTagLibSet);
+
+ this.tagLibraryResolver = builder.tagLibraryResolver == null ? nullTagLibraryResolver : builder.tagLibraryResolver;
+
+ this.includeDependencies = builder.savedState == null ? new IncludeDependencies() : builder.savedState.includeDependencies;
+
+ templateMatcher = builder.jetSpec == JETAST.JET_SPEC_V1 ?
+ (ITemplateMatcher)new JET1TemplateMatcher(JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_V1_TEMPLATES_DIR))
+ : (ITemplateMatcher)new JET2TemplateMatcher(sourceExtensions);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.compiler.IJETCompiler#compile(java.lang.String)
+ */
+ public CompileResult compile(String templatePath)
+ {
+ if(!isJETSourceFile(templatePath))
+ {
+ return CompileResult.IGNORED;
+ }
+
+ compilerOutput.preCompile(templatePath);
+
+ final JETCompilationUnit cu
+ = (JETCompilationUnit)new org.eclipse.jet.core.parser.ast.JETASTParser.Builder(jetSpec)
+ .templateResolver(templateResolver)
+ .predefinedTagLibraries(predefinedTagLibraries)
+ .tagLibraryResolver(tagLibraryResolver)
+ .build()
+ .parse(templatePath);
+
+ try
+ {
+ String oldOutputPath = uniqueNameGenerator.getGeneratedOutputPath(templatePath);
+
+ uniqueNameGenerator.ensureJavaOutputSet(templatePath, cu);
+
+ // run the code generator
+ TemplateRunner templateRunner = new TemplateRunner();
+ // XXX make this more open
+ String cgTemplatePath = jetSpec == JETAST.JET_SPEC_V1 ? "templates/v1/jet2java.jet" : "templates/v2/jet2java.jet"; //$NON-NLS-1$ //$NON-NLS-2$
+ String code = templateRunner.generate(cgTemplatePath, Collections.singletonMap("cu", cu)); //$NON-NLS-1$
+
+ // save the code to the output location
+ String outputPath = outputPath(cu.getOutputJavaPackage(), cu.getOutputJavaClassName());
+
+ if(oldOutputPath != null && !oldOutputPath.equals(outputPath))
+ {
+ compilerOutput.removeOutput(oldOutputPath);
+ }
+
+ compilerOutput.writeOutput(outputPath, NewLineUtil.setLineTerminator(code, NL), cu.getOutputEncoding());
+
+ if(cu.hasErrors() || cu.hasWarnings()) {
+ compilerOutput.recordProblems(templatePath, cu.getProblems());
+ }
+
+ updateDependencies(templatePath, cu);
+
+ }
+ catch (DuplicateGeneratedClassException e)
+ {
+ cu.createProblem(
+ ProblemSeverity.ERROR,
+ IProblem.MultipleTemplatesWithSameJavaClass,
+ JET2Messages.JET2Compiler_SameJavaClassAsOther,
+ new Object []{ e.getTemplatePath(), e.getOtherTemplatePath(), },
+ -1,
+ -1,
+ -1,
+ -1);
+ }
+
+ if (cu.hasErrors())
+ {
+ return CompileResult.ERRORS;
+ }
+ else if (cu.hasWarnings())
+ {
+ return CompileResult.WARNINGS;
+ }
+ else
+ {
+ return CompileResult.OK;
+ }
+ }
+
+ /**
+ * Update dependencies tracked by the compiler
+ * @param templatePath the templatePath
+ * @param cu the compilation unit
+ */
+ private void updateDependencies(String templatePath, JETCompilationUnit cu)
+ {
+ final TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
+ Set tlIdRefs = tlRefs.length == 0 ? Collections.EMPTY_SET : new HashSet(tlRefs.length);
+ for (int i = 0; i < tlRefs.length; i++)
+ {
+ tlIdRefs.add(tlRefs[i].getTagLibraryId());
+ }
+ pathToRefTagLibSet.put(templatePath, tlIdRefs);
+
+ includeDependencies.removeDependencies(templatePath);
+ includeDependencies.addDependencies(templatePath, IncludeDependenciesUtil.getDependencies(cu));
+ }
+
+ /**
+ * calculate the output path for a Java file given a Java package and classname
+ * @param javaPackage a Java package name, possible the empty string for the default package
+ * @param className a Java class name
+ * @return the output path
+ */
+ private String outputPath(final String javaPackage, final String className)
+ {
+ StringBuffer buffer = new StringBuffer(javaPackage.length() + className.length() + 6);
+ if(javaPackage.length() > 0) {
+ buffer.append(javaPackage.replace('.', '/')).append('/');
+ }
+ buffer.append(className).append(".java"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+
+ /**
+ * Calculate the output path for a Java class froma fully qualified class name
+ * @param fqClassName a fully qualified class name
+ * @return the output path
+ */
+ private String outputPath(final String fqClassName)
+ {
+ StringBuffer buffer = new StringBuffer(fqClassName.length() + ".java".length()); //$NON-NLS-1$
+ buffer.append(fqClassName.replace('.', '/')).append(".java"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+
+ /**
+ * Test whether a templatePath is to be compiled by this compiler
+ * @param templatePath a template path
+ * @return <code>true</code> if the template path has a known extension
+ */
+ private boolean isJETSourceFile(String templatePath)
+ {
+ return templateMatcher.isTemplate(templatePath);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.compiler.IJETCompiler#retrieveState()
+ */
+ public Serializable getMemento()
+ {
+ return new SaveStateMemento(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.compiler.IJETCompiler#finish()
+ */
+ public void finish()
+ {
+ if(templateLoaderClassName == null) return;
+
+ final LoaderGenerationParameters args = new LoaderGenerationParameters(templateLoaderPackage,
+ templateLoaderClassName, uniqueNameGenerator.getPathToFQNMap());
+
+ // run the code generator
+ TemplateRunner templateRunner = new TemplateRunner();
+ String code = templateRunner.generate("templates/jet2transform.jet", //$NON-NLS-1$
+ Collections.singletonMap("args", args)); //$NON-NLS-1$
+
+ compilerOutput.writeOutput(outputPath(templateLoaderPackage, templateLoaderClassName),
+ NewLineUtil.setLineTerminator(code, NL), null);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.compiler.IJETCompiler#clean()
+ */
+ public void clean()
+ {
+ // tell the output manager to remove generated template Class files
+ for (Iterator i = uniqueNameGenerator.clean().iterator(); i.hasNext();)
+ {
+ String fqJavaClass = (String)i.next();
+ compilerOutput.removeOutput(outputPath(fqJavaClass));
+ }
+ // tell the output manager to remove the generated class loader
+ if(templateLoaderClassName != null)
+ {
+ compilerOutput.removeOutput(outputPath(templateLoaderPackage, templateLoaderClassName));
+ }
+
+ // forget all our internal state
+ pathToRefTagLibSet.clear();
+ }
+
+ public void removeTemplate(String templatePath)
+ {
+ final String outputPath = uniqueNameGenerator.remove(templatePath);
+ if(outputPath != null)
+ {
+ compilerOutput.removeOutput(outputPath);
+ }
+ pathToRefTagLibSet.remove(templatePath);
+ }
+
+ public String[] getTagLibaryDependencies()
+ {
+ Set dependencies = new HashSet(predefinedTagLibraries.values());
+ for (Iterator i = pathToRefTagLibSet.values().iterator(); i.hasNext();)
+ {
+ Set templateDependencies = (Set)i.next();
+ dependencies.addAll(templateDependencies);
+ }
+ return (String[])dependencies.toArray(new String[dependencies.size()]);
+ }
+
+ public boolean isTemplate(String templatePath)
+ {
+ return isJETSourceFile(templatePath);
+ }
+
+ public String[] getAffectedTemplatePaths(String changedFilePath)
+ {
+ Set templatesToCompile = new HashSet(Arrays.asList(includeDependencies.getAffectedTemplates(changedFilePath)));
+ return (String[])templatesToCompile.toArray(new String[templatesToCompile.size()]);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TagUsageVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TagUsageVisitor.java
new file mode 100644
index 0000000..fa19876
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TagUsageVisitor.java
@@ -0,0 +1,79 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: TagUsageVisitor.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jet.core.parser.ast.JETASTVisitor;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.core.parser.ast.XMLBodyElement;
+import org.eclipse.jet.core.parser.ast.XMLEmptyElement;
+import org.eclipse.jet.taglib.TagLibraryReference;
+
+/**
+ * JET AST visitor that computes tag usage.
+ */
+public class TagUsageVisitor extends JETASTVisitor
+{
+ private boolean hasTags = false;
+
+ private Set nsPrefixesUsed = new HashSet();
+
+ public boolean visit(XMLBodyElement xmlBodyElement)
+ {
+ nsPrefixesUsed.add(xmlBodyElement.getNSPrefix());
+ hasTags = true;
+ return true;
+ }
+
+ public boolean visit(XMLEmptyElement xmlEmptyElement)
+ {
+ nsPrefixesUsed.add(xmlEmptyElement.getNSPrefix());
+ hasTags = true;
+ return true;
+ }
+
+ /**
+ * Test if the visited ast include JET tags
+ * @return <code>true</code> if the compilation unit had tags
+ */
+ public boolean hasTags() {
+ return hasTags;
+ }
+
+ /**
+ * Return the tag library references used by the the visited
+ * JET tags
+ * @param cu the compilation unit containing the visited elements
+ * @return a possibily empty array of tag library references
+ */
+ public TagLibraryReference[] getUsedTagLibraryReferences(JETCompilationUnit cu) {
+ final TagLibraryReference[] tlrefs = cu.getTagLibraryReferences();
+ List usedRefs = new ArrayList();
+ for (int i = 0; i < tlrefs.length; i++)
+ {
+ if(nsPrefixesUsed.contains(tlrefs[i].getPrefix())) {
+ usedRefs.add(tlrefs[i]);
+ }
+ }
+ return (TagLibraryReference[])usedRefs.toArray(new TagLibraryReference[usedRefs.size()]);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TemplateRunner.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TemplateRunner.java
index df59b31..922dce5 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TemplateRunner.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TemplateRunner.java
@@ -54,6 +54,6 @@ public class TemplateRunner
public String generate(String templatePath, Map arguments) {
JET2Writer out = new BodyContentWriter();
generate(templatePath, arguments, out);
- return out.getDocument().get();
+ return out.toString();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TextTrimmingVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TextTrimmingVisitor.java
deleted file mode 100644
index 8911930..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/TextTrimmingVisitor.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.compiler;
-
-
-import org.eclipse.jet.compiler.Comment;
-import org.eclipse.jet.compiler.DefaultJET2ASTVisitor;
-import org.eclipse.jet.compiler.JET2ASTElement;
-import org.eclipse.jet.compiler.JET2ASTVisitor;
-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.parser.LineInfo;
-
-
-/**
- * A JET AST Visitor that strips whitespace and new-lines
- *
- */
-public class TextTrimmingVisitor extends DefaultJET2ASTVisitor implements JET2ASTVisitor
-{
- /**
- *
- */
- public TextTrimmingVisitor()
- {
- super();
- }
-
- private void checkAndStrip(JET2ASTElement element)
- {
- if(element.removeLineWhenOtherwiseEmpty())
- {
- JET2ASTElement prev = element.getPrevElement();
- JET2ASTElement next = element.getNextElement();
- if(endsWithEmtpyLine(prev) && startsWithEmptyLine(next))
- {
- trimLastLine(prev);
- trimFirstLine(next);
- }
- }
- }
-
- private void trimLastLine(JET2ASTElement element)
- {
- if(element instanceof TextElement)
- {
- TextElement text = (TextElement)element;
- text.setTrimLastLine(true);
- }
- }
-
- private void trimFirstLine(JET2ASTElement element)
- {
- if(element instanceof TextElement)
- {
- TextElement text = (TextElement)element;
- text.setTrimFirstLine(true);
- }
- }
-
- private boolean startsWithEmptyLine(JET2ASTElement element)
- {
- if(element instanceof TextElement)
- {
- TextElement text = (TextElement)element;
- final LineInfo[] lines = text.getLines();
- if(lines.length > 0 && lines[0].hasDelimiter())
- {
- LineInfo line = lines[0];
- if(new String(text.getRawText(), line.getStart(), line.getEnd() - line.getStart()).trim().length() == 0)
- {
- // first line is all whitespace
- return true;
- }
- }
- }
- else if(element == null)
- {
- return true;
- }
- return false;
- }
-
- private boolean endsWithEmtpyLine(JET2ASTElement element)
- {
- if(element instanceof TextElement)
- {
- TextElement text = (TextElement)element;
- final LineInfo[] lines = text.getLines();
- if(lines.length > 0)
- {
- LineInfo line = lines[lines.length - 1];
- if(line.hasDelimiter()) {
- // last line has a delimiter => this element start on col # 1
- return true;
- }
- else if( lines.length > 1 && new String(text.getRawText(), line.getStart(), line.getEnd() - line.getStart()).trim().length() == 0)
- {
- // last line is all whitespace
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- else if(element == null)
- {
- return true;
- }
- return false;
- }
-
- public void visit(JET2Declaration declaration)
- {
- checkAndStrip(declaration);
- }
-
- public void visit(JET2Directive directive)
- {
- checkAndStrip(directive);
- }
-
- public void visit(JET2Expression expression)
- {
- checkAndStrip(expression);
- }
-
- public void visit(JET2Scriptlet scriptlet)
- {
- checkAndStrip(scriptlet);
- }
-
- public void visit(XMLEmptyElement xmlEmptyElement)
- {
- checkAndStrip(xmlEmptyElement);
- }
-
- public void visit(XMLBodyElement xmlBodyElement)
- {
- checkAndStrip(xmlBodyElement);
- }
-
- public void visit(XMLBodyElementEnd xmlBodyElementEnd)
- {
- checkAndStrip(xmlBodyElementEnd);
- }
-
- public void visit(Comment comment)
- {
- checkAndStrip(comment);
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java
new file mode 100644
index 0000000..f64f5b8
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java
@@ -0,0 +1,120 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: V2CodeGenVisitor.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.core.parser.ast.JETASTElement;
+import org.eclipse.jet.core.parser.ast.TextElement;
+import org.eclipse.jet.core.parser.ast.XMLElement;
+import org.eclipse.jet.internal.JavaUtil;
+
+/**
+ * AST Visitor used by code generation
+ */
+public class V2CodeGenVisitor extends SafeJETASTVisitor
+{
+ private static final String UNDERSCORE = "_"; //$NON-NLS-1$
+
+ private final String textPrefix = "TEXT_"; //$NON-NLS-1$
+ private final String tagVarPrefix = "_jettag_"; //$NON-NLS-1$
+
+ /**
+ * @param context
+ * @param out
+ * @param initialIndent
+ */
+ public V2CodeGenVisitor(JET2Context context, JET2Writer out, String stdIndent)
+ {
+ super(context, out, stdIndent);
+ }
+
+ public V2CodeGenVisitor(JET2Context context, JET2Writer out)
+ {
+ this(context, out, " "); //$NON-NLS-1$
+ }
+
+ public String tagVariableName(XMLElement element)
+ {
+ return tagVar(element);
+ }
+
+ public String tagVar(XMLElement element)
+ {
+ return tagVarPrefix + tagVariableSuffix(element);
+ }
+
+ /**
+ * Return the name of a unique variable to refer to the static information about the passed element.
+ * @param element
+ * @return the variable name
+ */
+ public String tagInfoVariableName(XMLElement element)
+ {
+ return tagInfoVar(element);
+ }
+
+ /**
+ * Return the name of a unique variable to refer to the static information about the passed element.
+ * @param element
+ * @return the variable name
+ */
+ public String tagInfoVar(XMLElement element)
+ {
+ return tagVariableSuffix(element);
+ }
+
+ /**
+ * Create a unique suffix of all variables that refer to the passed element
+ * @param element an XML Element
+ * @return the tag variable name
+ */
+ private String tagVariableSuffix(XMLElement element)
+ {
+ return element.getNSPrefix() + UNDERSCORE + element.getTagNCName() + UNDERSCORE + element.getLine() + UNDERSCORE
+ + element.getColumn();
+ }
+
+ public String textVar(int i) {
+ return textPrefix + i;
+ }
+
+ public boolean requiresOwnWriter(XMLElement element) {
+ return element.getTagDefinition().requiresNewWriter();
+ }
+
+ public String parentTagVar(XMLElement element) {
+ XMLElement parentXMLElement = null;
+ for(JETASTElement astParent = element.getParent(); astParent != null; astParent = astParent.getParent())
+ {
+ if(astParent instanceof XMLElement) {
+ parentXMLElement = (XMLElement)astParent;
+ break;
+ }
+ }
+ return parentXMLElement == null ? "null" : tagVar(parentXMLElement); //$NON-NLS-1$
+ }
+
+ public String textExpr(TextElement text) {
+ return JavaUtil.asJavaQuoteStringWithNLRemoved(text.getText());
+ }
+
+ public String nlsComment(TextElement text) {
+ return JavaUtil.nlsCommentsForJavaQuoteStringWithNLRemoved(text.getText());
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java
deleted file mode 100644
index 58ef03b..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.compiler;
-
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.compiler.Problem;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-
-
-/**
- * A JET Parser delegate that handles XML Elements.
- */
-public class XMLElementDelegate implements JETCoreElement
-{
-
- private static final String XML_TAG_CLOSE = ">"; //$NON-NLS-1$
-
- private static final String SLASH = "/"; //$NON-NLS-1$
-
- private static final String XML_CLOSE_TAG_OPEN = "</"; //$NON-NLS-1$
-
- private static final String XML_TAG_OPEN = "<"; //$NON-NLS-1$
-
- public XMLElementDelegate()
- {
- super();
- }
-
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- if (!(listener instanceof JETParseEventListener2))
- {
- return false;
- }
- JETParseEventListener2 jet2Listener = (JETParseEventListener2)listener;
-
- String elementOpen = XML_TAG_OPEN;
- if (!reader.matches(elementOpen))
- {
- return false;
- }
- JETMark start = reader.mark();
- reader.advance(elementOpen.length());
-
- boolean isEndTag = false;
- boolean isEmptyTag = false;
- if (reader.matches(SLASH))
- {
- isEndTag = true;
- reader.advance(1);
- elementOpen = XML_CLOSE_TAG_OPEN;
- }
-
- String tagName = reader.parseToken(false, false /*don't skip spaces*/);
-
- boolean knownInvalidTagName = jet2Listener.isKnownInvalidTagName(tagName);
- if (!jet2Listener.isKnownTag(tagName) && !knownInvalidTagName)
- {
- reader.reset(start);
- return false;
- }
-
- JETMark interiorStartMark = reader.mark();
- // check for the end position...
- JETMark endTagMark = reader.skipUntil(XML_TAG_CLOSE);
- if (endTagMark == null)
- {
- CompilerErrorUtil.recordUnterminatedElement(jet2Listener, XML_TAG_CLOSE, start, reader);
- return true;
- }
-
- // now reset to the tag interior for detailed parsing...
- reader.reset(interiorStartMark);
-
- Map attributeMap = Collections.EMPTY_MAP;
- if (isEndTag)
- {
- reader.skipSpaces();
- }
- else
- {
- // use Linked hash map to keep attributes in order of declaration
- attributeMap = new LinkedHashMap();
- reader.skipSpaces();
- while (reader.peekChar() != '>' && reader.peekChar() != '/')
- {
- JETMark[] attrMarks = reader.parseXmlAttribute();
- String name = new String(reader.getChars(attrMarks[0], attrMarks[1]));
- String value = new String(reader.getChars(attrMarks[3], attrMarks[4]));
- if (attributeMap.containsKey(name))
- {
- String msg = JET2Messages.XMLElementDelegate_DuplicateAttribute;
- jet2Listener.recordProblem(
- ParseProblemSeverity.ERROR,
- Problem.DuplicateAttribute,
- msg,
- null,
- attrMarks[0].getCursor(),
- attrMarks[4].getCursor(),
- attrMarks[0].getLine(), attrMarks[0].getCol());
- }
- else
- {
- attributeMap.put(name, value.substring(1, value.length() - 1));
- }
- reader.skipSpaces();
- }
- // attributeMap = reader.parseTagAttributes();
- }
- // find the closing char...
- if (reader.peekChar() == '/' && !isEndTag)
- {
- reader.nextChar();
- isEmptyTag = true;
- }
- if (reader.peekChar() != '>')
- {
- CompilerErrorUtil.recordUnterminatedElement(jet2Listener, ">", start, reader); //$NON-NLS-1$
- }
- reader.nextChar();
- JETMark stop = reader.mark();
- if(knownInvalidTagName)
- {
- jet2Listener.recordProblem(
- ParseProblemSeverity.WARNING,
- Problem.UnknownXMLTag,
- JET2Messages.XMLElementDelegate_UnknownXMLTag,
- new Object[] {tagName},
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
- reader.reset(start);
- return false;
- }
- else if (isEmptyTag)
- {
- jet2Listener.handleXMLEmptyTag(tagName, start, stop, attributeMap);
- }
- else if (isEndTag)
- {
- jet2Listener.handleXMLEndTag(tagName, start, stop);
- }
- else
- {
- jet2Listener.handleXMLStartTag(tagName, start, stop, attributeMap);
- }
- return true;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
index e6c9044..a2cd96b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
@@ -64,13 +64,15 @@ public class CodeGenTemplateLoader implements JET2TemplateLoader, JET2TemplateLo
}
private void initPathToFactoryMap() {
- pathToFactoryMap = new HashMap(8);
+ pathToFactoryMap = new HashMap(10);
addTemplate("templates/writeJavaExpression.jet", "org.eclipse.jet.internal.compiler.templates.WriteJavaExpressionTemplate" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/xmlStart.jet", "org.eclipse.jet.internal.compiler.templates.XMLStartGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/main.jet", "org.eclipse.jet.internal.compiler.templates.DummyMain" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/jet2transform.jet", "org.eclipse.jet.internal.compiler.templates.JET2TransformGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/xmlEnd.jet", "org.eclipse.jet.internal.compiler.templates.XMLEndGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
+ addTemplate("templates/v1/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.v1.JET1JavaGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
+ addTemplate("templates/v2/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.v2.JET2JavaGeneratorNew" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/tagDataDeclarations.jet", "org.eclipse.jet.internal.compiler.templates.TagDataDeclGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
addTemplate("templates/writeTextElement.jet", "org.eclipse.jet.internal.compiler.templates.WriteTextElementTemplate" ); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java
new file mode 100644
index 0000000..fa4244a
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java
@@ -0,0 +1,91 @@
+package org.eclipse.jet.internal.compiler.templates.v1;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.core.parser.ast.*;
+import org.eclipse.jet.internal.compiler.SafeJETASTVisitor;
+import java.util.Iterator;
+import org.eclipse.jet.internal.JavaUtil;
+
+public class JET1JavaGenerator implements JET2Template {
+
+ public JET1JavaGenerator() {
+ super();
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+
+ JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
+ out.write( "package " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaPackage() );
+ out.write( ";\r\n\r\n" ); //$NON-NLS-1$
+ for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ String importName = (String)i.next(); out.write( "import " ); //$NON-NLS-1$
+ out.write(importName);
+ out.write( ";\r\n" ); //$NON-NLS-1$
+ } out.write( "\r\npublic class " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( "\r\n{\r\n" ); //$NON-NLS-1$
+ cu.accept(new SafeJETASTVisitor(context,out) {
+ public boolean visit(JavaDeclaration decl) {
+ out.write( "\t" ); //$NON-NLS-1$
+ out.write( decl.getJavaContent() );
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ });
+ out.write( " protected static String nl;\r\n public static synchronized " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( " create(String lineSeparator)\r\n {\r\n nl = lineSeparator;\r\n " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( " result = new " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( "();\r\n nl = null;\r\n return result;\r\n }\r\n\r\n protected final String NL = nl == null ? (System.getProperties().getProperty(\"line.separator\")) : nl;\r\n" ); //$NON-NLS-1$
+ cu.accept(new SafeJETASTVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ textCount++;
+ out.write( " protected final String TEXT_" ); //$NON-NLS-1$
+ out.write(textCount);
+ out.write( " = " ); //$NON-NLS-1$
+ out.write(JavaUtil.asJavaQuoteStringWithNLRemoved(text.getText()));
+ out.write( ";" ); //$NON-NLS-1$
+ out.write(JavaUtil.nlsCommentsForJavaQuoteStringWithNLRemoved(text.getText()));
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ });
+ out.write( "\r\n public String generate(Object argument)\r\n {\r\n final StringBuffer stringBuffer = new StringBuffer();\r\n" ); //$NON-NLS-1$
+ cu.accept(new SafeJETASTVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ textCount++;
+ out.write( " stringBuffer.append(TEXT_" ); //$NON-NLS-1$
+ out.write(textCount);
+ out.write( ");\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ public boolean visit(JavaScriptlet scriptlet) {
+ out.write( " " ); //$NON-NLS-1$
+ out.write( scriptlet.getJavaContent() );
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ public boolean visit(JavaExpression expr) {
+ out.write( " stringBuffer.append(" ); //$NON-NLS-1$
+ out.write( expr.getJavaContent() );
+ out.write( ");\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ });
+ out.write( " return stringBuffer.toString();\r\n }\r\n}\r\n" ); //$NON-NLS-1$
+
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java
new file mode 100644
index 0000000..2c65349
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java
@@ -0,0 +1,206 @@
+package org.eclipse.jet.internal.compiler.templates.v2;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.core.parser.ast.*;
+import org.eclipse.jet.internal.compiler.V2CodeGenVisitor;
+import org.eclipse.jet.internal.compiler.TagUsageVisitor;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import java.util.Iterator;
+import org.eclipse.jet.internal.JavaUtil;
+
+public class JET2JavaGeneratorNew implements JET2Template {
+
+ public JET2JavaGeneratorNew() {
+ super();
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+
+ JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
+ TagUsageVisitor tuv = new TagUsageVisitor();
+ cu.accept(tuv);
+ TagLibraryReference[] tlrefs = tuv.getUsedTagLibraryReferences(cu);
+ out.write( "package " ); //$NON-NLS-1$
+ 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" ); //$NON-NLS-1$
+ if(tuv.hasTags()) { out.write( "import org.eclipse.jet.taglib.RuntimeTagElement;\r\nimport org.eclipse.jet.taglib.TagInfo;\r\n" ); //$NON-NLS-1$
+ } for(Iterator i=cu.getImports().iterator();i.hasNext();) { out.write( "import " ); //$NON-NLS-1$
+ out.write( (String)i.next() );
+ out.write( ";\r\n" ); //$NON-NLS-1$
+ } out.write( "\r\npublic class " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( " implements JET2Template {\r\n" ); //$NON-NLS-1$
+ for(int i = 0; i < tlrefs.length; i++ ) { out.write( " private static final String _jetns_" ); //$NON-NLS-1$
+ out.write( tlrefs[i].getPrefix() );
+ out.write( " = \"" ); //$NON-NLS-1$
+ out.write( tlrefs[i].getTagLibraryId() );
+ out.write( "\"; //$NON-NLS-1$\r\n" ); //$NON-NLS-1$
+ } out.write( "\r\n" ); //$NON-NLS-1$
+ cu.accept(new V2CodeGenVisitor(context,out) {
+ public boolean visit(JavaDeclaration decl) {
+ out.write( "\t" ); //$NON-NLS-1$
+ out.write( decl.getJavaContent() );
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ });
+ out.write( "\tpublic " ); //$NON-NLS-1$
+ out.write( cu.getOutputJavaClassName() );
+ out.write( "() {\r\n\t\tsuper();\r\n\t}\r\n\r\n private static final String NL = System.getProperties().getProperty(\"line.separator\");\r\n \r\n private static final class _TEXT {\r\n" ); //$NON-NLS-1$
+ cu.accept(new V2CodeGenVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ if(text.getText().length > 0) {
+ out.write( " private static final String " ); //$NON-NLS-1$
+ out.write( textVar(++textCount) );
+ out.write( " = " ); //$NON-NLS-1$
+ out.write(textExpr(text));
+ out.write( ";" ); //$NON-NLS-1$
+ out.write(nlsComment(text));
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ }
+ return true;
+ }
+ });
+ out.write( " }\r\n\r\n" ); //$NON-NLS-1$
+ if(tuv.hasTags()) { out.write( " private static final class _TAGS {\r\n" ); //$NON-NLS-1$
+ cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
+ public boolean visit(XMLBodyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public boolean visit(XMLEmptyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public void doElementVisit(XMLElement e) {
+ out.write( " private static final TagInfo " ); //$NON-NLS-1$
+ out.write( tagInfoVar(e) );
+ out.write( " = new TagInfo(\"" ); //$NON-NLS-1$
+ out.write(e.getName());
+ out.write( "\", //$NON-NLS-1$\r\n " ); //$NON-NLS-1$
+ out.write( e.getLine() );
+ out.write( ", " ); //$NON-NLS-1$
+ out.write( e.getColumn() );
+ out.write( ",\r\n new String[] {\r\n" ); //$NON-NLS-1$
+ for (Iterator i = e.getAttributes().keySet().iterator(); i.hasNext();) { out.write( " \"" ); //$NON-NLS-1$
+ out.write( (String) i.next() );
+ out.write( "\", //$NON-NLS-1$\r\n" ); //$NON-NLS-1$
+ } out.write( " },\r\n new String[] {\r\n" ); //$NON-NLS-1$
+ for (Iterator i = e.getAttributes().values().iterator(); i.hasNext();) {
+ String attrValue = (String) i.next(); out.write( " \"" ); //$NON-NLS-1$
+ out.write( JavaUtil.escapeJavaString(attrValue.toCharArray()) );
+ out.write( "\", //$NON-NLS-1$\r\n" ); //$NON-NLS-1$
+ } out.write( " } );\r\n" ); //$NON-NLS-1$
+ }
+ }); out.write( " }\r\n" ); //$NON-NLS-1$
+ } out.write( "\r\n\tpublic void generate(final JET2Context context, JET2Writer out) {\r\n" ); //$NON-NLS-1$
+ cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ if(text.getText().length > 0) {
+ out.write( " out.write(_TEXT." ); //$NON-NLS-1$
+ out.write(textVar(++textCount));
+ out.write( ");\r\n" ); //$NON-NLS-1$
+
+ }
+ return true;
+ }
+ public boolean visit(JavaScriptlet scriptlet) {
+ out.write( " " ); //$NON-NLS-1$
+ out.write( scriptlet.getJavaContent() );
+ out.write( "\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ public boolean visit(JavaExpression expr) {
+ out.write( " out.write(" ); //$NON-NLS-1$
+ out.write( expr.getJavaContent() );
+ out.write( ");\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ public boolean visit(XMLBodyElement e) {
+ out.write( " RuntimeTagElement " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( " = context.getTagFactory().createRuntimeTag(_jetns_" ); //$NON-NLS-1$
+ out.write( e.getNSPrefix() );
+ out.write( ", \"" ); //$NON-NLS-1$
+ out.write( e.getTagNCName() );
+ out.write( "\", \"" ); //$NON-NLS-1$
+ out.write( e.getName() );
+ out.write( "\", _TAGS." ); //$NON-NLS-1$
+ out.write( tagInfoVar(e) );
+ out.write( "); //$NON-NLS-1$ //$NON-NLS-2$\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".setRuntimeParent(" ); //$NON-NLS-1$
+ out.write( parentTagVar(e) );
+ out.write( ");\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".setTagInfo(_TAGS." ); //$NON-NLS-1$
+ out.write( tagInfoVar(e) );
+ out.write( ");\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".doStart(context, out);\r\n" ); //$NON-NLS-1$
+ if(requiresOwnWriter(e)) { out.write( " JET2Writer " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( "_saved_out = out;\r\n" ); //$NON-NLS-1$
+ } out.write( " while (" ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".okToProcessBody()) {\r\n" ); //$NON-NLS-1$
+ if(requiresOwnWriter(e)) { out.write( " out = out.newNestedContentWriter();\r\n" ); //$NON-NLS-1$
+ }
+ in();
+ return true;
+ }
+ public void endVisit(XMLBodyElement e) {
+ out();
+ out.write( " " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".handleBodyContent(out);\r\n }\r\n" ); //$NON-NLS-1$
+ if(requiresOwnWriter(e)) { out.write( " out = " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( "_saved_out;\r\n" ); //$NON-NLS-1$
+ } out.write( " " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".doEnd();\r\n" ); //$NON-NLS-1$
+
+
+ }
+ public boolean visit(XMLEmptyElement e) {
+ out.write( " RuntimeTagElement " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( " = context.getTagFactory().createRuntimeTag(_jetns_" ); //$NON-NLS-1$
+ out.write( e.getNSPrefix() );
+ out.write( ", \"" ); //$NON-NLS-1$
+ out.write( e.getTagNCName() );
+ out.write( "\", \"" ); //$NON-NLS-1$
+ out.write( e.getName() );
+ out.write( "\", _TAGS." ); //$NON-NLS-1$
+ out.write( tagInfoVar(e) );
+ out.write( "); //$NON-NLS-1$ //$NON-NLS-2$\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".setRuntimeParent(" ); //$NON-NLS-1$
+ out.write( parentTagVar(e) );
+ out.write( ");\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".setTagInfo(_TAGS." ); //$NON-NLS-1$
+ out.write( tagInfoVar(e) );
+ out.write( ");\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".doStart(context, out);\r\n " ); //$NON-NLS-1$
+ out.write( tagVar(e) );
+ out.write( ".doEnd();\r\n" ); //$NON-NLS-1$
+
+ return true;
+ }
+ });
+ out.write( " }\r\n}\r\n" ); //$NON-NLS-1$
+
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TagLibraryImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TagLibraryImpl.java
index 9169cde..7785e20 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TagLibraryImpl.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TagLibraryImpl.java
@@ -22,8 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagLibrary;
@@ -125,19 +123,6 @@ public class TagLibraryImpl implements TagLibrary
return deprecated;
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.TagLibrary#newTagElement(java.lang.String)
- */
- public CustomTag newTagElement(String tagNCName) throws CoreException
- {
- TagDefinition td = getTagDefinition(tagNCName);
- if (td == null)
- {
- throw new IllegalArgumentException();
- }
- return td.newTagElement();
- }
-
public void addTag(TagDefinition tagDefinition)
{
tagDefintionsByNCName.put(tagDefinition.getName(), tagDefinition);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
index 0d578df..2e6b40e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
@@ -67,6 +67,8 @@ public class JET2Messages extends NLS
public static String JET2Compiler_TagShouldBeEmptyFormat;
+ public static String JET2Context_ExecutionCancelled;
+
public static String JET2Context_InvalidVariableName;
public static String JETStreamMonitor_Debug;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
index 60a35cc..ab32b91 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
@@ -33,6 +33,7 @@ JET2Context_SuccessfulWithWarnings=Successful execution with warnings
JET2Bundle_ErrorOpeningJar=Error opening bundle JAR: {0}
JET2Bundle_CouldNotLoadLoader=Could not load JET template loader
JET2Context_ErrorsInExecution=Errors occurred during execution
+JET2Context_ExecutionCancelled=Execution cancelled
JET2Context_CommittingActions=Committing actions
JET2Compiler_ErrorWritingJava=Error writing transformation loader Java class
JET2Compiler_UnknownTagLibrary=Unknown tag library id {0}.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETProcess.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETProcess.java
index fb8b5c1..fc46445 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETProcess.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETProcess.java
@@ -32,7 +32,6 @@ import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamsProxy;
-import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Platform;
@@ -171,8 +170,8 @@ public class JETProcess extends PlatformObject implements IProcess
}
catch (CoreJETException e)
{
- status = BasicDiagnostic.toIStatus(e.getDiagnostic());
- context.logError(status.getMessage());
+ status = new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
+ context.logError(e.getLocalizedMessage());
}
terminated = true;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamMonitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamMonitor.java
index df2fcc8..fd1ce98 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamMonitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamMonitor.java
@@ -41,7 +41,7 @@ public class JETStreamMonitor implements IStreamMonitor, RuntimeTagLogger
public JETStreamMonitor(JET2Context context, int msgLevel)
{
- new RuntimeLoggerContextExtender(context).addListener(this);
+ RuntimeLoggerContextExtender.getInstance(context).addListener(this);
this.msgLevel = msgLevel;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamsProxy.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamsProxy.java
index 13d6004..63b22df 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamsProxy.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JETStreamsProxy.java
@@ -47,6 +47,7 @@ public class JETStreamsProxy implements IStreamsProxy
public JETStreamsProxy(JET2Context context, int levelFilter)
{
super();
+ RuntimeLoggerContextExtender.install(context);
this.outputStreamMonitor = createLogger(context, RuntimeLoggerContextExtender.INFO_LEVEL, levelFilter);
this.errorStreamMonitor = createLogger(context, RuntimeLoggerContextExtender.ERROR_LEVEL, levelFilter);
this.warningStreamMonitor = createLogger(context, RuntimeLoggerContextExtender.WARNING_LEVEL, levelFilter);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETCoreElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETCoreElement.java
deleted file mode 100644
index 16ea08d..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETCoreElement.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2002, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.parser;
-
-
-import org.eclipse.emf.codegen.jet.JETException;
-
-
-/**
- * The core elements we recognize;
- * these are stateless abstractions that represent the parsing action for a core tag.
- */
-public interface JETCoreElement
-{
- /**
- * Return true if the input contained the sequence that matched
- * the action corresponding to this core tag.
- */
- boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException;
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETMark.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETMark.java
deleted file mode 100644
index 5a100b5..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETMark.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2002, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.parser;
-
-
-import java.util.Stack;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.codegen.CodeGenPlugin;
-
-
-/**
- * A mark represents a point in the JET input.
- */
-public final class JETMark
-{
-
- /**
- * This is the character offset.
- */
- protected int cursor;
-
- /**
- * This is the id of the file.
- */
- protected int fileid;
-
- /**
- * This is the base URI for relative paths.
- */
- protected String baseDir;
-
- /**
- * This is the stream of characters.
- */
- protected char[] stream = null;
-
- /**
- * This is an array of lines descriptors.
- */
- protected LineInfo[] lineInfo = null;
-
- /**
- * This is the stack of inclusions.
- */
- protected Stack includeStack = null;
-
- /**
- * This is the encoding of the stream.
- */
- protected String encoding = null;
-
- /**
- * This is the reader that owns this mark.
- */
- protected JETReader reader;
-
- /**
- * Keep track of parser before parsing an included file.
- * This class keeps track of the parser before we switch to parsing an
- * included file. In other words, it's the parser's continuation to be
- * reinstalled after the included file parsing is done.
- */
- class IncludeState
- {
- int cursor;
-
- int fileid;
-
- String baseDir;
-
- String encoding;
-
- char[] stream = null;
-
- private final LineInfo[] lineInfo;
-
- IncludeState(int inCursor, LineInfo[] inLineInfo, int inFileid, String inBaseDir, String inEncoding, char[] inStream)
- {
- cursor = inCursor;
- lineInfo = inLineInfo;
- fileid = inFileid;
- baseDir = inBaseDir;
- encoding = inEncoding;
- stream = inStream;
- }
- }
-
- /**
- * Creates a new mark
- * @param reader JETReader this mark belongs to
- * @param inStream current stream for this mark
- * @param fileid id of requested jet file
- * @param inEncoding encoding of current file
- * @param inBaseDir base directory of requested jet file
- */
- JETMark(JETReader reader, char[] inStream, int fileid, String inBaseDir, String inEncoding)
- {
- this.reader = reader;
- this.stream = inStream;
- this.cursor = 0;
- this.lineInfo = LineInfo.calculateLines(inStream);
- this.fileid = fileid;
- this.baseDir = inBaseDir;
- this.encoding = inEncoding;
- this.includeStack = new Stack();
- }
-
- JETMark(JETMark other)
- {
- this.reader = other.reader;
- this.stream = other.stream;
- this.fileid = other.fileid;
- this.cursor = other.cursor;
- this.lineInfo = other.lineInfo;
- this.baseDir = other.baseDir;
- this.encoding = other.encoding;
-
- // clone includeStack without cloning contents
- //
- includeStack = new Stack();
- for (int i = 0; i < other.includeStack.size(); ++i)
- {
- includeStack.addElement(other.includeStack.elementAt(i));
- }
- }
-
- /**
- * Sets this mark's state to a new stream.
- * It will store the current stream in it's includeStack.
- * @param inStream new stream for mark
- * @param inFileid id of new file from which stream comes from
- * @param inBaseDir directory of file
- * @param inEncoding encoding of new file
- */
- public void pushStream(char[] inStream, int inFileid, String inBaseDir, String inEncoding)
- {
- // Store the current state in stack.
- //
- includeStack.push(new IncludeState(cursor, lineInfo, fileid, baseDir, encoding, stream));
-
- // Set the new variables.
- //
- cursor = 0;
- fileid = inFileid;
- baseDir = inBaseDir;
- encoding = inEncoding;
- stream = inStream;
- lineInfo = LineInfo.calculateLines(inStream);
- }
-
- /**
- * Restores this mark's state to a previously stored stream.
- */
- public boolean popStream()
- {
- // Make sure we have something to pop.
- //
- if (includeStack.size() <= 0)
- {
- return false;
- }
-
- // Get previous state in stack.
- //
- IncludeState state = (IncludeState)includeStack.pop();
-
- // Set the new variables.
- //
- cursor = state.cursor;
- lineInfo = state.lineInfo;
- fileid = state.fileid;
- baseDir = state.baseDir;
- stream = state.stream;
- return true;
- }
-
- public String getFile()
- {
- return reader.getFile(fileid);
- }
-
- public String getBaseURI()
- {
- return reader.getBaseURI(fileid);
- }
-
- public String getLocalFile()
- {
- String file = reader.getFile(fileid);
- if (file.startsWith("file:/")) //$NON-NLS-1$
- {
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- IFile iFile = workspaceRoot.getFileForLocation(new Path(file.substring(6)));
- file = iFile.getFullPath().toString();
- }
-
- return file;
- }
-
- public int getFileId()
- {
- return fileid;
- }
-
- public int getCursor()
- {
- return cursor;
- }
-
- public String toShortString()
- {
- return "(" + getLine() + "," + getCol() + ")"; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
- }
-
- public String toString()
- {
- return getLocalFile() + "(" + getLine() + "," + getCol() + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public String format(String key)
- {
- return CodeGenPlugin.getPlugin().getString(
- key,
- new Object []{ getLocalFile(), new Integer(getLine() + 1), new Integer(getCol() + 1), new Integer(cursor) });
- }
-
- public boolean equals(Object other)
- {
- if (other instanceof JETMark)
- {
- JETMark m = (JETMark)other;
- return this.reader == m.reader && this.fileid == m.fileid && this.cursor == m.cursor && this.getLine() == m.getLine() && this.getCol() == m.getCol();
- }
- return false;
- }
-
- /**
- * Return the one-based line number of the cursor.
- * @return Returns the line.
- */
- public int getLine()
- {
- return LineInfo.getLineNo(lineInfo, cursor);
- }
-
- /**
- * Return the one-based column number of the cursor.
- * @return the one based column number of the cursor.
- */
- public int getCol()
- {
- int lineIndex = getLine() - 1;
- if(lineIndex < lineInfo.length) {
- return cursor - lineInfo[lineIndex].getStart() + 1;
- } else {
- return cursor - (lineInfo[lineInfo.length - 1].getEnd() + lineInfo[lineInfo.length - 1].getDelimiter().length()) + 1;
- }
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener.java
deleted file mode 100644
index 9c45dd2..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2002, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.parser;
-
-
-import java.util.Map;
-
-import org.eclipse.emf.codegen.jet.JETException;
-
-
-/**
- * The interface for the JET code generation backend.
- */
-public interface JETParseEventListener
-{
- void beginPageProcessing() throws JETException;
-
- void handleDirective(String directive, JETMark start, JETMark stop, Map attributes) throws JETException;
-
- void handleExpression(JETMark start, JETMark stop, Map attributes) throws JETException;
-
- void handleCharData(char[] chars) throws JETException;
-
- void endPageProcessing() throws JETException;
-
- void handleScriptlet(JETMark start, JETMark stop, Map attributes) throws JETException;
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java
deleted file mode 100644
index 469a112..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.eclipse.jet.internal.parser;
-
-
-import java.util.Map;
-
-import org.eclipse.emf.codegen.jet.JETException;
-
-
-public interface JETParseEventListener2 extends JETParseEventListener
-{
-
- void handleComment(JETMark start, JETMark stop) throws JETException;
-
- void handleDeclaration(JETMark start, JETMark stop) throws JETException;
-
- void handleXMLEndTag(String tagName, JETMark start, JETMark stop) throws JETException;
-
- void handleXMLEmptyTag(String tagName, JETMark start, JETMark stop, Map attributeMap) throws JETException;
-
- void handleXMLStartTag(String tagName, JETMark start, JETMark stop, Map attributeMap) throws JETException;
-
- // void handleText(JETMark start, JETMark end);
-
- boolean isKnownTag(String tagName);
-
- boolean isKnownInvalidTagName(String tagName);
- /**
- * Record a parsing problem.
- * @param severity
- * @param problemId
- * @param message
- * @param msgArgs
- * @param start
- * @param end
- * @param line
- * @param colOffset TODO
- */
- void recordProblem(ParseProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line, int colOffset);
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java
deleted file mode 100644
index 7be9a5d..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java
+++ /dev/null
@@ -1,631 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2002, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-package org.eclipse.jet.internal.parser;
-
-
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.codegen.CodeGenPlugin;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.internal.compiler.CompilerErrorUtil;
-
-
-/**
- * This class and all those in this package is work derived from contributions of multiple authors as listed below.
- * Credit for all that is good is shared, responsibility for any problems lies solely with the latest authors.
- *
- * @author Anil K. Vijendran
- * @author Anselm Baird-Smith
- * @author David Charboneau
- * @author Harish Prabandham
- * @author Kevin Bauer
- * @author Mandar Raje
- * @author Paul R. Hoffman
- * @author Rajiv Mordani
- */
-public class JETParser
-{
- public interface Action
- {
- void execute() throws JETException;
- }
-
- public static class DelegatingListener implements JETParseEventListener2
- {
- protected JETParseEventListener delegate;
-
- protected JETParser.Action action;
-
- public DelegatingListener(JETParseEventListener delegate, JETParser.Action action)
- {
- this.delegate = delegate;
- this.action = action;
- }
-
- public void doAction() throws JETException
- {
- action.execute();
- }
-
- public void beginPageProcessing() throws JETException
- {
- delegate.beginPageProcessing();
- }
-
- public void endPageProcessing() throws JETException
- {
- delegate.endPageProcessing();
- }
-
- public void handleDirective(String directive, JETMark start, JETMark stop, Map attrs) throws JETException
- {
- doAction();
- delegate.handleDirective(directive, start, stop, attrs);
- }
-
- public void handleScriptlet(JETMark start, JETMark stop, Map attrs) throws JETException
- {
- doAction();
- delegate.handleScriptlet(start, stop, attrs);
- }
-
- public void handleExpression(JETMark start, JETMark stop, Map attrs) throws JETException
- {
- doAction();
- delegate.handleExpression(start, stop, attrs);
- }
-
- public void handleCharData(char[] chars) throws JETException
- {
- delegate.handleCharData(chars);
- }
-
- public void handleComment(JETMark start, JETMark stop) throws JETException
- {
- doAction();
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).handleComment(start, stop);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public void handleDeclaration(JETMark start, JETMark stop) throws JETException
- {
- doAction();
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).handleDeclaration(start, stop);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public void handleXMLEndTag(String tagName, JETMark start, JETMark stop) throws JETException
- {
- doAction();
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).handleXMLEndTag(tagName, start, stop);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public void handleXMLEmptyTag(String tagName, JETMark start, JETMark stop, Map attributeMap) throws JETException
- {
- doAction();
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).handleXMLEmptyTag(tagName, start, stop, attributeMap);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public void handleXMLStartTag(String tagName, JETMark start, JETMark stop, Map attributeMap) throws JETException
- {
- doAction();
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).handleXMLStartTag(tagName, start, stop, attributeMap);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public boolean isKnownTag(String tagName)
- {
- if (delegate instanceof JETParseEventListener2)
- {
- return ((JETParseEventListener2)delegate).isKnownTag(tagName);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public void recordProblem(ParseProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line, int colOffset)
- {
- if (delegate instanceof JETParseEventListener2)
- {
- ((JETParseEventListener2)delegate).recordProblem(severity, problemId, message, msgArgs, start, end, line, colOffset);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
-
- public boolean isKnownInvalidTagName(String tagName)
- {
- if (delegate instanceof JETParseEventListener2)
- {
- return ((JETParseEventListener2)delegate).isKnownInvalidTagName(tagName);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
- }
-
- /**
- * The input source we read from...
- */
- protected JETReader reader;
-
- /**
- * The backend that is notified of constructs recognized in the input...
- */
- protected JETParseEventListener listener;
-
- /*
- * Char buffer for HTML data
- */
- protected CharArrayWriter writer;
-
- protected List coreElements = new ArrayList();
-
- protected String openDirective = "<%@"; //$NON-NLS-1$
-
- protected String closeDirective = "%>"; //$NON-NLS-1$
-
- protected String openScriptlet = "<%"; //$NON-NLS-1$
-
- protected String closeScriptlet = "%>"; //$NON-NLS-1$
-
- protected String openExpr = "<%="; //$NON-NLS-1$
-
- protected String closeExpr = "%>"; //$NON-NLS-1$
-
- protected String quotedStartTag = "<\\%"; //$NON-NLS-1$
-
- protected String quotedEndTag = "%\\>"; //$NON-NLS-1$
-
- protected String startTag = "<%"; //$NON-NLS-1$
-
- protected String endTag = "%>"; //$NON-NLS-1$
-
- public JETParser(JETReader reader, final JETParseEventListener parseEventListener, JETCoreElement[] coreElements)
- {
- this.reader = reader;
- this.listener = new DelegatingListener(parseEventListener, new Action()
- {
- public void execute() throws JETException
- {
- JETParser.this.flushCharData();
- }
- });
-
- this.writer = new CharArrayWriter();
-
- for (int i = 0; i < coreElements.length; i++)
- {
- this.coreElements.add(coreElements[i]);
- }
- }
-
- public JETReader getReader()
- {
- return reader;
- }
-
- public void setStartTag(String tag)
- {
- openScriptlet = tag;
- openExpr = tag + "="; //$NON-NLS-1$
- openDirective = tag + "@"; //$NON-NLS-1$
- quotedStartTag = tag.charAt(0) + "\\" + tag.charAt(1); //$NON-NLS-1$
- startTag = tag;
- reader.setStartTag(tag);
- }
-
- public void setEndTag(String tag)
- {
- closeScriptlet = tag;
- closeExpr = tag;
- closeDirective = tag;
- quotedEndTag = tag.charAt(0) + "\\" + tag.charAt(1); //$NON-NLS-1$
- endTag = tag;
- reader.setEndTag(tag);
- }
-
- public String getOpenScriptlet()
- {
- return openScriptlet;
- }
-
- public String getCloseScriptlet()
- {
- return closeScriptlet;
- }
-
- public String getOpenExpr()
- {
- return openExpr;
- }
-
- public String getCloseExpr()
- {
- return closeExpr;
- }
-
- public String getOpenDirective()
- {
- return openDirective;
- }
-
- public String getCloseDirective()
- {
- return closeDirective;
- }
-
- public String getQuotedStartTag()
- {
- return quotedStartTag;
- }
-
- public String getQuotedEndTag()
- {
- return quotedEndTag;
- }
-
- public String getStartTag()
- {
- return startTag;
- }
-
- public String getEndTag()
- {
- return endTag;
- }
-
- public static class Scriptlet implements JETCoreElement
- {
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- String close, open;
- Map attrs = null;
-
- if (reader.matches(parser.getOpenScriptlet()))
- {
- open = parser.getOpenScriptlet();
- close = parser.getCloseScriptlet();
- }
- else
- {
- return false;
- }
-
- reader.advance(open.length());
-
- JETMark start = reader.mark();
- JETMark stop = reader.skipUntil(close);
- if (stop == null)
- {
- throw new JETException(CompilerErrorUtil.getUnterminatedMessage(open, close, reader));
- }
- listener.handleScriptlet(start, stop, attrs);
- return true;
- }
- }
-
- public static class Expression implements JETCoreElement
- {
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- String close, open;
- Map attrs = null;
-
- if (reader.matches(parser.getOpenExpr()))
- {
- open = parser.getOpenExpr();
- close = parser.getCloseExpr();
- }
- else
- {
- return false;
- }
-
- reader.advance(open.length());
-
- JETMark start = reader.mark();
- JETMark stop = reader.skipUntil(close);
- if (stop == null)
- {
- throw new JETException(CompilerErrorUtil.getUnterminatedMessage(open, close, reader));
- }
- listener.handleExpression(start, stop, attrs);
- return true;
- }
- }
-
- /**
- * Quoting in template text.
- * Entities &apos; and &quote;
- */
- public static class QuoteEscape implements JETCoreElement
- {
- /**
- * constants for escapes
- */
- protected static final String APOS = "&apos;"; //$NON-NLS-1$
-
- protected static final String QUOTE = "&quote;"; //$NON-NLS-1$
-
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- try
- {
- if (reader.matches(parser.getQuotedEndTag()))
- {
- reader.advance(parser.getQuotedEndTag().length());
- parser.writer.write(parser.getEndTag());
- parser.flushCharData();
- return true;
- }
- else if (reader.matches(APOS))
- {
- reader.advance(APOS.length());
- parser.writer.write("\'"); //$NON-NLS-1$
- parser.flushCharData();
- return true;
- }
- else if (reader.matches(QUOTE))
- {
- reader.advance(QUOTE.length());
- parser.writer.write("\""); //$NON-NLS-1$
- parser.flushCharData();
- return true;
- }
- }
- catch (IOException exception)
- {
- throw new JETException(exception);
- }
- return false;
- }
- }
-
- public static class Directive implements JETCoreElement
- {
- protected Collection directives = new ArrayList();
-
- public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
- {
- if (reader.matches(parser.getOpenDirective()))
- {
- JETMark start = reader.mark();
- reader.advance(parser.getOpenDirective().length());
- reader.skipSpaces();
-
- // Check which directive it is.
- //
- String match = null;
-
- for (Iterator i = directives.iterator(); i.hasNext();)
- {
- String directive = (String)i.next();
- if (reader.matches(directive))
- {
- match = directive;
- break;
- }
- }
-
- if (match == null)
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.bad.directive", //$NON-NLS-1$
- new Object []{ start.format("jet.mark.file.line.column") })); //$NON-NLS-1$
- //reader.reset(start);
- //return false;
- }
-
- reader.advance(match.length());
-
- // Parse the attr-val pairs.
- //
- Map attrs = reader.parseTagAttributes();
-
- // Match close.
- reader.skipSpaces();
- if (!reader.matches(parser.getCloseDirective()))
- {
- throw new JETException(CompilerErrorUtil.getUnterminatedMessage(parser.getOpenDirective(),
- parser.getCloseDirective(), reader));
- }
- else
- {
- reader.advance(parser.getCloseDirective().length());
- }
-
- JETMark stop = reader.mark();
- listener.handleDirective(match, start, stop, attrs);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public Collection getDirectives()
- {
- return directives;
- }
- }
-
- protected void flushCharData() throws JETException
- {
- char[] array = writer.toCharArray();
- if (array.length != 0) // Avoid unnecessary out.write("") statements...
- {
- writer = new CharArrayWriter();
- listener.handleCharData(array);
- }
- }
-
- public void parse() throws JETException
- {
- parse(null);
- }
-
- public void parse(String until) throws JETException
- {
- parse(until, null);
- }
-
- public void parse(String until, Class[] accept) throws JETException
- {
- while (reader.hasMoreInput())
- {
- if (until != null && reader.matches(until))
- {
- return;
- }
-
- Iterator e = coreElements.iterator();
-
- if (accept != null)
- {
- List v = new ArrayList();
- while (e.hasNext())
- {
- JETCoreElement c = (JETCoreElement)e.next();
- for (int i = 0; i < accept.length; i++)
- {
- if (c.getClass().equals(accept[i]))
- {
- v.add(c);
- }
- }
- }
- e = v.iterator();
- }
-
- boolean accepted = false;
- while (e.hasNext())
- {
- JETCoreElement c = (JETCoreElement)e.next();
- reader.mark();
- if (c.accept(listener, reader, this))
- {
- accepted = true;
- break;
- }
- }
- if (!accepted)
- {
- String s = reader.nextContent();
- writer.write(s, 0, s.length());
- }
- }
- flushCharData();
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java
deleted file mode 100644
index a70cd95..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java
+++ /dev/null
@@ -1,766 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2002, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.parser;
-
-
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.eclipse.emf.codegen.CodeGenPlugin;
-import org.eclipse.emf.codegen.jet.JETException;
-
-
-/**
- * JETReader is an input buffer for the JSP parser. It should allow
- * unlimited lookahead and pushback. It also has a bunch of parsing
- * utility methods for understanding htmlesque thingies.
- */
-public class JETReader
-{
- private static final char XML_TAG_START = '<';
-
- protected char startTagInitialChar = '<';
-
- protected char endTagInitialChar = '%';
-
- protected char endTagFinalChar = '>';
-
- protected JETMark current = null;
-
- protected String master = null;
-
- protected List sourceFiles = new ArrayList();
-
- protected List baseURIs = new ArrayList();
-
- protected int size = 0;
-
- protected boolean trimExtraNewLine = true;
-
- public JETReader(String baseURI, String locationURI, InputStream inputStream, String encoding) throws JETException
- {
- stackStream(baseURI, locationURI, inputStream, encoding);
- }
-
- public JETReader(String locationURI, InputStream inputStream, String encoding) throws JETException
- {
- this(null, locationURI, inputStream, encoding);
- }
-
- public String getFile(int fileid)
- {
- return (String)sourceFiles.get(fileid);
- }
-
- public String getBaseURI(int fileid)
- {
- return (String)baseURIs.get(fileid);
- }
-
- public void stackStream(String locationURI, InputStream iStream, String encoding) throws JETException
- {
- stackStream(null, locationURI, iStream, encoding);
- }
-
- /**
- * Stack a stream for parsing
- * @param iStream Stream ready to parse
- * @param encoding Optional encoding to read the file.
- */
- public void stackStream(String baseURI, String locationURI, InputStream iStream, String encoding) throws JETException
- {
- InputStreamReader reader = null;
- try
- {
- // Until the encoding can be specified within the template
- // we need to assume an encoding capable of working with any character set.
- if (encoding == null)
- {
- encoding = "UTF8"; //$NON-NLS-1$
- }
-
- // Register the file, and read its content:
- //
- int fileid = registerSourceFile(locationURI);
- registerBaseURI(baseURI);
- reader = new InputStreamReader(iStream, encoding);
- CharArrayWriter writer = new CharArrayWriter();
- char buf[] = new char [1024];
- for (int i = 0; (i = reader.read(buf)) != -1;)
- {
- // Remove zero width non-breaking space, which may be used as a byte order marker,
- // and may be ignored according to the Unicode FAQ: http://www.unicode.org/unicode/faq/utf_bom.html#38
- //
- if (buf[0] == '\uFEFF')
- {
- writer.write(buf, 1, i - 1);
- }
- else
- {
- writer.write(buf, 0, i);
- }
- }
- writer.close();
- if (current == null)
- {
- current = new JETMark(this, writer.toCharArray(), fileid, locationURI, encoding);
- }
- else
- {
- current.pushStream(writer.toCharArray(), fileid, locationURI, encoding);
- }
- }
- catch (UnsupportedEncodingException exception)
- {
- throw new JETException(exception);
- }
- catch (IOException exception)
- {
- throw new JETException(exception);
- }
- finally
- {
- if (reader != null)
- {
- try
- {
- reader.close();
- }
- catch (Exception exception)
- {
- throw new JETException(exception);
- }
- }
- }
- }
-
- public boolean popFile()
- {
- // Is stack created ? (will happen if the JET file we're looking at is missing.
- //
- if (current == null)
- {
- return false;
- }
-
- // Restore parser state:
- //
- size--;
-
- return current.popStream();
- }
-
- /**
- * Register a new source file.
- * This method is used to implement file inclusion. Each included file
- * gets a uniq identifier (which is the index in the array of source files).
- * @return The index of the now registered file.
- */
- protected int registerSourceFile(String file)
- {
- sourceFiles.add(file);
- ++this.size;
- return sourceFiles.size() - 1;
- }
-
- /**
- * Register a new baseURI.
- * This method is used to implement file inclusion. Each included file
- * gets a uniq identifier (which is the index in the array of base URIs).
- * @return The index of the now registered file.
- */
- protected void registerBaseURI(String baseURI)
- {
- baseURIs.add(baseURI);
- }
-
- /**
- * Returns whether more input is available. If the end of the buffer for an included file is reached, it will return
- * to the context of the previous file, and return whether more input is available from there. In this case, if
- * trimExtraNewLine is true, then an unwanted extra newline character will be suppressed. We consider the first
- * newline in the buffer we are returning to be unwanted if the ending buffer already has at least one trailing
- * newline.
- */
- public boolean hasMoreInput()
- {
- if (current.cursor < current.stream.length)
- {
- return true;
- }
-
- boolean nl = hasTrailingNewLine();
- while (popFile())
- {
- if (current.cursor < current.stream.length)
- {
- if (trimExtraNewLine && nl)
- {
- skipNewLine();
- }
- return true;
- }
- }
- return false;
- }
-
- /**
- * Tests whether the current stream has at least one trailing newline, optionally followed by spaces.
- */
- protected boolean hasTrailingNewLine()
- {
- if(current.lineInfo != null && current.lineInfo.length > 0)
- {
- return current.lineInfo[current.lineInfo.length - 1].getDelimiter().length() > 0;
- } else
- {
- return false;
- }
- }
-
- /**
- * If the next character would be a line break, moves the cursor past it.
- */
- protected void skipNewLine()
- {
- LineInfo li = LineInfo.getLineInfo(current.lineInfo, current.cursor);
- if(current.cursor >= li.getEnd()) {
- current.cursor = li.getEnd() + li.getDelimiter().length();
- }
- }
-
- public int nextChar()
- {
- if (!hasMoreInput())
- {
- return -1;
- }
-
- int ch = current.stream[current.cursor];
-
- ++current.cursor;
-
- return ch;
- }
-
- /**
- * Gets Content until the next potential JSP element. Because all elements
- * begin with a '&lt;' we can just move until we see the next one.
- */
- public String nextContent()
- {
- int cur_cursor = current.cursor;
- int len = current.stream.length;
- if (cur_cursor == len)
- return ""; //$NON-NLS-1$
- // pure obsfuscated genius!
- while (++current.cursor < len && (current.stream[current.cursor]) != startTagInitialChar && current.stream[current.cursor] != XML_TAG_START)
- {
- // do nothing
- }
-
- return new String(current.stream, cur_cursor, current.cursor - cur_cursor);
- }
-
- public char[] getChars(JETMark start, JETMark stop)
- {
- JETMark oldstart = mark();
- reset(start);
- CharArrayWriter writer = new CharArrayWriter();
- while (!stop.equals(mark()))
- {
- writer.write(nextChar());
- }
- writer.close();
- reset(oldstart);
- return writer.toCharArray();
- }
-
- public int peekChar()
- {
- if (hasMoreInput())
- {
- return current.stream[current.cursor];
- }
- else
- {
- return -1;
- }
- }
-
- public JETMark mark()
- {
- return new JETMark(current);
- }
-
- public void reset(JETMark mark)
- {
- current = new JETMark(mark);
- }
-
- public boolean matchesIgnoreCase(String string)
- {
- JETMark mark = mark();
- int ch = 0;
- int i = 0;
- do
- {
- ch = nextChar();
- if (Character.toLowerCase((char)ch) != string.charAt(i++))
- {
- reset(mark);
- return false;
- }
- }
- while (i < string.length());
- reset(mark);
- return true;
- }
-
- public boolean matches(String string)
- {
- JETMark mark = mark();
- int ch = 0;
- int i = 0;
- do
- {
- ch = nextChar();
- if (((char)ch) != string.charAt(i++))
- {
- reset(mark);
- return false;
- }
- }
- while (i < string.length());
- reset(mark);
- return true;
- }
-
- public void advance(int n)
- {
- while (--n >= 0)
- nextChar();
- }
-
- public int skipSpaces()
- {
- int i = 0;
- while (isSpace())
- {
- ++i;
- nextChar();
- }
- return i;
- }
-
- /**
- * Skip until the given string is matched in the stream.
- * When returned, the context is positioned past the end of the match.
- * @param limit The String to match.
- * @return A non-null <code>JETMark</code> instance if found,
- * <strong>null</strong> otherwise.
- */
- public JETMark skipUntil(String limit)
- {
- JETMark ret = null;
- int limlen = limit.length();
- int ch;
-
- skip: for (ret = mark(), ch = nextChar(); ch != -1; ret = mark(), ch = nextChar())
- {
- if (ch == limit.charAt(0))
- {
- for (int i = 1; i < limlen; i++)
- {
- if (Character.toLowerCase((char)nextChar()) != limit.charAt(i))
- {
- continue skip;
- }
- }
- return ret;
- }
- }
- return null;
- }
-
- protected boolean isSpace()
- {
- int c = peekChar();
- return c <= ' ' && c >= 0;
- }
-
- /**
- * Parse a space delimited token.
- * If quoted the token will consume all characters up to a matching quote,
- * otherwise, it consumes up to the first delimiter character.
- * @param quoted If <strong>true</strong> accept quoted strings.
- */
- public String parseToken(boolean quoted) throws JETException
- {
- return parseToken(quoted, true /* skip spaces*/);
- }
-
- /**
- * Parse an attribute/value pair, and store it in provided hash table.
- * The attribute/value pair is defined by:
- * <pre>
- * av := spaces token spaces '=' spaces token spaces
- * </pre>
- * Where <em>token</em> is defined by <code>parseToken</code> and
- * <em>spaces</em> is defined by <code>skipSpaces</code>.
- * The name is always considered case insensitive, hence stored in its
- * lower case version.
- * @param into The HashMap instance to save the result to.
- */
- protected void parseAttributeValue(HashMap into) throws JETException
- {
- // Get the attribute name:
- //
- skipSpaces();
- String name = parseToken(false);
-
- // Check for an equal sign:
- //
- skipSpaces();
- if (peekChar() != '=')
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.attr.novalue", new Object []{ name, mark().toString() })); //$NON-NLS-1$
- }
- nextChar();
-
- // Get the attribute value:
- //
- skipSpaces();
- String value = parseToken(true);
- skipSpaces();
-
- // Add the binding to the provided hashtable:
- //
- into.put(name, value);
- }
-
- /**
- * Parse some tag attributes for Beans.
- * The stream is assumed to be positioned right after the tag name. The
- * syntax recognized is:
- * <pre>
- * tag-attrs := empty | attr-list ("&gt;" | "--&gt;" | %&gt;)
- * attr-list := empty | av spaces attr-list
- * empty := spaces
- * </pre>
- * Where <em>av</em> is defined by <code>parseAttributeValue</code>.
- * @return A HashMap mapping String instances (variable names) into
- * String instances (variable values).
- */
- public HashMap parseTagAttributesBean() throws JETException
- {
- HashMap values = new HashMap(11);
- while (true)
- {
- skipSpaces();
- int ch = peekChar();
- if (ch == endTagFinalChar)
- {
- // End of the useBean tag.
- //
- return values;
- }
- else if (ch == '/')
- {
- JETMark mark = mark();
- nextChar();
-
- // XMLesque Close tags
- //
- try
- {
- if (nextChar() == endTagFinalChar)
- {
- return values;
- }
- }
- finally
- {
- reset(mark);
- }
- }
- if (ch == -1)
- {
- break;
- }
-
- // Parse as an attribute=value:
- //
- parseAttributeValue(values);
- }
-
- // Reached EOF:
- //
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.tag.attr.unterminated", new Object []{ mark().toString() })); //$NON-NLS-1$
- }
-
- public JETMark[] parseXmlAttribute() throws JETException
- {
- JETMark[] attributeMarks = new JETMark [5];
-
- attributeMarks[0] = mark(); // start of name
- String name = parseToken(false, false);
- attributeMarks[1] = mark(); // end of name
-
- skipSpaces();
- if (peekChar() != '=')
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.param.novalue", new Object []{ name, mark().toString() })); //$NON-NLS-1$
- }
- attributeMarks[2] = mark(); // equals
- nextChar();
-
- // Get the attribute value:
- skipSpaces();
- attributeMarks[3] = mark(); // value start
- parseToken(true /* quoted token */, false);
- attributeMarks[4] = mark();
-
- return attributeMarks;
- }
-
- /**
- * Parse some tag attributes. The stream is assumed to be positioned right
- * after the tag name. The syntax recognized is:
- *
- * <pre>
- * tag-attrs := empty | attr-list (&quot;&gt;&quot; | &quot;--&gt;&quot; | %&gt;)
- * attr-list := empty | av spaces attr-list
- * empty := spaces
- * </pre>
- *
- * Where <em>av</em> is defined by <code>parseAttributeValue</code>.
- *
- * @return A HashMap mapping String instances (variable names) into String
- * instances (variable values).
- */
- public HashMap parseTagAttributes() throws JETException
- {
- HashMap values = new LinkedHashMap(11);
- while (true)
- {
- skipSpaces();
- int ch = peekChar();
- if (ch == endTagFinalChar)
- {
- return values;
- }
-
- if (ch == '-')
- {
- JETMark mark = mark();
- nextChar();
- // Close NCSA like attributes "->"
- try
- {
- if (nextChar() == '-' && nextChar() == endTagFinalChar)
- {
- return values;
- }
- }
- finally
- {
- reset(mark);
- }
- }
- else if (ch == endTagInitialChar)
- {
- JETMark mark = mark();
- nextChar();
- // Close variable like attributes "%>"
- try
- {
- if (nextChar() == endTagFinalChar)
- {
- return values;
- }
- }
- finally
- {
- reset(mark);
- }
- }
- else if (ch == '/')
- {
- JETMark mark = mark();
- nextChar();
- // XMLesque Close tags
- try
- {
- if (nextChar() == endTagFinalChar)
- {
- return values;
- }
- }
- finally
- {
- reset(mark);
- }
- }
- if (ch == -1)
- {
- return values;
- }
- // Parse as an attribute=value:
- parseAttributeValue(values);
- }
- // Reached EOF:
- // throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.tag.attr.unterminated", new Object [] { mark().toString() }));
- }
-
- /**
- * Parse utils - Is current character a token delimiter ?
- * Delimiters are currently defined to be =, &gt;, &lt;, ", and ' or any
- * any space character as defined by <code>isSpace</code>.
- * @return A boolean.
- */
- protected boolean isDelimiter()
- {
- if (!isSpace())
- {
- int ch = peekChar();
-
- // Look for a single-char work delimiter:
- //
- if (ch == '=' || ch == endTagFinalChar || ch == '"' || ch == '\'' || ch == '/' || ch == '>')
- {
- return true;
- }
-
- // Look for an end-of-comment or end-of-tag:
- //
- if (ch == '-')
- {
- JETMark mark = mark();
- if (((ch = nextChar()) == endTagFinalChar) || ((ch == '-') && (nextChar() == endTagFinalChar)))
- {
- reset(mark);
- return true;
- }
- else
- {
- reset(mark);
- return false;
- }
- }
- return false;
- }
- else
- {
- return true;
- }
- }
-
- public void setStartTag(String startTag)
- {
- startTagInitialChar = startTag.charAt(0);
- }
-
- public void setEndTag(String endTag)
- {
- endTagFinalChar = endTag.charAt(endTag.length() - 1);
- endTagInitialChar = endTag.charAt(0);
- }
-
- /**
- * Parse a space delimited token.
- * If quoted the token will consume all characters up to a matching quote,
- * otherwise, it consumes up to the first delimiter character.
- * @param quoted If <strong>true</strong> accept quoted strings.
- * @param skipSpaces if <code>true</code>, skip leading spaces to find the token, false otherwise.
- * @return the token, or an empty string if no token is found.
- */
- public String parseToken(boolean quoted, boolean skipSpaces) throws JETException
- {
- StringBuffer stringBuffer = new StringBuffer();
- if (skipSpaces)
- {
- skipSpaces();
- }
- stringBuffer.setLength(0);
-
- int ch = peekChar();
-
- if (quoted)
- {
- if (ch == '"' || ch == '\'')
- {
- char endQuote = ch == '"' ? '"' : '\'';
-
- // Consume the open quote:
- //
- ch = nextChar();
- for (ch = nextChar(); ch != -1 && ch != endQuote; ch = nextChar())
- {
- if (ch == '\\')
- {
- ch = nextChar();
- }
- stringBuffer.append((char)ch);
- }
-
- // Check end of quote, skip closing quote:
- //
- if (ch == -1)
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.quotes.unterminated", new Object []{ mark().toString() })); //$NON-NLS-1$
- }
- }
- else
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.attr.quoted", new Object []{ mark().toString() })); //$NON-NLS-1$
- }
- }
- else
- {
- if (!isDelimiter())
- {
- // Read value until delimiter is found:
- do
- {
- ch = nextChar();
- // Take care of the quoting here.
- if (ch == '\\')
- {
- if (peekChar() == '"' || peekChar() == '\'' || peekChar() == endTagFinalChar || peekChar() == endTagInitialChar || peekChar() == '>')
- {
- ch = nextChar();
- }
- }
- else if (ch == -1)
- {
- break;
- }
- stringBuffer.append((char)ch);
- }
- while (!isDelimiter());
- }
- }
- return stringBuffer.toString();
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/ParseProblemSeverity.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/ParseProblemSeverity.java
index 2398102..16838f6 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/ParseProblemSeverity.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/ParseProblemSeverity.java
@@ -17,24 +17,23 @@
package org.eclipse.jet.internal.parser;
+
/**
* Enumeration of problem Severities
- *
+ * @deprecated
*/
public final class ParseProblemSeverity
{
- /**
- * The compilation unit has a problem, but it is will not prevent execution.
- */
- public static final ParseProblemSeverity WARNING = new ParseProblemSeverity("WARNING"); //$NON-NLS-1$
+ private final String display;
/**
- * The compilation unit has a problem that will prevent execution.
+ * @see java.lang.Object#toString()
*/
- public static final ParseProblemSeverity ERROR = new ParseProblemSeverity("ERROR"); //$NON-NLS-1$
-
- private final String display;
+ public String toString()
+ {
+ return display;
+ }
private ParseProblemSeverity(String display)
{
@@ -42,10 +41,12 @@ public final class ParseProblemSeverity
}
/**
- * @see java.lang.Object#toString()
+ * The compilation unit has a problem that will prevent execution.
*/
- public String toString()
- {
- return display;
- }
+ public static final ParseProblemSeverity ERROR = new ParseProblemSeverity("ERROR"); //$NON-NLS-1$
+ /**
+ * The compilation unit has a problem, but it is will not prevent execution.
+ */
+ public static final ParseProblemSeverity WARNING = new ParseProblemSeverity("WARNING"); //$NON-NLS-1$
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateInput.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateInput.java
new file mode 100644
index 0000000..dbaa075
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateInput.java
@@ -0,0 +1,92 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ResourceTemplateInput.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.parser.resources;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jet.core.parser.ITemplateInput;
+import org.eclipse.jet.core.parser.TemplateInputException;
+
+/**
+ * Implementation of JET template input based on an Eclipse workspace IResource
+ */
+public class ResourceTemplateInput implements ITemplateInput
+{
+
+ private final IFile file;
+
+ public ResourceTemplateInput(IFile file)
+ {
+ this.file = file;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.parser.ITemplateInput#getBaseLocation()
+ */
+ public URI getBaseLocation()
+ {
+ // The following doesn't work - we get a file:/ uri which is inconsistent with FileLocation.resolve(URL) uris
+ // return URI.create(file.getProject().getLocationURI().toString() + "/"); //$NON-NLS-1$
+ // Instead, return a platform URL:
+ return URI.create("platform:/resource/" + file.getProject().getName() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.parser.ITemplateInput#getReader()
+ */
+ public Reader getReader() throws TemplateInputException
+ {
+ try
+ {
+ return new BufferedReader(new InputStreamReader(file.getContents(), file.getCharset()));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new TemplateInputException(e);
+ }
+ catch (CoreException e)
+ {
+ throw new TemplateInputException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tools.parser.ITemplateInput#getTemplatePath()
+ */
+ public String getTemplatePath()
+ {
+ return file.getProjectRelativePath().toString();
+ }
+
+ public String getEncoding() throws TemplateInputException
+ {
+ try
+ {
+ return file.getCharset();
+ }
+ catch (CoreException e)
+ {
+ throw new TemplateInputException(e);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateResolverHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateResolverHelper.java
new file mode 100644
index 0000000..712b21f
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/ResourceTemplateResolverHelper.java
@@ -0,0 +1,54 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ResourceTemplateResolverHelper.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.parser.resources;
+
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jet.core.parser.ITemplateInput;
+import org.eclipse.jet.core.parser.ITemplateResolverHelper;
+
+/**
+ * @author pelder
+ */
+public class ResourceTemplateResolverHelper implements ITemplateResolverHelper
+{
+
+ private final IContainer container;
+
+ public ResourceTemplateResolverHelper(IContainer container)
+ {
+ this.container = container;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.parser.resources.ITemplateResolverHelper#createTemplateInput(java.net.URI, java.lang.String)
+ */
+ public ITemplateInput createTemplateInput(String templatePath)
+ {
+ return new ResourceTemplateInput(container.getFile(new Path(templatePath)));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.parser.resources.ITemplateResolverHelper#inputExists(java.net.URI, java.lang.String)
+ */
+ public boolean inputExists(String templatePath)
+ {
+ return container.getFile(new Path(templatePath)).exists();
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverBuilder.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverBuilder.java
new file mode 100644
index 0000000..e828cfd
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverBuilder.java
@@ -0,0 +1,76 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: WorkspaceTemplateResolverBuilder.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.parser.resources;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jet.core.parser.DefaultTemplateResolver;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+
+/**
+ * Builder for a template resolver that leverages knowledge from the Eclipse
+ * workspace if appropriate.
+ */
+public final class WorkspaceTemplateResolverBuilder {
+ private final List baseLocations = new ArrayList();
+
+ /**
+ * Create a builder with the given eclipse project as the base location
+ * @param project an {@link IProject}
+ */
+ public WorkspaceTemplateResolverBuilder(IProject project)
+ {
+ // don't use project.getLocationURI() - this is a file:/ URI
+ // Instead, create a platform:/resource/ URI
+ baseLocations.add(URI.create("platform:/resource/" + project.getName() + "/")); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ /**
+ * Add alternative locations as URIs
+ * @param baseLocations
+ * @return
+ */
+ public WorkspaceTemplateResolverBuilder addAltBaseLocations(URI[] baseLocations)
+ {
+ this.baseLocations.addAll(Arrays.asList(baseLocations));
+ return this;
+ }
+
+ /**
+ * Create the template resolver
+ * @return the template resolver
+ */
+ public ITemplateResolver build()
+ {
+ return new DefaultTemplateResolver.Builder(getBaseLocations())
+ .templateResolverHelperFactory(WorkspaceTemplateResolverHelperFactory.getInstance())
+ .build();
+ }
+
+ /**
+ * Return all base locations as URI
+ * @return
+ */
+ private URI[] getBaseLocations()
+ {
+ return (URI[])baseLocations.toArray(new URI[baseLocations.size()]);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverHelperFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverHelperFactory.java
new file mode 100644
index 0000000..a8e7c49
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/resources/WorkspaceTemplateResolverHelperFactory.java
@@ -0,0 +1,84 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: WorkspaceTemplateResolverHelperFactory.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.parser.resources;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.jet.core.parser.ITemplateResolverHelper;
+import org.eclipse.jet.core.parser.ITemplateResolverHelperFactory;
+
+/**
+ * Implement factory for resolving URIs that point into the workspace
+ */
+public class WorkspaceTemplateResolverHelperFactory implements ITemplateResolverHelperFactory
+{
+
+ private static final WorkspaceTemplateResolverHelperFactory instance = new WorkspaceTemplateResolverHelperFactory();
+
+ /**
+ * Return the singleton instance of this class
+ * @return the instance
+ */
+ public static ITemplateResolverHelperFactory getInstance() {
+ return instance;
+ }
+
+ private WorkspaceTemplateResolverHelperFactory()
+ {
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.tools.parser.ITemplateResolverHelperFactory#getTemplateResolverHelper(java.net.URI)
+ */
+ public ITemplateResolverHelper getTemplateResolverHelper(URI baseLocation)
+ {
+ IContainer container = getWorkspaceContainer(baseLocation);
+ ITemplateResolverHelper helper = null;
+ if(container != null) {
+ helper = new ResourceTemplateResolverHelper(container);
+ }
+ return helper;
+ }
+
+ private IContainer getWorkspaceContainer(URI baseLocation)
+ {
+ try
+ {
+ URI location = URI.create(FileLocator.resolve(baseLocation.toURL()).toExternalForm());
+ // fix FileLocator.resolve
+ if("file".equals(location.getScheme()) && location.getPath() == null) { //$NON-NLS-1$
+ location = URI.create("file:/" + location.getSchemeSpecificPart()); //$NON-NLS-1$
+ }
+ final IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(location);
+ return containers.length > 0 ? containers[0] : null;
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ catch (IOException e)
+ {
+ // ignore
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/CustomTagFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/CustomTagFactory.java
new file mode 100644
index 0000000..409b66d
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/CustomTagFactory.java
@@ -0,0 +1,37 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: CustomTagFactory.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.runtime;
+
+import org.eclipse.jet.taglib.CustomTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagDefinition;
+
+/**
+ * Protocol supported by some TagDefinition instances indicating that a tag definition can be created.
+ * @see TagDefinition
+ * @see CustomTag
+ */
+public interface CustomTagFactory
+{
+ /**
+ * Create a tag instance
+ * @return the custom tag instance
+ * @throws JET2TagException if the tag instance cannot be created.
+ */
+ public abstract CustomTag newTagElement() throws JET2TagException;
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2TemplateStatus.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2TemplateStatus.java
deleted file mode 100644
index 67e099e..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2TemplateStatus.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.taglib.TagInfo;
-
-
-/**
- * Status object for JET2 templates
- *
- */
-public class JET2TemplateStatus extends BasicDiagnostic implements Diagnostic
-{
- public static final int TAG_EXCEPTION = 1;
-
- private final String templatePath;
-
- private final TagInfo tagInfo;
-
- private final String templateBundleId;
-
- private final Throwable exception;
-
- public JET2TemplateStatus(int severity, String templateBundleId, String message, String templatePath, TagInfo tagInfo, Throwable exception)
- {
- super(severity, templateBundleId, TAG_EXCEPTION, message == null ? "" : message, null); //$NON-NLS-1$
-
-
-
- this.templateBundleId = templateBundleId;
- this.templatePath = templatePath;
- this.tagInfo = tagInfo;
- this.exception = exception;
- }
-
- /**
- * @return Returns the tagInfo.
- */
- public final TagInfo getTagInfo()
- {
- return tagInfo;
- }
-
- /**
- * @return Returns the templateBundleId.
- */
- public final String getTemplateBundleId()
- {
- return templateBundleId;
- }
-
- /**
- * @return Returns the templatePath.
- */
- public final String getTemplatePath()
- {
- return templatePath;
- }
-
- /**
- * @return Returns the exception.
- */
- public final Throwable getException()
- {
- return exception;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
index 70a21df..745e1a8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
@@ -32,12 +32,7 @@ import java.util.jar.JarFile;
import java.util.jar.Manifest;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.CoreJETException;
-import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.extensionpoints.TransformData;
@@ -323,7 +318,7 @@ public class JETBundleManager implements IJETBundleManager
/* (non-Javadoc)
* @see org.eclipse.jet.internal.runtime.IJETBundleManager#run(java.lang.String, org.eclipse.jet.transform.IJETRunnable, org.eclipse.core.runtime.IProgressMonitor)
*/
- public void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException
+ public void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws BundleException
{
monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
try
@@ -346,71 +341,6 @@ public class JETBundleManager implements IJETBundleManager
}
}
- public void runOld(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException
- {
- IJETBundleProvider provider = null;
- Bundle bundle = null;
- monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
- try
- {
- final IJETBundleDescriptor descriptor = getDescriptor(id);
- provider = getProvider(id);
- if(provider != null)
- {
- bundle = provider.load(id, new SubProgressMonitor(monitor, 10));
- }
- if(bundle != null)
- {
- final Class loader = bundle.loadClass(descriptor.getTemplateLoaderClass());
- final Object newInstance = loader.newInstance();
- if(newInstance instanceof JET2TemplateLoader)
- {
- runnable.run(descriptor, (JET2TemplateLoader)newInstance, new SubProgressMonitor(monitor, 90));
- }
- }
- }
- catch (BundleException e)
- {
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.TemplateBundleManager_CannotLoad, new Object[] {e}));
- }
- catch (ClassNotFoundException e)
- {
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotLoadLoader, new Object[] {e}));
- }
- catch (IllegalAccessException e)
- {
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
- }
- catch (InstantiationException e)
- {
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
- }
- finally
- {
- if(bundle != null)
- {
- try
- {
- provider.unload(bundle);
- }
- catch (BundleException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Bundle_CouldNotLoadJetBundle, e);
- }
- }
- monitor.done();
- }
-
- }
-
private IJETBundleProvider getProvider(String id)
{
@@ -425,7 +355,7 @@ public class JETBundleManager implements IJETBundleManager
return null;
}
- public void connect(final String id, final IProgressMonitor monitor) throws CoreJETException
+ public void connect(final String id, final IProgressMonitor monitor) throws BundleException
{
BundleWrapper wrappedBundle = null;
synchronized(bundlesById)
@@ -438,16 +368,7 @@ public class JETBundleManager implements IJETBundleManager
if(provider != null)
{
Bundle bundle;
- try
- {
- bundle = provider.load(id, monitor);
- }
- catch (BundleException e)
- {
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.TemplateBundleManager_CannotLoad, new Object[] {e}));
- }
+ bundle = provider.load(id, monitor);
wrappedBundle = new BundleWrapper(provider, bundle);
bundlesById.put(id, wrappedBundle);
@@ -459,9 +380,7 @@ public class JETBundleManager implements IJETBundleManager
}
else
{
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.TemplateBundleManager_CannotLoad, null));
+ throw new BundleException(JET2Messages.TemplateBundleManager_CannotLoad);
}
}
}
@@ -492,7 +411,7 @@ public class JETBundleManager implements IJETBundleManager
}
}
- public JET2TemplateLoader getTemplateLoader(String id) throws CoreJETException
+ public JET2TemplateLoader getTemplateLoader(String id) throws BundleException
{
synchronized(bundlesById)
{
@@ -510,26 +429,20 @@ public class JETBundleManager implements IJETBundleManager
}
catch (ClassNotFoundException e)
{
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotLoadLoader, new Object[] {e}));
+ throw new BundleException(
+ JET2Messages.JET2Bundle_CouldNotLoadLoader, e);
}
catch (IllegalAccessException e)
{
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ throw new BundleException(JET2Messages.JET2Bundle_CouldNotInstantiateLoader, e);
}
catch (InstantiationException e)
{
- throw new CoreJETException(
- new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ throw new BundleException(JET2Messages.JET2Bundle_CouldNotInstantiateLoader, e);
}
}
}
- throw new CoreJETException(new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
- JET2Messages.JET2Bundle_CouldNotLoadLoader, null));
+ throw new BundleException(JET2Messages.JET2Bundle_CouldNotLoadLoader);
}
public String[] getAllTransformIds()
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
index 25d8ba8..ed9afc4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.jet.AbstractContextExtender;
+import org.eclipse.jet.ContextLogEntry;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jet.transform.TransformContextExtender;
@@ -40,12 +41,65 @@ public class RuntimeLoggerContextExtender extends AbstractContextExtender
public static final int DEBUG_LEVEL = 1;
- private static final class ContextData
+ private static final class RuntimeLogger implements JET2Context.LogListener
{
private final List listeners = new ArrayList();
+
+ public void log(String message, TagInfo td, String templatePath, int level)
+ {
+ for (Iterator i = listeners.iterator(); i.hasNext();)
+ {
+ RuntimeTagLogger logger = (RuntimeTagLogger)i.next();
+ logger.log(message, td, templatePath, level);
+ }
+ }
+ public void log(ContextLogEntry entry)
+ {
+ log(entry.getMessage(), entry.getTagInfo(), entry.getTemplatePath(), getLevel(entry.getSeverity()));
+ }
+ private int getLevel(int severity)
+ {
+ switch(severity)
+ {
+ case ContextLogEntry.ERROR:
+ case ContextLogEntry.CANCEL:
+ return RuntimeLoggerContextExtender.ERROR_LEVEL;
+ case ContextLogEntry.WARNING:
+ return RuntimeLoggerContextExtender.WARNING_LEVEL;
+ case ContextLogEntry.INFO:
+ case ContextLogEntry.OK:
+ return RuntimeLoggerContextExtender.INFO_LEVEL;
+ default:
+ return RuntimeLoggerContextExtender.ERROR_LEVEL;
+
+ }
+ }
}
- public RuntimeLoggerContextExtender(JET2Context context)
+ /**
+ * Get the runtime logger instance. This method
+ * will not install this context extender. Use {@link #install(JET2Context)}
+ * to install the context extender
+ * @param context the context
+ * @return the installed context extender or <code>null</code>
+ */
+ public static RuntimeLoggerContextExtender getInstance(JET2Context context) {
+ if(context.hasContextExtender(RuntimeLoggerContextExtender.class)) {
+ return new RuntimeLoggerContextExtender(context);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @param context
+ */
+ public static void install(JET2Context context) {
+ new RuntimeLoggerContextExtender(context);
+ }
+
+ private RuntimeLoggerContextExtender(JET2Context context)
{
super(context);
}
@@ -55,29 +109,31 @@ public class RuntimeLoggerContextExtender extends AbstractContextExtender
*/
protected Object createExtendedData(JET2Context context)
{
- return new ContextData();
+ final RuntimeLogger runtimeLogger = new RuntimeLogger();
+ context.addLogListener(runtimeLogger);
+ return runtimeLogger;
}
- private ContextData getData()
+ private RuntimeLogger getRuntimeLogger()
{
- return (ContextData)getExtendedData();
+ return (RuntimeLogger)getExtendedData();
}
public void addListener(RuntimeTagLogger logger)
{
- getData().listeners.add(logger);
+ getRuntimeLogger().listeners.add(logger);
}
public void removeListener(RuntimeTagLogger logger)
{
- getData().listeners.remove(logger);
+ getRuntimeLogger().listeners.remove(logger);
}
public static void log(JET2Context context, String message, TagInfo td, int level)
{
if (context.hasContextExtender(RuntimeLoggerContextExtender.class))
{
- RuntimeLoggerContextExtender rl = new RuntimeLoggerContextExtender(context);
+ RuntimeLoggerContextExtender rl = getInstance(context);
String templatePath = null;
if(context.hasContextExtender(TransformContextExtender.class)) {
TransformContextExtender tce = new TransformContextExtender(context);
@@ -89,7 +145,7 @@ public class RuntimeLoggerContextExtender extends AbstractContextExtender
public void log(String message, TagInfo td, String templatePath, int level)
{
- for (Iterator i = getData().listeners.iterator(); i.hasNext();)
+ for (Iterator i = getRuntimeLogger().listeners.iterator(); i.hasNext();)
{
RuntimeTagLogger logger = (RuntimeTagLogger)i.next();
logger.log(message, td, templatePath, level);
@@ -100,8 +156,7 @@ public class RuntimeLoggerContextExtender extends AbstractContextExtender
{
if (context.hasContextExtender(RuntimeLoggerContextExtender.class))
{
- RuntimeLoggerContextExtender rl = new RuntimeLoggerContextExtender(context);
- rl.log(message, tagInfo, templatePath, level);
+ getInstance(context).getRuntimeLogger().log(message, tagInfo, templatePath, level);
}
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeContainerRuntimeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeContainerRuntimeTag.java
index 1e2d9d4..c1bbf1d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeContainerRuntimeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeContainerRuntimeTag.java
@@ -21,6 +21,7 @@ package org.eclipse.jet.internal.runtime;
import java.text.MessageFormat;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -107,7 +108,7 @@ public class SafeContainerRuntimeTag extends SafeCustomRuntimeTag
RuntimeLoggerContextExtender.log(getContext(),
MessageFormat.format(
JET2Messages.TraceRuntimeTags_SetBodyContents,
- new Object[] {bodyContent.getDocument().get()}),
+ new Object[] {((BufferedJET2Writer)bodyContent).getContent()}),
getTagInfo(), RuntimeLoggerContextExtender.TRACE_LEVEL);
untrustedTag.setBodyContent(bodyContent);
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeFunctionRuntimeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeFunctionRuntimeTag.java
index ebcb91b..a77db9c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeFunctionRuntimeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeFunctionRuntimeTag.java
@@ -21,6 +21,7 @@ package org.eclipse.jet.internal.runtime;
import java.text.MessageFormat;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -79,7 +80,7 @@ public class SafeFunctionRuntimeTag extends SafeCustomRuntimeTag
public void doRun() throws Exception
{
FunctionTag untrustedTag = (FunctionTag)getUntrustedTag();
- functionResult = untrustedTag.doFunction(getTagInfo(), getContext(), bodyContent.toString());
+ functionResult = untrustedTag.doFunction(getTagInfo(), getContext(), ((BufferedJET2Writer)bodyContent).getContent());
}
});
RuntimeLoggerContextExtender.log(getContext(), MessageFormat.format(
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TagFactoryImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TagFactoryImpl.java
index 898283a..bd7a471 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TagFactoryImpl.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TagFactoryImpl.java
@@ -20,7 +20,6 @@ package org.eclipse.jet.internal.runtime;
import java.text.MessageFormat;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.ConditionalTag;
@@ -30,8 +29,10 @@ import org.eclipse.jet.taglib.CustomTagKind;
import org.eclipse.jet.taglib.EmptyTag;
import org.eclipse.jet.taglib.FunctionTag;
import org.eclipse.jet.taglib.IteratingTag;
+import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.OtherTag;
import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagFactory;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jet.taglib.TagLibraryManager;
@@ -68,41 +69,43 @@ public class TagFactoryImpl implements TagFactory
}
try
{
- CustomTag newCustomTag = tagLibrary.newTagElement(tagNCName);
- CustomTagKind kind = newCustomTag.getKind();
- if (kind == CustomTagKind.CONDITIONAL)
- {
- return new SafeConditionalRuntimeTag((ConditionalTag)newCustomTag);
+ final TagDefinition tagDefinition = tagLibrary.getTagDefinition(tagNCName);
+ if(tagDefinition instanceof CustomTagFactory) {
+ CustomTag newCustomTag = ((CustomTagFactory)tagDefinition).newTagElement();
+ CustomTagKind kind = newCustomTag.getKind();
+ if (kind == CustomTagKind.CONDITIONAL)
+ {
+ return new SafeConditionalRuntimeTag((ConditionalTag)newCustomTag);
+ }
+ else if (kind == CustomTagKind.EMPTY)
+ {
+ return new SafeEmptyRuntimeTag((EmptyTag)newCustomTag);
+ }
+ else if (kind == CustomTagKind.FUNCTION)
+ {
+ return new SafeFunctionRuntimeTag((FunctionTag)newCustomTag);
+ }
+ else if (kind == CustomTagKind.ITERATING)
+ {
+ return new SafeIteratingRuntimeTag((IteratingTag)newCustomTag);
+ }
+ else if (kind == CustomTagKind.OTHER)
+ {
+ return new SafeOtherRuntimeTag((OtherTag)newCustomTag);
+ }
+ else if (kind == CustomTagKind.CONTAINER)
+ {
+ return new SafeContainerRuntimeTag((ContainerTag)newCustomTag);
+ }
}
- else if (kind == CustomTagKind.EMPTY)
- {
- return new SafeEmptyRuntimeTag((EmptyTag)newCustomTag);
- }
- else if (kind == CustomTagKind.FUNCTION)
- {
- return new SafeFunctionRuntimeTag((FunctionTag)newCustomTag);
- }
- else if (kind == CustomTagKind.ITERATING)
- {
- return new SafeIteratingRuntimeTag((IteratingTag)newCustomTag);
- }
- else if (kind == CustomTagKind.OTHER)
- {
- return new SafeOtherRuntimeTag((OtherTag)newCustomTag);
- }
- else if (kind == CustomTagKind.CONTAINER)
- {
- return new SafeContainerRuntimeTag((ContainerTag)newCustomTag);
- }
- return new DoNothingRuntimeTagElement();
}
- catch (CoreException e)
+ catch (JET2TagException e)
{
// TODO Improve so that tag developers can find the problem faster.
String msg = JET2Messages.TagFactoryImpl_TagCreateFailed;
context.logError(tagInfo, MessageFormat.format(msg, new Object []{ tagNCName, libraryId }), e);
- return new DoNothingRuntimeTagElement();
}
+ return new DoNothingRuntimeTagElement();
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java
deleted file mode 100644
index 27ff6dc..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.runtime.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.CoreJETException;
-
-/**
- * A wrapper that makes a CoreException seem like a DiagnosticException.
- */
-public class CoreExceptionWrapper extends CoreJETException
-{
-
- public CoreExceptionWrapper(CoreException e)
- {
- super(diagnosticFor(e.getStatus()));
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 5977946863300207215L;
-
- /**
- * Return a Diagnostic equivalent to the passed IStatus.
- * @param status an IStatus.
- * @return the equivalent Diagnostic
- */
- public static Diagnostic diagnosticFor(IStatus status)
- {
- BasicDiagnostic bd = new BasicDiagnostic(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), new Object[] {status.getException()});
- final List childDiagnostics = childDiagnosticsFor(status);
- for (Iterator i = childDiagnostics.iterator(); i.hasNext();)
- {
- Diagnostic diagnostic = (Diagnostic)i.next();
- bd.add(diagnostic);
- }
- return bd;
- }
-
- /**
- * Create a list of Diagnostic objects equivalent to the child IStatus objects of the passed IStatus.
- * @param status the IStatus containing the child IStatus objects to wrap.
- * @return a possibly empty List of Diagnostic objects.
- */
- private static List childDiagnosticsFor(IStatus status)
- {
- if(!status.isMultiStatus()) {
- return Collections.EMPTY_LIST;
- }
- final IStatus[] childStati = status.getChildren();
- List result = new ArrayList(childStati.length);
- for (int i = 0; i < childStati.length; i++)
- {
- result.add(diagnosticFor(childStati[i]));
- }
- return result;
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/JETTemplateModelLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/JETTemplateModelLoader.java
index c7c705e..20827ac 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/JETTemplateModelLoader.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/JETTemplateModelLoader.java
@@ -17,10 +17,11 @@
package org.eclipse.jet.internal.runtime.model;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URL;
-import org.eclipse.jet.compiler.JET2CompilationUnit;
+import org.eclipse.jet.core.parser.ast.JETAST;
+import org.eclipse.jet.core.parser.ast.JETASTParser;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
import org.eclipse.jet.runtime.model.IModelLoader;
/**
@@ -50,23 +51,7 @@ public class JETTemplateModelLoader implements IModelLoader
*/
public Object load(URL modelUrl, String kind) throws IOException
{
- JET2CompilationUnit cu = new JET2CompilationUnit();
- final InputStream modelStream = modelUrl.openStream();
- try {
- cu.parse(modelStream, "UTF-8"); //$NON-NLS-1$
- } finally {
- if(modelStream != null) {
- try
- {
- modelStream.close();
- }
- catch (IOException e)
- {
- // nothing we can do, and we should never throw exceptions from finally clauses.
- }
- }
- }
- return cu;
+ throw new UnsupportedOperationException();
}
/* (non-Javadoc)
@@ -74,8 +59,9 @@ public class JETTemplateModelLoader implements IModelLoader
*/
public Object loadFromString(String serializedModel, String kind) throws IOException
{
- JET2CompilationUnit cu = new JET2CompilationUnit();
- cu.parse(serializedModel);
+ JETCompilationUnit cu = (JETCompilationUnit)new JETASTParser.Builder(JETAST.JET_SPEC_V2)
+ .build()
+ .parse(serializedModel.toCharArray());
return cu;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
index 1be71ad..46754d4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
@@ -25,11 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jet.CoreJETException;
-import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.runtime.model.ILoaderFactory;
import org.eclipse.jet.runtime.model.ILoaderManager;
@@ -270,7 +266,7 @@ public class LoaderManager implements ILoaderManager
{
final String msg = MessageFormat.format(JET2Messages.LoaderManager_MultipleLoaders,
new Object []{ url, candidateLoaders.toString() });
- throw new CoreJETException(new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK, msg, null));
+ throw new CoreJETException(msg);
}
}
@@ -279,7 +275,7 @@ public class LoaderManager implements ILoaderManager
if(loader == null)
{
final String msg = MessageFormat.format(JET2Messages.LoaderManager_CouldNotFindLoader, new Object []{ url });
- throw new CoreJETException(new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK, msg, null));
+ throw new CoreJETException(msg);
}
return loader;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagDefinitionImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagDefinitionImpl.java
new file mode 100644
index 0000000..7ff4978
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagDefinitionImpl.java
@@ -0,0 +1,139 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionTagDefinitionImpl.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.taglib;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.runtime.CustomTagFactory;
+import org.eclipse.jet.taglib.CustomTag;
+import org.eclipse.jet.taglib.CustomTagKind;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagAttributeDefinition;
+import org.eclipse.jet.taglib.TagDefinition;
+import org.eclipse.jet.taglib.TagLibrary;
+
+/**
+ * Implementation of TagDefinition that is backed by a loaded Extension point element
+ */
+public class ExtensionTagDefinitionImpl extends TagDefinitionImpl implements TagDefinition, CustomTagFactory
+{
+
+ private static final String CLASS__ATTR = "class"; //$NON-NLS-1$
+
+ private static final String USE__ATTR = "use"; //$NON-NLS-1$
+
+ private static final String USE__VALUE__REQUIRED = "required"; //$NON-NLS-1$
+
+ private static final String NAME__ATTR = "name"; //$NON-NLS-1$
+
+ private static final String ATTRIBUTE__ELEMENT = "attribute"; //$NON-NLS-1$
+
+ private static final String ALLOW_AS_EMPTY__ATTR = "allowAsEmpty"; //$NON-NLS-1$
+
+ private static final String CONTENT_PROCESSING__VALUE__CUSTOM = "custom"; //$NON-NLS-1$
+
+ private static final String CONTENT_PROCESSING__ATTR = "processContents"; //$NON-NLS-1$
+
+ private static final String DEPRECATED__ATTR = "deprecated"; //$NON-NLS-1$
+
+ private static final String TYPE__ATTR = "type"; //$NON-NLS-1$
+
+ private static final String WHEN_CONTAINING_LINE_IS_EMPTY__ATTR = "whenContainingLineIsEmpty"; //$NON-NLS-1$
+
+ private static final String REMOVE = "remove"; //$NON-NLS-1$
+
+ private final IConfigurationElement configElement2;
+
+ public static ExtensionTagDefinitionImpl createInstance(String tagName, IConfigurationElement configElement, CustomTagKind kind, TagLibrary tagLibrary)
+ {
+ boolean deprecated = Boolean.valueOf(configElement.getAttribute(DEPRECATED__ATTR)).booleanValue();
+ boolean customContentProcessing = CONTENT_PROCESSING__VALUE__CUSTOM.equals(configElement.getAttribute(CONTENT_PROCESSING__ATTR));
+ boolean allowAsEmpty = Boolean.valueOf(configElement.getAttribute(ALLOW_AS_EMPTY__ATTR)).booleanValue();
+
+ String removeWhenEmpty = configElement.getAttribute(WHEN_CONTAINING_LINE_IS_EMPTY__ATTR);
+ boolean removeWhenContainingLineIsEmpty;
+
+ if(removeWhenEmpty == null)
+ {
+ removeWhenContainingLineIsEmpty =
+ kind != CustomTagKind.EMPTY && kind != CustomTagKind.FUNCTION;
+ }
+ else
+ {
+ removeWhenContainingLineIsEmpty = REMOVE.equals(removeWhenEmpty);
+ }
+
+ String description = ExtensionTagLibraryImpl.getDescription(configElement).trim();
+
+ ExtensionTagDefinitionImpl td = new ExtensionTagDefinitionImpl(configElement, tagLibrary, tagName, kind,
+ description, customContentProcessing, allowAsEmpty,
+ deprecated, removeWhenContainingLineIsEmpty );
+
+ IConfigurationElement[] children = configElement.getChildren(ATTRIBUTE__ELEMENT);
+ for (int i = 0; i < children.length; i++)
+ {
+ TagAttributeDefinition tad = new TagAttributeDefinitionImpl(
+ children[i].getAttribute(NAME__ATTR),
+ USE__VALUE__REQUIRED.equalsIgnoreCase(children[i].getAttribute(USE__ATTR)),
+ Boolean.valueOf(children[i].getAttribute(DEPRECATED__ATTR)).booleanValue(),
+ ExtensionTagLibraryImpl.getDescription(children[i]),
+ children[i].getAttribute(TYPE__ATTR));
+ if (tad.getName() != null)
+ {
+ td.addTagAttribute(tad);
+ }
+ else
+ {
+ String msg = JET2Messages.TagDefinitionImpl_MissingName;
+ InternalJET2Platform.logError(MessageFormat.format(msg, new Object []{
+ children[i].getDeclaringExtension().getExtensionPointUniqueIdentifier(),
+ children[i].getDeclaringExtension().getNamespace() }));
+ }
+ }
+
+ return td;
+ }
+
+ private ExtensionTagDefinitionImpl(IConfigurationElement configElement, TagLibrary tagLibrary, String tagName, CustomTagKind kind, String description, boolean customContentProcessing, boolean allowAsEmpty, boolean deprecated, boolean removeWhenContainingLineIsEmpty)
+ {
+ super(tagLibrary, tagName, kind,
+ description, customContentProcessing, allowAsEmpty,
+ deprecated, removeWhenContainingLineIsEmpty);
+ configElement2 = configElement;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.CustomTagFactory#newTagElement()
+ */
+ public CustomTag newTagElement() throws JET2TagException
+ {
+ try
+ {
+ return (CustomTag)configElement2.createExecutableExtension(CLASS__ATTR);
+ }
+ catch (CoreException e)
+ {
+ throw new JET2TagException(e);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagLibraryImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagLibraryImpl.java
index 40887f4..7d89c73 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagLibraryImpl.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/ExtensionTagLibraryImpl.java
@@ -25,9 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.CustomTagKind;
import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagLibrary;
@@ -110,7 +108,7 @@ public class ExtensionTagLibraryImpl implements TagLibrary
CustomTagKind kind = (CustomTagKind)tagToKindMap.get(children[i].getName());
if (kind != null && tagName != null && !tagMap.containsKey(tagName))
{
- tagMap.put(tagName, new TagDefinitionImpl(tagName, children[i], kind, this));
+ tagMap.put(tagName, ExtensionTagDefinitionImpl.createInstance(tagName, children[i], kind, this));
}
}
}
@@ -150,16 +148,6 @@ public class ExtensionTagLibraryImpl implements TagLibrary
/* (non-Javadoc)
* @see org.eclipse.jet.taglib.TagLibrary#newTagElement(java.lang.String)
*/
- public CustomTag newTagElement(String tagNCName) throws CoreException
- {
- TagDefinition td = getTagDefinition((tagNCName));
- if (td == null)
- {
- throw new IllegalArgumentException();
- }
- return td.newTagElement();
- }
-
public String[] getTagNames()
{
if (tagNames == null)
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
index 3f2bbf4..3c74cbd 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
@@ -18,7 +18,6 @@
package org.eclipse.jet.internal.taglib;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -26,11 +25,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.CustomTagKind;
import org.eclipse.jet.taglib.TagAttributeDefinition;
import org.eclipse.jet.taglib.TagDefinition;
@@ -41,39 +35,13 @@ import org.eclipse.jet.taglib.TagLibrary;
* Implementation of TagDefinition.
*
*/
-public final class TagDefinitionImpl implements TagDefinition
+public class TagDefinitionImpl implements TagDefinition
{
- private static final String CLASS__ATTR = "class"; //$NON-NLS-1$
-
- private static final String USE__ATTR = "use"; //$NON-NLS-1$
-
- private static final String USE__VALUE__REQUIRED = "required"; //$NON-NLS-1$
-
- private static final String NAME__ATTR = "name"; //$NON-NLS-1$
-
- private static final String ATTRIBUTE__ELEMENT = "attribute"; //$NON-NLS-1$
-
- private static final String ALLOW_AS_EMPTY__ATTR = "allowAsEmpty"; //$NON-NLS-1$
-
- private static final String CONTENT_PROCESSING__VALUE__CUSTOM = "custom"; //$NON-NLS-1$
-
- private static final String CONTENT_PROCESSING__ATTR = "processContents"; //$NON-NLS-1$
-
- private static final String DEPRECATED__ATTR = "deprecated"; //$NON-NLS-1$
-
- private static final String TYPE__ATTR = "type"; //$NON-NLS-1$
-
- private static final String WHEN_CONTAINING_LINE_IS_EMPTY__ATTR = "whenContainingLineIsEmpty"; //$NON-NLS-1$
-
- private static final String REMOVE = "remove"; //$NON-NLS-1$
-
private final String name;
private final CustomTagKind kind;
- private final IConfigurationElement configElement;
-
private final Map attributeDefinitions;
private final boolean deprecated;
@@ -101,63 +69,8 @@ public final class TagDefinitionImpl implements TagDefinition
this.deprecated = deprecated;
this.removeWhenContainingLineIsEmpty = removeWhenContainingLineIsEmpty;
attributeDefinitions = new HashMap();
- configElement = null;
}
- /**
- *
- * @param tagName the name of the tag
- * @param configElement the configuration defining the tag
- * @param kind the kind of the tag
- * @param tagLibrary the parent tag library
- */
- public TagDefinitionImpl(String tagName, IConfigurationElement configElement, CustomTagKind kind, TagLibrary tagLibrary)
- {
- super();
- this.configElement = configElement;
- this.kind = kind;
- name = tagName;
- this.tagLibrary = tagLibrary;
-
- deprecated = Boolean.valueOf(configElement.getAttribute(DEPRECATED__ATTR)).booleanValue();
- customContentProcessing = CONTENT_PROCESSING__VALUE__CUSTOM.equals(configElement.getAttribute(CONTENT_PROCESSING__ATTR));
- allowAsEmpty = Boolean.valueOf(configElement.getAttribute(ALLOW_AS_EMPTY__ATTR)).booleanValue();
-
- String removeWhenEmpty = configElement.getAttribute(WHEN_CONTAINING_LINE_IS_EMPTY__ATTR);
- if(removeWhenEmpty == null)
- {
- removeWhenContainingLineIsEmpty =
- kind != CustomTagKind.EMPTY && kind != CustomTagKind.FUNCTION;
- }
- else
- {
- removeWhenContainingLineIsEmpty = REMOVE.equals(removeWhenEmpty);
- }
-
- description = ExtensionTagLibraryImpl.getDescription(configElement);
- IConfigurationElement[] children = configElement.getChildren(ATTRIBUTE__ELEMENT);
- attributeDefinitions = new HashMap(children.length);
- for (int i = 0; i < children.length; i++)
- {
- TagAttributeDefinition tad = new TagAttributeDefinitionImpl(
- children[i].getAttribute(NAME__ATTR),
- USE__VALUE__REQUIRED.equalsIgnoreCase(children[i].getAttribute(USE__ATTR)),
- Boolean.valueOf(children[i].getAttribute(DEPRECATED__ATTR)).booleanValue(),
- ExtensionTagLibraryImpl.getDescription(children[i]),
- children[i].getAttribute(TYPE__ATTR));
- if (tad.getName() != null)
- {
- addTagAttribute(tad);
- }
- else
- {
- String msg = JET2Messages.TagDefinitionImpl_MissingName;
- InternalJET2Platform.logError(MessageFormat.format(msg, new Object []{
- children[i].getDeclaringExtension().getExtensionPointUniqueIdentifier(),
- children[i].getDeclaringExtension().getNamespace() }));
- }
- }
- }
/**
* @param tagAttributeDefinition
*/
@@ -182,11 +95,6 @@ public final class TagDefinitionImpl implements TagDefinition
return kind;
}
- public CustomTag newTagElement() throws CoreException
- {
- return configElement != null ? (CustomTag)configElement.createExecutableExtension(CLASS__ATTR) : null;
- }
-
public TagAttributeDefinition getAttributeDefinition(String attrName)
{
return (TagAttributeDefinition)attributeDefinitions.get(attrName);
@@ -231,7 +139,7 @@ public final class TagDefinitionImpl implements TagDefinition
public boolean isEmptyTagAllowed()
{
boolean allowed = false;
- if (kind == CustomTagKind.EMPTY)
+ if (kind == CustomTagKind.EMPTY || kind == CustomTagKind.OTHER)
{
allowed = true;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java
deleted file mode 100644
index 3153732..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.internal.taglib;
-
-import org.eclipse.jet.taglib.TagLibrary;
-import org.eclipse.jet.taglib.TagLibraryManager;
-import org.eclipse.jet.taglib.TagLibraryReference;
-
-/**
- * Standard implementation of TagLibraryReference.
- */
-public class TagLibraryReferenceImpl implements TagLibraryReference
-{
-
- private final String prefix;
- private final String id;
- private final boolean autoImport;
-
- public TagLibraryReferenceImpl(String prefix, String id, boolean autoImport)
- {
- this.prefix = prefix;
- this.id = id;
- this.autoImport = autoImport;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.TagLibraryReference#getPrefix()
- */
- public String getPrefix()
- {
- return prefix;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibraryId()
- */
- public String getTagLibraryId()
- {
- return id;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibrary()
- */
- public TagLibrary getTagLibrary()
- {
- return TagLibraryManager.getInstance().getTagLibrary(id);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.TagLibraryReference#isAutoImport()
- */
- public boolean isAutoImport()
- {
- return autoImport;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
index e0c301f..44e73f6 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InitialCodeTag.java
@@ -19,6 +19,8 @@ package org.eclipse.jet.internal.taglib.control;
import java.text.MessageFormat;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -49,7 +51,11 @@ public class InitialCodeTag extends AbstractContainerTag
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- initialCodeOffset = out.getDocument().getLength();
+ if(out instanceof BufferedJET2Writer) {
+ initialCodeOffset = ((BodyContentWriter)out).getContentLength();
+ } else {
+ throw new IllegalArgumentException();
+ }
}
/* (non-Javadoc)
@@ -64,7 +70,11 @@ public class InitialCodeTag extends AbstractContainerTag
throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_IllegalParent, new Object []{ "userRegion" })); //$NON-NLS-1$
}
- ((UserRegionTag)getParent()).setInitiaCodeRegion(initialCodeOffset, out.getDocument().getLength(), unmodifiedMarker);
+ if (out instanceof BodyContentWriter){
+ ((UserRegionTag)getParent()).setInitiaCodeRegion(initialCodeOffset, ((BufferedJET2Writer)out).getContentLength(), unmodifiedMarker);
+ } else {
+ throw new IllegalArgumentException();
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java
index 6308c6e..142ccda 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java
@@ -16,6 +16,7 @@
*/
package org.eclipse.jet.internal.taglib.control;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.AbstractContainerTag;
@@ -44,7 +45,13 @@ public class MarkerTag extends AbstractContainerTag
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- startOffset = out.getLength();
+ if(out instanceof BufferedJET2Writer) {
+ BufferedJET2Writer bufferedOut = (BufferedJET2Writer)out;
+ startOffset = bufferedOut.getContentLength();
+ } else {
+ // expected out to be a BufferedJET2Writer
+ throw new IllegalArgumentException();
+ }
}
/* (non-Javadoc)
@@ -52,9 +59,24 @@ public class MarkerTag extends AbstractContainerTag
*/
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- String description = getAttribute("description"); //$NON-NLS-1$
- int endOffset = out.getLength();
- MarkerHelper.createMarkerOnWriter(out, startOffset, endOffset, description, td, TransformContextExtender.getInstance(context).getTemplatePath());
+ if (out instanceof BufferedJET2Writer)
+ {
+ BufferedJET2Writer bufferedOut = (BufferedJET2Writer)out;
+ String description = getAttribute("description"); //$NON-NLS-1$
+ int endOffset = bufferedOut.getContentLength();
+ MarkerHelper.createMarkerOnWriter(
+ bufferedOut,
+ startOffset,
+ endOffset,
+ description,
+ td,
+ TransformContextExtender.getInstance(context).getTemplatePath());
+ }
+ else
+ {
+ // expected out to be a BufferedJET2Writer
+ throw new IllegalArgumentException();
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
index 181d724..fafd586 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/UserRegionTag.java
@@ -18,6 +18,7 @@ package org.eclipse.jet.internal.taglib.control;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.AbstractContainerTag;
@@ -52,7 +53,11 @@ public class UserRegionTag extends AbstractContainerTag
*/
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- UserRegionHelper.markUserRegion(out, userRegionOffset, out.getDocument().getLength());
+ if(out instanceof BufferedJET2Writer) {
+ UserRegionHelper.markUserRegion(out, userRegionOffset, ((BufferedJET2Writer)out).getContentLength());
+ } else {
+ throw new IllegalArgumentException();
+ }
if (initialCodeStart >= 0)
{
UserRegionHelper.markInitialCode(out, initialCodeStart, initialCodeEnd, unmodifiedMarker);
@@ -64,7 +69,11 @@ public class UserRegionTag extends AbstractContainerTag
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- userRegionOffset = out.getDocument().getLength();
+ if(out instanceof BufferedJET2Writer) {
+ userRegionOffset = ((BufferedJET2Writer)out).getContentLength();
+ } else {
+ throw new IllegalArgumentException();
+ }
}
/**
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
index 0dc6041..255dd2c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.codegen.util.ImportManager;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
@@ -30,6 +31,9 @@ import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jet.taglib.java.JavaActionsUtil;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -53,14 +57,32 @@ public class ImportsLocationTag extends AbstractEmptyTag
public void finalizeContent(JET2Writer writer, Object file)
{
- Position[] importLocations = writer.getPositions(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
-
- // there should be exactly one of these (see ensureNoEarlierImportLocations())
-
- if (importLocations.length > 0)
- {
- ImportsPosition position = (ImportsPosition)importLocations[0];
- writer.replace(position.offset, position.length, position.getImportManager().computeSortedImports());
+ if(writer instanceof BufferedJET2Writer) {
+ IDocument document = (IDocument)((BufferedJET2Writer)writer).getAdapter(IDocument.class);
+ if(document != null) {
+ try
+ {
+ Position[] importLocations = document.getPositions(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+
+ // there should be exactly one of these (see ensureNoEarlierImportLocations())
+
+ if (importLocations.length > 0)
+ {
+ ImportsPosition position = (ImportsPosition)importLocations[0];
+ document.replace(position.offset, position.length, position.getImportManager().computeSortedImports());
+ }
+ }
+ catch (BadPositionCategoryException e)
+ {
+ // should not happen
+ throw new RuntimeException(e);
+ }
+ catch (BadLocationException e)
+ {
+ // should not happen
+ throw new RuntimeException(e);
+ }
+ }
}
}
@@ -106,7 +128,11 @@ public class ImportsLocationTag extends AbstractEmptyTag
*/
public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
-
+ if(!(out instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ final BufferedJET2Writer bufferedWriter = ((BufferedJET2Writer)out);
+ final IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
// validate that this is the first instance of this tag to execute...
// We do this by looking for an IMPORTS_POSITION_CATEGORY on this writer and all parents.
@@ -114,33 +140,55 @@ public class ImportsLocationTag extends AbstractEmptyTag
String compilationUnitPackage = getAttribute("package"); //$NON-NLS-1$
- int importsOffset = out.getLength();
+ int importsOffset = bufferedWriter.getContentLength();
// write something so that the position updater won't treat the position as end of file, and
// constantly move it.
out.write(" "); //$NON-NLS-1$
- Position importsPosition = new ImportsPosition(importsOffset, compilationUnitPackage, out.getDocument().get());
-
- out.addPositionCategory(IMPORTS_POSITION_CATEGORY);
- out.addPosition(IMPORTS_POSITION_CATEGORY, importsPosition);
+ Position importsPosition = new ImportsPosition(importsOffset, compilationUnitPackage, bufferedWriter.getContent());
- out.addEventListener(IMPORTS_LISTENER_CATEGORY, new WriterEventListener());
+ document.addPositionCategory(IMPORTS_POSITION_CATEGORY);
+ try
+ {
+ document.addPosition(IMPORTS_POSITION_CATEGORY, importsPosition);
+ }
+ catch (BadLocationException e)
+ {
+ throw new JET2TagException(e);
+ }
+ catch (BadPositionCategoryException e)
+ {
+ throw new JET2TagException(e);
+ }
+ bufferedWriter.addEventListener(IMPORTS_LISTENER_CATEGORY, new WriterEventListener());
}
private void ensureNoEarlierImportsLocation(JET2Writer writer) throws JET2TagException
{
- // defense add of the category, in case it is not already added to the document
- writer.addPositionCategory(IMPORTS_POSITION_CATEGORY);
-
- Position[] positions = writer.getPositions(IMPORTS_POSITION_CATEGORY);
- if (positions.length > 0)
- {
- throw new JET2TagException(JET2Messages.ImportsLocationTag_AllowedOnlyOnce);
- }
-
- if (writer.getParentWriter() != null)
- {
- ensureNoEarlierImportsLocation(writer.getParentWriter());
+ if(writer instanceof BufferedJET2Writer) {
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)writer;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
+ // defense add of the category, in case it is not already added to the document
+ document.addPositionCategory(IMPORTS_POSITION_CATEGORY);
+
+ try
+ {
+ Position[] positions = document.getPositions(IMPORTS_POSITION_CATEGORY);
+ if (positions.length > 0)
+ {
+ throw new JET2TagException(JET2Messages.ImportsLocationTag_AllowedOnlyOnce);
+ }
+ }
+ catch (BadPositionCategoryException e)
+ {
+ // should not happen. Throw an runtime exception so we know about this
+ throw new RuntimeException(e);
+ }
+
+ if (writer.getParentWriter() != null)
+ {
+ ensureNoEarlierImportsLocation(writer.getParentWriter());
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
index 0ee75ff..7814c04 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.codegen.jmerge.PropertyMerger;
import org.eclipse.jdt.core.jdom.DOMFactory;
import org.eclipse.jdt.core.jdom.IDOMCompilationUnit;
import org.eclipse.jdt.core.jdom.IDOMFactory;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
@@ -37,6 +38,9 @@ import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jet.taglib.TagUtil;
import org.eclipse.jet.transform.TransformContextExtender;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
/**
@@ -117,12 +121,12 @@ public class MergeTag extends AbstractEmptyTag
{
String targetPropertiesString = TagUtil.getContents(file.getLocation());
- merger.setSourceProperties(writer.getDocument().get());
+ merger.setSourceProperties(((BufferedJET2Writer)writer).getContent());
merger.setTargetProperties(targetPropertiesString);
merger.merge();
- writer.getDocument().set(merger.getTargetProperties());
+ ((BufferedJET2Writer)writer).setContent(merger.getTargetProperties());
}
catch (CoreException e)
{
@@ -138,10 +142,13 @@ public class MergeTag extends AbstractEmptyTag
*/
private void jmerge(JET2Writer writer, IFile iFile) throws JET2TagException
{
- final Position[] positions = writer.getPositions(JMERGE_POSITION_CATEGORY);
-
+ // cast with impunity - we know the following will work because the writer was set
+ // up this way. If we're wrong, the runtime exception is as good as any.
+ final IDocument document = (IDocument)((BufferedJET2Writer)writer).getAdapter(IDocument.class);
try
{
+ final Position[] positions = document.getPositions(JMERGE_POSITION_CATEGORY);
+
String targetCUSource = TagUtil.getContents(iFile.getLocation());
IDOMFactory domFactory = new DOMFactory();
@@ -153,13 +160,18 @@ public class MergeTag extends AbstractEmptyTag
merger.merge();
- writer.getDocument().set(targetCU.getContents());
+ ((BufferedJET2Writer)writer).setContent(targetCU.getContents());
}
catch (CoreException e)
{
final String msg = JET2Messages.MergeTag_CouldNotRead;
throw new JET2TagException(MessageFormat.format(msg, new Object []{ iFile.getFullPath() }));
}
+ catch (BadPositionCategoryException e)
+ {
+ // This should not happen. Wrap in a runtime exception
+ throw new RuntimeException(e);
+ }
}
/* (non-Javadoc)
@@ -187,6 +199,12 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
*/
public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
+ if(!(out instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)out;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
+
String rules = getAttribute("rules"); //$NON-NLS-1$
if(rules == null)
{
@@ -209,11 +227,11 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
{
URL rulesURL = new URL(baseURL, rules);
- out.getDocument().addPositionCategory(JMERGE_POSITION_CATEGORY);
+ document.addPositionCategory(JMERGE_POSITION_CATEGORY);
- out.addPosition(JMERGE_POSITION_CATEGORY, new MergePosition(rulesURL, out.getDocument().getLength()));
+ document.addPosition(JMERGE_POSITION_CATEGORY, new MergePosition(rulesURL, bufferedWriter.getContentLength()));
- out.addEventListener(JMERGE_POSITION_CATEGORY, new JMergeProcessor());
+ bufferedWriter.addEventListener(JMERGE_POSITION_CATEGORY, new JMergeProcessor());
}
catch (MalformedURLException e)
{
@@ -221,6 +239,14 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
throw new JET2TagException(MessageFormat.format(msg,
new Object[] {baseURL.toExternalForm(), rules}));
}
+ catch (BadLocationException e)
+ {
+ throw new JET2TagException(e);
+ }
+ catch (BadPositionCategoryException e)
+ {
+ throw new JET2TagException(e);
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/CustomTagKind.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/CustomTagKind.java
deleted file mode 100644
index fea4e26..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/CustomTagKind.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.eclipse.jet.taglib;
-
-
-/**
- * An enumeration of the deferent kinds of tags.
- *
- */
-public final class CustomTagKind
-{
-
- /**
- * A tag declared in the tagLibrary extension using the 'tag' element.
- */
- public static final CustomTagKind OTHER = new CustomTagKind("OTHER"); //$NON-NLS-1$
-
- /**
- * A tag declared in the tagLibrary extension using the 'emptyTag' element.
- * Empty tags must take the form of an XML empty tag (&lt;<i>tagName</i> ... /&gt;), and
- * create any content or perform any actions based solely on the elements context and attribute values.
- */
- public static final CustomTagKind EMPTY = new CustomTagKind("EMPTY"); //$NON-NLS-1$
-
- /**
- * A tag declared in the tagLibrary extension using the 'functionTag' element.
- * Function tags must take the form of an XML begin/end tag pair (&lt;tagName ... &;gt><i>content</i>&lt;/tagName&gt;).
- * A function tag creates output by evaluating a function upon the elements content, its context and attribute values.
- */
- public static final CustomTagKind FUNCTION = new CustomTagKind("FUNCTION"); //$NON-NLS-1$
-
- /**
- * A tag declared in the tagLibrary extension using the 'iteratingTag' element.
- * Iterating tags must take the form of an XML begin/end tag pair.
- * An iterating tag creates output by repeating evaluating a condition based on the element's context and attributes.
- * Each time the condition evaluates to <code>true</code>, the elements contents are written to the output.
- */
- public static final CustomTagKind ITERATING = new CustomTagKind("ITERATING"); //$NON-NLS-1$
-
- /**
- * A tag declared in the tagLibrary extension using the 'conditionalTag' element.
- * Conditional tags must take the form of an XML begin/end tag pair.
- * A conditional tag creates output by evaluating a condition based on the element's context and attributes.
- * If the condition evaluates to <code>true</code>, the elements contents are written to the output.
- */
- public static final CustomTagKind CONDITIONAL = new CustomTagKind("CONDITIONAL"); //$NON-NLS-1$
-
- /**
- * A tag declared in the tagLibrary extension using the 'containerTag' element.
- * Container tags must tag the form of an XML begin/end tag pari.
- * A container tag preforms actions prior to its content being processed and
- * after its content has been processed.
- */
- public static final CustomTagKind CONTAINER = new CustomTagKind("CONTAINER"); //$NON-NLS-1$
-
- private final String display;
-
- private CustomTagKind(String display)
- {
- this.display = display;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- return display;
- }
-
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/JET2TagException.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/JET2TagException.java
deleted file mode 100644
index b67e11d..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/JET2TagException.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-/**
- * Encapsulate an execution error during tag execution.
- *
- */
-public class JET2TagException extends RuntimeException
-{
-
- /**
- *
- */
- private static final long serialVersionUID = -2909288156948233977L;
-
- /**
- *
- */
- public JET2TagException()
- {
- super();
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public JET2TagException(String message)
- {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
- */
- public JET2TagException(String message, Throwable cause)
- {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public JET2TagException(Throwable cause)
- {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
index f4bef12..bd2dce1 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
@@ -22,10 +22,13 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
@@ -70,26 +73,31 @@ public class MarkerHelper implements IWriterListener
public void postCommitContent(JET2Writer writer, Object file) throws JET2TagException
{
+ if(!(writer instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)writer;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
if(file instanceof IFile)
{
IFile iFile = (IFile)file;
try
{
iFile.deleteMarkers(TASKMARKER_ID, false, IResource.DEPTH_ZERO);
- Position[] positions = writer.getPositions(MARKER_CATEGORY);
+ Position[] positions = document.getPositions(MARKER_CATEGORY);
for (int i = 0; i < positions.length; i++)
{
MarkerPosition markerPos = (MarkerPosition)positions[i];
final IMarker marker = iFile.createMarker(TASKMARKER_ID);
- int line = writer.getDocument().getLineOfOffset(markerPos.offset);
+ int line = document.getLineOfOffset(markerPos.offset);
int start = markerPos.offset;
int end = markerPos.offset + markerPos.length;
// for empty marked regions, turn this into a marker on the line.
if(start == end)
{
- final IRegion lineInformation = writer.getDocument().getLineInformation(line);
+ final IRegion lineInformation = document.getLineInformation(line);
start = lineInformation.getOffset();
end = start + lineInformation.getLength();
}
@@ -97,7 +105,7 @@ public class MarkerHelper implements IWriterListener
String msg = markerPos.description;
if(msg == null || msg.length() == 0)
{
- msg = writer.getDocument().get(start, end - start);
+ msg = bufferedWriter.getContent(start, end - start);
}
marker.setAttribute(IMarker.LINE_NUMBER, line);
marker.setAttribute(IMarker.CHAR_START, start);
@@ -115,15 +123,50 @@ public class MarkerHelper implements IWriterListener
{
throw new JET2TagException(e);
}
+ catch (BadPositionCategoryException e)
+ {
+ throw new JET2TagException(e);
+ }
}
}
+ /**
+ * Specify a region of the writer that will become a workspace marker when the
+ * file contents are committed.
+ * @param writer the current writter
+ * @param start the start offset of the marker within the current buffer
+ * @param end the offset of the first character after the marker
+ * @param description the marker descrpition
+ * @param tagInfo the tag information of the tag creating the marker. May be <code>null</code>
+ * @param templatePath the path of the currently executing template. May be <code>null</code>.
+ * @throws IllegalArgumentException if writer is not a {@link BufferedJET2Writer}, or if
+ * start and end are not with in the writer contents.
+ */
public static void createMarkerOnWriter(JET2Writer writer, int start, int end, String description, TagInfo tagInfo, String templatePath)
{
- writer.addPositionCategory(MARKER_CATEGORY);
- final MarkerPosition markerPosition = new MarkerPosition(start, end - start, description, tagInfo, templatePath);
- writer.addPosition(MARKER_CATEGORY, markerPosition);
- writer.addEventListener(MARKER_CATEGORY, new MarkerHelper());
+ if(!(writer instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ try
+ {
+ IDocument document = (IDocument)((BufferedJET2Writer)writer).getAdapter(IDocument.class);
+ if(document == null) {
+ throw new UnsupportedOperationException();
+ }
+ document.addPositionCategory(MARKER_CATEGORY);
+ final MarkerPosition markerPosition = new MarkerPosition(start, end - start, description, tagInfo, templatePath);
+ document.addPosition(MARKER_CATEGORY, markerPosition);
+ writer.addEventListener(MARKER_CATEGORY, new MarkerHelper());
+ }
+ catch (BadLocationException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ catch (BadPositionCategoryException e)
+ {
+ // should not happen, wrap in RuntimeException
+ throw new RuntimeException();
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/RuntimeTagElement.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/RuntimeTagElement.java
deleted file mode 100644
index 7df1fc6..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/RuntimeTagElement.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package org.eclipse.jet.taglib;
-
-
-import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.JET2Writer;
-
-
-/**
- * Defines the execution behavior an XML Element in a JET2 compiled template.
- * <P>
- * Clients do not typically use the class directly.
- * </P>
- * <P>
- * The tag has the following life cycle:
- * <BL>
- * <LI>Tag constructor is called.</LI>
- * <LI>Parent tag is set via {@link #setRuntimeParent(RuntimeTagElement) setParent()}. If the tag has no parent, <code>null</code> is passed.</LI>
- * <li>The tag context is set via {@link #setTagInfo(TagInfo)}.</li>
- * <LI>The tag is readied for operation by a call to {@link #doStart(JET2Context, JET2Writer) doStart()}.</LI>
- * <LI>If the element has body content (that is, it is not an empty tag, but a begin-tag/end-tag pair), then
- * {@link #okToProcessBody() okToProcessBody()} is called.</LI>
- * <LI>If {@link #okToProcessBody() okToProcessBody()} returns <code>true</code>, then {@link #handleBodyContent(JET2Writer) handleBodyContent()} is called.</LI>
- * <LI>{@link #okToProcessBody() okToProcessBody()} and {@link #handleBodyContent(JET2Writer) handleBodyContent()} are called
- * repeatedly until {@link #okToProcessBody() okToProcessBody()} returns <code>false</code>.</LI>
- * <LI>Once body processing is complete, {@link #doEnd() doEnd()} is called.</LI>
- * </BL>
- * </P>
- * <P>
- * This interface is not intended to be implemented by clients.
- * </P>
- */
-public interface RuntimeTagElement
-{
-
- /**
- * Set the parent tag of the element. This method always called once, after construction,
- * and before {@link #doStart(JET2Context, JET2Writer) ready()} is called.
- * @param parentTag the parent tag, or <code>null</code> if the tag has no parent in the template.
- */
- public abstract void setRuntimeParent(RuntimeTagElement parentTag);
-
- /**
- * Provide the tag with information on its context within the template, include attribute values
- * and position.
- * @param tagInfo the tag information. Will never by <code>null</code>.
- * @see TagInfo
- */
- public abstract void setTagInfo(TagInfo tagInfo);
-
- /**
- * Return the tag context set by {@link #setTagInfo(TagInfo)}.
- * @return the tag context, or <code>null</code> if not yet set.
- */
- public abstract TagInfo getTagInfo();
-
- /**
- * Perform any actions associated with the start of the tag element.
- * @param context
- * @param out
- */
- public abstract void doStart(JET2Context context, JET2Writer out);
-
- /**
- * Perform any actions associated with the end of the tag element.
- *
- */
- public abstract void doEnd();
-
- /**
- * Determine if the tag element's body should be processed.
- * If the tag element has a body (even an empty body), then this method is called repeatedly until <code>false</code>
- * is returned. Each time <code>true</code> is returned, {@link #handleBodyContent(JET2Writer)} is called.
- *
- * @return <code>true</code> if the body should be processed, <code>false</code> otherwise.
- */
- public abstract boolean okToProcessBody();
-
- /**
- * Handle the body content of the tag element.
- * This method is called once everytime a call to {@link #okToProcessBody() okToProcessBody()} returns <code>true</code>.
- * @param bodyContent the writer containing the body content. Will never by <code>null</code>.
- */
- public abstract void handleBodyContent(JET2Writer bodyContent);
-
- /**
- * Return the context passed to {@link #doStart(JET2Context, JET2Writer)}.
- * @return the context
- */
- public abstract JET2Context getContext();
-
- /**
- * Return the writer passed to {@link #doStart(JET2Context, JET2Writer)}.
- * @return the current output writer
- */
- public abstract JET2Writer getWriter();
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagAttributeDefinition.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagAttributeDefinition.java
deleted file mode 100644
index 4c88c0e..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagAttributeDefinition.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-/**
- * Expose the details of a Custom Tag attribute
- *
- */
-public interface TagAttributeDefinition
-{
-
- /**
- * An attribute whose value is any legal string. Value is "string".
- */
- public static final String STRING_TYPE = "string"; //$NON-NLS-1$
-
- /**
- * An attribute whose value is either "true" or "false". Value is "boolean".
- */
- public static final String BOOLEAN_TYPE = "boolean"; //$NON-NLS-1$
-
- /**
- * An attribute whose value is an XPath expression. "Value is "xpath".
- */
- public static final String XPATH_TYPE = "xpath"; //$NON-NLS-1$
-
- /**
- * Return the attribute's name
- * @return the attribute name
- */
- public abstract String getName();
-
- /**
- * Return the attribute's description if provided
- * @return the description or an empty string.
- */
- public abstract String getDescription();
-
- /**
- * Return the attributes's type
- * @return the attribute's type
- * @see #BOOLEAN_TYPE
- * @see #STRING_TYPE
- * @see #XPATH_TYPE
- */
- public abstract String getType();
-
- /**
- * Test if the element is required
- * @return <code>true</code> if the element is required, <code>false</code> otherwise.
- */
- public abstract boolean isRequired();
-
- /**
- * Test if the element has been deprecated
- * @return <code>true</code> if the element has been deprecated, <code>false</code> otherwise.
- */
- public abstract boolean isDeprecated();
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagDefinition.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagDefinition.java
deleted file mode 100644
index e9e0480..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagDefinition.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-
-
-/**
- * Expose the definition of a tag, as declared in a 'org.eclipse.jet.tagLibraries' extension.
- * <P>
- * This interface is not intended to be implemented by clients.
- * </P>
- */
-public interface TagDefinition
-{
-
- /**
- * Return the name of the tag as it is registered in the tag library
- * @return the tag's name
- */
- public abstract String getName();
-
- public abstract String getDescription();
-
- /**
- * Return the tag kind ({@link CustomTagKind}).
- * @return the tag kind.
- */
- public abstract CustomTagKind getKind();
-
- /**
- * Create a new instance of the tag element
- * @return the created element
- * @throws CoreException if the element cannot be created
- */
- public abstract CustomTag newTagElement() throws CoreException;
-
- /**
- * Return the definition of the named attribute
- * @param name the attribute name
- * @return the attribute definition, or <code>null</code> if the <code>name</code> is not
- * an attribute of the named tag.
- */
- public abstract TagAttributeDefinition getAttributeDefinition(String name);
-
- /**
- * Return a list of attribute definitions for this tag
- * @return a List of {@link TagAttributeDefinition} objects. The empty list is returned if there
- * are no attribute definitions for this tag definition.
- */
- public abstract List getAttributeDefinitions();
-
- /**
- * Test if the tag is declared to be deprecated.
- * @return <code>true</code> if the tag is deprecated.
- */
- public abstract boolean isDeprecated();
-
- /**
- * Test whether the tag requires a new writer for its contents.
- * The following tag declaration will have the value set to <code>true</code>:
- * <bl>
- * <li><code>functionTag</code></li>
- * <li><code>containerTag</code> with <code>processContents</code> set to <code>custom</code>.</li>
- * <li><code>conditionalTag</code> with <code>processContents</code> set to <code>custom</code>.</li>
- * <li><code>iteratingTag</code> with <code>processContents</code> set to <code>custom</code>.</li>
- * </bl>
- * @return <code>true</code> if a new writer is required, <code>false</code> otherwise.
- */
- public abstract boolean requiresNewWriter();
-
- /**
- * Test whether the tag is allowed to be specified in the empty tag form: &lt;tagName/&gt;.
- * The following tag declarations will have the value set to <code>true</code>.
- * <bl>
- * <li><code>emptyTag</code></li>
- * <li><code>containerTag</code> with <code>allowAsEmpty</code> set to <code>true</code>.</li>
- * </bl>
- * @return <code>true</code> if the tag may be expressed as a empty tag.
- */
- public abstract boolean isEmptyTagAllowed();
-
- /**
- * Test whether the tag is allowed to have content (even empty content). That is, this
- * method tests whether a tag of the form:
- * <blockquote>
- * &lt;tagName&gt; ... &lt;/tagName&gt;
- * </blockquote>
- * The following tag declarations will have the value set to <code>true</code>:
- * <bl>
- * <li><code>functionTag</code></li>
- * <li><code>containerTag</code></li>
- * <li><code>conditionalTag</code></li>
- * <li><code>iteratingTag</code></li>
- * </bl>
- * @return <code>true</code> if the tag may be expressed as a content tag.
- */
- public abstract boolean isContentAllowed();
-
- /**
- * Return the {@link TagLibrary} that contains this tag definition.
- * @return a TagLibrary instance.
- */
- public abstract TagLibrary getTagLibrary();
-
- /**
- * Indicate whether the compiler should remove whitespace including the trailing
- * new line from tags that occur on an otherwise empty line.
- * @return <code>true</code> if such whitespace should be removed.
- */
- public abstract boolean removeWhenContainingLineIsEmpty();
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagFactory.java
deleted file mode 100644
index ce932e9..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-/**
- * Factory used by compiled JET2 templates to instantiate
- * custom XML Elements.
- * <p>
- * This class is not typically used directly by clients.
- * </p>
- */
-public interface TagFactory
-{
-
- RuntimeTagElement createRuntimeTag(String libraryId, String tagNCName, String tagQName, TagInfo tagInfo);
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagInfo.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagInfo.java
deleted file mode 100644
index 109f509..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagInfo.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-
-/**
- * Define contextual information for a custom tag. The class is immutable. The Tag context is
- * the mechanism by which custom tag code accesses the tag parameters code in a template.
- * <p>Contextual information includes:</p>
- * <bl>
- * <li>the tag location in the source template (line # and start, end offsets)</li>
- * <li>the raw attribute values as specified in template.
- * </bl>
- * <p>
- * <b>This class is instantiated in the compiled JET2 template. Clients would not normally instantiate
- * instances of this class.</b>
- * </p>
- */
-public final class TagInfo
-{
-
- private final int line;
-
- private final Map attrMap;
-
- private final String tagName;
-
- private final int col;
-
- public TagInfo(String tagName, int line, int col, String[] attrNames, String attrValues[])
- {
- this.tagName = tagName;
- this.line = line;
- this.col = col;
-
- if (attrNames == null || attrValues == null)
- {
- throw new NullPointerException();
- }
- if (attrNames.length != attrValues.length)
- {
- throw new IllegalArgumentException();
- }
- // use Linked has map so that attributes retain their original order.
- this.attrMap = new LinkedHashMap(attrNames.length);
- for (int i = 0; i < attrNames.length; i++)
- {
- attrMap.put(attrNames[i], attrValues[i]);
- }
- }
-
- /**
- * Construct a TagInfo
- * @param tagName
- * @param line
- * @param start
- * @param end
- * @param attrNames
- * @param attrValues
- * @deprecated Use {@link #TagInfo(String, int, int, String[], String[])} instead.
- */
- public TagInfo(String tagName, int line, int start, int end, String[] attrNames, String[] attrValues)
- {
- this(tagName, line, 1, attrNames, attrValues);
- }
-
- /**
- * Return the one-based line number of the start of the tag.
- * @return Returns the line.
- */
- public final int getLine()
- {
- return line;
- }
-
- /**
- * Return the value of an attribute.
- * @param name the attribute name. Cannot be <code>null</code>.
- * @return the attribute value, or <code>null</code> if the attribute was not set on the tag.
- * @throws NullPointerException if <code>name</code> is <code>null</code>.
- */
- public final String getAttribute(String name)
- {
- if (name == null)
- {
- throw new NullPointerException();
- }
- return (String)attrMap.get(name);
- }
-
- /**
- * Test whether an attribute value was set.
- * @param name the attribute name. Cannot be <code>null</code>.
- * @return <code>true</code> if the attribute was set, <code>false</code> otherwise.
- * @throws NullPointerException if <code>name</code> is <code>null</code>.
- */
- public final boolean hasAttribute(String name)
- {
- return attrMap.containsKey(name);
- }
-
- public String toString()
- {
- return "[" + line + ":" + col + " " + tagName + " " + attrMap + "]"; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**
- * Return the tag name, as specified in the input, complete with namespace prefix.
- * @return Returns the tagName.
- */
- public final String getTagName()
- {
- return tagName;
- }
-
- /**
- * Return an array of attribute names
- * @return an possibly empty array of String values.
- */
- public final String[] getAttributeNames()
- {
- return (String[])attrMap.keySet().toArray(new String[attrMap.size()]);
- }
-
- /**
- * Return the one-based column number of the start of the tag withing the tag's start line.
- * @return Returns the col.
- */
- public final int getCol()
- {
- return col;
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibrary.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibrary.java
deleted file mode 100644
index 7c9db57..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibrary.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.taglib;
-
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jet.taglib.CustomTag;
-import org.eclipse.jet.taglib.TagDefinition;
-
-
-/**
- * Provide access to the tags in a tag library.
- *
- * <P>
- * This interface is not intended to be implemented by clients.
- * </P>
- */
-public interface TagLibrary
-{
-
- /**
- * Return the string identifier of the tag library.
- * @return the tag library id
- */
- public abstract String getLibraryId();
-
- public abstract String getLibraryName();
-
- public abstract String getDefaultPrefix();
-
- public abstract String getDescription();
-
- /**
- * Return the {@link TagDefinition} for the named tag.
- * @param name the name of a tag in the tag library.
- * @return the definitions or <code>null</code> if the named tag is in the library
- * @throws NullPointerException if <code>name</code> is null.
- */
- public abstract TagDefinition getTagDefinition(String name);
-
- /**
- * Return a sort array of tags in the library
- * @return an array of Strings; an empty array is returned if the library has no tags.
- */
- public abstract String[] getTagNames();
-
- /**
- *
- * @param tagNCName the unqualified name of the tag
- * @return the new tag element
- * @throws CoreException if the custom tag cannot be created
- */
- public abstract CustomTag newTagElement(String tagNCName) throws CoreException;
-
- /**
- * Test if the named tag is in the tag library.
- * @param tagNCName
- * @return if the tag is defined by the library
- */
- public abstract boolean hasTag(String tagNCName);
-
- /**
- * Test if the tag library has been deprecated.
- * @return <code>true</code> if the library has been deprecated, <code>false</code> otherwise.
- */
- public abstract boolean isDeprecated();
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java
deleted file mode 100644
index aaaf2e5..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-package org.eclipse.jet.taglib;
-
-/**
- * Represent a reference to a tag library by a template or a transform.
- */
-public interface TagLibraryReference
-{
-
- /**
- * Return the prefix that is mapped to the tag library.
- * @return a string
- */
- public abstract String getPrefix();
-
- /**
- * Return the tag library id.
- * @return a string
- */
- public abstract String getTagLibraryId();
-
- /**
- * Return the TagLibrary description object.
- * @return an TagLibrary instance
- */
- public abstract TagLibrary getTagLibrary();
-
- /**
- * Test whether the tag library is automatically imported bundle templates.
- * @return <code>true</code> if the library is an auto imported library.
- */
- public abstract boolean isAutoImport();
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
index 105fc59..d9c6acc 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
@@ -3,9 +3,11 @@ package org.eclipse.jet.taglib;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -58,10 +60,12 @@ public final class UserRegionHelper implements IWriterListener
public void finalizeContent(JET2Writer writer, Object file)
{
- if (file instanceof IFile)
+ if (file instanceof IFile && writer instanceof BufferedJET2Writer)
{
IFile iFile = (IFile)file;
- if (iFile.exists())
+ BufferedJET2Writer bufferedwriter = (BufferedJET2Writer)writer;
+ IDocument document = (IDocument)bufferedwriter.getAdapter(IDocument.class);
+ if (iFile.exists() && document != null)
{
String fileContents;
try
@@ -73,12 +77,11 @@ public final class UserRegionHelper implements IWriterListener
return;
}
- Position[] rtPositions = writer.getPositions(UserRegionHelper.USERREGION_POSITION_CATEGORY);
- Position[] icPositions = writer.getPositions(UserRegionHelper.INITIALCODE_POSITION_CATEGORY);
- IDocument document = writer.getDocument();
- for (int i = 0; i < rtPositions.length; i++)
+ try
{
- try
+ Position[] rtPositions = document.getPositions(UserRegionHelper.USERREGION_POSITION_CATEGORY);
+ Position[] icPositions = document.getPositions(UserRegionHelper.INITIALCODE_POSITION_CATEGORY);
+ for (int i = 0; i < rtPositions.length; i++)
{
// don't assume there will be an initial code
// position, find it...
@@ -99,8 +102,8 @@ public final class UserRegionHelper implements IWriterListener
final Position endMarkerPosition = new Position(endMarkerOffset, userRegionPosition.offset + userRegionPosition.length
- endMarkerOffset);
- final String beginMarker = document.get(beginMarkerPosition.offset, beginMarkerPosition.length);
- final String endMarker = document.get(endMarkerPosition.offset, endMarkerPosition.length);
+ final String beginMarker = bufferedwriter.getContent(beginMarkerPosition.offset, beginMarkerPosition.length);
+ final String endMarker = bufferedwriter.getContent(endMarkerPosition.offset, endMarkerPosition.length);
final int existingRegionOffset = fileContents.indexOf(beginMarker);
if (existingRegionOffset != -1)
@@ -109,21 +112,20 @@ public final class UserRegionHelper implements IWriterListener
if (existingEndMarkerOffset != -1)
{
final String existingRegion = fileContents.substring(existingRegionOffset, existingEndMarkerOffset + endMarker.length());
- if (!existingRegion.equals(document.get(userRegionPosition.offset, userRegionPosition.length))
+ if (!existingRegion.equals(bufferedwriter.getContent(userRegionPosition.offset, userRegionPosition.length))
&& (unmodifiedMarker == null || existingRegion.indexOf(unmodifiedMarker) == -1))
{
- document.replace(userRegionPosition.offset, userRegionPosition.length, existingRegion);
+ bufferedwriter.replaceContent(userRegionPosition.offset, userRegionPosition.length, existingRegion);
}
}
}
-
- }
- catch (BadLocationException e)
- {
- // should not happen
- throw new RuntimeException(e);
}
}
+ catch (BadPositionCategoryException e)
+ {
+ // should not happen. Track with a Runtime exception
+ throw new RuntimeException(e);
+ }
}
}
@@ -163,17 +165,37 @@ public final class UserRegionHelper implements IWriterListener
*/
public static void markInitialCode(JET2Writer out, final int initialCodeStart, int initialCodeEnd, String unmodifiedMarker)
{
- out.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
- if (unmodifiedMarker == null)
+ if(!(out instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)out;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
+ if(document == null) {
+ throw new NullPointerException();
+ }
+ document.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
+ try
+ {
+ if (unmodifiedMarker == null)
+ {
+ document.addPosition(INITIALCODE_POSITION_CATEGORY, new Position(initialCodeStart, initialCodeEnd - initialCodeStart));
+ }
+ else
+ {
+ document.addPosition(INITIALCODE_POSITION_CATEGORY, new PositionWithUnmodifiedMarker(
+ initialCodeStart,
+ initialCodeEnd - initialCodeStart,
+ unmodifiedMarker));
+ }
+ }
+ catch (BadLocationException e)
{
- out.addPosition(INITIALCODE_POSITION_CATEGORY, new Position(initialCodeStart, initialCodeEnd - initialCodeStart));
+ throw new IllegalArgumentException();
}
- else
+ catch (BadPositionCategoryException e)
{
- out.addPosition(INITIALCODE_POSITION_CATEGORY, new PositionWithUnmodifiedMarker(
- initialCodeStart,
- initialCodeEnd - initialCodeStart,
- unmodifiedMarker));
+ // should not happen. We did an addPositionCategory. Throw a runtime exception to track
+ throw new RuntimeException(e);
}
}
@@ -197,8 +219,29 @@ public final class UserRegionHelper implements IWriterListener
*/
public static void markUserRegion(JET2Writer out, int regionStart, int regionEnd)
{
- out.addPositionCategory(USERREGION_POSITION_CATEGORY);
- out.addPosition(USERREGION_POSITION_CATEGORY, new Position(regionStart, regionEnd - regionStart));
- out.addEventListener(ROUNDTRIP_LISTENER_CATEGORY, new UserRegionHelper());
+ if(!(out instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)out;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
+ if(document == null) {
+ throw new NullPointerException();
+ }
+ document.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
+ document.addPositionCategory(USERREGION_POSITION_CATEGORY);
+ try
+ {
+ document.addPosition(USERREGION_POSITION_CATEGORY, new Position(regionStart, regionEnd - regionStart));
+ out.addEventListener(ROUNDTRIP_LISTENER_CATEGORY, new UserRegionHelper());
+ }
+ catch (BadLocationException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ catch (BadPositionCategoryException e)
+ {
+ // Should not happen - we did addPositionCategory. Throw a RuntimeException to track this.
+ throw new RuntimeException(e);
+ }
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
index 86bb471..48456dc 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
@@ -33,6 +33,7 @@ import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
@@ -41,6 +42,8 @@ import org.eclipse.jet.internal.taglib.java.ImportsLocationTag.ImportsPosition;
import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.workspace.ActionsUtil;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -178,23 +181,36 @@ public class JavaActionsUtil
*/
public static ImportManager getImportManager(JET2Writer writer) throws JET2TagException
{
-
+ if(!(writer instanceof BufferedJET2Writer)) {
+ throw new IllegalArgumentException();
+ }
+ BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)writer;
+ IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
+
// defensive add of the category...
- writer.addPositionCategory(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+ document.addPositionCategory(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
- Position[] positions = writer.getPositions(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
- if (positions.length > 0)
+ try
{
- ImportsPosition position = (ImportsPosition)positions[0];
- return position.getImportManager();
- }
- else if (writer.getParentWriter() != null)
- {
- return getImportManager(writer.getParentWriter());
+ Position[] positions = document.getPositions(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+ if (positions.length > 0)
+ {
+ ImportsPosition position = (ImportsPosition)positions[0];
+ return position.getImportManager();
+ }
+ else if (writer.getParentWriter() != null)
+ {
+ return getImportManager(writer.getParentWriter());
+ }
+ else
+ {
+ throw new JET2TagException(JET2Messages.ImportsLocationTag_MissingImportsLocation);
+ }
}
- else
+ catch (BadPositionCategoryException e)
{
- throw new JET2TagException(JET2Messages.ImportsLocationTag_MissingImportsLocation);
+ // Should not happen. Track with a runtime exception
+ throw new RuntimeException(e);
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
index 55f4e1d..4a41a1d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
@@ -44,6 +44,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.JET2TagException;
@@ -105,18 +106,36 @@ public final class ActionsUtil
JET2Writer writer,
IProgressMonitor monitor) throws JET2TagException
{
- writer.finalizeContent(file);
+ finalizeContent(writer, file);
boolean written = writeTextFile(file, replace, encoding, derived, writer.toString(), monitor);
if (written)
{
- writer.contentCommitted(file);
+ contentCommitted(writer, file);
}
return written;
}
+ private static final void finalizeContent(JET2Writer writer, Object committedObject) throws JET2TagException
+ {
+ final IWriterListener[] eventListeners = writer.getEventListeners();
+ for (int i = 0; i < eventListeners.length; i++)
+ {
+ eventListeners[i].finalizeContent(writer, committedObject);
+ }
+ }
+
+ private static final void contentCommitted(JET2Writer writer, Object committedObject) throws JET2TagException
+ {
+ final IWriterListener[] eventListeners = writer.getEventListeners();
+ for (int i = 0; i < eventListeners.length; i++)
+ {
+ eventListeners[i].postCommitContent(writer, committedObject);
+ }
+ }
+
/**
* Write the specified text file from a string.
* @param file the file to write
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java
index 26bec87..78d3f20 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java
@@ -18,8 +18,8 @@ package org.eclipse.jet.transform;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2TemplateLoader;
+import org.osgi.framework.BundleException;
/**
@@ -61,18 +61,18 @@ public interface IJETBundleManager
* @param id the transform id
* @param runnable a runnable
* @param monitor a progress monitor
- * @throws CoreJETException if an error occurs loading the transform bundle.
+ * @throws BundleException TODO
*/
- public abstract void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException;
+ public abstract void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws BundleException;
/**
* Record a connection to the specified JET transform bundle. If this is the first connection, the bundle is
* loaded.
* @param id the transform id
* @param monitor a progress monitor
- * @throws CoreJETException if an error occurs loading the transform bundle.
+ * @throws BundleException TODO
*/
- public abstract void connect(String id, IProgressMonitor monitor) throws CoreJETException;
+ public abstract void connect(String id, IProgressMonitor monitor) throws BundleException;
/**
* Record a disconnection fromt he specified JET transform bundle. If this is the last connection, the bundle
@@ -86,9 +86,9 @@ public interface IJETBundleManager
* must be bracketed by calls to {@link #connect(String, IProgressMonitor)} and {@link #disconnect(String)}.
* @param id the JET transform
* @return the template loader instance
- * @throws CoreJETException if the loader could not be found or loaded.
+ * @throws BundleException TODO
*/
- public abstract JET2TemplateLoader getTemplateLoader(String id) throws CoreJETException;
+ public abstract JET2TemplateLoader getTemplateLoader(String id) throws BundleException;
/**
* Return an array of transform available ids.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
index 1dacebb..bff316e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
@@ -47,6 +47,7 @@ import org.eclipse.jet.internal.runtime.model.WorkspaceLoadContext;
import org.eclipse.jet.runtime.model.ILoadContext;
import org.eclipse.jet.runtime.model.IModelLoader;
import org.eclipse.jet.taglib.JET2TagException;
+import org.osgi.framework.BundleException;
/**
@@ -393,7 +394,7 @@ public class TransformContextExtender extends AbstractContextExtender
throw new JET2TagException(MessageFormat.format(msg, new Object[] {getId()}));
}
}
- catch (CoreJETException e)
+ catch (BundleException e)
{
throw new JET2TagException(e);
}
@@ -433,7 +434,7 @@ public class TransformContextExtender extends AbstractContextExtender
execute(descriptor.getMainTemplate(), new BodyContentWriter());
}
- catch (CoreJETException e)
+ catch (BundleException e)
{
throw new JET2TagException(e);
}
diff --git a/plugins/org.eclipse.jet/templates/v1/jet2java.jet b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
new file mode 100644
index 0000000..9daafd4
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
@@ -0,0 +1,79 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates.v1"
+ class="JET1JavaGenerator"
+ %>
+<%@jet imports="org.eclipse.jet.tools.parser.ast.*"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.SafeJETASTVisitor"%>
+<%@jet imports="java.util.Iterator"%>
+<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
+<%
+ JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
+%>
+package <%= cu.getOutputJavaPackage() %>;
+
+<% for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ String importName = (String)i.next();%>
+import <%=importName%>;
+<% } %>
+
+public class <%= cu.getOutputJavaClassName() %>
+{
+<% cu.accept(new SafeJETASTVisitor(context,out) {
+ public boolean visit(JavaDeclaration decl) {
+%>
+ <%= decl.getJavaContent() %>
+<%
+ return true;
+ }
+ });
+%>
+ protected static String nl;
+ public static synchronized <%= cu.getOutputJavaClassName() %> create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ <%= cu.getOutputJavaClassName() %> result = new <%= cu.getOutputJavaClassName() %>();
+ nl = null;
+ return result;
+ }
+
+ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+<% cu.accept(new SafeJETASTVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ textCount++;
+%>
+ protected final String TEXT_<%=textCount%> = <%=JavaUtil.asJavaQuoteStringWithNLRemoved(text.getText())%>;<%=JavaUtil.nlsCommentsForJavaQuoteStringWithNLRemoved(text.getText())%>
+<%
+ return true;
+ }
+ });
+%>
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+<% cu.accept(new SafeJETASTVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ textCount++;
+%>
+ stringBuffer.append(TEXT_<%=textCount%>);
+<%
+ return true;
+ }
+ public boolean visit(JavaScriptlet scriptlet) {
+%>
+ <%= scriptlet.getJavaContent() %>
+<%
+ return true;
+ }
+ public boolean visit(JavaExpression expr) {
+%>
+ stringBuffer.append(<%= expr.getJavaContent() %>);
+<%
+ return true;
+ }
+ });
+%>
+ return stringBuffer.toString();
+ }
+}
diff --git a/plugins/org.eclipse.jet/templates/v2/jet2java.jet b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
new file mode 100644
index 0000000..2015776
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
@@ -0,0 +1,160 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates.v2"
+ class="JET2JavaGeneratorNew"
+ %>
+<%@jet imports="org.eclipse.jet.tools.parser.ast.*"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.V2CodeGenVisitor"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.TagUsageVisitor"%>
+<%@jet imports="org.eclipse.jet.taglib.TagLibraryReference"%>
+<%@jet imports="java.util.Iterator"%>
+<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
+<%
+ JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
+ TagUsageVisitor tuv = new TagUsageVisitor();
+ cu.accept(tuv);
+ TagLibraryReference[] tlrefs = tuv.getUsedTagLibraryReferences(cu);
+%>
+package <%= cu.getOutputJavaPackage() %>;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+<% if(tuv.hasTags()) { %>
+import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagInfo;
+<% } %>
+<% for(Iterator i=cu.getImports().iterator();i.hasNext();) { %>
+import <%= (String)i.next() %>;
+<% } %>
+
+public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
+<% for(int i = 0; i < tlrefs.length; i++ ) { %>
+ private static final String _jetns_<%= tlrefs[i].getPrefix() %> = "<%= tlrefs[i].getTagLibraryId() %>"; //$NON-NLS-1$
+<% } %>
+
+<% cu.accept(new V2CodeGenVisitor(context,out) {
+ public boolean visit(JavaDeclaration decl) {
+%>
+ <%= decl.getJavaContent() %>
+<%
+ return true;
+ }
+ });
+%>
+ public <%= cu.getOutputJavaClassName() %>() {
+ super();
+ }
+
+ private static final String NL = System.getProperties().getProperty("line.separator");
+
+ private static final class _TEXT {
+<% cu.accept(new V2CodeGenVisitor(context,out) {
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ if(text.getText().length > 0) {
+%>
+ private static final String <%= textVar(++textCount) %> = <%=textExpr(text)%>;<%=nlsComment(text)%>
+<%
+ }
+ return true;
+ }
+ });
+%>
+ }
+
+<% if(tuv.hasTags()) { %>
+ private static final class _TAGS {
+<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
+ public boolean visit(XMLBodyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public boolean visit(XMLEmptyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public void doElementVisit(XMLElement e) {
+%>
+ private static final TagInfo <%= tagInfoVar(e) %> = new TagInfo("<%=e.getName()%>", //$NON-NLS-1$
+ <%= e.getLine() %>, <%= e.getColumn() %>,
+ new String[] {
+<% for (Iterator i = e.getAttributes().keySet().iterator(); i.hasNext();) { %>
+ "<%= (String) i.next() %>", //$NON-NLS-1$
+<% } %>
+ },
+ new String[] {
+<% for (Iterator i = e.getAttributes().values().iterator(); i.hasNext();) {
+ String attrValue = (String) i.next(); %>
+ "<%= JavaUtil.escapeJavaString(attrValue.toCharArray()) %>", //$NON-NLS-1$
+<% } %>
+ } );
+<% }
+ }); %>
+ }
+<% } %>
+
+ public void generate(final JET2Context context, JET2Writer out) {
+<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
+ private int textCount = 0;
+ public boolean visit(TextElement text) {
+ if(text.getText().length > 0) {
+%>
+ out.write(_TEXT.<%=textVar(++textCount)%>);
+<%
+ }
+ return true;
+ }
+ public boolean visit(JavaScriptlet scriptlet) {
+%>
+ <%= scriptlet.getJavaContent() %>
+<%
+ return true;
+ }
+ public boolean visit(JavaExpression expr) {
+%>
+ out.write(<%= expr.getJavaContent() %>);
+<%
+ return true;
+ }
+ public boolean visit(XMLBodyElement e) {
+%>
+ RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _TAGS.<%= tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
+ <%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
+ <%= tagVar(e) %>.setTagInfo(_TAGS.<%= tagInfoVar(e) %>);
+ <%= tagVar(e) %>.doStart(context, out);
+<% if(requiresOwnWriter(e)) { %>
+ JET2Writer <%= tagVar(e) %>_saved_out = out;
+<% } %>
+ while (<%= tagVar(e) %>.okToProcessBody()) {
+<% if(requiresOwnWriter(e)) { %>
+ out = out.newNestedContentWriter();
+<% } %>
+<%
+ in();
+ return true;
+ }
+ public void endVisit(XMLBodyElement e) {
+ out();
+%>
+ <%= tagVar(e) %>.handleBodyContent(out);
+ }
+<% if(requiresOwnWriter(e)) { %>
+ out = <%= tagVar(e) %>_saved_out;
+<% } %>
+ <%= tagVar(e) %>.doEnd();
+<%
+
+ }
+ public boolean visit(XMLEmptyElement e) {
+%>
+ RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _TAGS.<%= tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
+ <%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
+ <%= tagVar(e) %>.setTagInfo(_TAGS.<%= tagInfoVar(e) %>);
+ <%= tagVar(e) %>.doStart(context, out);
+ <%= tagVar(e) %>.doEnd();
+<%
+ return true;
+ }
+ });
+%>
+ }
+}
diff --git a/tests/org.eclipse.jet.tests-feature/feature.xml b/tests/org.eclipse.jet.tests-feature/feature.xml
index 39775c2..69d7c27 100644
--- a/tests/org.eclipse.jet.tests-feature/feature.xml
+++ b/tests/org.eclipse.jet.tests-feature/feature.xml
@@ -55,4 +55,11 @@ http://www.eclipse.org/legal/epl-v10.html
version="0.0.0"
fragment="true"/>
+ <plugin
+ id="org.eclipse.jet.tests.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
diff --git a/tests/org.eclipse.jet.tests/.classpath b/tests/org.eclipse.jet.tests/.classpath
index 751c8f2..ce73933 100644
--- a/tests/org.eclipse.jet.tests/.classpath
+++ b/tests/org.eclipse.jet.tests/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.core.prefs
index f32ef68..96cf3d5 100644
--- a/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,21 @@
-#Thu Feb 02 16:59:31 EST 2006
+#Tue Apr 03 15:27:11 EDT 2007
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
@@ -47,3 +56,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..f992ce5
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Tue Apr 03 14:56:39 EDT 2007
+eclipse.preferences.version=1
+internal.default.compliance=user
diff --git a/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
index 5570f00..bd84436 100644
--- a/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
@@ -15,3 +15,4 @@ Require-Bundle: org.eclipse.jet,
org.eclipse.core.filebuffers,
org.eclipse.core.resources
Bundle-Vendor: %providerName
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/changedTemplates/simple.v2.input.jet b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/changedTemplates/simple.v2.input.jet
new file mode 100644
index 0000000..3681ee5
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/changedTemplates/simple.v2.input.jet
@@ -0,0 +1,11 @@
+<%@jet class="ChangedInput"%>
+<%@taglib id="org.eclipse.jet.tests.TestLibrary" prefix="test" %>
+"isAllUpper", "nl", "other", "tokenize", "upper"
+
+<test:tokenize string="a,b,c,d,e,f,g" sep="," var="token">
+<test:other>some text</test:other>
+<test:isAllUpper var="token">
+</test:isAllUpper>
+<test:upper>foo</test:upper><test:nl/>
+<test:other/>
+</test:tokenize> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet
new file mode 100644
index 0000000..2bc9dfc
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet
@@ -0,0 +1,10 @@
+<%@taglib id="org.eclipse.jet.tests.TestLibrary" prefix="test" %>
+"isAllUpper", "nl", "other", "tokenize", "upper"
+
+<test:tokenize string="a,b,c,d,e,f,g" sep="," var="token">
+<test:other>some text</test:other>
+<test:isAllUpper var="token">
+</test:isAllUpper>
+<test:upper>foo</test:upper><test:nl/>
+<test:other/>
+</test:tokenize> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java
new file mode 100644
index 0000000..92b9eeb
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java
@@ -0,0 +1,125 @@
+package org.eclipse.jet.compiled;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagInfo;
+
+public class _jet_simplev2input implements JET2Template {
+ private static final String _jetns_test = "org.eclipse.jet.tests.TestLibrary"; //$NON-NLS-1$
+
+ public _jet_simplev2input() {
+ super();
+ }
+
+ private static final String NL = System.getProperties().getProperty("line.separator");
+
+ private static final class _TEXT {
+ private static final String TEXT_1 = "\"isAllUpper\", \"nl\", \"other\", \"tokenize\", \"upper\"" + NL + NL; //$NON-NLS-1$
+ private static final String TEXT_2 = "some text"; //$NON-NLS-1$
+ private static final String TEXT_3 = NL;
+ private static final String TEXT_4 = "foo"; //$NON-NLS-1$
+ private static final String TEXT_5 = NL;
+ }
+
+ private static final class _TAGS {
+ private static final TagInfo test_tokenize_4_1 = new TagInfo("test:tokenize", //$NON-NLS-1$
+ 4, 1,
+ new String[] {
+ "sep", //$NON-NLS-1$
+ "var", //$NON-NLS-1$
+ "string", //$NON-NLS-1$
+ },
+ new String[] {
+ ",", //$NON-NLS-1$
+ "token", //$NON-NLS-1$
+ "a,b,c,d,e,f,g", //$NON-NLS-1$
+ } );
+ private static final TagInfo test_other_5_1 = new TagInfo("test:other", //$NON-NLS-1$
+ 5, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ private static final TagInfo test_isAllUpper_6_1 = new TagInfo("test:isAllUpper", //$NON-NLS-1$
+ 6, 1,
+ new String[] {
+ "var", //$NON-NLS-1$
+ },
+ new String[] {
+ "token", //$NON-NLS-1$
+ } );
+ private static final TagInfo test_upper_8_1 = new TagInfo("test:upper", //$NON-NLS-1$
+ 8, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ private static final TagInfo test_nl_8_29 = new TagInfo("test:nl", //$NON-NLS-1$
+ 8, 29,
+ new String[] {
+ },
+ new String[] {
+ } );
+ private static final TagInfo test_other_9_1 = new TagInfo("test:other", //$NON-NLS-1$
+ 9, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+ out.write(_TEXT.TEXT_1);
+ RuntimeTagElement _jettag_test_tokenize_4_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "tokenize", "test:tokenize", _TAGS.test_tokenize_4_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_tokenize_4_1.setRuntimeParent(null);
+ _jettag_test_tokenize_4_1.setTagInfo(_TAGS.test_tokenize_4_1);
+ _jettag_test_tokenize_4_1.doStart(context, out);
+ while (_jettag_test_tokenize_4_1.okToProcessBody()) {
+ RuntimeTagElement _jettag_test_other_5_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "other", "test:other", _TAGS.test_other_5_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_other_5_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_other_5_1.setTagInfo(_TAGS.test_other_5_1);
+ _jettag_test_other_5_1.doStart(context, out);
+ while (_jettag_test_other_5_1.okToProcessBody()) {
+ out.write(_TEXT.TEXT_2);
+ _jettag_test_other_5_1.handleBodyContent(out);
+ }
+ _jettag_test_other_5_1.doEnd();
+ out.write(_TEXT.TEXT_3);
+ RuntimeTagElement _jettag_test_isAllUpper_6_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "isAllUpper", "test:isAllUpper", _TAGS.test_isAllUpper_6_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_isAllUpper_6_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_isAllUpper_6_1.setTagInfo(_TAGS.test_isAllUpper_6_1);
+ _jettag_test_isAllUpper_6_1.doStart(context, out);
+ while (_jettag_test_isAllUpper_6_1.okToProcessBody()) {
+ _jettag_test_isAllUpper_6_1.handleBodyContent(out);
+ }
+ _jettag_test_isAllUpper_6_1.doEnd();
+ RuntimeTagElement _jettag_test_upper_8_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "upper", "test:upper", _TAGS.test_upper_8_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_upper_8_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_upper_8_1.setTagInfo(_TAGS.test_upper_8_1);
+ _jettag_test_upper_8_1.doStart(context, out);
+ JET2Writer _jettag_test_upper_8_1_saved_out = out;
+ while (_jettag_test_upper_8_1.okToProcessBody()) {
+ out = out.newNestedContentWriter();
+ out.write(_TEXT.TEXT_4);
+ _jettag_test_upper_8_1.handleBodyContent(out);
+ }
+ out = _jettag_test_upper_8_1_saved_out;
+ _jettag_test_upper_8_1.doEnd();
+ RuntimeTagElement _jettag_test_nl_8_29 = context.getTagFactory().createRuntimeTag(_jetns_test, "nl", "test:nl", _TAGS.test_nl_8_29); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_nl_8_29.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_nl_8_29.setTagInfo(_TAGS.test_nl_8_29);
+ _jettag_test_nl_8_29.doStart(context, out);
+ _jettag_test_nl_8_29.doEnd();
+ out.write(_TEXT.TEXT_5);
+ RuntimeTagElement _jettag_test_other_9_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "other", "test:other", _TAGS.test_other_9_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_other_9_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_other_9_1.setTagInfo(_TAGS.test_other_9_1);
+ _jettag_test_other_9_1.doStart(context, out);
+ _jettag_test_other_9_1.doEnd();
+ _jettag_test_tokenize_4_1.handleBodyContent(out);
+ }
+ _jettag_test_tokenize_4_1.doEnd();
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input2.jet b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input2.jet
new file mode 100644
index 0000000..2bc9dfc
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input2.jet
@@ -0,0 +1,10 @@
+<%@taglib id="org.eclipse.jet.tests.TestLibrary" prefix="test" %>
+"isAllUpper", "nl", "other", "tokenize", "upper"
+
+<test:tokenize string="a,b,c,d,e,f,g" sep="," var="token">
+<test:other>some text</test:other>
+<test:isAllUpper var="token">
+</test:isAllUpper>
+<test:upper>foo</test:upper><test:nl/>
+<test:other/>
+</test:tokenize> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java
new file mode 100644
index 0000000..c73aeff
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java
@@ -0,0 +1,80 @@
+package org.eclipse.jet.compiled;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2TemplateLoaderExtension;
+import org.eclipse.jet.JET2Template;
+
+public class TemplateLoaderClass implements JET2TemplateLoader, JET2TemplateLoaderExtension {
+
+ private static final class TemplateFactoryMethod {
+
+ private final String templatePath;
+ private final String templateClass;
+
+ public TemplateFactoryMethod(String templatePath, String templateClass) {
+ this.templatePath = templatePath;
+ this.templateClass = templateClass;
+
+ }
+
+ public String getTemplateClass() {
+ return templateClass;
+ }
+
+ public String getTemplatePath() {
+ return templatePath;
+ }
+
+ public JET2Template newTemplate() {
+ JET2Template template = null;
+ try {
+ template = (JET2Template) Class.forName(templateClass).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+ return template;
+ }
+
+
+ }
+
+ private Map pathToFactoryMap = null;
+
+ private JET2TemplateLoader delegate = null;
+
+ public TemplateLoaderClass() {
+ super();
+ }
+
+ public JET2Template getTemplate(String templatePath) {
+ if(pathToFactoryMap == null) {
+ initPathToFactoryMap();
+ }
+ TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
+ return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
+ }
+
+ private void addTemplate(String templatePath, String templateClass) {
+ pathToFactoryMap.put(templatePath, //$NON-NLS-1$
+ new TemplateFactoryMethod(templatePath, templateClass));
+ }
+
+ private void initPathToFactoryMap() {
+ pathToFactoryMap = new HashMap(2);
+ addTemplate("simple.v2.input.jet", "org.eclipse.jet.compiled._jet_simplev2input" ); //$NON-NLS-1$ //$NON-NLS-2$
+ addTemplate("simple.v2.input2.jet", "org.eclipse.jet.compiled._jet_simplev2input2" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void setDelegateLoader(JET2TemplateLoader loader) {
+ this.delegate = loader;
+ }
+
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
+ }
+}
+
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat
new file mode 100644
index 0000000..23c0af8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat
@@ -0,0 +1 @@
+simple.v2.pat
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat2 b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat2
new file mode 100644
index 0000000..0ff28f8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat2
@@ -0,0 +1 @@
+simple.v2.pat2
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat3 b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat3
new file mode 100644
index 0000000..8ecde48
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat3
@@ -0,0 +1 @@
+simple.v2.pat3
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat4 b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat4
new file mode 100644
index 0000000..768f2a8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.pat4
@@ -0,0 +1 @@
+simple.v2.pat4
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet
new file mode 100644
index 0000000..e77b527
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet
@@ -0,0 +1,3 @@
+This template uses a predefined tag library:
+
+<c:get select="$useMe/@attr"/>
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java
new file mode 100644
index 0000000..578bafa
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java
@@ -0,0 +1,23 @@
+package org.eclipse.jet.compiled;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+
+public class _jet_simplev2usePredefTagLibs implements JET2Template {
+
+ public _jet_simplev2usePredefTagLibs() {
+ super();
+ }
+
+ private static final String NL = System.getProperties().getProperty("line.separator");
+
+ private static final class _TEXT {
+ private static final String TEXT_1 = "This template uses a predefined tag library:" + NL + NL + "<c:get select=\"$useMe/@attr\"/>" + NL; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ public void generate(final JET2Context context, JET2Writer out) {
+ out.write(_TEXT.TEXT_1);
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java
new file mode 100644
index 0000000..2eeaaed
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java
@@ -0,0 +1,43 @@
+package org.eclipse.jet.compiled;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagInfo;
+
+public class _jet_simplev2usePredefTagLibs implements JET2Template {
+ private static final String _jetns_c = "org.eclipse.jet.controlTags"; //$NON-NLS-1$
+
+ public _jet_simplev2usePredefTagLibs() {
+ super();
+ }
+
+ private static final String NL = System.getProperties().getProperty("line.separator");
+
+ private static final class _TEXT {
+ private static final String TEXT_1 = "This template uses a predefined tag library:" + NL + NL; //$NON-NLS-1$
+ private static final String TEXT_2 = NL;
+ }
+
+ private static final class _TAGS {
+ private static final TagInfo c_get_3_1 = new TagInfo("c:get", //$NON-NLS-1$
+ 3, 1,
+ new String[] {
+ "select", //$NON-NLS-1$
+ },
+ new String[] {
+ "$useMe/@attr", //$NON-NLS-1$
+ } );
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+ out.write(_TEXT.TEXT_1);
+ RuntimeTagElement _jettag_c_get_3_1 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _TAGS.c_get_3_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_c_get_3_1.setRuntimeParent(null);
+ _jettag_c_get_3_1.setTagInfo(_TAGS.c_get_3_1);
+ _jettag_c_get_3_1.doStart(context, out);
+ _jettag_c_get_3_1.doEnd();
+ out.write(_TEXT.TEXT_2);
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.astdump.expected b/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.astdump.expected
new file mode 100644
index 0000000..b99d6d3
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.astdump.expected
@@ -0,0 +1,41 @@
+<directive name="taglib" line="1" col="1">
+ <attribute name="id">org.eclipse.jet.tests.TestLibrary</attribute>
+ <attribute name="prefix">test</attribute>
+</directive>
+<data>"isAllUpper", "nl", "other", "tokenize", "upper"
+
+</data>
+<tag name="test:tokenize" line="4" col="1">
+ <attribute name="sep">,</attribute>
+ <attribute name="var">token</attribute>
+ <attribute name="string">a,b,c,d,e,f,g</attribute>
+ <content>
+ <data></data>
+ <tag name="test:other" line="5" col="1">
+ <content>
+ <data>some text</data>
+ </content>
+ </tag>
+ <data>
+</data>
+ <tag name="test:isAllUpper" line="6" col="1">
+ <attribute name="var">token</attribute>
+ <content>
+ <data></data>
+ </content>
+ </tag>
+ <data></data>
+ <tag name="test:upper" line="8" col="1">
+ <content>
+ <data>foo</data>
+ </content>
+ </tag>
+ <tag name="test:nl" line="8" col="29">
+ </tag>
+ <data>
+</data>
+ <tag name="test:other" line="9" col="1">
+ </tag>
+ <data></data>
+ </content>
+</tag>
diff --git a/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.expected.java b/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.expected.java
new file mode 100644
index 0000000..7e4b77e
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/taglibs.jet.JETASTParser.expected.java
@@ -0,0 +1,114 @@
+package org.eclipse.jet.compiled;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagInfo;
+
+public class X implements JET2Template {
+ public static final String _jetns_test = "org.eclipse.jet.tests.TestLibrary"; //$NON-NLS-1$
+
+ public X() {
+ super();
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+ final TagInfo _jettd_test_tokenize_4_1 = new TagInfo("test:tokenize", //$NON-NLS-1$
+ 4, 1,
+ new String[] {
+ "sep", //$NON-NLS-1$
+ "var", //$NON-NLS-1$
+ "string", //$NON-NLS-1$
+ },
+ new String[] {
+ ",", //$NON-NLS-1$
+ "token", //$NON-NLS-1$
+ "a,b,c,d,e,f,g", //$NON-NLS-1$
+ } );
+ final TagInfo _jettd_test_other_5_1 = new TagInfo("test:other", //$NON-NLS-1$
+ 5, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ final TagInfo _jettd_test_isAllUpper_6_1 = new TagInfo("test:isAllUpper", //$NON-NLS-1$
+ 6, 1,
+ new String[] {
+ "var", //$NON-NLS-1$
+ },
+ new String[] {
+ "token", //$NON-NLS-1$
+ } );
+ final TagInfo _jettd_test_upper_8_1 = new TagInfo("test:upper", //$NON-NLS-1$
+ 8, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ final TagInfo _jettd_test_nl_8_29 = new TagInfo("test:nl", //$NON-NLS-1$
+ 8, 29,
+ new String[] {
+ },
+ new String[] {
+ } );
+ final TagInfo _jettd_test_other_9_1 = new TagInfo("test:other", //$NON-NLS-1$
+ 9, 1,
+ new String[] {
+ },
+ new String[] {
+ } );
+ out.write( "\"isAllUpper\", \"nl\", \"other\", \"tokenize\", \"upper\"\r\n\r\n" ); //$NON-NLS-1$
+ RuntimeTagElement _jettag_test_tokenize_4_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "tokenize", "test:tokenize", _jettd_test_tokenize_4_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_tokenize_4_1.setRuntimeParent(null);
+ _jettag_test_tokenize_4_1.setTagInfo(_jettd_test_tokenize_4_1);
+ _jettag_test_tokenize_4_1.doStart(context, out);
+ while (_jettag_test_tokenize_4_1.okToProcessBody()) {
+ RuntimeTagElement _jettag_test_other_5_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "other", "test:other", _jettd_test_other_5_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_other_5_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_other_5_1.setTagInfo(_jettd_test_other_5_1);
+ _jettag_test_other_5_1.doStart(context, out);
+ while (_jettag_test_other_5_1.okToProcessBody()) {
+ out.write( "some text" ); //$NON-NLS-1$
+ _jettag_test_other_5_1.handleBodyContent(out);
+ }
+ _jettag_test_other_5_1.doEnd();
+ out.write( "\r\n" ); //$NON-NLS-1$
+ RuntimeTagElement _jettag_test_isAllUpper_6_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "isAllUpper", "test:isAllUpper", _jettd_test_isAllUpper_6_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_isAllUpper_6_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_isAllUpper_6_1.setTagInfo(_jettd_test_isAllUpper_6_1);
+ _jettag_test_isAllUpper_6_1.doStart(context, out);
+ while (_jettag_test_isAllUpper_6_1.okToProcessBody()) {
+ _jettag_test_isAllUpper_6_1.handleBodyContent(out);
+ }
+ _jettag_test_isAllUpper_6_1.doEnd();
+ RuntimeTagElement _jettag_test_upper_8_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "upper", "test:upper", _jettd_test_upper_8_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_upper_8_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_upper_8_1.setTagInfo(_jettd_test_upper_8_1);
+ _jettag_test_upper_8_1.doStart(context, out);
+ JET2Writer _jettag_test_upper_8_1_saved_out = out;
+ while (_jettag_test_upper_8_1.okToProcessBody()) {
+ out = out.newNestedContentWriter();
+ out.write( "foo" ); //$NON-NLS-1$
+ _jettag_test_upper_8_1.handleBodyContent(out);
+ }
+ out = _jettag_test_upper_8_1_saved_out;
+ _jettag_test_upper_8_1.doEnd();
+ RuntimeTagElement _jettag_test_nl_8_29 = context.getTagFactory().createRuntimeTag(_jetns_test, "nl", "test:nl", _jettd_test_nl_8_29); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_nl_8_29.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_nl_8_29.setTagInfo(_jettd_test_nl_8_29);
+ _jettag_test_nl_8_29.doStart(context, out);
+ _jettag_test_nl_8_29.doEnd();
+ out.write( "\r\n" ); //$NON-NLS-1$
+ RuntimeTagElement _jettag_test_other_9_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "other", "test:other", _jettd_test_other_9_1); //$NON-NLS-1$ //$NON-NLS-2$
+ _jettag_test_other_9_1.setRuntimeParent(_jettag_test_tokenize_4_1);
+ _jettag_test_other_9_1.setTagInfo(_jettd_test_other_9_1);
+ _jettag_test_other_9_1.doStart(context, out);
+ _jettag_test_other_9_1.doEnd();
+ _jettag_test_tokenize_4_1.handleBodyContent(out);
+ }
+ _jettag_test_tokenize_4_1.doEnd();
+
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/data/taglibs.jet.expected.java b/tests/org.eclipse.jet.tests/data/taglibs.jet.expected.java
index 2611bf7..7e4b77e 100644
--- a/tests/org.eclipse.jet.tests/data/taglibs.jet.expected.java
+++ b/tests/org.eclipse.jet.tests/data/taglibs.jet.expected.java
@@ -58,13 +58,12 @@ public class X implements JET2Template {
},
new String[] {
} );
- out.write( "\r\n\"isAllUpper\", \"nl\", \"other\", \"tokenize\", \"upper\"\r\n\r\n" ); //$NON-NLS-1$
+ out.write( "\"isAllUpper\", \"nl\", \"other\", \"tokenize\", \"upper\"\r\n\r\n" ); //$NON-NLS-1$
RuntimeTagElement _jettag_test_tokenize_4_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "tokenize", "test:tokenize", _jettd_test_tokenize_4_1); //$NON-NLS-1$ //$NON-NLS-2$
_jettag_test_tokenize_4_1.setRuntimeParent(null);
_jettag_test_tokenize_4_1.setTagInfo(_jettd_test_tokenize_4_1);
_jettag_test_tokenize_4_1.doStart(context, out);
while (_jettag_test_tokenize_4_1.okToProcessBody()) {
- out.write( "\r\n" ); //$NON-NLS-1$
RuntimeTagElement _jettag_test_other_5_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "other", "test:other", _jettd_test_other_5_1); //$NON-NLS-1$ //$NON-NLS-2$
_jettag_test_other_5_1.setRuntimeParent(_jettag_test_tokenize_4_1);
_jettag_test_other_5_1.setTagInfo(_jettd_test_other_5_1);
@@ -80,11 +79,9 @@ public class X implements JET2Template {
_jettag_test_isAllUpper_6_1.setTagInfo(_jettd_test_isAllUpper_6_1);
_jettag_test_isAllUpper_6_1.doStart(context, out);
while (_jettag_test_isAllUpper_6_1.okToProcessBody()) {
- out.write( "\r\n" ); //$NON-NLS-1$
_jettag_test_isAllUpper_6_1.handleBodyContent(out);
}
_jettag_test_isAllUpper_6_1.doEnd();
- out.write( "\r\n" ); //$NON-NLS-1$
RuntimeTagElement _jettag_test_upper_8_1 = context.getTagFactory().createRuntimeTag(_jetns_test, "upper", "test:upper", _jettd_test_upper_8_1); //$NON-NLS-1$ //$NON-NLS-2$
_jettag_test_upper_8_1.setRuntimeParent(_jettag_test_tokenize_4_1);
_jettag_test_upper_8_1.setTagInfo(_jettd_test_upper_8_1);
@@ -108,7 +105,6 @@ public class X implements JET2Template {
_jettag_test_other_9_1.setTagInfo(_jettd_test_other_9_1);
_jettag_test_other_9_1.doStart(context, out);
_jettag_test_other_9_1.doEnd();
- out.write( "\r\n" ); //$NON-NLS-1$
_jettag_test_tokenize_4_1.handleBodyContent(out);
}
_jettag_test_tokenize_4_1.doEnd();
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
index be0b1b5..cb7b1d0 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
@@ -10,6 +10,7 @@ public class AllTests {
"Test for org.eclipse.jet.tests.compiler");
//$JUnit-BEGIN$
suite.addTestSuite(TestJETParser.class);
+ suite.addTestSuite(TestSimplifiedCompiler.class);
suite.addTestSuite(TestJET2Parser.class);
suite.addTest(TextTrimmingTests.suite());
suite.addTestSuite(LineInfoTests.class);
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
index cb59f25..5d2c819 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
@@ -18,7 +18,6 @@ import junit.framework.TestCase;
import org.eclipse.jet.compiler.Comment;
import org.eclipse.jet.compiler.JET2ASTVisitor;
import org.eclipse.jet.compiler.JET2CompilationUnit;
-import org.eclipse.jet.compiler.JET2Compiler;
import org.eclipse.jet.compiler.JET2Declaration;
import org.eclipse.jet.compiler.JET2Directive;
import org.eclipse.jet.compiler.JET2Expression;
@@ -28,8 +27,11 @@ 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.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.core.parser.IProblem;
+import org.eclipse.jet.core.parser.ProblemSeverity;
import org.eclipse.jet.internal.compiler.TemplateRunner;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jet.internal.core.NewLineUtil;
import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.tests.FileUtils;
@@ -52,7 +54,7 @@ public class TestJET2Parser extends TestCase {
}
public String getLog() {
- return buffer.toString();
+ return NewLineUtil.setLineTerminator(buffer, NL);
}
@@ -133,7 +135,7 @@ public class TestJET2Parser extends TestCase {
*/
public void visit(TextElement text) {
doIndent();
- buffer.append("<data>").append(text.getText()).append("</data>").append(NL);
+ buffer.append("<data>").append(text.getRawText()).append("</data>").append(NL);
}
/* (non-Javadoc)
@@ -196,6 +198,10 @@ public class TestJET2Parser extends TestCase {
}
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
private FileInputStream getFileContentsAsStream(String urlString) throws IOException, MalformedURLException, FileNotFoundException {
String fileName = FileUtils.resolveURLToLocationString(urlString);
FileInputStream inputStream = new FileInputStream(new File(fileName));
@@ -249,10 +255,10 @@ public class TestJET2Parser extends TestCase {
JET2CompilationUnit cu = new JET2CompilationUnit();
cu.parse(is, "UTF-8");
- cu.setOutputJavaPackage(JET2Compiler.DEFAULT_COMPILED_TEMPLATE_PACKAGE);
+ cu.setOutputJavaPackage(JETCompilerOptions.DEFAULT_COMPILED_TEMPLATE_PACKAGE);
cu.setOutputJavaClassName("X");
- String result = new TemplateRunner().generate("templates/jet2java.jet", Collections.singletonMap("cu", cu));
+ String result = new TemplateRunner().generate("templates/jet2java.jet", Collections.singletonMap("cu", cu.getDelegateCU()));
assertEquals(FileUtils.getFileContents(urlString + ".expected.java", true), result);
@@ -268,17 +274,21 @@ public class TestJET2Parser extends TestCase {
Problem[] problems = getSortedProblems(cu);
- assertEquals("Number of problems", 2, problems.length);
+ assertEquals("Number of problems", 3, problems.length);
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 8, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.MissingXmlEndTag, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.MissingXmlEndTag, problems[0].getId());
- assertEquals("Problem 2 line number", 10, problems[1].getLineNumber());
- assertEquals("Problem 2 severity", ParseProblemSeverity.WARNING, problems[1].getSeverity());
- assertEquals("Problem 2 id", Problem.TagInterpretedAsEmptyTag, problems[1].getId());
+ assertEquals("Problem 2 line number", 8, problems[1].getLineNumber());
+ assertEquals("Problem 2 severity", ProblemSeverity.ERROR, problems[1].getProblemSeverity());
+ assertEquals("Problem 2 id", IProblem.TagCannotHaveContent, problems[1].getId());
+
+ assertEquals("Problem 2 line number", 10, problems[2].getLineNumber());
+ assertEquals("Problem 2 severity", ProblemSeverity.WARNING, problems[2].getProblemSeverity());
+ assertEquals("Problem 2 id", IProblem.TagInterpretedAsEmptyTag, problems[2].getId());
}
@@ -298,8 +308,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.UnterminatedXMLTag, problems[0].getId());
}
@@ -318,8 +328,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.UnterminatedXMLTag, problems[0].getId());
}
@@ -338,8 +348,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 1, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.JETException, problems[0].getId());
}
@@ -358,8 +368,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.JETException, problems[0].getId());
}
@@ -378,8 +388,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.JETException, problems[0].getId());
}
@@ -398,8 +408,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.UnterminatedXMLTag, problems[0].getId());
}
@@ -418,8 +428,8 @@ public class TestJET2Parser extends TestCase {
// This assertions correspond to comments in bug147714.jet
assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.UnterminatedXMLTag, problems[0].getId());
}
@@ -459,8 +469,8 @@ public class TestJET2Parser extends TestCase {
assertTrue("At least one problem", problems.length > 0);
- assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
- assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+ assertEquals("Problem 1 severity", ProblemSeverity.ERROR, problems[0].getProblemSeverity());
+ assertEquals("Problem 1 id", IProblem.JETException, problems[0].getId());
assertEquals("Problem 1 line number", 4, problems[0].getLineNumber());
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
index 3ddd6e6..a680374 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
@@ -12,17 +12,18 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.jet.compiler.Problem;
-import org.eclipse.jet.internal.compiler.CommentElementDelegate;
-import org.eclipse.jet.internal.compiler.DeclarationElementDelegate;
-import org.eclipse.jet.internal.compiler.XMLElementDelegate;
-import org.eclipse.jet.internal.parser.JETCoreElement;
-import org.eclipse.jet.internal.parser.JETMark;
-import org.eclipse.jet.internal.parser.JETParseEventListener2;
-import org.eclipse.jet.internal.parser.JETParser;
-import org.eclipse.jet.internal.parser.JETReader;
-import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jet.core.parser.IProblem;
+import org.eclipse.jet.core.parser.ProblemSeverity;
+import org.eclipse.jet.internal.core.NewLineUtil;
+import org.eclipse.jet.internal.core.parser.jasper.CommentElementDelegate;
+import org.eclipse.jet.internal.core.parser.jasper.DeclarationElementDelegate;
+import org.eclipse.jet.internal.core.parser.jasper.JETCoreElement;
+import org.eclipse.jet.internal.core.parser.jasper.JETException;
+import org.eclipse.jet.internal.core.parser.jasper.JETMark;
+import org.eclipse.jet.internal.core.parser.jasper.JETParseEventListener2;
+import org.eclipse.jet.internal.core.parser.jasper.JETParser;
+import org.eclipse.jet.internal.core.parser.jasper.JETReader;
+import org.eclipse.jet.internal.core.parser.jasper.XMLElementDelegate;
import org.eclipse.jet.tests.FileUtils;
public class TestJETParser extends TestCase {
@@ -30,7 +31,7 @@ public class TestJETParser extends TestCase {
private static class SavedProblem {
- private final ParseProblemSeverity severity;
+ private final ProblemSeverity severity;
private final int problemId;
private final String message;
private final Object[] msgArgs;
@@ -38,7 +39,7 @@ public class TestJETParser extends TestCase {
private final int end;
private final int line;
- public SavedProblem(ParseProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line) {
+ public SavedProblem(ProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line) {
this.severity = severity;
this.problemId = problemId;
this.message = message;
@@ -86,7 +87,7 @@ public class TestJETParser extends TestCase {
/**
* @return Returns the severity.
*/
- public final ParseProblemSeverity getSeverity() {
+ public final ProblemSeverity getSeverity() {
return severity;
}
@@ -125,12 +126,12 @@ public class TestJETParser extends TestCase {
}
public void endPageProcessing() throws JETException {
- doIndent();
- buffer.append("</jet2>").append(NL);
+// doIndent();
+// buffer.append("</jet2>").append(NL);
}
public String getLog() {
- return buffer.toString();
+ return NewLineUtil.setLineTerminator(buffer, NL);
}
public void handleCharData(char[] chars) throws JETException {
@@ -235,7 +236,7 @@ public class TestJETParser extends TestCase {
return problems;
}
- public void recordProblem(ParseProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line, int colOffset) {
+ public void recordProblem(ProblemSeverity severity, int problemId, String message, Object[] msgArgs, int start, int end, int line, int colOffset) {
problems.add(new SavedProblem(severity, problemId, message, msgArgs, start, end, line));
}
@@ -275,7 +276,7 @@ public class TestJETParser extends TestCase {
final List problems = listener.getProblems();
assertEquals(1, problems.size());
SavedProblem problem = (SavedProblem) problems.get(0);
- assertEquals(ParseProblemSeverity.ERROR, problem.getSeverity());
+ assertEquals(ProblemSeverity.ERROR, problem.getSeverity());
assertEquals(expectedProblemId, problem.getProblemId());
}
@@ -290,7 +291,7 @@ public class TestJETParser extends TestCase {
String urlString = "platform:/plugin/org.eclipse.jet.tests/data/unclosedComment.jet";
String openChars = "<%--";
- doUnclosedElementTest(urlString, openChars, Problem.UnterminatedXMLTag);
+ doUnclosedElementTest(urlString, openChars, IProblem.UnterminatedXMLTag);