Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratischenko2014-11-10 11:37:47 +0000
committeratischenko2014-11-10 11:38:40 +0000
commita0b091cb9c21aadf1d33bd203073be53ac3a68b5 (patch)
treebb3285006d2daacb7307f6cccc917b70e409a1d6 /plugins/developer/org.eclipse.papyrus.def
parent7c4c7d985c7e2ec92657a98144f5786172f788dd (diff)
downloadorg.eclipse.papyrus-a0b091cb9c21aadf1d33bd203073be53ac3a68b5.tar.gz
org.eclipse.papyrus-a0b091cb9c21aadf1d33bd203073be53ac3a68b5.tar.xz
org.eclipse.papyrus-a0b091cb9c21aadf1d33bd203073be53ac3a68b5.zip
Bug 436038 - [Regeneration] Avoid useless empty-line diff while
switching from xpand to xtend templates. avoid if without block even for 1 statement Signed-off-by: atischenko <ticher777@gmail.com>
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.def')
-rw-r--r--plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/commands/CreateNodeCommand.xtend3
-rw-r--r--plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/editor/DocumentProvider.xtend59
-rw-r--r--plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/expressions/AbstractExpression.xtend64
3 files changed, 125 insertions, 1 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/commands/CreateNodeCommand.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/commands/CreateNodeCommand.xtend
index fa2c0163aa8..93db05c6778 100644
--- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/commands/CreateNodeCommand.xtend
+++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/commands/CreateNodeCommand.xtend
@@ -197,8 +197,9 @@ import xpt.diagram.Utils_qvto
org.eclipse.papyrus.infra.viewpoints.policy.ModelAddData data = org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker.getCurrent().getChildAddData(diagram, target, «varName»);
if (data.isPermitted()) {
if (data.isPathDefined()) {
- if (!data.execute(target, «varName»))
+ if (!data.execute(target, «varName»)) {
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newErrorCommandResult("Failed to follow the policy-specified for the insertion of the new element");
+ }
} else {
«extraLineBreak»
«IF containmentMetaFeature != null»
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/editor/DocumentProvider.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/editor/DocumentProvider.xtend
index aeea7a7b507..160bfebf636 100644
--- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/editor/DocumentProvider.xtend
+++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/editor/DocumentProvider.xtend
@@ -88,4 +88,63 @@ import xpt.Externalizer
}
}
'''
+
+ override createEditingDomain(GenDiagram it) '''
+ «generatedMemberComment»
+ private org.eclipse.emf.transaction.TransactionalEditingDomain createEditingDomain() {
+ org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory.getInstance().createEditingDomain();
+ editingDomain.setID("«editingDomainID»"); «nonNLS(1)»
+ final org.eclipse.emf.transaction.NotificationFilter diagramResourceModifiedFilter = org.eclipse.emf.transaction.NotificationFilter.createNotifierFilter(editingDomain.getResourceSet()).and(org.eclipse.emf.transaction.NotificationFilter.createEventTypeFilter(org.eclipse.emf.common.notify.Notification.ADD)).and(org.eclipse.emf.transaction.NotificationFilter.createFeatureFilter(org.eclipse.emf.ecore.resource.ResourceSet.class, org.eclipse.emf.ecore.resource.ResourceSet.RESOURCE_SET__RESOURCES));
+ editingDomain.getResourceSet().eAdapters().add(new org.eclipse.emf.common.notify.Adapter() {
+
+ private org.eclipse.emf.common.notify.Notifier myTarger;
+
+ public org.eclipse.emf.common.notify.Notifier getTarget() {
+ return myTarger;
+ }
+
+ public boolean isAdapterForType(Object type) {
+ return false;
+ }
+
+ public void notifyChanged(org.eclipse.emf.common.notify.Notification notification) {
+ if (diagramResourceModifiedFilter.matches(notification)) {
+ Object value = notification.getNewValue();
+ if (value instanceof org.eclipse.emf.ecore.resource.Resource) {
+ ((org.eclipse.emf.ecore.resource.Resource) value).setTrackingModification(true);
+ }
+ }
+ }
+
+ public void setTarget(org.eclipse.emf.common.notify.Notifier newTarget) {
+ myTarger = newTarget;
+ }
+
+ });
+
+ return editingDomain;
+ }
+ '''
+
+ override computeSchedulingRule(GenDiagram it) '''
+ «generatedMemberComment»
+ private org.eclipse.core.runtime.jobs.ISchedulingRule computeSchedulingRule(org.eclipse.core.resources.IResource toCreateOrModify) {
+ if (toCreateOrModify.exists()) {
+ return org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(toCreateOrModify);
+ }
+ org.eclipse.core.resources.IResource parent = toCreateOrModify;
+ do {«/*FIXME [MG] the bug is closed long ago, still need? */»
+ /*
+ * XXX This is a workaround for
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
+ * IResourceRuleFactory.createRule should iterate the hierarchy
+ * itself.
+ */
+ toCreateOrModify = parent;
+ parent = toCreateOrModify.getParent();
+ } while (parent != null && !parent.exists());
+
+ return org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRuleFactory().createRule(toCreateOrModify);
+ }
+ '''
} \ No newline at end of file
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/expressions/AbstractExpression.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/expressions/AbstractExpression.xtend
new file mode 100644
index 00000000000..781e36c7202
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/expressions/AbstractExpression.xtend
@@ -0,0 +1,64 @@
+package aspects.xpt.expressions
+
+import org.eclipse.gmf.codegen.gmfgen.GenDiagram
+import com.google.inject.Inject
+import aspects.xpt.Common
+import com.google.inject.Singleton
+
+@Singleton class AbstractExpression extends xpt.expressions.AbstractExpression {
+
+ @Inject extension Common
+
+ override performCast(GenDiagram it) '''
+ «generatedMemberComment(
+ 'Expression may return number value which is not directly compatible with feature type (e.g. Double when Integer is expected), or EEnumLiteral meta-object when literal instance is expected')»
+ public static Object performCast(Object value, org.eclipse.emf.ecore.EDataType targetType) {
+ if (targetType instanceof org.eclipse.emf.ecore.EEnum) {
+ if (value instanceof org.eclipse.emf.ecore.EEnumLiteral) {
+ org.eclipse.emf.ecore.EEnumLiteral literal = (org.eclipse.emf.ecore.EEnumLiteral) value;
+ return (literal.getInstance() != null) ? literal.getInstance() : literal;
+ }
+ }
+ if (false == value instanceof Number || targetType == null || targetType.getInstanceClass() == null) {
+ return value;
+ }
+ Class<?> targetClass = targetType.getInstanceClass();
+ Number num = (Number) value;
+ Class<?> valClass = value.getClass();
+ Class<?> targetWrapperClass = targetClass;
+ if (targetClass.isPrimitive()) {
+ targetWrapperClass = org.eclipse.emf.ecore.util.EcoreUtil.wrapperClassFor(targetClass);
+ }
+ if (valClass.equals(targetWrapperClass)) {
+ return value;
+ }
+ if (Number.class.isAssignableFrom(targetWrapperClass)) {
+ if (targetWrapperClass.equals(Byte.class)) {
+ return new Byte(num.byteValue());
+ }
+ if (targetWrapperClass.equals(Integer.class)) {
+ return new Integer(num.intValue());
+ }
+ if (targetWrapperClass.equals(Short.class)) {
+ return new Short(num.shortValue());
+ }
+ if (targetWrapperClass.equals(Long.class)) {
+ return new Long(num.longValue());
+ }
+ if (targetWrapperClass.equals(BigInteger.class)) {
+ return BigInteger.valueOf(num.longValue());
+ }
+ if (targetWrapperClass.equals(Float.class)) {
+ return new Float(num.floatValue());
+ }
+ if (targetWrapperClass.equals(Double.class)) {
+ return new Double(num.doubleValue());
+ }
+ if (targetWrapperClass.equals(BigDecimal.class)) {
+ return new BigDecimal(num.doubleValue());
+ }
+ }
+ return value;
+ }
+ '''
+} \ No newline at end of file

Back to the top