Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2010-04-26 17:13:39 -0400
committeratikhomirov2010-04-26 17:13:39 -0400
commitd8ba0101081ed068a0936768ec141536707c8197 (patch)
tree2a3f597bc7ba78dfa33eee9aa8af0741e946b171
parent28ed6d70034b0a3fb024e61c5970a0b157d17ce4 (diff)
downloadorg.eclipse.gmf-tooling-d8ba0101081ed068a0936768ec141536707c8197.tar.gz
org.eclipse.gmf-tooling-d8ba0101081ed068a0936768ec141536707c8197.tar.xz
org.eclipse.gmf-tooling-d8ba0101081ed068a0936768ec141536707c8197.zip
[231330] reduce use of static fields - LinkCostraints are no-brainer
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/plugin/Activator.xpt22
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt6
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt5
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt39
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt20
5 files changed, 78 insertions, 14 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates/plugin/Activator.xpt b/plugins/org.eclipse.gmf.codegen/templates/plugin/Activator.xpt
new file mode 100644
index 000000000..e8759e9ff
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/plugin/Activator.xpt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010 Artem Tikhomirov and others
+ *
+ * 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:
+ * Artem Tikhomirov (independent) - Initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
+
+// FIXME For 2.3, delegates to legacy xpt::plugin::Activator template.
+// Refactoring (moving templates out from xpt) pending.
+«DEFINE Main FOR gmfgen::GenPlugin-»
+«EXPAND xpt::plugin::Activator::Activator-»
+«ENDDEFINE»
+
+// access to the sole Activator instance
+«DEFINE instanceAccess FOR gmfgen::GenEditorGenerator»«plugin.getActivatorQualifiedClassName()».getInstance()«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
index b4ef201be..d43728fed 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2009 Borland Software Corporation
+ * Copyright (c) 2007, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -54,8 +54,10 @@
return «EXPAND validatorInvocation FOR link»(getSource(), getTarget());
«ENDDEFINE»
+// FIXME In fact, BaseItemSemanticEditPolicy knows what arguments and in which order should be passed to the canCreate method,
+// hence, need to refactor this invocation to delegate complete call to the policy.
«DEFINE validatorInvocation FOR gmfgen::GenLink-»
-«diagram.getBaseItemSemanticEditPolicyQualifiedClassName()».«diagram.getLinkCreationConstraintsClassName()».canCreate«getUniqueIdentifier()-»
+«EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canCreateCall-»
«ENDDEFINE»
«REM»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
index b1796aa76..0fbc17922 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2009 Borland Software Corporation
+ * Copyright (c) 2007, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -193,8 +193,9 @@
«ENDIF-»
«ENDDEFINE»
+// FIXME refactor: only BaseItemSemanticEditPolicy knows arguments and their order
«DEFINE checkLinkConstraintInvocation FOR gmfgen::GenLink-»
- «diagram.getBaseItemSemanticEditPolicyQualifiedClassName()».«diagram.getLinkCreationConstraintsClassName()».canExist«getUniqueIdentifier()»
+«EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canExistCall»
«ENDDEFINE»
«REM»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
index 2b1fff338..0c1d31610 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
@@ -299,6 +299,18 @@ protected org.eclipse.gef.commands.Command getReorientRelationshipCommand(org.ec
}
«ENDDEFINE»
+«DEFINE _accessLinkConstraints FOR gmfgen::GenDiagram-»
+«getBaseItemSemanticEditPolicyQualifiedClassName()».«getLinkCreationConstraintsClassName()».getInstance()«-»
+«ENDDEFINE»
+
+«DEFINE canExistCall FOR gmfgen::GenLink-»
+«EXPAND _accessLinkConstraints FOR diagram».canExist«getUniqueIdentifier()-»
+«ENDDEFINE»
+
+«DEFINE canCreateCall FOR gmfgen::GenLink-»
+«EXPAND _accessLinkConstraints FOR diagram».canCreate«getUniqueIdentifier()-»
+«ENDDEFINE»
+
«REM»
FIXME need to check constraint's provider to ensure we don't generate a field
@@ -315,41 +327,54 @@ public static class «getLinkCreationConstraintsClassName()» {
«FOREACH getValidLinkConstraints(self) AS lc-»
«IF lc.sourceEnd <> null-»
«EXPAND xpt::Common::generatedMemberComment»
- private static «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «sourceConstraintFieldName(lc.link)»;
+ private «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «sourceConstraintFieldName(lc.link)»;
«ENDIF-»
«IF lc.targetEnd <> null-»
«EXPAND xpt::Common::generatedMemberComment»
- private static «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «targetConstraintFieldName(lc.link)»;
+ private «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «targetConstraintFieldName(lc.link)»;
«ENDIF-»
«ENDFOREACH»
«ENDIF-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «getLinkCreationConstraintsClassName()»() {
+ // use static method #getInstance() to access instance
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «getLinkCreationConstraintsClassName()» getInstance() {
+ «getLinkCreationConstraintsClassName()» cached = «EXPAND plugin::Activator::instanceAccess FOR editorGen».getLinkConstraints();
+ if (cached == null) {
+ «EXPAND plugin::Activator::instanceAccess FOR editorGen».setLinkConstraints(cached = new «getLinkCreationConstraintsClassName()»());
+ }
+ return cached;
+ }
+
«EXPAND canCreate FOREACH links-»
«EXPAND canExist FOREACH links-»
}
«ENDDEFINE»
«DEFINE canCreate FOR gmfgen::GenLink»
-
«EXPAND xpt::Common::generatedMemberComment»
-public static boolean canCreate«getUniqueIdentifier()»(«EXPAND canCreateParameters FOR modelFacet») {
+public boolean canCreate«getUniqueIdentifier()»(«EXPAND canCreateParameters FOR modelFacet») {
«EXPAND checkEMFConstraints FOR modelFacet-»
return canExist«getUniqueIdentifier()»(«EXPAND canCreateValues FOR modelFacet»);
}
+
«ENDDEFINE»
«REM»
XXX for now, both constraints are injected into single method
- which may nob be suitable for modification especially when mixing
+ which may not be suitable for modification especially when mixing
java and ocl constraints (former requires manual code).
Better approach would be:
if either is non-null and providers are not the same - introduce two methods,
to check source and target separately. Otherwize, do it inplace.
«ENDREM»
«DEFINE canExist FOR gmfgen::GenLink»
-
«EXPAND xpt::Common::generatedMemberComment»
- public static boolean canExist«getUniqueIdentifier()»(«EXPAND canCreateParameters FOR modelFacet») {
+ public boolean canExist«getUniqueIdentifier()»(«EXPAND canCreateParameters FOR modelFacet») {
«IF creationConstraints <> null and (creationConstraints.isValid() and null <> getDiagram().editorGen.expressionProviders)-»
try {
«IF null <> creationConstraints.sourceEnd-»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
index 4c0651a23..4e8526608 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2009 Borland Software Corporation
+ * Copyright (c) 2007, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -34,6 +34,9 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
«EXPAND xpt::Common::generatedMemberComment»
private «editorGen.diagram.getDocumentProviderQualifiedClassName()» documentProvider;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «editorGen.diagram.getLinkCreationConstraintsQualifiedClassName()» linkConstraints;
«EXPAND xpt::Common::generatedMemberComment»
public «activatorClassName»() {
@@ -51,6 +54,7 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
public void stop(org.osgi.framework.BundleContext context) throws Exception {
adapterFactory.dispose();
adapterFactory = null;
+ linkConstraints = null;
instance = null;
super.stop(context);
}
@@ -62,13 +66,13 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.emf.edit.provider.ComposedAdapterFactory createAdapterFactory() {
- java.util.List factories = new java.util.ArrayList();
+ «EXPAND CodeStyle::newGenericInstance('java.util.ArrayList', 'org.eclipse.emf.common.notify.AdapterFactory', 'factories') FOR editorGen.diagram»();
fillItemProviderFactories(factories);
return new org.eclipse.emf.edit.provider.ComposedAdapterFactory(factories);
}
«EXPAND xpt::Common::generatedMemberComment»
- protected void fillItemProviderFactories(java.util.List factories) {
+ protected void fillItemProviderFactories(«EXPAND CodeStyle::G('java.util.List', 'org.eclipse.emf.common.notify.AdapterFactory') FOR editorGen.diagram» factories) {
«EXPAND MetaModel::PopulateItemProviderFactories('factories') FOR editorGen-»
factories.add(new org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory());
factories.add(new org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory());
@@ -158,6 +162,16 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
}
«EXPAND xpt::Common::generatedMemberComment»
+ public «editorGen.diagram.getLinkCreationConstraintsQualifiedClassName()» getLinkConstraints() {
+ return linkConstraints;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setLinkConstraints(«editorGen.diagram.getLinkCreationConstraintsQualifiedClassName()» lc) {
+ this.linkConstraints = lc;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
public void logError(String error) {
logError(error, null);
}

Back to the top