diff options
20 files changed, 584 insertions, 244 deletions
diff --git a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java index e26d13720..fe46c5abf 100644 --- a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java +++ b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java @@ -63,7 +63,7 @@ public class InnerClassViewmapProducer extends DefaultViewmapProducer { assert figureNameSwitch != null; fqnSwitch = figureNameSwitch; processedFigures = new HashSet(); - figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy); + figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy, true); } public Viewmap create(Node node) { diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java index 9d7e34145..b7fb8860d 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java @@ -80,12 +80,14 @@ import org.osgi.framework.Bundle; public class FigureGenerator implements TextEmitter { private GraphDefDispatcher myTopDispatcher; private GraphDefDispatcher myInnerDispatcher; + private final boolean myIsInnerClassCode; - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch) { - this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode()); + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean asInnerClass) { + this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode(), asInnerClass); } - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy) { + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy, boolean placeStaticFieldsOutsideClassBody) { + myIsInnerClassCode = placeStaticFieldsOutsideClassBody; final Bundle thisBundle = Platform.getBundle("org.eclipse.gmf.graphdef.codegen"); final String[] variables = new String[] { "org.eclipse.gmf.graphdef", @@ -177,9 +179,9 @@ public class FigureGenerator implements TextEmitter { public String go(Figure fig, ImportAssistant importManager/*, Feedback feedback*/) { String res = null; - myTopDispatcher.setImportManager(importManager); - myInnerDispatcher.setImportManager(importManager); - Object args = new Object[] {fig, importManager, myTopDispatcher.getFQNSwitch(), myInnerDispatcher}; + myTopDispatcher.resetForNewClass(importManager); + myInnerDispatcher.resetForNewClass(importManager); + Object args = new Object[] {fig, importManager, myTopDispatcher.getFQNSwitch(), myInnerDispatcher, Boolean.valueOf(myIsInnerClassCode)}; res = myTopDispatcher.dispatch(fig, args); if (res == null) { throw new IllegalStateException(); diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java index 9eb244038..14e6563db 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java @@ -27,12 +27,18 @@ public class GraphDefDispatcher extends DispatcherImpl { private ImportAssistant myImportManager; private final FigureQualifiedNameSwitch myFqnSwitch; private final MapModeCodeGenStrategy myMapModeStrategy; + private final StaticFieldsManager myStaticFieldsManager; public GraphDefDispatcher(EmitterFactory factory, KeyMap keyMap, FigureQualifiedNameSwitch fqnSwitch, MapModeCodeGenStrategy mapModeStrategy) { super(factory, keyMap); assert mapModeStrategy != null; myFqnSwitch = fqnSwitch; - myMapModeStrategy = mapModeStrategy; + myMapModeStrategy = mapModeStrategy; + myStaticFieldsManager = new StaticFieldsManager(); + } + + public StaticFieldsManager getStaticFieldsManager(){ + return myStaticFieldsManager; } public String DPtoLP(int deviceUnit){ @@ -46,12 +52,13 @@ public class GraphDefDispatcher extends DispatcherImpl { public ImportAssistant getImportManager() { return myImportManager; } - + /** * Not good. Would be better to have importManager as part of Args, perhaps. */ - /*package-local*/ void setImportManager(ImportAssistant manager) { - myImportManager = manager; + /*package-local*/ void resetForNewClass(ImportAssistant assistant) { + setImportManager(assistant); + myStaticFieldsManager.reset(); } public FigureQualifiedNameSwitch getFQNSwitch() { @@ -73,6 +80,10 @@ public class GraphDefDispatcher extends DispatcherImpl { public LayoutArgs createLayoutArgs(Args inherit, String managerVarName, String constraintVarName) { return new LayoutArgs(inherit, managerVarName, constraintVarName); } + + private void setImportManager(ImportAssistant manager) { + myImportManager = manager; + } public static class Args { private final Figure myFigure; diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java index 06955f8ef..74fe79487 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java @@ -129,7 +129,7 @@ public class StandaloneGenerator extends GeneratorBase { strategy = new MapModeCodeGenStrategy.StaticIdentityMapMode(); } - myFigureGenerator = new FigureGenerator(fqnSwitch, strategy); + myFigureGenerator = new FigureGenerator(fqnSwitch, strategy, false); myAuxiliaryGenerators = new StandaloneEmitters(); } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java new file mode 100644 index 000000000..9499bf30a --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2006 Borland Software Corporation + * + * 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: + * Michael Golubev (Borland) - initial API and implementation + */ + +package org.eclipse.gmf.graphdef.codegen; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class StaticFieldsManager { + private final Map/*<String, StaticField>*/ myFields = new HashMap/*<String, StaticField>*/(); + private final Map/*<String, StaticField>*/ myFieldsRO = Collections.unmodifiableMap(myFields); + private final String myDeclaringClassPrefix; + + public StaticFieldsManager(String declaringClassName){ + myDeclaringClassPrefix = (declaringClassName == null || declaringClassName.length() == 0) ? + "" : declaringClassName + "."; + } + + public StaticFieldsManager(){ + this(null); + } + + public String addStaticField(String type, String nameHint, String value) { + int suffix = 0; + String actualName; + do { + actualName = nameHint + ((suffix == 0) ? "" : "_" + suffix); + suffix++; + } while (myFields.containsKey(actualName)); + StaticField field = new StaticField(type, actualName, value); + myFields.put(actualName, field); + return myDeclaringClassPrefix + actualName; + } + + public void reset() { + myFields.clear(); + } + + public Iterator allFields() { + return myFieldsRO.values().iterator(); + } + + public static class StaticField { + private final String myType; + private final String myName; + private final String myValue; + + public StaticField(String type, String name, String value){ + myType = type; + myName = name; + myValue = value; + } + + public String getName() { + return myName; + } + + public String getType() { + return myType; + } + + public String getValue() { + return myValue; + } + } +} diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java index 45d63e1be..08ff21c27 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java @@ -18,58 +18,41 @@ public class FigureAttrGenerator protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "\t\t"; protected final String TEXT_2 = ".setForegroundColor("; - protected final String TEXT_3 = "new "; - protected final String TEXT_4 = "(null, "; - protected final String TEXT_5 = ", "; - protected final String TEXT_6 = ", "; - protected final String TEXT_7 = ")"; - protected final String TEXT_8 = "."; - protected final String TEXT_9 = ");"; - protected final String TEXT_10 = NL + "\t\t"; - protected final String TEXT_11 = ".setBackgroundColor("; - protected final String TEXT_12 = "new "; - protected final String TEXT_13 = "(null, "; - protected final String TEXT_14 = ", "; - protected final String TEXT_15 = ", "; - protected final String TEXT_16 = ")"; - protected final String TEXT_17 = "."; - protected final String TEXT_18 = ");"; - protected final String TEXT_19 = NL + "\t\t"; - protected final String TEXT_20 = ".setPreferredSize("; - protected final String TEXT_21 = ", "; - protected final String TEXT_22 = ");"; - protected final String TEXT_23 = NL + "\t\t"; - protected final String TEXT_24 = ".setSize("; - protected final String TEXT_25 = ", "; - protected final String TEXT_26 = ");"; - protected final String TEXT_27 = NL + "\t\t"; - protected final String TEXT_28 = ".setMaximumSize(new "; - protected final String TEXT_29 = "("; - protected final String TEXT_30 = ", "; - protected final String TEXT_31 = "));"; - protected final String TEXT_32 = NL + "\t\t"; - protected final String TEXT_33 = ".setMinimumSize(new "; - protected final String TEXT_34 = "("; - protected final String TEXT_35 = ", "; - protected final String TEXT_36 = "));"; - protected final String TEXT_37 = NL + "\t\t"; - protected final String TEXT_38 = ".setFont(new "; - protected final String TEXT_39 = "("; - protected final String TEXT_40 = ".getCurrent(), \""; - protected final String TEXT_41 = "\", "; - protected final String TEXT_42 = ", "; - protected final String TEXT_43 = "."; - protected final String TEXT_44 = "));"; - protected final String TEXT_45 = NL + "\t\t"; - protected final String TEXT_46 = ".setBorder(new "; - protected final String TEXT_47 = "("; - protected final String TEXT_48 = ", "; - protected final String TEXT_49 = ", "; - protected final String TEXT_50 = ", "; - protected final String TEXT_51 = "));"; - protected final String TEXT_52 = NL + "\t\t"; - protected final String TEXT_53 = ".setBorder("; - protected final String TEXT_54 = ");"; + protected final String TEXT_3 = NL + NL + ");"; + protected final String TEXT_4 = NL + "\t\t"; + protected final String TEXT_5 = ".setBackgroundColor("; + protected final String TEXT_6 = NL + NL + ");"; + protected final String TEXT_7 = NL + "\t\t"; + protected final String TEXT_8 = ".setPreferredSize("; + protected final String TEXT_9 = ", "; + protected final String TEXT_10 = ");"; + protected final String TEXT_11 = NL + "\t\t"; + protected final String TEXT_12 = ".setSize("; + protected final String TEXT_13 = ", "; + protected final String TEXT_14 = ");"; + protected final String TEXT_15 = NL + "\t\t"; + protected final String TEXT_16 = ".setMaximumSize(new "; + protected final String TEXT_17 = "("; + protected final String TEXT_18 = ", "; + protected final String TEXT_19 = "));"; + protected final String TEXT_20 = NL + "\t\t"; + protected final String TEXT_21 = ".setMinimumSize(new "; + protected final String TEXT_22 = "("; + protected final String TEXT_23 = ", "; + protected final String TEXT_24 = "));"; + protected final String TEXT_25 = NL + "\t\t"; + protected final String TEXT_26 = ".setFont(" + NL + "\t\t\t"; + protected final String TEXT_27 = ");"; + protected final String TEXT_28 = NL + "\t\t"; + protected final String TEXT_29 = ".setBorder(new "; + protected final String TEXT_30 = "("; + protected final String TEXT_31 = ", "; + protected final String TEXT_32 = ", "; + protected final String TEXT_33 = ", "; + protected final String TEXT_34 = "));"; + protected final String TEXT_35 = NL + "\t\t"; + protected final String TEXT_36 = ".setBorder("; + protected final String TEXT_37 = ");"; public String generate(Object argument) { @@ -81,89 +64,99 @@ final String figureVarName = args.getVariableName(); final GraphDefDispatcher dispatcher = args.getDispatcher(); final ImportAssistant importManager = dispatcher.getImportManager(); - Color colorVal; + +Color colorVal; +String colorName; if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())) { colorVal = figureInstance.getForegroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_FORE"; stringBuffer.append(TEXT_1); stringBuffer.append(figureVarName); stringBuffer.append(TEXT_2); - if (colorVal instanceof RGBColor) { + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_3); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_8); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_9); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) { colorVal = figureInstance.getBackgroundColor(); - stringBuffer.append(TEXT_10); + colorName = figureInstance.getName().toUpperCase() + "_BACK"; + stringBuffer.append(TEXT_4); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_11); - if (colorVal instanceof RGBColor) { - stringBuffer.append(TEXT_12); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_13); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_14); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_15); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_16); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_17); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_5); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + + stringBuffer.append(TEXT_6); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) { Dimension d = figureInstance.getPreferredSize(); - stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_7); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_8); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_9); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_10); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) { Point p = figureInstance.getSize(); - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_11); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_12); stringBuffer.append(dispatcher.DPtoLP(p.getX())); - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_13); stringBuffer.append(dispatcher.DPtoLP(p.getY())); - stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_14); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) { Dimension d = figureInstance.getMaximumSize(); - stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_15); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_28); + stringBuffer.append(TEXT_16); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_17); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_30); + stringBuffer.append(TEXT_18); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_31); + stringBuffer.append(TEXT_19); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) { Dimension d = figureInstance.getMinimumSize(); - stringBuffer.append(TEXT_32); + stringBuffer.append(TEXT_20); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_21); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_34); + stringBuffer.append(TEXT_22); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_35); + stringBuffer.append(TEXT_23); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_24); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) { // XXX possible CCE when fonts other than Basic added to model BasicFont font = (BasicFont) figureInstance.getFont(); @@ -175,43 +168,37 @@ if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor()) } } - stringBuffer.append(TEXT_37); + stringBuffer.append(TEXT_25); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_38); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Font")); - stringBuffer.append(TEXT_39); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.widgets.Display")); - stringBuffer.append(TEXT_40); - stringBuffer.append(fontName); - stringBuffer.append(TEXT_41); - stringBuffer.append(font.getHeight()); - stringBuffer.append(TEXT_42); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT")); - stringBuffer.append(TEXT_43); - stringBuffer.append(font.getStyle().getLiteral()); - stringBuffer.append(TEXT_44); + stringBuffer.append(TEXT_26); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField( + importManager.getImportedName("org.eclipse.swt.graphics.Font"), + figureInstance.getName().toUpperCase() + "_FONT", + "new " + importManager.getImportedName("org.eclipse.swt.graphics.Font") + "(" + importManager.getImportedName("org.eclipse.swt.widgets.Display") + ".getCurrent(), \"" + fontName + "\", " + font.getHeight() + ", " + importManager.getImportedName("org.eclipse.swt.SWT") + "." + font.getStyle().getLiteral() + ")" + )); + stringBuffer.append(TEXT_27); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) { Insets insets = figureInstance.getInsets(); - stringBuffer.append(TEXT_45); + stringBuffer.append(TEXT_28); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_46); + stringBuffer.append(TEXT_29); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder")); - stringBuffer.append(TEXT_47); + stringBuffer.append(TEXT_30); stringBuffer.append(dispatcher.DPtoLP(insets.getTop())); - stringBuffer.append(TEXT_48); + stringBuffer.append(TEXT_31); stringBuffer.append(dispatcher.DPtoLP(insets.getLeft())); - stringBuffer.append(TEXT_49); + stringBuffer.append(TEXT_32); stringBuffer.append(dispatcher.DPtoLP(insets.getBottom())); - stringBuffer.append(TEXT_50); + stringBuffer.append(TEXT_33); stringBuffer.append(dispatcher.DPtoLP(insets.getRight())); - stringBuffer.append(TEXT_51); + stringBuffer.append(TEXT_34); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) { Border border = figureInstance.getBorder(); - stringBuffer.append(TEXT_52); + stringBuffer.append(TEXT_35); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_53); + stringBuffer.append(TEXT_36); stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher})); - stringBuffer.append(TEXT_54); + stringBuffer.append(TEXT_37); } return stringBuffer.toString(); } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java index fa91cb5c9..17476b376 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java @@ -18,29 +18,17 @@ public class NewLineBorderExpressionGenerator protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "new "; protected final String TEXT_2 = "("; - protected final String TEXT_3 = "new "; - protected final String TEXT_4 = "(null, "; - protected final String TEXT_5 = ", "; - protected final String TEXT_6 = ", "; - protected final String TEXT_7 = ")"; - protected final String TEXT_8 = "."; - protected final String TEXT_9 = ", "; + protected final String TEXT_3 = NL + NL + ", "; + protected final String TEXT_4 = ")"; + protected final String TEXT_5 = NL + "new "; + protected final String TEXT_6 = "("; + protected final String TEXT_7 = NL + NL + ")"; + protected final String TEXT_8 = NL + "new "; + protected final String TEXT_9 = "("; protected final String TEXT_10 = ")"; protected final String TEXT_11 = NL + "new "; - protected final String TEXT_12 = "("; - protected final String TEXT_13 = "new "; - protected final String TEXT_14 = "(null, "; - protected final String TEXT_15 = ", "; - protected final String TEXT_16 = ", "; - protected final String TEXT_17 = ")"; - protected final String TEXT_18 = "."; - protected final String TEXT_19 = ")"; - protected final String TEXT_20 = NL + "new "; - protected final String TEXT_21 = "("; - protected final String TEXT_22 = ")"; - protected final String TEXT_23 = NL + "new "; - protected final String TEXT_24 = "()"; - protected final String TEXT_25 = NL; + protected final String TEXT_12 = "()"; + protected final String TEXT_13 = NL; public String generate(Object argument) { @@ -59,69 +47,76 @@ final ImportAssistant importManager = dispatcher.getImportManager(); boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color()); boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width()); Color colorVal = (hasColor) ? border.getColor() : null; + String colorName = (hasColor) ? "BORDER" : null; if (hasColor && hasWidth){ stringBuffer.append(TEXT_1); stringBuffer.append(borderClazz); stringBuffer.append(TEXT_2); - if (colorVal instanceof RGBColor) { + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_3); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_8); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_9); stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); - stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_4); } else if (hasColor && !hasWidth) { - stringBuffer.append(TEXT_11); + stringBuffer.append(TEXT_5); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_12); - if (colorVal instanceof RGBColor) { - stringBuffer.append(TEXT_13); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_14); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_15); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_16); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_17); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_18); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_6); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + + stringBuffer.append(TEXT_7); } else if (!hasColor && hasWidth){ - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_8); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_9); stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_10); } else { - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_11); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_12); } - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_13); return stringBuffer.toString(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java index c534fc735..383d2eeb2 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java @@ -3,7 +3,8 @@ package org.eclipse.gmf.graphdef.codegen.templates; import org.eclipse.gmf.gmfgraph.*; import org.eclipse.gmf.gmfgraph.util.*; import org.eclipse.gmf.common.codegen.*; -import org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher; +import org.eclipse.gmf.graphdef.codegen.*; +import java.util.Iterator; public class TopConnectionGenerator { @@ -35,7 +36,19 @@ public class TopConnectionGenerator protected final String TEXT_16 = " createTargetDecoration() {"; protected final String TEXT_17 = NL; protected final String TEXT_18 = NL + "\t\treturn df;" + NL + "\t}"; - protected final String TEXT_19 = NL + "}"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + "}" + NL + "\t"; + protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_22 = " "; + protected final String TEXT_23 = " = "; + protected final String TEXT_24 = ";"; + protected final String TEXT_25 = NL + "\t"; + protected final String TEXT_26 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_27 = " "; + protected final String TEXT_28 = " = "; + protected final String TEXT_29 = ";"; + protected final String TEXT_30 = NL + "}"; + protected final String TEXT_31 = NL; public String generate(Object argument) { @@ -46,6 +59,7 @@ PolylineConnection figure = (PolylineConnection) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean isInnerClass = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -86,7 +100,45 @@ if (figure.getTargetDecoration() != null) { stringBuffer.append(TEXT_18); } stringBuffer.append(TEXT_19); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ + stringBuffer.append(TEXT_20); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_21); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_22); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_23); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_24); + +} + + } else { + stringBuffer.append(TEXT_25); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_26); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_27); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_28); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_29); + +} + + stringBuffer.append(TEXT_30); + } importManager.emitSortedImports(); + stringBuffer.append(TEXT_31); return stringBuffer.toString(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java index 2709ef656..cf51e8846 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java @@ -4,6 +4,7 @@ import org.eclipse.gmf.gmfgraph.*; import org.eclipse.gmf.gmfgraph.util.*; import org.eclipse.gmf.common.codegen.*; import org.eclipse.gmf.graphdef.codegen.*; +import java.util.Iterator;; public class TopFigureGenerator { @@ -30,8 +31,19 @@ public class TopFigureGenerator protected final String TEXT_11 = NL; protected final String TEXT_12 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = "; protected final String TEXT_13 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t"; - protected final String TEXT_14 = NL + "}"; - protected final String TEXT_15 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL + "}" + NL + "\t"; + protected final String TEXT_16 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_17 = " "; + protected final String TEXT_18 = " = "; + protected final String TEXT_19 = ";"; + protected final String TEXT_20 = NL + "\t"; + protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_22 = " "; + protected final String TEXT_23 = " = "; + protected final String TEXT_24 = ";"; + protected final String TEXT_25 = NL + "}"; + protected final String TEXT_26 = NL; public String generate(Object argument) { @@ -42,6 +54,7 @@ Figure figure = (Figure) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean isInnerClass = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -81,8 +94,45 @@ for (java.util.Iterator it = figure.getChildren().iterator(); it.hasNext(); ) { stringBuffer.append(TEXT_13); } stringBuffer.append(TEXT_14); - importManager.emitSortedImports(); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ stringBuffer.append(TEXT_15); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_16); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_17); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_18); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_19); + +} + + } else { + stringBuffer.append(TEXT_20); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_21); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_22); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_23); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_24); + +} + + stringBuffer.append(TEXT_25); + } + importManager.emitSortedImports(); + stringBuffer.append(TEXT_26); return stringBuffer.toString(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc index 9ed864a0e..a88e72277 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc @@ -1 +1,17 @@ -<%if (colorVal instanceof RGBColor) {%>new <%=importManager.getImportedName("org.eclipse.swt.graphics.Color")%>(null, <%=((RGBColor) colorVal).getRed()%>, <%=((RGBColor) colorVal).getGreen()%>, <%=((RGBColor) colorVal).getBlue()%>)<%} else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants")%>.<%=((ConstantColor) colorVal).getValue().getLiteral()%><%}%>
\ No newline at end of file +<% +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; +%><%=dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)%> +<% } else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()%> +<% } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } +%> + diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet index 5cac62da6..d15a4f8a5 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet @@ -7,12 +7,16 @@ final String figureVarName = args.getVariableName(); final GraphDefDispatcher dispatcher = args.getDispatcher(); final ImportAssistant importManager = dispatcher.getImportManager(); %> -<%Color colorVal; +<% +Color colorVal; +String colorName; if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())) { - colorVal = figureInstance.getForegroundColor();%> + colorVal = figureInstance.getForegroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_FORE";%> <%=figureVarName%>.setForegroundColor(<%@ include file="../Color.jetinc"%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) { - colorVal = figureInstance.getBackgroundColor();%> + colorVal = figureInstance.getBackgroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_BACK";%> <%=figureVarName%>.setBackgroundColor(<%@ include file="../Color.jetinc"%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) { Dimension d = figureInstance.getPreferredSize();%> @@ -37,7 +41,12 @@ if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor()) } } %> - <%=figureVarName%>.setFont(new <%=importManager.getImportedName("org.eclipse.swt.graphics.Font")%>(<%=importManager.getImportedName("org.eclipse.swt.widgets.Display")%>.getCurrent(), "<%=fontName%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>)); + <%=figureVarName%>.setFont( + <%=dispatcher.getStaticFieldsManager().addStaticField( + importManager.getImportedName("org.eclipse.swt.graphics.Font"), + figureInstance.getName().toUpperCase() + "_FONT", + "new " + importManager.getImportedName("org.eclipse.swt.graphics.Font") + "(" + importManager.getImportedName("org.eclipse.swt.widgets.Display") + ".getCurrent(), \"" + fontName + "\", " + font.getHeight() + ", " + importManager.getImportedName("org.eclipse.swt.SWT") + "." + font.getStyle().getLiteral() + ")" + )%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) { Insets insets = figureInstance.getInsets();%> <%=figureVarName%>.setBorder(new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=dispatcher.DPtoLP(insets.getTop())%>, <%=dispatcher.DPtoLP(insets.getLeft())%>, <%=dispatcher.DPtoLP(insets.getBottom())%>, <%=dispatcher.DPtoLP(insets.getRight())%>)); diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet index 9a1e9de42..35824e222 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet @@ -14,6 +14,7 @@ final ImportAssistant importManager = dispatcher.getImportManager(); boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color()); boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width()); Color colorVal = (hasColor) ? border.getColor() : null; + String colorName = (hasColor) ? "BORDER" : null; if (hasColor && hasWidth){ %> new <%=borderClazz%>(<%@ include file="../Color.jetinc"%>, <%=dispatcher.DPtoLP(border.getWidth())%>) diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet index b84b34cef..aa4f4dba1 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet @@ -1,11 +1,12 @@ <%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopFigureGenerator" - imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.*"%> + imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator;"%> <% Object[] args = (Object[]) argument; Figure figure = (Figure) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean isInnerClass = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -33,4 +34,5 @@ GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figur <%if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/%> <%@ include file="localCoordinates.jetinc"%> <%}%> -}<%importManager.emitSortedImports();%> +<%@ include file="classFooter.jetinc"%> +<%importManager.emitSortedImports();%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet index 3ee0477b8..c20e4c0c8 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet @@ -1,11 +1,12 @@ <%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopConnectionGenerator" - imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher"%> + imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator"%> <% Object[] args = (Object[]) argument; PolylineConnection figure = (PolylineConnection) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean isInnerClass = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -50,4 +51,5 @@ if (figure.getTargetDecoration() != null) {%> return df; } <%}%> -}<%importManager.emitSortedImports();%>
\ No newline at end of file +<%@ include file="classFooter.jetinc"%> +<%importManager.emitSortedImports();%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc new file mode 100644 index 000000000..2143d1a51 --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc @@ -0,0 +1,10 @@ +<% +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ %> +} + <%@ include file="staticFields.jetinc"%> +<% } else { %> + <%@ include file="staticFields.jetinc"%> +} +<%}%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc new file mode 100644 index 000000000..2ddbf7166 --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc @@ -0,0 +1,12 @@ +<% +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); %> + + /** + * @generated + */ + public static final <%=next.getType()%> <%=next.getName()%> = <%=next.getValue()%>; +<% +} +%> diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java index 87dd2da74..37729856b 100644 --- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java +++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java @@ -11,6 +11,8 @@ */ package org.eclipse.gmf.tests.gen; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Arrays; import org.eclipse.draw2d.BendpointConnectionRouter; @@ -28,11 +30,17 @@ import org.eclipse.gmf.gmfgraph.CustomDecoration; import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.Dimension; import org.eclipse.gmf.gmfgraph.Figure; +import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Insets; +import org.eclipse.gmf.gmfgraph.Label; +import org.eclipse.gmf.gmfgraph.LineBorder; +import org.eclipse.gmf.gmfgraph.Rectangle; import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; import org.eclipse.gmf.graphdef.codegen.FigureGenerator; import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; /** * @author artem @@ -65,7 +73,7 @@ public class FigureCodegenTest extends FigureCodegenTestBase { public void testGenFigureWithoutPackageStmt() { myFigurePackageName = null; - setCustomFigureGenerator(new FigureGenerator(new RuntimeFQNSwitch())); + setCustomFigureGenerator(new FigureGenerator(new RuntimeFQNSwitch(), false)); testGenComplexShape(); } @@ -206,4 +214,100 @@ public class FigureCodegenTest extends FigureCodegenTestBase { custom.setName(CodeGenUtil.getSimpleClassName(ScrollBar.class.getName())); performTests(custom, CHECK_CAN_CREATE_INSTANCE); } + + public void testFigureWithTwoBorderedChildren(){ + //check that border color static fields do not clash with each other + Figure root = GMFGraphFactory.eINSTANCE.createRectangle(); + root.setName("MultiBorderedRoot"); + + Figure constantlyBordered = GMFGraphFactory.eINSTANCE.createRectangle(); + constantlyBordered.setName("WithRedConstantBorder"); + LineBorder constantRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder(); + constantRedBorder.setColor(createConstantColor(ColorConstants.RED_LITERAL)); + constantRedBorder.setWidth(5); + constantlyBordered.setBorder(constantRedBorder); + root.getChildren().add(constantlyBordered); + + Figure rgbBordered = GMFGraphFactory.eINSTANCE.createRectangle(); + rgbBordered.setName("WithRedRGBBorder"); + LineBorder rgbRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder(); + rgbRedBorder.setColor(createRGBColor(255, 0, 0)); + rgbRedBorder.setWidth(7); + rgbBordered.setBorder(rgbRedBorder); + root.getChildren().add(rgbBordered); + + FigureCheck staticFieldsCheck = new StaticFieldsChecker(1, Color.class); + performTests(root, combineChecks(new GenericFigureCheck(root), staticFieldsCheck)); + } + + public void testFigureWithStaticFieldsForColorAndFonts(){ + Figure root = GMFGraphFactory.eINSTANCE.createEllipse(); + root.setName("FullOfColorsAndFonts"); + root.setFont(createBasicFont("Arial", 23, FontStyle.BOLD_LITERAL)); + root.setForegroundColor(createConstantColor(ColorConstants.ORANGE_LITERAL)); + root.setBackgroundColor(createConstantColor(ColorConstants.GREEN_LITERAL)); + + Label sansLabel = GMFGraphFactory.eINSTANCE.createLabel(); + sansLabel.setName("SansLabel"); + sansLabel.setFont(createBasicFont("Sans", 8, FontStyle.ITALIC_LITERAL)); + sansLabel.setForegroundColor(createConstantColor(ColorConstants.BLUE_LITERAL)); + root.getChildren().add(sansLabel); + + Label tahomaLabel = GMFGraphFactory.eINSTANCE.createLabel(); + tahomaLabel.setName("TahomaLabel"); + tahomaLabel.setFont(createBasicFont("Tahoma", 12, FontStyle.NORMAL_LITERAL)); + tahomaLabel.setForegroundColor(createConstantColor(ColorConstants.YELLOW_LITERAL)); + root.getChildren().add(tahomaLabel); + + Rectangle deepLabelContainer = GMFGraphFactory.eINSTANCE.createRectangle(); + deepLabelContainer.setName("DeepLabelContainer"); + deepLabelContainer.setForegroundColor(createRGBColor(123, 23, 3)); + deepLabelContainer.setBackgroundColor(createRGBColor(2, 123, 23)); + root.getChildren().add(deepLabelContainer); + + Label defaultFontLabel = GMFGraphFactory.eINSTANCE.createLabel(); + defaultFontLabel.setName("DefaultFontLabel"); + defaultFontLabel.setFont(createBasicFont(null, 34, FontStyle.BOLD_LITERAL)); + defaultFontLabel.setForegroundColor(createConstantColor(ColorConstants.CYAN_LITERAL)); + deepLabelContainer.getChildren().add(defaultFontLabel); + + FigureCheck fontFieldsCheck = new StaticFieldsChecker(4, Font.class); //root + 3 labels + FigureCheck colorFieldsCheck = new StaticFieldsChecker(2, Color.class); // only RGB colors should get field + + performTests(root, combineChecks(fontFieldsCheck, colorFieldsCheck)); + } + + public void testConnectionWithColor(){ + org.eclipse.gmf.gmfgraph.PolylineConnection link = GMFGraphFactory.eINSTANCE.createPolylineConnection(); + link.setName("AlmostRedLink"); + link.setForegroundColor(createRGBColor(255, 1, 1)); + + FigureCheck colorFieldsCheck = new StaticFieldsChecker(1, Color.class); + performTests(link, colorFieldsCheck); + } + + private static class StaticFieldsChecker extends FigureCheck { + private final int myExpectedFieldCount; + private final Class myFieldClazz; + + public StaticFieldsChecker(int expectedFieldCount, Class fieldClazz){ + myExpectedFieldCount = expectedFieldCount; + myFieldClazz = fieldClazz; + } + + public void checkFigure(IFigure figure) { + Class figureClazz = figure.getClass(); + Field[] fields = figureClazz.getDeclaredFields(); + int staticFinalFields = 0; + for (int i = 0; i < fields.length; i++){ + Field next = fields[i]; + int modifiers = next.getModifiers(); + if (myFieldClazz.equals(next.getType()) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)){ + staticFinalFields++; + } + } + assertTrue("Expected: at least " + myExpectedFieldCount +" constants of type :" + myFieldClazz.getName() + ". Actual: " + staticFinalFields, staticFinalFields >= myExpectedFieldCount); + } + } + } diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java index 2346fa310..689dcae4c 100644 --- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java +++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java @@ -33,6 +33,7 @@ import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.Ellipse; import org.eclipse.gmf.gmfgraph.Figure; import org.eclipse.gmf.gmfgraph.FigureGallery; +import org.eclipse.gmf.gmfgraph.Font; import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Label; @@ -41,6 +42,7 @@ import org.eclipse.gmf.gmfgraph.Point; import org.eclipse.gmf.gmfgraph.Polygon; import org.eclipse.gmf.gmfgraph.PolygonDecoration; import org.eclipse.gmf.gmfgraph.PolylineConnection; +import org.eclipse.gmf.gmfgraph.RGBColor; import org.eclipse.gmf.gmfgraph.Rectangle; import org.eclipse.gmf.gmfgraph.RoundedRectangle; import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; @@ -142,7 +144,7 @@ public class FigureCodegenTestBase extends TestCase { try { StandaloneGenerator generator = new StandaloneGenerator(new GalleryProcessor(gallery), config, new RuntimeFQNSwitch()); generator.run(); - assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); + assertTrue(generator.getRunStatus().toString(), generator.getRunStatus().getSeverity() < IStatus.ERROR); Bundle bundle = installPlugin(config.getPluginID()); @@ -210,22 +212,12 @@ public class FigureCodegenTestBase extends TestCase { Label l1 = GMFGraphFactory.eINSTANCE.createLabel(); l1.setText("aaaaa"); l1.setName("L1"); - BasicFont f1 = GMFGraphFactory.eINSTANCE.createBasicFont(); - f1.setFaceName("Arial"); - f1.setHeight(9); - f1.setStyle(FontStyle.ITALIC_LITERAL); - l1.setFont(f1); - ConstantColor c = GMFGraphFactory.eINSTANCE.createConstantColor(); - c.setValue(ColorConstants.CYAN_LITERAL); - l1.setForegroundColor(c); + l1.setFont(createBasicFont("Arial", 9, FontStyle.ITALIC_LITERAL)); + l1.setForegroundColor(createConstantColor(ColorConstants.CYAN_LITERAL)); Label l2 = GMFGraphFactory.eINSTANCE.createLabel(); l2.setText("bbbbb"); l2.setName("L2"); - BasicFont f2 = GMFGraphFactory.eINSTANCE.createBasicFont(); - f2.setFaceName("Helvetica"); - f2.setHeight(12); - f2.setStyle(FontStyle.BOLD_LITERAL); - l2.setFont(f2); + l2.setFont(createBasicFont("Helvetica", 12, FontStyle.BOLD_LITERAL)); r.getChildren().add(l1); r.getChildren().add(l2); return r; @@ -302,7 +294,7 @@ public class FigureCodegenTestBase extends TestCase { private FigureGenerator getGenerator() { if (figureGenerator == null) { - figureGenerator = new FigureGenerator(new RuntimeFQNSwitch()); + figureGenerator = new FigureGenerator(new RuntimeFQNSwitch(), false); } return figureGenerator; } @@ -350,6 +342,28 @@ public class FigureCodegenTestBase extends TestCase { return combineChecks(new FigureCheck[] {first, second}); } + protected static final ConstantColor createConstantColor(ColorConstants constant) { + ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor(); + result.setValue(constant); + return result; + } + + protected static final RGBColor createRGBColor(int red, int green, int blue) { + RGBColor result = GMFGraphFactory.eINSTANCE.createRGBColor(); + result.setRed(red); + result.setGreen(green); + result.setBlue(blue); + return result; + } + + protected static final Font createBasicFont(String name, int height, FontStyle style){ + BasicFont result = GMFGraphFactory.eINSTANCE.createBasicFont(); + result.setFaceName(name); + result.setHeight(height); + result.setStyle(style); + return result; + } + protected static class GeneratedClassData { private final Figure myFigureDef; private final Class myLoadedClass; diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java index dbb44be1a..00ea229e8 100644 --- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java +++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java @@ -79,6 +79,6 @@ public class MapModeStrategyTest extends FigureCodegenTestBase { } private FigureGenerator createGenerator(MapModeCodeGenStrategy strategy) { - return new FigureGenerator(new RuntimeFQNSwitch(), strategy); + return new FigureGenerator(new RuntimeFQNSwitch(), strategy, false); } } diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java index 7f6560c58..d31a4a62d 100644 --- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java +++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java @@ -15,11 +15,10 @@ package org.eclipse.gmf.tests.gen; import java.util.Iterator; import org.eclipse.gmf.gmfgraph.BasicFont; -import org.eclipse.gmf.gmfgraph.Color; import org.eclipse.gmf.gmfgraph.ColorConstants; import org.eclipse.gmf.gmfgraph.CompoundBorder; -import org.eclipse.gmf.gmfgraph.ConstantColor; import org.eclipse.gmf.gmfgraph.Dimension; +import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Insets; import org.eclipse.gmf.gmfgraph.LineBorder; @@ -53,6 +52,13 @@ public class ShapePropertiesTest extends FigureCodegenTestBase { shape.setName("Bold"); performTests(shape); } + + public void testShapeFont(){ + Shape shape = GMFGraphFactory.eINSTANCE.createRoundedRectangle(); + shape.setName("WithArialFont"); + shape.setFont(createBasicFont("Arial", 10, FontStyle.NORMAL_LITERAL)); + performTests(shape); + } public void testShapeInsets() { Rectangle withInsets = GMFGraphFactory.eINSTANCE.createRectangle(); @@ -192,8 +198,6 @@ public class ShapePropertiesTest extends FigureCodegenTestBase { performTests(root); } - - private Dimension createDimension(int x, int y){ Dimension result = GMFGraphFactory.eINSTANCE.createDimension(); result.setDx(x); @@ -201,12 +205,4 @@ public class ShapePropertiesTest extends FigureCodegenTestBase { return result; } - private Color createConstantColor(ColorConstants constant) { - ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor(); - result.setValue(constant); - return result; - } - - - } |