Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2012-02-06 20:59:36 +0000
committermgolubev2012-04-29 17:16:35 +0000
commitc7b6d15d81d0268ca53ec8d6024d310e25e9d151 (patch)
tree263b81403a5dd4fc5ffa004880a694a532db69a8
parenta4e9f384aff27b519ebe450cb1800640b472eeba (diff)
downloadorg.eclipse.gmf-tooling-c7b6d15d81d0268ca53ec8d6024d310e25e9d151.tar.gz
org.eclipse.gmf-tooling-c7b6d15d81d0268ca53ec8d6024d310e25e9d151.tar.xz
org.eclipse.gmf-tooling-c7b6d15d81d0268ca53ec8d6024d310e25e9d151.zip
Generate auto-updatable OCL expression-based labels
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt15
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt7
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt12
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto51
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/parsers/ExpressionLabelParser.xpt51
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/Common.xpt4
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/Utils.qvto4
7 files changed, 122 insertions, 22 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
index 0ceb958de..71c5c7b3b 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
@@ -14,6 +14,7 @@
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«EXTENSION xpt::diagram::ViewmapAttributesUtils»
«EXTENSION impl::diagram::editparts::ChoiceUtils»
+«EXTENSION impl::parsers::expression»
«DEFINE fields FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
@@ -22,7 +23,7 @@
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.runtime.common.ui.services.parser.IParser parser;
- «IF isOclChoiceLabel()-»
+ «IF isOclChoiceLabel() || isViewExpressionDefiedAndOcl()-»
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker.Registrator myOclRegistrator;
«ELSE-»
@@ -31,7 +32,7 @@
«ENDIF-»
«EXPAND xpt::Common::generatedMemberComment»
- private String defaultText;
+ private String defaultText;
«ENDDEFINE»
«DEFINE methods(needsRefreshBounds : Boolean, readOnly : Boolean, useElementIcon : Boolean, viewmap : gmfgen::Viewmap,
@@ -104,7 +105,7 @@
«EXPAND getFontStyleOwnerView(viewmap)-»
-«IF isOclChoiceLabelWithShowExpr()-»
+«IF isOclChoiceLabelWithShowExpr() OR isViewExpressionDefiedAndOcl()-»
«EXPAND getOclTracker-»
«ENDIF-»
@@ -515,7 +516,11 @@
super.addSemanticListeners();
«ENDIF-»
((org.eclipse.gmf.tooling.runtime.parsers.OclChoiceParser) getParser()).installListeners(this, getOclRegistrator());
-«ELSE-»
+«ELSEIF isViewExpressionDefiedAndOcl()-»
+ «getActiveOclPackageName()».common.OclTracker tracker = getTracker();
+ tracker.initialize(resolveSemanticElement());
+ tracker.installListeners(getEditingDomain(), this, getOclRegistrator());
+«ELSE-»
if (getParser() instanceof org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) {
org.eclipse.emf.ecore.EObject element = resolveSemanticElement();
parserElements = ((org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
@@ -532,7 +537,7 @@
«DEFINE removeSemanticListeners FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected void removeSemanticListeners() {
-«IF isOclChoiceLabel()-»
+«IF isOclChoiceLabel() || isViewExpressionDefiedAndOcl()-»
((org.eclipse.gmf.tooling.runtime.parsers.OclChoiceParser) getParser()).uninstallListeners();
«IF isOclChoiceLabelWithShowExpr()-»
getTracker().uninstallListeners();
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
index 9eaae5046..9d8412b4a 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
@@ -37,10 +37,15 @@
«ENDIF-»
«ENDDEFINE»
+«DEFINE getExpression(gmfgen::ExpressionLabelParser parser, ValueExpression expression) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: getExpression'»«ENDDEFINE»
+«DEFINE getExpression(gmfgen::ExpressionLabelParser parser, ValueExpression expression) FOR gmfgen::GenExpressionInterpreter-»
+ «EXPAND xpt::expressions::getExpression::getExpression(expression, parser.expressionContext)-»
+«ENDDEFINE»
+
«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: _evaluateAndReturnExpressionResult'»«ENDDEFINE»
«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionInterpreter-»
org.eclipse.emf.ecore.EObject target = (org.eclipse.emf.ecore.EObject) element.getAdapter(org.eclipse.emf.ecore.EObject.class);
-Object result = «EXPAND xpt::expressions::getExpression::getExpression(expression, parser.expressionContext)».evaluate(target);
+Object result = «EXPAND getExpression(parser, expression)».evaluate(target);
return String.valueOf(result);
«ENDDEFINE»
«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenJavaExpressionProvider-»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
index 6ddcaf761..484b3cbfe 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
@@ -17,6 +17,7 @@
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
«EXTENSION xpt::providers::ParserUtils»
+«EXTENSION impl::parsers::expression»
«DEFINE accessorMethod_delegate2providers FOR gmfgen::GenParsers-»
«EXPAND xpt::Common::generatedMemberComment('Utility method that consults ParserService')»
@@ -187,7 +188,7 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
«parserFieldName(element)» = new «qualifiedName»();
}
return «parserFieldName(element)»;
- }
+ }
«ENDDEFINE»
«DEFINE _parser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::ExternalParser-»
@@ -301,6 +302,12 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
/*Intentionally modelFacet typed as general LMF, because ExpressionLabelModelFacet is merely a marker*/
«DEFINE _parser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::ExpressionLabelParser»
+«IF isViewExpressionDefinedAndOcl()-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ «IF holder.extensibleViaService»private«ELSE»public«ENDIF» org.eclipse.gmf.runtime.common.ui.services.parser.IParser «parserAccessorName(element)»() {
+ return new «getQualifiedClassName()»();
+ }
+«ELSE-»
«EXPAND xpt::Common::generatedMemberComment»
private «getQualifiedClassName()» «parserFieldName(element)»;
@@ -311,4 +318,5 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
}
return «parserFieldName(element)»;
}
-«ENDDEFINE» \ No newline at end of file
+«ENDIF-»
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto
new file mode 100644
index 000000000..71904280b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto
@@ -0,0 +1,51 @@
+import xpt.diagram.Utils;
+modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
+library expression;
+
+helper gmfgen::ExpressionLabelParser::isViewExpressionDefinedAndOcl() : Boolean {
+ return not(self.viewExpression.oclIsUndefined()) and self.viewExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter);
+}
+
+helper gmfgen::GenParserImplementation::isViewExpressionDefinedAndOcl() : Boolean {
+ return false;
+}
+
+helper getActiveOclPackageName() : String {
+ return 'org.eclipse.gmf.tooling.runtime.ocl.expressions';
+}
+
+helper gmfgen::ExpressionLabelParser::isImpactAnalyzerKind() : Boolean {
+ return isImpactAnalyzerKind(self.viewExpression.body);
+}
+
+helper gmfgen::GenParserImplementation::isImpactAnalyzerKind() : Boolean {
+ return false
+}
+
+helper gmfgen::GenCommonBase::isViewExpressionDefiedAndOcl() : Boolean {
+ return let labelModelFacet : gmfgen::LabelModelFacet
+ = if self.oclIsKindOf(gmfgen::GenChildLabelNode) then self.oclAsType(gmfgen::GenChildLabelNode).labelModelFacet
+ else (if self.oclIsKindOf(gmfgen::GenLabel) then self.oclAsType(gmfgen::GenLabel).modelFacet
+ else null
+ endif)
+ endif
+ in if labelModelFacet = null
+ then false
+ else labelModelFacet.parser.isViewExpressionDefinedAndOcl()
+ endif;
+}
+
+helper gmfgen::GenCommonBase::isViewExpressionDefiedAndOclAndImpactAnalyzerKind() : Boolean {
+ return let labelModelFacet : gmfgen::LabelModelFacet
+ = if self.oclIsKindOf(gmfgen::GenChildLabelNode) then self.oclAsType(gmfgen::GenChildLabelNode).labelModelFacet
+ else (if self.oclIsKindOf(gmfgen::GenLabel) then self.oclAsType(gmfgen::GenLabel).modelFacet
+ else null
+ endif)
+ endif
+ in if labelModelFacet = null
+ then false
+ else (labelModelFacet.parser.isViewExpressionDefinedAndOcl()
+ and labelModelFacet.parser.isImpactAnalyzerKind()
+ )
+ endif;
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/parsers/ExpressionLabelParser.xpt b/plugins/org.eclipse.gmf.codegen/templates/parsers/ExpressionLabelParser.xpt
index 71287ebc8..ddfbd57df 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/parsers/ExpressionLabelParser.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/parsers/ExpressionLabelParser.xpt
@@ -14,6 +14,8 @@
«EXTENSION xpt::StringOperations»
+«EXTENSION impl::parsers::expression»
+
«DEFINE Main FOR gmfgen::ExpressionLabelParser-»
«EXPAND xpt::Common::copyright FOR holder.editorGen-»
«EXPAND xpt::Common::packageStatement FOR self.getQualifiedClassName()»
@@ -28,10 +30,43 @@ public class «self.getQualifiedClassName().xpandSplit('\\.')->last()»«EXPAND
«ENDDEFINE»
«DEFINE additions FOR gmfgen::ExpressionLabelParser»«ENDDEFINE»
-«DEFINE extendsList FOR gmfgen::ExpressionLabelParser»«ENDDEFINE»
-«DEFINE implementsList FOR gmfgen::ExpressionLabelParser» implements org.eclipse.gmf.runtime.common.ui.services.parser.IParser«ENDDEFINE»
+«DEFINE extendsList FOR gmfgen::ExpressionLabelParser»
+ «IF isViewExpressionDefinedAndOcl()-»
+ «IF isImpactAnalyzerKind()-»
+ extends org.eclipse.gmf.tooling.runtime.ocl.parsers.ImpactAnalyzerParserBase
+ «ELSE-»
+ extends org.eclipse.gmf.tooling.runtime.ocl.parsers.ActiveOclParserBase
+ «ENDIF-»
+ «ENDIF-»
+«ENDDEFINE»
+«DEFINE implementsList FOR gmfgen::ExpressionLabelParser-»
+ «IF not(isViewExpressionDefinedAndOcl())-»
+ implements org.eclipse.gmf.runtime.common.ui.services.parser.IParser
+ «ENDIF-»
+«ENDDEFINE»
«DEFINE body FOR gmfgen::ExpressionLabelParser»
+
+«IF isViewExpressionDefinedAndOcl()-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ @Override
+ protected String getExpressionBody() {
+ return «EXPAND impl::parsers::ExpressionLabelParser::getExpression(self, viewExpression) FOR viewExpression.provider».body();
+ }
+«ELSE-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String getPrintString(org.eclipse.core.runtime.IAdaptable element, int flags) {
+ «EXPAND impl::parsers::ExpressionLabelParser::accessViewExpression-»
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean isAffectingEvent(Object event, int flags) {
+ // XXX Any event is recognized as important, unless there's a way to extract this information from expression itself.
+ // TODO analyze expressions (e.g. using OCL parser) to find out structural features in use
+ return true;
+ }
+«ENDIF-»
+
«EXPAND xpt::Common::generatedMemberComment»
public String getEditString(org.eclipse.core.runtime.IAdaptable element, int flags) {
«EXPAND impl::parsers::ExpressionLabelParser::accessEditExpression-»
@@ -61,18 +96,6 @@ public class «self.getQualifiedClassName().xpandSplit('\\.')->last()»«EXPAND
}
«EXPAND xpt::Common::generatedMemberComment»
- public String getPrintString(org.eclipse.core.runtime.IAdaptable element, int flags) {
- «EXPAND impl::parsers::ExpressionLabelParser::accessViewExpression-»
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- public boolean isAffectingEvent(Object event, int flags) {
- // XXX Any event is recognized as important, unless there's a way to extract this information from expression itself.
- // TODO analyze expressions (e.g. using OCL parser) to find out structural features in use
- return true;
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.jface.text.contentassist.IContentAssistProcessor getCompletionProcessor(org.eclipse.core.runtime.IAdaptable element) {
return null;
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/Common.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/Common.xpt
index b49221aeb..cb9a46879 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/Common.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/Common.xpt
@@ -82,6 +82,10 @@
package «LET self.xpandSplit('\\.') AS tmpVar»«FOREACH if tmpVar->size() < 2 then Sequence{}[String] else tmpVar->subSequence(1, tmpVar->size() - 1) endif AS s SEPARATOR '.'»«s»«ENDFOREACH»;«ENDLET»«ENDIF-»
«ENDDEFINE»
+«DEFINE disqualifiedClassName FOR String-»
+«self.xpandSplit('\\.')->last()»
+«ENDDEFINE»
+
// Provides handy single point to override generation of assert statements
// TODO refactor this Common.xpt into different flavours - like CommonCodeStyle (nls, assert), CommonSnippets(pkgStmt, setCharset, getSaveOptions) and so on
// TODO condition.xpandToCharList()->count('"') / 2 gives better guess about number of nonNLS to generate
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/Utils.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/Utils.qvto
index f74dc9159..3be39253a 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/Utils.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/Utils.qvto
@@ -61,4 +61,8 @@ helper gmfgen::GenCommonBase::hasFillStyleInCustom() : Boolean {
-- if diagram is in pixel map mode, no reason to use getMapMode()
helper gmfgen::GenDiagram::isPixelMapMode() : Boolean {
return self.units = 'Pixel';
+}
+
+helper isImpactAnalyzerKind(oclExpression : String) : Boolean {
+ return oclExpression.startsWith('--IA');
} \ No newline at end of file

Back to the top