Sfoglia il codice sorgente

Creation of import slots for properties, not only variable definitions. Made resolution of import slots aware of package names as namespace. Some further refactorings to simplify code. (#635)

Thomas Kutz 9 anni fa
parent
commit
c85c25197e

+ 1 - 1
plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/StructureMapping.xtend

@@ -72,7 +72,7 @@ class StructureMapping {
 	def dispatch Scope mapScope(ImportScope scope) {
 		val _scope = scope.createScope
 		for (Import imp : scope.imports) {
-			val decls = resolver.getImportedElementsOfType(imp, VariableDefinition)
+			val decls = resolver.getImportedElementsOfType(imp, org.yakindu.base.types.Property)
 			for (Declaration decl : decls) {
 				val importDecl = SGraphFactory.eINSTANCE.createImportDeclaration
 				importDecl.name = decl.name

+ 9 - 8
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/util/ImportResolver.java

@@ -13,12 +13,12 @@ package org.yakindu.sct.model.stext.util;
 
 import java.util.List;
 
-import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.xtext.resource.IContainer;
 import org.eclipse.xtext.resource.IEObjectDescription;
 import org.eclipse.xtext.resource.IResourceDescription;
@@ -52,18 +52,19 @@ public class ImportResolver {
 	 * @return imported elements of given type
 	 */
 	public <T extends EObject> List<T> getImportedElementsOfType(Import importDeclaration, Class<T> type) {
-		List<T> varDefs = Lists.newArrayList();
+		List<T> elements = Lists.newArrayList();
 		Package importedPackage = getPackageForNamespace(importDeclaration.eResource(), importDeclaration.getImportedNamespace());
 		if (importedPackage != null) {
-			TreeIterator<EObject> iter = importedPackage.eAllContents();
-			while (iter.hasNext()) {
-				EObject next = iter.next();
-				if (type.isInstance(next)) {
-					varDefs.add(type.cast(next));
+			if (importedPackage.eIsProxy()) {
+				importedPackage = (Package) EcoreUtil.resolve(importedPackage, importDeclaration);
+			}
+			for (EObject content : importedPackage.eContents()) {
+				if (type.isInstance(content)) {
+					elements.add(type.cast(content));
 				}
 			}
 		}
-		return varDefs;
+		return elements;
 	}
 
 	/**

+ 17 - 18
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/DefaultExecutionSlotResolver.xtend

@@ -27,6 +27,7 @@ import org.yakindu.sct.simulation.core.sruntime.CompositeSlot
 import org.yakindu.sct.simulation.core.sruntime.ExecutionContext
 import org.yakindu.sct.simulation.core.sruntime.ExecutionSlot
 import org.yakindu.sct.simulation.core.sruntime.ExecutionVariable
+import org.eclipse.xtext.EcoreUtil2
 
 /**
  * Default implementation for resolving execution slots based on expressions.
@@ -39,10 +40,7 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 	extension IQualifiedNameProvider nameProvider
 
 	def dispatch ExecutionSlot resolve(ExecutionContext context, FeatureCall e) {
-		if (e.feature instanceof VariableDefinition) {
-			return context.getVariable(e.feature.fullyQualifiedName.toString)
-		}
-		if (e.feature instanceof Operation) {
+		if (e.feature instanceof VariableDefinition || e.feature instanceof Operation) {
 			return context.getVariable(e.feature.fullyQualifiedName.toString)
 		}
 		if (e.feature instanceof Property || e.feature instanceof Event) {
@@ -54,7 +52,7 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 				calls.add(0, current.feature)
 			}
 
-			// first: get the root slot where to start the search searching
+			// first: get the root slot where to start the search
 			val root = (current.owner as ElementReferenceExpression).reference
 			var ExecutionSlot featureSlot = null
 			
@@ -63,13 +61,9 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 				calls.remove(0)
 			}
 			else {
-				var varDefFqn = getFqn(root).toString
-				featureSlot = context.getSlot(varDefFqn)
-				if (featureSlot == null) {
-					featureSlot = context.getSlot(root.fullyQualifiedName.toString)
-					if (featureSlot == null)
-						return null // could not find starting slot for feature call
-				}
+				featureSlot = packageNamespaceAwareResolve(context, root)
+				if (featureSlot == null)
+					return null // could not find starting slot for feature call
 			}
 			// go through all calls and traverse execution context hierarchy accordingly
 			for (EObject feature : calls) {
@@ -81,21 +75,26 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 					//					TODO (featureSlot as ExecutionVariable).value
 				}
 			}
-
 			return featureSlot
 		}
 	}
 	
 	def dispatch ExecutionSlot resolve(ExecutionContext context, ElementReferenceExpression e) {
-		context.getSlot(e.reference.fullyQualifiedName.toString)
+		packageNamespaceAwareResolve(context, e.reference)
 	}
 	
-	def dispatch ExecutionSlot resolve(ExecutionContext context, AssignmentExpression e) {
-		return context.resolve(e.varRef)
+	def protected ExecutionSlot packageNamespaceAwareResolve(ExecutionContext context, EObject element) {
+		val pkg = EcoreUtil2.getContainerOfType(element, org.yakindu.base.types.Package)
+		if (pkg != null) {
+			context.getSlot(pkg.name + "." + element.fullyQualifiedName.toString)
+		}
+		else {
+			context.getSlot(element.fullyQualifiedName.toString)
+		}
 	}
 	
-	def getFqn(EObject varDef) {
-		varDef.getFullyQualifiedName
+	def dispatch ExecutionSlot resolve(ExecutionContext context, AssignmentExpression e) {
+		return context.resolve(e.varRef)
 	}
 
 	def private name(EObject e) {