Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-02-05 23:00:50 +0000
committeratikhomirov2006-02-05 23:00:50 +0000
commitcca1c54b02ecf140e00c95d229bd7eebacff9302 (patch)
treeb5cb7c28da4c28f8f8549057afd58ac67e1c50ce /plugins/org.eclipse.gmf.graphdef.codegen/templates
parent15116d3fbfecf3c31d6f716805521acf323bd601 (diff)
downloadorg.eclipse.gmf-tooling-cca1c54b02ecf140e00c95d229bd7eebacff9302.tar.gz
org.eclipse.gmf-tooling-cca1c54b02ecf140e00c95d229bd7eebacff9302.tar.xz
org.eclipse.gmf-tooling-cca1c54b02ecf140e00c95d229bd7eebacff9302.zip
provisional framework that supports (double-)dispatch from templates to
a) avoid lengthy if instanceof elseif checks, b) solve scope and name visibility issues when extracting common code into jetinc
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/templates')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/ConcreteShape.javajet12
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/CustomFigure.javajet3
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/PolylineConnection.javajet8
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.javajet (renamed from plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.jetinc)14
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/instantiate.jetinc2
5 files changed, 21 insertions, 18 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/ConcreteShape.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/ConcreteShape.javajet
index e7b74457c..448a04e09 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/ConcreteShape.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/ConcreteShape.javajet
@@ -1,10 +1,11 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="ShapeGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* java.util.*"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.Dispatcher java.util.*"%>
<%
Object[] args = (Object[]) argument;
Shape shapeFig = (Shape) args[0];
final ImportAssistant importManager = (ImportAssistant) args[1];
final GMFGraphSwitch fqnSwitch = new FigureQualifiedNameSwitch();
+final Dispatcher dispatcher = (Dispatcher) args[2];
%>
<%importManager.markImportLocation(stringBuffer);%>
@@ -18,14 +19,9 @@ public class <%=shapeFig.getName()%> extends <%=importManager.getImportedName((S
* @generated
*/
public <%=shapeFig.getName()%>() {
+<%=dispatcher.dispatch("ShapeAttrs", dispatcher.create(shapeFig, "this", importManager, fqnSwitch))%>
<%
-{
-Shape figureInstance = shapeFig;
-String figureVarName = "this";
-%>
-<%@ include file="ShapeAttrs.jetinc" %>
-<%
-}for (Iterator it = shapeFig.getResolvedChildren().iterator(); it.hasNext();) {
+for (Iterator it = shapeFig.getResolvedChildren().iterator(); it.hasNext();) {
Figure next = (Figure) it.next();%>
setFigure<%=next.getName()%>(createFigure<%=next.getName()%>());
add(getFigure<%=next.getName()%>());
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/CustomFigure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/CustomFigure.javajet
index 467bb587f..981d23bae 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/CustomFigure.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/CustomFigure.javajet
@@ -1,10 +1,11 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="CustomFigureGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* java.util.*"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.Dispatcher java.util.*"%>
<%
Object[] args = (Object[]) argument;
CustomFigure figure = (CustomFigure) args[0];
final ImportAssistant importManager = (ImportAssistant) args[1];
final GMFGraphSwitch fqnSwitch = new FigureQualifiedNameSwitch();
+final Dispatcher dispatcher = (Dispatcher) args[2];
%>
<%importManager.markImportLocation(stringBuffer);%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/PolylineConnection.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/PolylineConnection.javajet
index ed1c25606..ca11d4de0 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/PolylineConnection.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/PolylineConnection.javajet
@@ -1,11 +1,12 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="ConnectionGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* java.util.*"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.Dispatcher java.util.*"%>
<%
Object[] args = (Object[]) argument;
PolylineConnection figure = (PolylineConnection) args[0];
final ImportAssistant importManager = (ImportAssistant) args[1];
final GMFGraphSwitch fqnSwitch = new FigureQualifiedNameSwitch();
+final Dispatcher dispatcher = (Dispatcher) args[2];
%>
<%importManager.markImportLocation(stringBuffer);%>
@@ -19,10 +20,7 @@ public class <%=figure.getName()%> extends <%=importManager.getImportedName("org
* @generated
*/
public <%=figure.getName()%>() {
-<% { // scope
-Shape figureInstance = figure;
-String figureVarName = "this";%>
-<%@ include file="ShapeAttrs.jetinc" %><% }// scope %>
+<%=dispatcher.dispatch("ShapeAttrs", dispatcher.create(figure, "this", importManager, fqnSwitch))%>
<%if (figure.getSourceDecoration() != null) {%>
setSourceDecoration(createSourceDecoration());
<%}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.javajet
index 312ad4d7f..815afd334 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.jetinc
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/ShapeAttrs.javajet
@@ -1,3 +1,11 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="ShapeAttrsGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.common.codegen.* java.util.* org.eclipse.gmf.graphdef.codegen.Dispatcher"%>
+<%
+Dispatcher.Args args = (Dispatcher.Args) argument;
+final Shape figureInstance = (Shape) args.getFigure();
+final String figureVarName = args.getVariableName();
+final ImportAssistant importManager = args.getImportManager();
+%>
<%
// PERHAPS, do this with reflection?
%><%if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getShape_Fill())) {%>
@@ -7,7 +15,7 @@
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineWidth())) {%>
<%=figureVarName%>.setLineWidth(<%=figureInstance.getLineWidth()%>);
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineKind())) {%>
- <%=figureVarName%>.setLineStyle(org.eclipse.draw2d.Graphics.<%=figureInstance.getLineKind().getName()%>);
+ <%=figureVarName%>.setLineStyle(<%=importManager.getImportedName("org.eclipse.draw2d.Graphics")%>.<%=figureInstance.getLineKind().getName()%>);
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getShape_XorFill())) {%>
<%=figureVarName%>.setFillXOR(<%=figureInstance.isXorFill()%>);
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getShape_XorOutline())) {%>
@@ -15,8 +23,8 @@
<%} if (figureInstance instanceof Polyline && !((Polyline) figureInstance).getTemplate().isEmpty()) {
for (Iterator pointIt = ((Polyline) figureInstance).getTemplate().iterator(); pointIt.hasNext(); ) {
Point p = (Point) pointIt.next();%>
- <%=figureVarName%>.addPoint(new org.eclipse.draw2d.geometry.Point(<%=p.getX()%>, <%=p.getY()%>));
+ <%=figureVarName%>.addPoint(new <%=importManager.getImportedName("org.eclipse.draw2d.geometry.Point")%>(<%=p.getX()%>, <%=p.getY()%>));
<%}%><%} else if (figureInstance instanceof RoundedRectangle) {
RoundedRectangle rrFigure = (RoundedRectangle) figureInstance;%>
- <%=figureVarName%>.setCornerDimensions(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(<%=rrFigure.getCornerWidth()%>), getMapMode().DPtoLP(<%=rrFigure.getCornerHeight()%>)));
+ <%=figureVarName%>.setCornerDimensions(new <%=importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")%>(getMapMode().DPtoLP(<%=rrFigure.getCornerWidth()%>), getMapMode().DPtoLP(<%=rrFigure.getCornerHeight()%>)));
<%}%><%@ include file="FigureAttrs.jetinc"%> \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/instantiate.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/instantiate.jetinc
index f4b9584c1..99cc56df9 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/instantiate.jetinc
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/instantiate.jetinc
@@ -9,7 +9,7 @@ if (figureMarker instanceof CustomFigure) {
<%} else if (figureMarker instanceof Shape) {
Shape figureInstance = (Shape) figureMarker;%>
<%=fqnSwitch.doSwitch(figureMarker)%> <%=figureVarName%> = new <%=fqnSwitch.doSwitch(figureMarker)%>();
-<%@ include file="ShapeAttrs.jetinc"%>
+<%=dispatcher.dispatch("ShapeAttrs", dispatcher.create(figureInstance, figureVarName, importManager, fqnSwitch))%>
<%} else if (figureMarker instanceof FigureRef) {%>
org.eclipse.draw2d.IFigure <%=figureVarName%> = new <%=((FigureRef) figureMarker).getFigure().getName()%>();
<%} else if (figureMarker instanceof Label) {

Back to the top