Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-02-14 04:45:41 -0500
committerAnsgar Radermacher2015-02-15 15:39:30 -0500
commitafc8d2893584cef98d649d1ed7b9acb5b413248a (patch)
tree6473cd7d27741147011c08f197113e8f811eaf53
parentcf42db7cc155ea51da5733df134455dea7322514 (diff)
downloadorg.eclipse.papyrus-afc8d2893584cef98d649d1ed7b9acb5b413248a.tar.gz
org.eclipse.papyrus-afc8d2893584cef98d649d1ed7b9acb5b413248a.tar.xz
org.eclipse.papyrus-afc8d2893584cef98d649d1ed7b9acb5b413248a.zip
448727 - [State Machine Diagram] Xtext seems to fail when using auto-completion on transition "F2 edition"
-rw-r--r--plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contentassist/UmlTransitionProposalProvider.java32
-rw-r--r--plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contributions/TransitionEditorConfigurationContribution.java85
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java8
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/InvalidStringUtil.java39
4 files changed, 96 insertions, 68 deletions
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contentassist/UmlTransitionProposalProvider.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contentassist/UmlTransitionProposalProvider.java
index bdc6904db35..3242b639426 100644
--- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contentassist/UmlTransitionProposalProvider.java
+++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contentassist/UmlTransitionProposalProvider.java
@@ -1,6 +1,17 @@
-/*
- * generated by Xtext
- */
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
package org.eclipse.papyrus.uml.textedit.transition.xtext.ui.contentassist;
import java.util.ArrayList;
@@ -27,8 +38,10 @@ public class UmlTransitionProposalProvider extends AbstractUmlTransitionProposal
@Override
public void complete_CallOrSignalEventRule(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- // TODO Auto-generated method stub
TransitionRule rule = (TransitionRule) model;
+ if (model == null) {
+ return;
+ }
List<EObject> operationAndSignals = UmlTransitionScopeProvider.getVisibleOperationAndSignals(ContextElementUtil.getContextElement(model.eResource()));
List<EObject> alreadyUsedOperationAndSignals = new ArrayList<EObject>();
if (rule != null && rule.getTriggers() != null && !rule.getTriggers().isEmpty()) {
@@ -52,16 +65,17 @@ public class UmlTransitionProposalProvider extends AbstractUmlTransitionProposal
context.getSelectedText().length(), // Replacement length
completionString.length(), // cursorPosition
null, // image
- opOrSignal.getName() + " - " + (opOrSignal instanceof Operation ? "Operation" : "Signal"), // displayString
+ opOrSignal.getName() + " - " + (opOrSignal instanceof Operation ? //$NON-NLS-1$
+ "Operation" : //$NON-NLS-1$
+ "Signal"), // displayString //$NON-NLS-1$
null, // contextInformation
- (opOrSignal instanceof Operation ? "Operation associated with the CallEvent of this trigger" : "Signal associated with the SignalEvent of this trigger") // additionalProposalInfo
+ (opOrSignal instanceof Operation ?
+ "Operation associated with the CallEvent of this trigger" :
+ "Signal associated with the SignalEvent of this trigger") // additionalProposalInfo
);
// acceptor.accept(new CompletionProposal(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo))
acceptor.accept(completionProposal);
}
}
}
-
-
-
}
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contributions/TransitionEditorConfigurationContribution.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contributions/TransitionEditorConfigurationContribution.java
index d9da654415d..f3f54b0c60c 100644
--- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contributions/TransitionEditorConfigurationContribution.java
+++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.transition.xtext.ui/src/org/eclipse/papyrus/uml/textedit/transition/xtext/ui/contributions/TransitionEditorConfigurationContribution.java
@@ -87,7 +87,7 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.xtext.glue.PopupEditorConfiguration#getTextToEdit(java.lang.Object)
*/
@SuppressWarnings("nls")
@@ -183,7 +183,7 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor
* , org.eclipse.core.runtime.IAdaptable)
@@ -214,28 +214,50 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
// ////////////////////////////////////////////////////////////////////////////////////////////////
// Create the new triggers
- if (transitionRuleObject.getTriggers() != null) {
- for (EventRule eventRule : transitionRuleObject.getTriggers()) {
- Trigger newTrigger = UMLFactory.eINSTANCE.createTrigger();
- this.newTriggers.add(newTrigger);
- newTrigger.setEvent(createUMLEvent(eventRule));
+ if (transitionRuleObject != null) {
+ if (transitionRuleObject.getTriggers() != null) {
+ for (EventRule eventRule : transitionRuleObject.getTriggers()) {
+ Trigger newTrigger = UMLFactory.eINSTANCE.createTrigger();
+ this.newTriggers.add(newTrigger);
+ newTrigger.setEvent(createUMLEvent(eventRule));
+ }
+ transition.getTriggers().addAll(this.newTriggers);
+ }
+ // Create the new constraint
+ if (transitionRuleObject.getGuard() != null && transitionRuleObject.getGuard().getConstraint() != null) {
+ this.newConstraint = transition.createGuard(EMPTY);
+ OpaqueExpression guardSpecification = UMLFactory.eINSTANCE.createOpaqueExpression();
+ guardSpecification.getLanguages().add(NATURAL_LANGUAGE);
+ guardSpecification.getBodies().add(EMPTY + transitionRuleObject.getGuard().getConstraint());
+ this.newConstraint.setSpecification(guardSpecification);
}
- transition.getTriggers().addAll(this.newTriggers);
- }
- // Create the new constraint
- if (transitionRuleObject.getGuard() != null && transitionRuleObject.getGuard().getConstraint() != null) {
- this.newConstraint = transition.createGuard(EMPTY);
- OpaqueExpression guardSpecification = UMLFactory.eINSTANCE.createOpaqueExpression();
- guardSpecification.getLanguages().add(NATURAL_LANGUAGE);
- guardSpecification.getBodies().add(EMPTY + transitionRuleObject.getGuard().getConstraint());
- this.newConstraint.setSpecification(guardSpecification);
- }
- boolean hasEffect = transitionRuleObject.getEffect() != null && transitionRuleObject.getEffect().getKind() != null && transitionRuleObject.getEffect().getBehaviorName() != null;
- BehaviorKind oldKind = getBehaviorKind(transition.getEffect());
+ boolean hasEffect = transitionRuleObject.getEffect() != null && transitionRuleObject.getEffect().getKind() != null && transitionRuleObject.getEffect().getBehaviorName() != null;
+ BehaviorKind oldKind = getBehaviorKind(transition.getEffect());
- if ((!hasEffect) || (transitionRuleObject.getEffect().getKind() != oldKind)) {
- // delete owned effect behavior
+ if ((!hasEffect) || (transitionRuleObject.getEffect().getKind() != oldKind)) {
+ // delete owned effect behavior
+ Behavior effect = transition.getEffect();
+ transition.setEffect(null);
+ if (effect != null) {
+ effect.destroy();
+ }
+ }
+
+ // Create the new behavior
+ if (hasEffect) {
+ String behaviorName = transitionRuleObject.getEffect().getBehaviorName();
+ if (transition.getEffect() == null) {
+ // behavior does exist yet => create
+ Behavior newEffectBehavior = createUMLBehavior(transitionRuleObject.getEffect().getKind(), behaviorName);
+ transition.setEffect(newEffectBehavior);
+ } else {
+ transition.getEffect().setName(behaviorName);
+ }
+ }
+ }
+ else {
+ // no effect, remove it.
Behavior effect = transition.getEffect();
transition.setEffect(null);
if (effect != null) {
@@ -243,18 +265,6 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
}
}
- // Create the new behavior
- if (hasEffect) {
- String behaviorName = transitionRuleObject.getEffect().getBehaviorName();
- if (transition.getEffect() == null) {
- // behavior does exist yet => create
- Behavior newEffectBehavior = createUMLBehavior(transitionRuleObject.getEffect().getKind(), behaviorName);
- transition.setEffect(newEffectBehavior);
- } else {
- transition.getEffect().setName(behaviorName);
- }
- }
-
return CommandResult.newOKCommandResult(transition);
}
@@ -501,8 +511,6 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
@Override
protected ICommand getParseCommand(EObject modelObject, EObject xtextObject) {
- // first: retrieves / determines if the xtextObject is a TransitionRule object
- EObject modifiedObject = xtextObject;
if (!(modelObject instanceof Transition)) {
return null;
@@ -510,13 +518,8 @@ public class TransitionEditorConfigurationContribution extends DefaultXtextDirec
Transition transition = (Transition) modelObject;
- while (xtextObject != null && !(xtextObject instanceof TransitionRule)) {
- modifiedObject = modifiedObject.eContainer();
- }
- if (modifiedObject == null) {
- return null;
- }
TransitionRule transitionRuleObject = (TransitionRule) xtextObject;
+ // transitionRuleObject may be null, if we have no input left
// Creates and executes the update command
try {
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java
index b88eb98cd33..cb4d125c690 100644
--- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java
@@ -145,7 +145,10 @@ public abstract class DefaultXtextDirectEditorConfiguration extends DefaultDirec
EcoreUtil2.resolveLazyCrossReferences(context.getFakeResource(), CancelIndicator.NullImpl);
if (!context.getFakeResource().getParseResult().hasSyntaxErrors() && context.getFakeResource().getErrors().size() == 0) {
EObject xtextObject = context.getFakeResource().getParseResult().getRootASTElement();
- result.add(DefaultXtextDirectEditorConfiguration.this.getParseCommand(semanticObject, xtextObject));
+ ICommand cmd = DefaultXtextDirectEditorConfiguration.this.getParseCommand(semanticObject, xtextObject);
+ if (cmd != null) {
+ result.add(DefaultXtextDirectEditorConfiguration.this.getParseCommand(semanticObject, xtextObject));
+ }
} else {
result.add(createInvalidStringCommand(newString, semanticObject));
}
@@ -179,6 +182,9 @@ public abstract class DefaultXtextDirectEditorConfiguration extends DefaultDirec
if (semanticObject instanceof Element) {
String textualRepresentation = InvalidStringUtil.getTextualRepresentation((Element) semanticObject);
if (textualRepresentation != null) {
+ // register invalid string adapter. If we edit existing models, the invalid string may exist
+ // although we have not created the invalid string in this session.
+ registerInvalidStringAdapter(semanticObject);
return textualRepresentation;
}
}
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/InvalidStringUtil.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/InvalidStringUtil.java
index abfd151713b..e474a2f03b4 100644
--- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/InvalidStringUtil.java
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/InvalidStringUtil.java
@@ -32,7 +32,17 @@ import org.eclipse.uml2.uml.Stereotype;
*/
public class InvalidStringUtil {
- public static String ACTION_LANGUAGE_PROFILE_NAME = "ActionLanguage";
+ /**
+ * Stereotype name for textual representation
+ */
+ public static final String TEXTUAL_REPRESENTATION = "TextualRepresentation"; //$NON-NLS-1$
+
+ /**
+ * Attribute of TextualRepresentation stereotype that indicates used language
+ */
+ public static final String LANGUAGE = "language"; //$NON-NLS-1$
+
+ public static String ACTION_LANGUAGE_PROFILE_NAME = "ActionLanguage"; //$NON-NLS-1$
/**
* The Action Language profile
@@ -83,17 +93,13 @@ public class InvalidStringUtil {
textualRepresentationStereotype);
} else {
// There is a chance to find it if the root model has ActionLanguage
- // profile applied
- // In this case, the stereotype is included in
+ // profile applied. In this case, the stereotype is included in
// comment.getApplicableStereotypes()
- List<Stereotype> applicableStereotypes = comment
- .getApplicableStereotypes();
+ List<Stereotype> applicableStereotypes = comment.getApplicableStereotypes();
for (int i = 0; i < applicableStereotypes.size()
&& textualRepresentationStereotype == null; i++) {
- if (applicableStereotypes.get(i).getName()
- .equals("TextualRepresentation")) {
- textualRepresentationStereotype = applicableStereotypes
- .get(i);
+ if (applicableStereotypes.get(i).getName().equals(TEXTUAL_REPRESENTATION)) {
+ textualRepresentationStereotype = applicableStereotypes.get(i);
}
}
}
@@ -106,15 +112,14 @@ public class InvalidStringUtil {
*/
public static boolean isActionLanguageProfileApplied(Element element) {
if (actionLanguageProfile == null) {
- IRegisteredProfile registeredActionLanguageProfile = Registry.getRegisteredProfile(ACTION_LANGUAGE_PROFILE_NAME, null);
+ IRegisteredProfile registeredActionLanguageProfile =
+ Registry.getRegisteredProfile(ACTION_LANGUAGE_PROFILE_NAME, null);
URI modelUri = registeredActionLanguageProfile.getUri();
Package root = PackageUtil.getRootPackage(element);
- Resource modelResource = root.eResource().getResourceSet()
- .getResource(modelUri, true);
+ Resource modelResource = root.eResource().getResourceSet().getResource(modelUri, true);
if (modelResource.getContents().get(0) instanceof Profile) {
- actionLanguageProfile = (Profile) modelResource.getContents()
- .get(0);
+ actionLanguageProfile = (Profile) modelResource.getContents().get(0);
}
}
List<Profile> appliedProfiles = PackageUtil.getRootPackage(element).getAppliedProfiles();
@@ -123,6 +128,7 @@ public class InvalidStringUtil {
/**
* @param element
+ * @param languageId
* @return
*/
public static Comment createTextualRepresentationComment(Element element, String languageId) {
@@ -133,12 +139,11 @@ public class InvalidStringUtil {
actionLanguageProfile, true);
}
clean();
- // This is just to force retrieval of the textual representation
- // stereotype
+ // Force retrieval of variable textualRepresentationStereotype (side effect of evaluation below)
isATextualRepresentationComment(textualRepresentationComment);
textualRepresentationComment
.applyStereotype(textualRepresentationStereotype);
- textualRepresentationComment.setValue(textualRepresentationStereotype, "language", languageId);
+ textualRepresentationComment.setValue(textualRepresentationStereotype, LANGUAGE, languageId);
return textualRepresentationComment;
}

Back to the top