summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-05-09 10:04:22 (EDT)
committer pelder2007-05-09 10:04:22 (EDT)
commitae7ecbc6e4e2f6559b37696db329830b621ef1fa (patch)
tree8155dff7169d34164d63635e3093a32d6e11604d
parent269b1296015b580d2ead157245a5bc42e922b999 (diff)
downloadorg.eclipse.jet-ae7ecbc6e4e2f6559b37696db329830b621ef1fa.zip
org.eclipse.jet-ae7ecbc6e4e2f6559b37696db329830b621ef1fa.tar.gz
org.eclipse.jet-ae7ecbc6e4e2f6559b37696db329830b621ef1fa.tar.bz2
[176402] <java:merge> tag NPE's when attempting to merging Java 5 code
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/javaTags/mergeTag.html6
-rw-r--r--plugins/org.eclipse.jet/Generate Taglib Docs - org.eclipse.jet (plugin.xml).launch6
-rw-r--r--plugins/org.eclipse.jet/plugin.xml8
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java61
4 files changed, 62 insertions, 19 deletions
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/javaTags/mergeTag.html b/doc/org.eclipse.jet.doc/references/taglibs/javaTags/mergeTag.html
index 1fb457f..bb27b58 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/javaTags/mergeTag.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/javaTags/mergeTag.html
@@ -33,7 +33,7 @@
<TR>
<TD width="10%">full tag</TD>
<TD><SPAN style="font-family: monospace">
- &lt;java:merge rules=&quot;<I>value</I>&quot; rulesContext=&quot;<I>value</I>&quot;/&gt;<br>
+ &lt;java:merge rules=&quot;<I>value</I>&quot; rulesContext=&quot;<I>value</I>&quot; facade=&quot;<I>value</I>&quot;/&gt;<br>
</SPAN></TD>
</TR>
</TBODY>
@@ -52,6 +52,10 @@
<TD width="10%">rulesContext</TD>
<TD><BR> The context for resolving relative 'rules' URLs. Possible values are 'transform' or 'workspace'. If the value is 'transform', then the 'rules' URL is treated as a JET project relative path. If the value is 'workspace', then the 'rules' URL is treated as an Eclipse workspace relative path. The default is 'transform'.<BR> </TD>
</TR>
+ <TR>
+ <TD width="10%">facade</TD>
+ <TD><BR> Specify the merge facade class to use. Default is for EMF 2.2 is org.eclipse.emf.codegen.merge.java.facade.jdom.JDOMFacadeHelper. For EMF 2.3 and later, the default is org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper.<BR> </TD>
+ </TR>
</TBODY>
</TABLE>
<HR>
diff --git a/plugins/org.eclipse.jet/Generate Taglib Docs - org.eclipse.jet (plugin.xml).launch b/plugins/org.eclipse.jet/Generate Taglib Docs - org.eclipse.jet (plugin.xml).launch
new file mode 100644
index 0000000..cfb5816
--- /dev/null
+++ b/plugins/org.eclipse.jet/Generate Taglib Docs - org.eclipse.jet (plugin.xml).launch
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.jet.jet2Transformation">
+<stringAttribute key="org.eclipse.jet.id" value="org.eclipse.jet.transforms.taglibdoc"/>
+<intAttribute key="org.eclipse.jet.logFilterLevel" value="3"/>
+<stringAttribute key="org.eclipse.jet.source" value="org.eclipse.jet/plugin.xml"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 1cd64ab..1e37d43 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -792,6 +792,14 @@ This tag may occur only once in a template.
The context for resolving relative 'rules' URLs. Possible values are 'transform' or 'workspace'. If the value is 'transform', then the 'rules' URL is treated as a JET project relative path. If the value is 'workspace', then the 'rules' URL is treated as an Eclipse workspace relative path. The default is 'transform'.
</description>
</attribute>
+ <attribute
+ name="facade"
+ type="string"
+ use="optional">
+ <description>
+ Specify the merge facade class to use. Default is for EMF 2.2 is org.eclipse.emf.codegen.merge.java.facade.jdom.JDOMFacadeHelper. For EMF 2.3 and later, the default is org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper.
+ </description>
+ </attribute>
</emptyTag><containerTag
class="org.eclipse.jet.internal.taglib.java.PackageTag"
name="package"
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 cfd9048..6da8613 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
@@ -21,12 +21,13 @@ import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.codegen.jmerge.JControlModel;
-import org.eclipse.emf.codegen.jmerge.JMerger;
-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.emf.codegen.CodeGenPlugin;
+import org.eclipse.emf.codegen.merge.java.JControlModel;
+import org.eclipse.emf.codegen.merge.java.JMerger;
+import org.eclipse.emf.codegen.merge.java.facade.FacadeHelper;
+import org.eclipse.emf.codegen.merge.java.facade.JCompilationUnit;
+import org.eclipse.emf.codegen.merge.properties.PropertyMerger;
+import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
@@ -40,7 +41,6 @@ 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.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -50,8 +50,9 @@ import org.eclipse.jface.text.Position;
public class MergeTag extends AbstractEmptyTag
{
- private final String EMF_CODEGEN_RULES_URL = "platform:/plugin/org.eclipse.emf.codegen.ecore/templates/emf-merge.xml"; //$NON-NLS-1$
-
+ private static final String EMF_CODEGEN_RULES_URL = "platform:/plugin/org.eclipse.emf.codegen.ecore/templates/emf-merge.xml"; //$NON-NLS-1$
+ private static final String AST_FACADE = "org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper"; //$NON-NLS-1$
+ private static final String JDOM_FACADE = "org.eclipse.emf.codegen.merge.java.facade.jdom.JDOMFacadeHelper"; //$NON-NLS-1$
/**
* Position marker for JMergeable content.
*/
@@ -59,11 +60,13 @@ public class MergeTag extends AbstractEmptyTag
{
private final URL rulesURL;
+ private final FacadeHelper facadeHelper;
- public MergePosition(URL rulesURL, int offset)
+ public MergePosition(URL rulesURL, int offset, FacadeHelper facadeHelper)
{
super(offset);
this.rulesURL = rulesURL;
+ this.facadeHelper = facadeHelper;
}
@@ -75,6 +78,11 @@ public class MergeTag extends AbstractEmptyTag
return rulesURL;
}
+ public FacadeHelper getFacadeHelper()
+ {
+ return facadeHelper;
+ }
+
}
/**
@@ -151,16 +159,21 @@ public class MergeTag extends AbstractEmptyTag
final Position[] positions = document.getPositions(JMERGE_POSITION_CATEGORY);
String targetCUSource = TagUtil.getContents(iFile.getLocation());
- IDOMFactory domFactory = new DOMFactory();
- IDOMCompilationUnit sourceCU = domFactory.createCompilationUnit(writer.toString(), iFile.getName());
+ MergePosition mergePosition = (MergePosition)positions[0];
+ FacadeHelper facadeHelper = mergePosition.getFacadeHelper();
+ JControlModel controlModel = new JControlModel();
+
+ controlModel.initialize(facadeHelper, mergePosition.getRulesURL().toExternalForm());
- IDOMCompilationUnit targetCU = domFactory.createCompilationUnit(targetCUSource, iFile.getName());
- JControlModel controlModel = new JControlModel(((MergePosition)positions[0]).getRulesURL().toExternalForm());
- JMerger merger = new JMerger(controlModel, sourceCU, targetCU);
+ JMerger merger = new JMerger(controlModel);
+ JCompilationUnit sourceCU = facadeHelper.createCompilationUnit(iFile.getName(), writer.toString());
+ JCompilationUnit targetCU = facadeHelper.createCompilationUnit(iFile.getName(), targetCUSource);
+ merger.setSourceCompilationUnit(sourceCU);
+ merger.setTargetCompilationUnit(targetCU);
+
merger.merge();
-
((BufferedJET2Writer)writer).setContent(targetCU.getContents());
}
catch (CoreException e)
@@ -173,8 +186,8 @@ public class MergeTag extends AbstractEmptyTag
// This should not happen. Wrap in a runtime exception
throw new RuntimeException(e);
}
+
}
-
/* (non-Javadoc)
* @see org.eclipse.jet.IWriterListener#postCommitContent(org.eclipse.jet.JET2Writer, java.lang.Object)
*/
@@ -217,6 +230,13 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
rulesContext = "transform"; //$NON-NLS-1$
}
+ String facade = getAttribute("facade"); //$NON-NLS-1$
+ if(facade == null) {
+ String emfCodeGenVersion = (String)CodeGenPlugin.getPlugin().getBundle().getHeaders().get("Bundle-Version"); //$NON-NLS-1$
+ // The AST facade rules don't seem to work well in 2.2.x
+ facade = emfCodeGenVersion.startsWith("2.2.") ? JDOM_FACADE : AST_FACADE; //$NON-NLS-1$
+ }
+
final URL baseURL = TransformContextExtender.getInstance(context).getBaseURL(rulesContext);
if(rules.startsWith("/")) //$NON-NLS-1$
@@ -226,11 +246,16 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
try
{
+ FacadeHelper facadeHelper = CodeGenUtil.instantiateFacadeHelper(facade);
+ if(facadeHelper == null) {
+ throw new JET2TagException(MessageFormat.format("Unknown JMerge facade helper: {0}",
+ new Object []{ facade }));
+ }
URL rulesURL = new URL(baseURL, rules);
DocumentHelper.installPositionCategory(document, JMERGE_POSITION_CATEGORY);
- document.addPosition(JMERGE_POSITION_CATEGORY, new MergePosition(rulesURL, bufferedWriter.getContentLength()));
+ document.addPosition(JMERGE_POSITION_CATEGORY, new MergePosition(rulesURL, bufferedWriter.getContentLength(), facadeHelper));
bufferedWriter.addEventListener(JMERGE_POSITION_CATEGORY, new JMergeProcessor());
}