浏览代码

added content assist for entry and exit - refactored stext scoping therefore

rherrmannr 7 年之前
父节点
当前提交
4c5b2d2da1

+ 3 - 2
plugins/org.yakindu.sct.model.stext.ui/META-INF/MANIFEST.MF

@@ -21,8 +21,9 @@ Require-Bundle: org.yakindu.sct.model.stext;visibility:=reexport,
  org.yakindu.sct.doc.user,
  org.yakindu.base.xtext.utils.jface,
  org.eclipse.xtext.ui.shared
-Import-Package: org.apache.log4j,
- org.apache.commons.logging
+Import-Package: org.antlr.analysis;version="3.2.0",
+ org.apache.commons.logging,
+ org.apache.log4j
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.yakindu.sct.model.stext.ui;
   uses:="org.eclipse.ui.plugin,

+ 65 - 0
plugins/org.yakindu.sct.model.stext.ui/src/org/yakindu/sct/model/stext/ui/contentassist/STextProposalProvider.java

@@ -45,7 +45,13 @@ import org.yakindu.base.expressions.expressions.ElementReferenceExpression;
 import org.yakindu.base.expressions.expressions.FeatureCall;
 import org.yakindu.base.types.Operation;
 import org.yakindu.base.types.Type;
+import org.yakindu.sct.model.sgraph.Entry;
+import org.yakindu.sct.model.sgraph.Exit;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.SpecificationElement;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport;
 import org.yakindu.sct.model.stext.services.STextGrammarAccess;
@@ -53,9 +59,11 @@ import org.yakindu.sct.model.stext.stext.InterfaceScope;
 import org.yakindu.sct.model.stext.stext.InternalScope;
 import org.yakindu.sct.model.stext.stext.SimpleScope;
 import org.yakindu.sct.model.stext.stext.StatechartSpecification;
+import org.yakindu.sct.model.stext.stext.TransitionReaction;
 import org.yakindu.sct.model.stext.stext.TransitionSpecification;
 import org.yakindu.sct.model.stext.stext.VariableDefinition;
 import org.yakindu.sct.model.stext.ui.internal.STextActivator;
+import org.yakindu.sct.model.stext.utils.STextUtils;
 
 import com.google.common.base.Function;
 import com.google.inject.Inject;
@@ -79,6 +87,9 @@ public class STextProposalProvider extends AbstractSTextProposalProvider {
 	@Inject
 	private IPackageImport2URIMapper mapper;
 
+	@Inject
+	private STextUtils utils; 
+	
 	public static class StrikeThroughStyler extends Styler {
 
 		@Override
@@ -372,7 +383,61 @@ public class STextProposalProvider extends AbstractSTextProposalProvider {
 				proposalText + " - " + ruleCall.getRule().getName(), null, context);
 		priorityOptimizer.accept(proposal);
 	}
+	
+	@Override
+	public void complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context,
+			ICompletionProposalAcceptor acceptor) {
+		if (model instanceof TransitionReaction) {
+			SpecificationElement contextElement = utils.getContextElement(model);
+			if (contextElement instanceof Transition) {
+				Transition transition = (Transition) contextElement;
+				// check if outgoing or incoming transition
+				EObject eContainer = ruleCall.eContainer();
+				Vertex state = null;
+				boolean entry = false;
+				if (eContainer instanceof Assignment) {
+					String feature = ((Assignment) eContainer).getFeature();
+					if ("entrypoint".equals(feature)) {
+						state = transition.getTarget();
+						entry = true;
+					} else if ("exitpoint".equals(feature)) {
+						entry = false;
+						state = transition.getSource();
+					} else {
+						super.complete_ID(model, ruleCall, context, acceptor);
+					}
+				}
+				if (state instanceof State) {
+					createContentAssistForEntryAndExit((State) state, entry, context, acceptor);
+				}
+			}
+		}
+		super.complete_ID(model, ruleCall, context, acceptor);
+	}
 
+	private void createContentAssistForEntryAndExit(State state, boolean entry, ContentAssistContext context,
+			ICompletionProposalAcceptor acceptor) {
+		for (Region region : state.getRegions()) {
+			for (Vertex vertex : region.getVertices()) {
+				if (entry) {
+					if (vertex instanceof Entry) {
+						String assist = vertex.getName();
+						if (assist.length() > 0) {
+							acceptor.accept(createCompletionProposal(assist, context));
+						}
+					}
+				} else {
+					if (vertex instanceof Exit) {
+						String assist = vertex.getName();
+						if (assist.length() > 0) {
+							acceptor.accept(createCompletionProposal(assist, context));
+						}
+					}
+				}
+			}
+		}
+	}
+	
 	public void completeActiveStateReferenceExpression_Value(EObject model, Assignment assignment,
 			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
 		lookupCrossReference(((CrossReference) assignment.getTerminal()), context, acceptor);

+ 1 - 0
plugins/org.yakindu.sct.model.stext/META-INF/MANIFEST.MF

@@ -43,5 +43,6 @@ Export-Package: org.yakindu.sct.model.stext,
  org.yakindu.sct.model.stext.stext.util,
  org.yakindu.sct.model.stext.tasks,
  org.yakindu.sct.model.stext.terminals,
+ org.yakindu.sct.model.stext.utils,
  org.yakindu.sct.model.stext.validation
 Bundle-ClassPath: .

+ 8 - 32
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/scoping/STextScopeProvider.java

@@ -50,6 +50,7 @@ import org.yakindu.sct.model.stext.scoping.ContextPredicateProvider.EmptyPredica
 import org.yakindu.sct.model.stext.stext.InterfaceScope;
 import org.yakindu.sct.model.stext.stext.InternalScope;
 import org.yakindu.sct.model.stext.stext.StatechartSpecification;
+import org.yakindu.sct.model.stext.utils.STextUtils;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Lists;
@@ -72,9 +73,12 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	private IQualifiedNameProvider nameProvider;
 	@Inject
 	private ContextPredicateProvider predicateProvider;
+	
+	@Inject
+	private STextUtils utils;
 
 	public IScope scope_ActiveStateReferenceExpression_value(EObject context, EReference reference) {
-		Statechart statechart = getStatechart(context);
+		Statechart statechart = utils.getStatechart(context);
 		if (statechart == null)
 			return IScope.NULLSCOPE;
 		List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
@@ -86,7 +90,7 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 
 	protected List<ImportNormalizer> getActiveStateNormalizer(EObject context) {
 		List<ImportNormalizer> normalizer = Lists.newArrayList();
-		SpecificationElement contextElement = getContextElement(context);
+		SpecificationElement contextElement = utils.getContextElement(context);
 		if (contextElement == null)
 			return normalizer;
 		Region containingRegion = EcoreUtil2.getContainerOfType(contextElement, Region.class);
@@ -187,7 +191,7 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	 */
 	protected IScope getNamedTopLevelScope(final EObject context, EReference reference) {
 		List<EObject> scopeCandidates = Lists.newArrayList();
-		ScopedElement scopedElement = getScopedElement(context);
+		ScopedElement scopedElement = utils.getScopedElement(context);
 		if (scopedElement == null)
 			return IScope.NULLSCOPE;
 		EList<Scope> scopes = scopedElement.getScopes();
@@ -207,7 +211,7 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	 */
 	protected IScope getUnnamedTopLevelScope(final EObject context, EReference reference) {
 		List<EObject> scopeCandidates = Lists.newArrayList();
-		ScopedElement scopedElement = getScopedElement(context);
+		ScopedElement scopedElement = utils.getScopedElement(context);
 		if (scopedElement == null)
 			return IScope.NULLSCOPE;
 		EList<Scope> scopes = scopedElement.getScopes();
@@ -227,33 +231,5 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 		return Scopes.scopeFor(scopeCandidates, scope);
 	}
 
-	protected SpecificationElement getContextElement(EObject context) {
-		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
-				ContextElementAdapter.class);
-
-		if (provider == null) {
-			return EcoreUtil2.getContainerOfType(context, SpecificationElement.class);
-		} else {
-			return (SpecificationElement) provider.getElement();
-		}
-	}
 
-	protected ScopedElement getScopedElement(EObject context) {
-		ScopedElement scopedElement = EcoreUtil2.getContainerOfType(context, ScopedElement.class);
-		if (EcoreUtil.getRootContainer(context) instanceof StatechartSpecification && scopedElement != null)
-			return scopedElement;
-		return getStatechart(context);
-	}
-
-	protected Statechart getStatechart(EObject context) {
-		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
-				ContextElementAdapter.class);
-
-		if (provider == null) {
-			return EcoreUtil2.getContainerOfType(context, Statechart.class);
-		} else {
-			return (Statechart) EcoreUtil.getObjectByType(provider.getElement().eResource().getContents(),
-					SGraphPackage.Literals.STATECHART);
-		}
-	}
 }

+ 43 - 0
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/utils/STextUtils.java

@@ -0,0 +1,43 @@
+package org.yakindu.sct.model.stext.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.EcoreUtil2;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.model.sgraph.ScopedElement;
+import org.yakindu.sct.model.sgraph.SpecificationElement;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
+import org.yakindu.sct.model.stext.stext.StatechartSpecification;
+
+public class STextUtils {
+	public SpecificationElement getContextElement(EObject context) {
+		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
+				ContextElementAdapter.class);
+
+		if (provider == null) {
+			return EcoreUtil2.getContainerOfType(context, SpecificationElement.class);
+		} else {
+			return (SpecificationElement) provider.getElement();
+		}
+	}
+	
+	public ScopedElement getScopedElement(EObject context) {
+		ScopedElement scopedElement = EcoreUtil2.getContainerOfType(context, ScopedElement.class);
+		if (EcoreUtil.getRootContainer(context) instanceof StatechartSpecification && scopedElement != null)
+			return scopedElement;
+		return getStatechart(context);
+	}
+
+	public Statechart getStatechart(EObject context) {
+		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
+				ContextElementAdapter.class);
+
+		if (provider == null) {
+			return EcoreUtil2.getContainerOfType(context, Statechart.class);
+		} else {
+			return (Statechart) EcoreUtil.getObjectByType(provider.getElement().eResource().getContents(),
+					SGraphPackage.Literals.STATECHART);
+		}
+	}
+}