summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-05-30 14:49:35 (EDT)
committer pelder2006-05-30 14:49:35 (EDT)
commite25795ed52ec6fc0f517676fcaa053e656edeea1 (patch)
treeacef696e5301e3086670697ae59686efbb9b451b
parent8c788435724d3b50a2fcb9c1b7439899b5315a7e (diff)
downloadorg.eclipse.jet-e25795ed52ec6fc0f517676fcaa053e656edeea1.zip
org.eclipse.jet-e25795ed52ec6fc0f517676fcaa053e656edeea1.tar.gz
org.eclipse.jet-e25795ed52ec6fc0f517676fcaa053e656edeea1.tar.bz2
[144515] Add support the @jet directive, except for nlString and skeleton.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java211
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java36
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java8
-rw-r--r--plugins/org.eclipse.jet/templates/jet2java.javajet4
5 files changed, 214 insertions, 86 deletions
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
index 67fd129..4b2e803 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
@@ -19,13 +19,23 @@ 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.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;
@@ -45,7 +55,7 @@ class ASTCompilerParseListener implements JETParseEventListener2
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
{
@@ -204,59 +214,140 @@ class ASTCompilerParseListener implements JETParseEventListener2
if (TAGLIB__DIRECTIVE.equalsIgnoreCase(directive))
{
- String prefix = ((String)attributes.get(PREFIX__ATTR)).trim().toLowerCase();
- String id = (String)attributes.get(ID__ATTR);
+ handleTagLibDirective(start, stop, attributes);
+ }
+ else if(JET__DIRECTIVE.equalsIgnoreCase(directive))
+ {
+ handleJetDirective(start, stop, attributes);
+ }
+ }
- 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)
+
+ 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))
{
- compilationUnit.createProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnknownTagLibrary,
- JET2Messages.JET2Compiler_UnknownTagLibrary,
- new Object []{ id },
- start.getCursor(),
- stop.getCursor(),
- start.getLine(), start.getCol());
+ recordProblem(ParseProblemSeverity.ERROR, Problem.UnknownAttributeInTag,
+ JET2Messages.JET2Compiler_UnknownAttribute, new Object[] {attrName},
+ start.getCursor(), stop.getCursor(), start.getLine(), start.getCol());
}
- else
+ if(deprecatedJETAttributes.contains(attrName))
{
- tagLibManager.add(prefix, id);
+ 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);
+ }
}
/**
@@ -531,4 +622,30 @@ class ASTCompilerParseListener implements JETParseEventListener2
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$
+ JETCoreElement[] coreElements = new JETCoreElement []{
+ directive,
+ new JETParser.Expression(),
+ new CommentElementDelegate(),
+ new DeclarationElementDelegate(),
+ new JETParser.Scriptlet(),
+ 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();
+
+ }
}
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 b2bd65d..48c44e7 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
@@ -25,17 +25,14 @@ import java.io.UnsupportedEncodingException;
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.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.JETParser;
import org.eclipse.jet.internal.parser.JETReader;
import org.eclipse.jet.internal.parser.ParseProblemSeverity;
import org.eclipse.jet.taglib.TagLibraryReference;
@@ -68,6 +65,8 @@ public final class JET2CompilationUnit extends JET2ASTElement
private TagLibraryReference[] tagLibraryReferences;
+ private Set imports = new LinkedHashSet();
+
public JET2CompilationUnit()
{
super(new JET2AST(), -1, -1, -1, -1);
@@ -146,21 +145,8 @@ public final class JET2CompilationUnit extends JET2ASTElement
ASTCompilerParseListener listener = new ASTCompilerParseListener(this, reader,
predefinedLibraryMap != null ? predefinedLibraryMap : Collections.EMPTY_MAP);
- JETParser.Directive directive = new JETParser.Directive();
- directive.getDirectives().add("jet"); //$NON-NLS-1$
- directive.getDirectives().add("taglib"); //$NON-NLS-1$
- JETCoreElement[] coreElements = new JETCoreElement []{
- directive,
- new JETParser.Expression(),
- new CommentElementDelegate(),
- new DeclarationElementDelegate(),
- new JETParser.Scriptlet(),
- new XMLElementDelegate(), };
- JETParser parser = new JETParser(reader, listener, coreElements);
-
- listener.beginPageProcessing();
- parser.parse();
- listener.endPageProcessing();
+
+ listener.parse(reader);
tagLibraryReferences = listener.getTagLibraryReferences();
return;
@@ -168,7 +154,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
catch (JETException e)
{
// create a minimal compilation unit with the exeception recorded as the error.
- this.createProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), null, -1, -1, -1, -1);
+ this.createProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), null, 0, 0, 1, 1);
}
finally
{
@@ -178,8 +164,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
}
catch (IOException e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // ignore the io exception, can't do anything about it;
}
}
}
@@ -328,4 +313,14 @@ public final class JET2CompilationUnit extends JET2ASTElement
{
return tagLibraryReferences;
}
+
+ public void addImports(List list)
+ {
+ imports .addAll(list);
+ }
+
+ public Set getImports()
+ {
+ return Collections.unmodifiableSet(imports);
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
index 09c654a..bb4556a 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
@@ -19,14 +19,17 @@ public class JET2JavaGenerator
protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
protected final String TEXT_1 = "package ";
- protected final String TEXT_2 = ";" + NL + "" + NL + "import org.eclipse.jet.JET2Context;" + NL + "import org.eclipse.jet.JET2Template;" + NL + "import org.eclipse.jet.JET2Writer;" + NL + "import org.eclipse.jet.taglib.RuntimeTagElement;" + NL + "import org.eclipse.jet.taglib.TagInfo;" + NL + "" + NL + "public class ";
- protected final String TEXT_3 = " implements JET2Template {" + NL + "" + NL + "\t";
- protected final String TEXT_4 = NL + NL + "\t";
- protected final String TEXT_5 = NL + "\t" + NL + "\tpublic ";
- protected final String TEXT_6 = "() {" + NL + "\t\tsuper();" + NL + "\t}" + NL + "" + NL + "\tpublic void generate(JET2Context context, JET2Writer out) {" + NL + "\t\t" + NL + "\t\t";
- protected final String TEXT_7 = NL + NL + "\t\t";
- protected final String TEXT_8 = NL + "\t}" + NL + "" + NL + "}";
- protected final String TEXT_9 = NL + " ";
+ protected final String TEXT_2 = ";" + NL + "" + NL + "import org.eclipse.jet.JET2Context;" + NL + "import org.eclipse.jet.JET2Template;" + NL + "import org.eclipse.jet.JET2Writer;" + NL + "import org.eclipse.jet.taglib.RuntimeTagElement;" + NL + "import org.eclipse.jet.taglib.TagInfo;";
+ protected final String TEXT_3 = NL + "import ";
+ protected final String TEXT_4 = ";";
+ protected final String TEXT_5 = NL + NL + "public class ";
+ protected final String TEXT_6 = " implements JET2Template {" + NL + "" + NL + "\t";
+ protected final String TEXT_7 = NL + NL + "\t";
+ protected final String TEXT_8 = NL + "\t" + NL + "\tpublic ";
+ protected final String TEXT_9 = "() {" + NL + "\t\tsuper();" + NL + "\t}" + NL + "" + NL + "\tpublic void generate(JET2Context context, JET2Writer out) {" + NL + "\t\t" + NL + "\t\t";
+ protected final String TEXT_10 = NL + NL + "\t\t";
+ protected final String TEXT_11 = NL + "\t}" + NL + "" + NL + "}";
+ protected final String TEXT_12 = NL + " ";
public String generate(Object argument)
{
@@ -93,19 +96,26 @@ public class JET2JavaGenerator
stringBuffer.append(TEXT_1);
stringBuffer.append( cu.getOutputJavaPackage() );
stringBuffer.append(TEXT_2);
- stringBuffer.append( cu.getOutputJavaClassName() );
+ for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ String importName = (String)i.next();
stringBuffer.append(TEXT_3);
- stringBuffer.append( tagNamespaceVariables );
+ stringBuffer.append(importName);
stringBuffer.append(TEXT_4);
- stringBuffer.append( declarations );
+ }
stringBuffer.append(TEXT_5);
stringBuffer.append( cu.getOutputJavaClassName() );
stringBuffer.append(TEXT_6);
- stringBuffer.append( tagDataDeclarations );
+ stringBuffer.append( tagNamespaceVariables );
stringBuffer.append(TEXT_7);
- stringBuffer.append( generatedBody.getBuffer() );
+ stringBuffer.append( declarations );
stringBuffer.append(TEXT_8);
+ stringBuffer.append( cu.getOutputJavaClassName() );
stringBuffer.append(TEXT_9);
+ stringBuffer.append( tagDataDeclarations );
+ stringBuffer.append(TEXT_10);
+ stringBuffer.append( generatedBody.getBuffer() );
+ stringBuffer.append(TEXT_11);
+ stringBuffer.append(TEXT_12);
return stringBuffer.toString();
}
}
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
index 2605a84..d377485 100644
--- 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
@@ -37,6 +37,8 @@ import org.eclipse.emf.codegen.jet.JETException;
*/
public class JETReader
{
+ private static final char XML_TAG_START = '<';
+
protected char startTagInitialChar = '<';
protected char endTagInitialChar = '%';
@@ -271,7 +273,7 @@ public class JETReader
if (cur_cursor == len)
return ""; //$NON-NLS-1$
// pure obsfuscated genius!
- while (++current.cursor < len && (current.stream[current.cursor]) != startTagInitialChar)
+ while (++current.cursor < len && (current.stream[current.cursor]) != startTagInitialChar && current.stream[current.cursor] != XML_TAG_START)
{
// do nothing
}
@@ -644,7 +646,7 @@ public class JETReader
// Look for a single-char work delimiter:
//
- if (ch == '=' || ch == endTagFinalChar || ch == '"' || ch == '\'' || ch == '/')
+ if (ch == '=' || ch == endTagFinalChar || ch == '"' || ch == '\'' || ch == '/' || ch == '>')
{
return true;
}
@@ -744,7 +746,7 @@ public class JETReader
// Take care of the quoting here.
if (ch == '\\')
{
- if (peekChar() == '"' || peekChar() == '\'' || peekChar() == endTagFinalChar || peekChar() == endTagInitialChar)
+ if (peekChar() == '"' || peekChar() == '\'' || peekChar() == endTagFinalChar || peekChar() == endTagInitialChar || peekChar() == '>')
{
ch = nextChar();
}
diff --git a/plugins/org.eclipse.jet/templates/jet2java.javajet b/plugins/org.eclipse.jet/templates/jet2java.javajet
index cf4ec76..1c29187 100644
--- a/plugins/org.eclipse.jet/templates/jet2java.javajet
+++ b/plugins/org.eclipse.jet/templates/jet2java.javajet
@@ -68,6 +68,10 @@ import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;
+<% for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ String importName = (String)i.next();%>
+import <%=importName%>;
+<% } %>
public class <%= cu.getOutputJavaClassName() %> implements JET2Template {