summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-03 15:11:34 (EDT)
committerpelder2006-04-03 15:11:34 (EDT)
commitf0572af35411ed8d41b7da2e021732a849170d98 (patch)
tree68df9c4a4da80de925be62a9c46c34d3887bab39
parentde01baad84509b7ff10b69e7d1cbeb3741f75524 (diff)
downloadorg.eclipse.jet-f0572af35411ed8d41b7da2e021732a849170d98.zip
org.eclipse.jet-f0572af35411ed8d41b7da2e021732a849170d98.tar.gz
org.eclipse.jet-f0572af35411ed8d41b7da2e021732a849170d98.tar.bz2
[131183] Complete implementation of <java:*> tags.
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(org.eclipse.jet.JET2Writer).xml4
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(boolean).xml4
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(org.eclipse.core.runtime.IProgressMonitor).xml4
-rw-r--r--plugins/org.eclipse.jet/.settings/org.eclipse.core.resources.prefs5
-rw-r--r--plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--plugins/org.eclipse.jet/plugin.xml47
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/AbstractJavaFileTag.java101
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImpliedImportTag.java7
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportTag.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java16
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaClassTag.java19
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaFileAction.java110
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaPackageAction.java75
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaResourceTag.java20
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/PackageTag.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java204
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaImportsUtil.java27
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java6
18 files changed, 609 insertions, 87 deletions
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(org.eclipse.jet.JET2Writer).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(org.eclipse.jet.JET2Writer).xml
new file mode 100644
index 0000000..2ac59fd
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(org.eclipse.jet.JET2Writer).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/taglib/java/JavaImportsUtil.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(boolean).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(boolean).xml
new file mode 100644
index 0000000..df6188b
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(boolean).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/taglib/workspace/ActionsUtil.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(org.eclipse.core.runtime.IProgressMonitor).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(org.eclipse.core.runtime.IProgressMonitor).xml
new file mode 100644
index 0000000..e64fc8c
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(org.eclipse.core.runtime.IProgressMonitor).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(...)'" flags="393218" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/taglib/workspace/ActionsUtil.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.jet/.settings/org.eclipse.core.resources.prefs
index c84b593..bf40941 100644
--- a/plugins/org.eclipse.jet/.settings/org.eclipse.core.resources.prefs
+++ b/plugins/org.eclipse.jet/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,6 @@
-#Thu Feb 23 10:59:14 EST 2006
+#Sat Apr 01 07:23:58 EST 2006
eclipse.preferences.version=1
+encoding//.deprecations/DEPRECATE_org.eclipse.jet.taglib.java.JavaImportsUtil.getImportManager(org.eclipse.jet.JET2Writer).xml=utf-8
+encoding//.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.checkpointWorkspace(boolean).xml=utf-8
+encoding//.deprecations/DEPRECATE_org.eclipse.jet.taglib.workspace.ActionsUtil.ensureProjectIsBuilt(org.eclipse.core.runtime.IProgressMonitor).xml=utf-8
encoding//src/org/eclipse/jet/internal/l10n/JET2Messages.properties=8859_1
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 385653d..4b4a80c 100644
--- a/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.jet/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Mon Mar 06 08:50:45 EST 2006
+#Mon Apr 03 09:49:33 EDT 2006
eclipse.preferences.version=1
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=52
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index a3a5f5e..d8940e0 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -805,9 +805,9 @@ This tag may occur only once in a template.
</description>
</attribute>
<description>
- *** PROTOTYPE *** Record a name as being implicitly imported. This is a name that a sibling class of the one being generated by the current template.
+ Record a name as being implicitly imported. This is a name that a sibling class of the one being generated by the current template.
-This tag must occur after the initial &apos;importsLocation&apos; tag, but before any &apos;imports&apos; tags in the template.
+This tag must occur after the initial &amp;apos;importsLocation&amp;apos; tag, but before any &amp;apos;imports&amp;apos; tags in the template.
</description>
</emptyTag>
<functionTag
@@ -876,6 +876,22 @@ This tag must be preceded by a 'importsLocation' tag.
use="optional">
<description/>
</attribute>
+ <attribute
+ name="template"
+ type="string"
+ use="required"/>
+ <attribute
+ name="replace"
+ type="boolean"
+ use="optional"/>
+ <attribute
+ name="encoding"
+ type="string"
+ use="optional"/>
+ <attribute
+ name="derived"
+ type="boolean"
+ use="optional"/>
</emptyTag>
<emptyTag
class="org.eclipse.jet.internal.taglib.java.JavaClassTag"
@@ -915,24 +931,19 @@ This tag must be preceded by a 'importsLocation' tag.
name="project"
type="string"
use="optional"/>
- </emptyTag>
- <containerTag
- allowAsEmpty="true"
- class="org.eclipse.jet.internal.taglib.java.SrcFolderTag"
- name="srcFolder"
- processContents="standard">
- <description>
- Create a source folder with the specified path. If the path is relative, it is relative to any containing 'ws:folder' or 'ws:project' , or the default project (if any), if there is no such tag.
- </description>
<attribute
- name="path"
+ name="replace"
+ type="boolean"
+ use="optional"/>
+ <attribute
+ name="encoding"
type="string"
- use="required">
- <description>
- The path of the source folder. If this path is absolute, it is treated as a workspace relative path. Otherwise, it is relative to any containing 'ws:folder' or 'ws:project' tag, the default project (if set), or the workspace itself.
- </description>
- </attribute>
- </containerTag>
+ use="optional"/>
+ <attribute
+ name="derived"
+ type="boolean"
+ use="optional"/>
+ </emptyTag>
<emptyTag
class="org.eclipse.jet.internal.taglib.java.MergeTag"
name="merge"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/AbstractJavaFileTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/AbstractJavaFileTag.java
new file mode 100644
index 0000000..17966d9
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/AbstractJavaFileTag.java
@@ -0,0 +1,101 @@
+/**
+ * <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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.java;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+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.jet.taglib.workspace.WorkspaceContextExtender;
+import org.eclipse.jet.transform.TransformContextExtender;
+
+/**
+ * Abstract implementation common to &lt;java:class&gt; and &lt;java:resource&gt;
+ */
+public abstract class AbstractJavaFileTag extends AbstractEmptyTag
+{
+
+ /**
+ *
+ */
+ public AbstractJavaFileTag()
+ {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.EmptyTag#doAction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+ */
+ public final void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ String fileName = getFileName();
+
+ String pkgName = getAttribute("package"); //$NON-NLS-1$
+ String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
+ String template = getAttribute("template"); //$NON-NLS-1$
+ String encoding = getAttribute("encoding"); //$NON-NLS-1$
+ boolean derived = Boolean.valueOf(getAttribute("derived")).booleanValue(); //$NON-NLS-1$
+ boolean replace = true;
+ if(td.hasAttribute("replace")) //$NON-NLS-1$
+ {
+ replace = Boolean.valueOf(getAttribute("replace")).booleanValue(); //$NON-NLS-1$
+ }
+
+ WorkspaceContextExtender wce = WorkspaceContextExtender.getInstance(context);
+
+ IPath srcFolderPath;
+ if (srcFolder == null && pkgName == null)
+ {
+ // look for a containing <java:package> tag, and copy values from it
+ PackageTag pkgTag = JavaActionsUtil.findContainingJavaPackageTag(this);
+ pkgName = pkgTag.getPackageName();
+ srcFolderPath = pkgTag.getSourceFolderPath();
+ }
+ else if (srcFolder == null)
+ {
+ // look for a container tag such as <ws:folder> or <ws:project>
+ // and use that as the source folder
+ srcFolderPath = wce.getContainer().getFullPath().makeRelative();
+ }
+ else
+ {
+ srcFolderPath = new Path(srcFolder).makeRelative();
+ if (srcFolderPath.segmentCount() == 0)
+ {
+ String attribute = "sourceFolder"; //$NON-NLS-1$
+ final String msg = JET2Messages.AbstractJavaFileTag_EmptyAttributeNotAllowed;
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{attribute}));
+ }
+ }
+
+ BodyContentWriter content = new BodyContentWriter();
+ final TransformContextExtender tce = TransformContextExtender.getInstance(context);
+ tce.execute(template, content);
+ wce.addAction(new JavaFileAction(srcFolderPath, pkgName, fileName, content,
+ replace, encoding, derived, td, tce.getTemplatePath()));
+ }
+
+ protected abstract String getFileName() throws JET2TagException;
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImpliedImportTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImpliedImportTag.java
index 21335d8..62aa576 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImpliedImportTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImpliedImportTag.java
@@ -18,11 +18,13 @@
package org.eclipse.jet.internal.taglib.java;
+import org.eclipse.emf.codegen.util.ImportManager;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
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;
/**
@@ -46,8 +48,9 @@ public class ImpliedImportTag extends AbstractEmptyTag
*/
public void doAction(TagInfo tc, JET2Context context, JET2Writer out) throws JET2TagException
{
- // TODO Auto-generated method stub
-
+ String name = getAttribute("name"); //$NON-NLS-1$
+ ImportManager importManager = JavaActionsUtil.getImportManager(getOut());
+ importManager.addPseudoImport(name);
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportTag.java
index c5f18c4..8f0c791 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportTag.java
@@ -23,7 +23,7 @@ import org.eclipse.jet.JET2Context;
import org.eclipse.jet.taglib.AbstractFunctionTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.taglib.java.JavaImportsUtil;
+import org.eclipse.jet.taglib.java.JavaActionsUtil;
/**
@@ -46,7 +46,7 @@ public class ImportTag extends AbstractFunctionTag
*/
public String doFunction(TagInfo tc, JET2Context context, String bodyContent) throws JET2TagException
{
- ImportManager importManager = JavaImportsUtil.getImportManager(getOut());
+ ImportManager importManager = JavaActionsUtil.getImportManager(getOut());
importManager.addImport(bodyContent);
return importManager.getImportedName(bodyContent);
}
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 884b217..0dc6041 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
@@ -18,6 +18,9 @@
package org.eclipse.jet.internal.taglib.java;
+import java.util.ArrayList;
+
+import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.codegen.util.ImportManager;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
@@ -26,7 +29,7 @@ import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.taglib.java.JavaImportsUtil;
+import org.eclipse.jet.taglib.java.JavaActionsUtil;
import org.eclipse.jface.text.Position;
@@ -72,11 +75,12 @@ public class ImportsLocationTag extends AbstractEmptyTag
private final ImportManager importManager;
- public ImportsPosition(int start, String compilationUnitPackage)
+ public ImportsPosition(int start, String compilationUnitPackage, String preceedingContents)
{
super(start);
importManager = new ImportManager(compilationUnitPackage);
- importManager.addCompilationUnitImports(compilationUnitPackage);
+ importManager.addJavaLangImports(new ArrayList(CodeGenUtil.getJavaDefaultTypes()));
+ importManager.addCompilationUnitImports(preceedingContents);
}
/**
@@ -114,7 +118,7 @@ public class ImportsLocationTag extends AbstractEmptyTag
// 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);
+ Position importsPosition = new ImportsPosition(importsOffset, compilationUnitPackage, out.getDocument().get());
out.addPositionCategory(IMPORTS_POSITION_CATEGORY);
out.addPosition(IMPORTS_POSITION_CATEGORY, importsPosition);
@@ -145,11 +149,11 @@ public class ImportsLocationTag extends AbstractEmptyTag
* @param writer
* @return
* @throws JET2TagException
- * @deprecated Use {@link JavaImportsUtil#getImportManager(JET2Writer)} instead.
+ * @deprecated Use {@link JavaActionsUtil#getImportManager(JET2Writer)} instead.
*/
public static ImportManager getImportManager(JET2Writer writer) throws JET2TagException
{
- return JavaImportsUtil.getImportManager(writer);
+ return JavaActionsUtil.getImportManager(writer);
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaClassTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaClassTag.java
index fab4fcb..0e10051 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaClassTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaClassTag.java
@@ -16,16 +16,14 @@
*/
package org.eclipse.jet.internal.taglib.java;
-import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.taglib.AbstractEmptyTag;
+
import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jet.taglib.TagInfo;
+
/**
* Implement the standard JET2 Java tag 'class'.
*/
-public class JavaClassTag extends AbstractEmptyTag
+public class JavaClassTag extends AbstractJavaFileTag
{
/**
@@ -36,15 +34,10 @@ public class JavaClassTag extends AbstractEmptyTag
super();
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.EmptyTag#doAction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
- */
- public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ protected String getFileName() throws JET2TagException
{
-// String name = getAttribute("name"); //$NON-NLS-1$
-// String pkgName = getAttribute("package"); //$NON-NLS-1$
-// String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
- throw new JET2TagException("not implemented yet"); //$NON-NLS-1$
+ return getAttribute("name") + ".java"; //$NON-NLS-1$//$NON-NLS-2$
}
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaFileAction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaFileAction.java
new file mode 100644
index 0000000..49dcc8b
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaFileAction.java
@@ -0,0 +1,110 @@
+/**
+ * <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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.java;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.java.JavaActionsUtil;
+import org.eclipse.jet.taglib.workspace.AbstractWorkspaceAction;
+import org.eclipse.jet.taglib.workspace.ActionsUtil;
+import org.eclipse.jet.taglib.workspace.IWorkspaceAction;
+
+/**
+ * Action for creating files in a Java context
+ */
+public final class JavaFileAction extends AbstractWorkspaceAction implements IWorkspaceAction
+{
+
+ protected final IPath srcFolderPath;
+ protected final String pkgName;
+ protected final String fileName;
+ private final BodyContentWriter content;
+ private final boolean replace;
+ private final String encoding;
+ private final boolean derived;
+ private IFile file;
+
+ public JavaFileAction(IPath srcFolderPath, String pkgName, String fileName, BodyContentWriter content, boolean replace, String encoding, boolean derived, TagInfo td, String templatePath)
+ {
+ super(td, templatePath);
+ this.srcFolderPath = srcFolderPath;
+ this.pkgName = pkgName;
+ this.fileName = fileName;
+ this.content = content;
+ this.replace = replace;
+ this.encoding = encoding;
+ this.derived = derived;
+ }
+
+ /**
+ * @return
+ * @throws JET2TagException
+ */
+ private final IFile getUnderlyingFile() throws JET2TagException
+ {
+ if(file == null) {
+ file = JavaActionsUtil.getResourceForJavaResource(srcFolderPath, pkgName, fileName);
+ }
+ return file;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#getResource()
+ */
+ public final IResource getResource() throws JET2TagException
+ {
+ return getUnderlyingFile();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#performAction(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public final void performAction(IProgressMonitor monitor) throws JET2TagException
+ {
+ IFile targetFile = getUnderlyingFile();
+
+ ActionsUtil.writeTextFileFromWriter(targetFile, replace, encoding, derived , content, monitor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#requiresValidateEdit()
+ */
+ public final boolean requiresValidateEdit() throws JET2TagException
+ {
+ if(!replace)
+ {
+ return false;
+ }
+ try
+ {
+ IFile res = getUnderlyingFile();
+ return res.exists() && res.getResourceAttributes().isReadOnly();
+ }
+ catch (JET2TagException e)
+ {
+ return false;
+ }
+ }
+
+
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaPackageAction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaPackageAction.java
new file mode 100644
index 0000000..a184578
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaPackageAction.java
@@ -0,0 +1,75 @@
+/**
+ * <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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.java;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.java.JavaActionsUtil;
+import org.eclipse.jet.taglib.workspace.AbstractWorkspaceAction;
+import org.eclipse.jet.taglib.workspace.ActionsUtil;
+import org.eclipse.jet.taglib.workspace.IWorkspaceAction;
+
+/**
+ * @author pelder
+ */
+public class JavaPackageAction extends AbstractWorkspaceAction implements IWorkspaceAction
+{
+
+ private final IPath srcFolderPath;
+ private final String packageName;
+
+ public JavaPackageAction(IPath srcFolderPath, String packageName, TagInfo td, String templatePath)
+ {
+ super(td, templatePath);
+ this.srcFolderPath = srcFolderPath;
+ this.packageName = packageName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#getResource()
+ */
+ public IResource getResource() throws JET2TagException
+ {
+ // spec for this method says its only called ir requiresValidateEdit
+ // is true. Assert the correctness of this
+ throw new IllegalStateException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#performAction(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void performAction(IProgressMonitor monitor) throws JET2TagException
+ {
+ IFolder folder = JavaActionsUtil.getFolderForPackage(srcFolderPath, packageName);
+
+ ActionsUtil.ensureFolderExists(folder, monitor);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.workspace.IWorkspaceAction#requiresValidateEdit()
+ */
+ public boolean requiresValidateEdit() throws JET2TagException
+ {
+ return false; // validateEdit only works on files
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaResourceTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaResourceTag.java
index 6b7be78..ac5f4d3 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaResourceTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/JavaResourceTag.java
@@ -16,16 +16,12 @@
*/
package org.eclipse.jet.internal.taglib.java;
-import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jet.taglib.TagInfo;
/**
* Implement the standard JET2 Java tag 'resource'.
*/
-public class JavaResourceTag extends AbstractEmptyTag
+public class JavaResourceTag extends AbstractJavaFileTag
{
/**
@@ -36,15 +32,15 @@ public class JavaResourceTag extends AbstractEmptyTag
super();
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.EmptyTag#doAction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+
+ /**
+ * @return
+ * @throws JET2TagException
*/
- public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ protected String getFileName() throws JET2TagException
{
-// String name = getAttribute("name"); //$NON-NLS-1$
-// String pkgName = getAttribute("package"); //$NON-NLS-1$
-// String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
- throw new JET2TagException("not implemented yet"); //$NON-NLS-1$
+ String fileName = getAttribute("name"); //$NON-NLS-1$
+ return fileName;
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/PackageTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/PackageTag.java
index 9f40be3..d84e208 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/PackageTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/PackageTag.java
@@ -16,11 +16,17 @@
*/
package org.eclipse.jet.internal.taglib.java;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.AbstractContainerTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.workspace.WorkspaceContextExtender;
+import org.eclipse.jet.transform.TransformContextExtender;
+
/**
* Implement the standard JET2 Java tag 'package.
@@ -28,6 +34,9 @@ import org.eclipse.jet.taglib.TagInfo;
public class PackageTag extends AbstractContainerTag
{
+ private String packageName;
+ private IPath srcFolderPath;
+
/**
*
*/
@@ -41,10 +50,23 @@ public class PackageTag extends AbstractContainerTag
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
-// String name = getAttribute("name"); //$NON-NLS-1$
-// String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
+ packageName = getAttribute("name"); //$NON-NLS-1$
+ String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
+
+ WorkspaceContextExtender wce = WorkspaceContextExtender.getInstance(context);
+
- throw new JET2TagException("not implemented yet"); //$NON-NLS-1$
+ if(srcFolder != null)
+ {
+ srcFolderPath = new Path(srcFolder);
+ }
+ else
+ {
+ srcFolderPath = wce.getContainer().getFullPath().makeRelative();
+ }
+
+ wce.addAction(new JavaPackageAction(srcFolderPath, packageName,
+ td, TransformContextExtender.getInstance(context).getTemplatePath()));
}
/* (non-Javadoc)
@@ -52,12 +74,17 @@ public class PackageTag extends AbstractContainerTag
*/
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
+ // nothing to do
+ }
+
+
+ public String getPackageName()
+ {
+ return packageName;
}
- public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ public IPath getSourceFolderPath()
{
-// String name = getAttribute("name"); //$NON-NLS-1$
-// String srcFolder = getAttribute("srcFolder"); //$NON-NLS-1$
- throw new JET2TagException("not implemented yet"); //$NON-NLS-1$
+ return srcFolderPath;
}
}
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
new file mode 100644
index 0000000..cc2f4f7
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
@@ -0,0 +1,204 @@
+/**
+ * <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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.taglib.java;
+
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.codegen.util.ImportManager;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+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.JET2Writer;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
+import org.eclipse.jet.internal.taglib.java.PackageTag;
+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.Position;
+
+
+/**
+ * Utility class for Java related actions.
+ */
+public class JavaActionsUtil
+{
+
+ /**
+ *
+ */
+ private JavaActionsUtil()
+ {
+ super();
+ }
+
+ /**
+ * @param sourceFolder
+ * @param packageName
+ * @return
+ * @throws JET2TagException
+ */
+ public static IFolder getFolderForPackage(IPath sourceFolder, String packageName) throws JET2TagException
+ {
+ IFolder result = null;
+ if (sourceFolder == null || packageName == null)
+ {
+ throw new NullPointerException();
+ }
+ if (sourceFolder.segmentCount() == 0)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ // if the JDT is not sync'd with the workspace changes, this may return null.
+ IJavaElement jElementForFolder = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getFolder(sourceFolder));
+
+ if (jElementForFolder == null)
+ {
+ // checkpoint the workspace (inform the builders) of our changes to date...
+ ActionsUtil.checkpointWorkspace(true, new NullProgressMonitor());
+ // and try again...
+ jElementForFolder = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getFolder(sourceFolder));
+ }
+
+ if (jElementForFolder != null)
+ {
+ // find the package fragment root corresponding to sourceFolder
+ if (!(jElementForFolder instanceof IPackageFragmentRoot))
+ {
+ throw new JET2TagException(MessageFormat.format(JET2Messages.JavaActionsUtil_InvalidSourceFolder, new Object []{ sourceFolder.toString() }));
+ }
+ IPackageFragmentRoot root = (IPackageFragmentRoot)jElementForFolder;
+ final IPackageFragment packageFragment = root.getPackageFragment(packageName);
+ result = (IFolder)packageFragment.getResource();
+ }
+ else
+ {
+ // sourceFolder wasn't a package root, maybe its just a project name, and we need to use the first package
+ // root in that project that contains the packageName
+ if (sourceFolder.segmentCount() >= 1)
+ {
+ String msg;
+ msg = JET2Messages.JavaActionsUtil_InvalidSourceFolder;
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{ sourceFolder.toString() }));
+ }
+ IJavaProject jProject = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(sourceFolder.segment(0)));
+ try
+ {
+ result = findOrCreateJavaPackage(jProject, packageName);
+ }
+ catch (JavaModelException e1)
+ {
+ final String msg = JET2Messages.JavaActionsUtil_CannotFindSourceFolder;
+ // it's serious this time, throw an exception;
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{ sourceFolder.segment(0), packageName, }));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param jProject
+ * @param packageName
+ * @return
+ * @throws JavaModelException
+ */
+ private static IFolder findOrCreateJavaPackage(IJavaProject jProject, String packageName) throws JavaModelException
+ {
+ final IPackageFragment[] fragments = jProject.getPackageFragments();
+ for (int i = 0; i < fragments.length; i++)
+ {
+ if (packageName.equals(fragments[i].getElementName()))
+ {
+ return (IFolder)fragments[i].getResource();
+ }
+ }
+ // didn't find an existing fragment, we'll create a fragment in the first package root...
+ final IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots();
+ for (int i = 0; i < roots.length; i++)
+ {
+ if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE)
+ {
+ IPackageFragment fragment = roots[i].getPackageFragment(packageName);
+ return (IFolder)fragment.getResource();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the imports manager installed in the current writer.
+ * @param writer the current writer. Cannot be <code>null</code>.
+ * @return the imports manager installed on the writer.
+ * @throws JET2TagException if no &lt;java:importsLocation&gt; tag has executed on the writer.
+ * @throws NullPointerException if <code>writer</code> is <code>null</code>.
+ */
+ public static ImportManager getImportManager(JET2Writer writer) throws JET2TagException
+ {
+
+ // defensive add of the category...
+ writer.addPositionCategory(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+
+ Position[] positions = writer.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);
+ }
+ }
+
+ public static PackageTag findContainingJavaPackageTag(CustomTag tag) throws JET2TagException
+ {
+ for (CustomTag parent = tag.getParent(); parent != null; parent = parent.getParent())
+ {
+ if (parent instanceof PackageTag)
+ {
+ return (PackageTag)parent;
+ }
+ }
+
+ final String msg = JET2Messages.JavaActionsUtil_RequiresAttrOrContainerTag;
+ String attrName = "packageName"; //$NON-NLS-1$
+ String tagName = "<java:package>"; //$NON-NLS-1$
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{ attrName, tagName }));
+ }
+
+ public static IFile getResourceForJavaResource(IPath srcFolderPath, String pkgName, String fileName) throws JET2TagException
+ {
+ IFolder folder = getFolderForPackage(srcFolderPath, pkgName);
+ return folder.getFile(fileName);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaImportsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaImportsUtil.java
index 19de48e..0cc4505 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaImportsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaImportsUtil.java
@@ -16,13 +16,12 @@
*/
package org.eclipse.jet.taglib.java;
+
+
import org.eclipse.emf.codegen.util.ImportManager;
import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
-import org.eclipse.jet.internal.taglib.java.ImportsLocationTag.ImportsPosition;
import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jface.text.Position;
+
/**
* Utility function for sharing access to {@link ImportManager} created by the &lt;java:importsManager;&gt; tags.
@@ -47,27 +46,11 @@ public final class JavaImportsUtil
* @return the imports manager installed on the writer.
* @throws JET2TagException if no &lt;java:importsLocation&gt; tag has executed on the writer.
* @throws NullPointerException if <code>writer</code> is <code>null</code>.
+ * @deprecated Use {@link JavaActionsUtil#getImportManager(JET2Writer)} instead
*/
public static ImportManager getImportManager(JET2Writer writer) throws JET2TagException
{
-
- // defensive add of the category...
- writer.addPositionCategory(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
-
- Position[] positions = writer.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);
- }
+ return JavaActionsUtil.getImportManager(writer);
}
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java
index 1253af2..4730a7b 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java
@@ -9,7 +9,7 @@ import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.taglib.java.JavaImportsUtil;
+import org.eclipse.jet.taglib.java.JavaActionsUtil;
import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.Position;
@@ -109,7 +109,7 @@ public class TestImportsLocationTag extends TestCase {
final ImportManager tagInstalledMananger = verifyImportManagerInstalled(writer);
// Test: get the installed imports tag the public way...
- final ImportManager importManager = JavaImportsUtil.getImportManager(writer);
+ final ImportManager importManager = JavaActionsUtil.getImportManager(writer);
// Verify
assertEquals(tagInstalledMananger, importManager);
@@ -123,7 +123,7 @@ public class TestImportsLocationTag extends TestCase {
// Test: get the installed imports tag the public way...
try {
- JavaImportsUtil.getImportManager(writer);
+ JavaActionsUtil.getImportManager(writer);
fail("Expected thrown JET2TagException");
} catch(JET2TagException e) {
// success