Browse Source

Allow registration of different Type Systems

Andreas Mülder 10 years ago
parent
commit
5d07475b15

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

@@ -1,10 +1,11 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
-Bundle-Name: Yakindu Statechart Tools (SCT) SGraph Model
+Bundle-Name: %pluginName
 Bundle-SymbolicName: org.yakindu.sct.model.sgraph;singleton:=true
 Bundle-Version: 2.4.1.qualifier
 Bundle-ClassPath: .
-Bundle-Vendor: statecharts.org
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.yakindu.sct.model.sgraph,
  org.yakindu.sct.model.sgraph.impl,

+ 2 - 0
plugins/org.yakindu.sct.model.sgraph/model/emf/sgraph.ecore

@@ -32,6 +32,8 @@
   <eClassifiers xsi:type="ecore:EClass" name="Statechart" eSuperTypes="#//SpecificationElement #//ReactiveElement #//ScopedElement #//CompositeElement ../../../org.yakindu.base.types/model/base.ecore#//NamedElement ../../../org.yakindu.base.types/model/base.ecore#//DocumentedElement">
     <eStructuralFeatures xsi:type="ecore:EReference" name="imports" upperBound="-1"
         eType="#//Import" containment="true"/>
+    <eStructuralFeatures xsi:type="ecore:EAttribute" name="typesystemURI" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
+        defaultValueLiteral="Default"/>
   </eClassifiers>
   <eClassifiers xsi:type="ecore:EClass" name="Entry" eSuperTypes="#//Pseudostate">
     <eStructuralFeatures xsi:type="ecore:EAttribute" name="kind" eType="#//EntryKind"/>

+ 11 - 0
plugins/org.yakindu.sct.model.sgraph/plugin.properties

@@ -0,0 +1,11 @@
+# Copyright (c) 2011 committers of YAKINDU and others.
+# 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:
+# committers of YAKINDU - initial API and implementation
+# 
+
+pluginName = SGraph Model
+providerName = www.example.org

+ 29 - 1
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/SGraphPackage.java

@@ -697,6 +697,15 @@ public interface SGraphPackage extends EPackage {
 	 */
 	int STATECHART__IMPORTS = SPECIFICATION_ELEMENT_FEATURE_COUNT + 7;
 
+	/**
+	 * The feature id for the '<em><b>Typesystem URI</b></em>' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 * @ordered
+	 */
+	int STATECHART__TYPESYSTEM_URI = SPECIFICATION_ELEMENT_FEATURE_COUNT + 8;
+
 	/**
 	 * The number of structural features of the '<em>Statechart</em>' class.
 	 * <!-- begin-user-doc -->
@@ -704,7 +713,7 @@ public interface SGraphPackage extends EPackage {
 	 * @generated
 	 * @ordered
 	 */
-	int STATECHART_FEATURE_COUNT = SPECIFICATION_ELEMENT_FEATURE_COUNT + 8;
+	int STATECHART_FEATURE_COUNT = SPECIFICATION_ELEMENT_FEATURE_COUNT + 9;
 
 	/**
 	 * The meta object id for the '{@link org.yakindu.sct.model.sgraph.impl.EntryImpl <em>Entry</em>}' class.
@@ -1738,6 +1747,17 @@ public interface SGraphPackage extends EPackage {
 	 */
 	EReference getStatechart_Imports();
 
+	/**
+	 * Returns the meta object for the attribute '{@link org.yakindu.sct.model.sgraph.Statechart#getTypesystemURI <em>Typesystem URI</em>}'.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @return the meta object for the attribute '<em>Typesystem URI</em>'.
+	 * @see org.yakindu.sct.model.sgraph.Statechart#getTypesystemURI()
+	 * @see #getStatechart()
+	 * @generated
+	 */
+	EAttribute getStatechart_TypesystemURI();
+
 	/**
 	 * Returns the meta object for class '{@link org.yakindu.sct.model.sgraph.Entry <em>Entry</em>}'.
 	 * <!-- begin-user-doc -->
@@ -2324,6 +2344,14 @@ public interface SGraphPackage extends EPackage {
 		 */
 		EReference STATECHART__IMPORTS = eINSTANCE.getStatechart_Imports();
 
+		/**
+		 * The meta object literal for the '<em><b>Typesystem URI</b></em>' attribute feature.
+		 * <!-- begin-user-doc -->
+		 * <!-- end-user-doc -->
+		 * @generated
+		 */
+		EAttribute STATECHART__TYPESYSTEM_URI = eINSTANCE.getStatechart_TypesystemURI();
+
 		/**
 		 * The meta object literal for the '{@link org.yakindu.sct.model.sgraph.impl.EntryImpl <em>Entry</em>}' class.
 		 * <!-- begin-user-doc -->

+ 28 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/Statechart.java

@@ -24,6 +24,7 @@ import org.yakindu.base.base.NamedElement;
  * The following features are supported:
  * <ul>
  *   <li>{@link org.yakindu.sct.model.sgraph.Statechart#getImports <em>Imports</em>}</li>
+ *   <li>{@link org.yakindu.sct.model.sgraph.Statechart#getTypesystemURI <em>Typesystem URI</em>}</li>
  * </ul>
  * </p>
  *
@@ -55,4 +56,31 @@ public interface Statechart extends SpecificationElement, ReactiveElement, Scope
 	 */
 	EList<Import> getImports();
 
+	/**
+	 * Returns the value of the '<em><b>Typesystem URI</b></em>' attribute.
+	 * The default value is <code>"Default"</code>.
+	 * <!-- begin-user-doc -->
+	 * <p>
+	 * If the meaning of the '<em>Typesystem URI</em>' attribute isn't clear,
+	 * there really should be more of a description here...
+	 * </p>
+	 * <!-- end-user-doc -->
+	 * @return the value of the '<em>Typesystem URI</em>' attribute.
+	 * @see #setTypesystemURI(String)
+	 * @see org.yakindu.sct.model.sgraph.SGraphPackage#getStatechart_TypesystemURI()
+	 * @model default="Default"
+	 * @generated
+	 */
+	String getTypesystemURI();
+
+	/**
+	 * Sets the value of the '{@link org.yakindu.sct.model.sgraph.Statechart#getTypesystemURI <em>Typesystem URI</em>}' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @param value the new value of the '<em>Typesystem URI</em>' attribute.
+	 * @see #getTypesystemURI()
+	 * @generated
+	 */
+	void setTypesystemURI(String value);
+
 } // Statechart

+ 11 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/impl/SGraphPackageImpl.java

@@ -619,6 +619,15 @@ public class SGraphPackageImpl extends EPackageImpl implements SGraphPackage {
 		return (EReference)statechartEClass.getEStructuralFeatures().get(0);
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public EAttribute getStatechart_TypesystemURI() {
+		return (EAttribute)statechartEClass.getEStructuralFeatures().get(1);
+	}
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
@@ -907,6 +916,7 @@ public class SGraphPackageImpl extends EPackageImpl implements SGraphPackage {
 
 		statechartEClass = createEClass(STATECHART);
 		createEReference(statechartEClass, STATECHART__IMPORTS);
+		createEAttribute(statechartEClass, STATECHART__TYPESYSTEM_URI);
 
 		entryEClass = createEClass(ENTRY);
 		createEAttribute(entryEClass, ENTRY__KIND);
@@ -1056,6 +1066,7 @@ public class SGraphPackageImpl extends EPackageImpl implements SGraphPackage {
 
 		initEClass(statechartEClass, Statechart.class, "Statechart", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEReference(getStatechart_Imports(), this.getImport(), null, "imports", null, 0, -1, Statechart.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+		initEAttribute(getStatechart_TypesystemURI(), ecorePackage.getEString(), "typesystemURI", "Default", 0, 1, Statechart.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 
 		initEClass(entryEClass, Entry.class, "Entry", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEAttribute(getEntry_Kind(), this.getEntryKind(), "kind", null, 0, 1, Entry.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);

+ 54 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/impl/StatechartImpl.java

@@ -50,6 +50,7 @@ import org.yakindu.sct.model.sgraph.Statechart;
  *   <li>{@link org.yakindu.sct.model.sgraph.impl.StatechartImpl#getName <em>Name</em>}</li>
  *   <li>{@link org.yakindu.sct.model.sgraph.impl.StatechartImpl#getDocumentation <em>Documentation</em>}</li>
  *   <li>{@link org.yakindu.sct.model.sgraph.impl.StatechartImpl#getImports <em>Imports</em>}</li>
+ *   <li>{@link org.yakindu.sct.model.sgraph.impl.StatechartImpl#getTypesystemURI <em>Typesystem URI</em>}</li>
  * </ul>
  * </p>
  *
@@ -147,6 +148,26 @@ public class StatechartImpl extends SpecificationElementImpl implements
 	 */
 	protected EList<Import> imports;
 
+	/**
+	 * The default value of the '{@link #getTypesystemURI() <em>Typesystem URI</em>}' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @see #getTypesystemURI()
+	 * @generated
+	 * @ordered
+	 */
+	protected static final String TYPESYSTEM_URI_EDEFAULT = "Default";
+
+	/**
+	 * The cached value of the '{@link #getTypesystemURI() <em>Typesystem URI</em>}' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @see #getTypesystemURI()
+	 * @generated
+	 * @ordered
+	 */
+	protected String typesystemURI = TYPESYSTEM_URI_EDEFAULT;
+
 	/**
 	 * <!-- begin-user-doc --> <!-- end-user-doc -->
 	 * @generated
@@ -287,6 +308,27 @@ public class StatechartImpl extends SpecificationElementImpl implements
 		return imports;
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public String getTypesystemURI() {
+		return typesystemURI;
+	}
+
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public void setTypesystemURI(String newTypesystemURI) {
+		String oldTypesystemURI = typesystemURI;
+		typesystemURI = newTypesystemURI;
+		if (eNotificationRequired())
+			eNotify(new ENotificationImpl(this, Notification.SET, SGraphPackage.STATECHART__TYPESYSTEM_URI, oldTypesystemURI, typesystemURI));
+	}
+
 	/**
 	 * <!-- begin-user-doc --> <!-- end-user-doc -->
 	 * @generated
@@ -343,6 +385,8 @@ public class StatechartImpl extends SpecificationElementImpl implements
 				return getDocumentation();
 			case SGraphPackage.STATECHART__IMPORTS:
 				return getImports();
+			case SGraphPackage.STATECHART__TYPESYSTEM_URI:
+				return getTypesystemURI();
 		}
 		return super.eGet(featureID, resolve, coreType);
 	}
@@ -376,6 +420,9 @@ public class StatechartImpl extends SpecificationElementImpl implements
 				getImports().clear();
 				getImports().addAll((Collection<? extends Import>)newValue);
 				return;
+			case SGraphPackage.STATECHART__TYPESYSTEM_URI:
+				setTypesystemURI((String)newValue);
+				return;
 		}
 		super.eSet(featureID, newValue);
 	}
@@ -405,6 +452,9 @@ public class StatechartImpl extends SpecificationElementImpl implements
 			case SGraphPackage.STATECHART__IMPORTS:
 				getImports().clear();
 				return;
+			case SGraphPackage.STATECHART__TYPESYSTEM_URI:
+				setTypesystemURI(TYPESYSTEM_URI_EDEFAULT);
+				return;
 		}
 		super.eUnset(featureID);
 	}
@@ -432,6 +482,8 @@ public class StatechartImpl extends SpecificationElementImpl implements
 				return DOCUMENTATION_EDEFAULT == null ? documentation != null : !DOCUMENTATION_EDEFAULT.equals(documentation);
 			case SGraphPackage.STATECHART__IMPORTS:
 				return imports != null && !imports.isEmpty();
+			case SGraphPackage.STATECHART__TYPESYSTEM_URI:
+				return TYPESYSTEM_URI_EDEFAULT == null ? typesystemURI != null : !TYPESYSTEM_URI_EDEFAULT.equals(typesystemURI);
 		}
 		return super.eIsSet(featureID);
 	}
@@ -533,6 +585,8 @@ public class StatechartImpl extends SpecificationElementImpl implements
 		result.append(name);
 		result.append(", documentation: ");
 		result.append(documentation);
+		result.append(", typesystemURI: ");
+		result.append(typesystemURI);
 		result.append(')');
 		return result.toString();
 	}

+ 0 - 6
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/STextRuntimeModule.java

@@ -15,8 +15,6 @@ import org.eclipse.xtext.linking.ILinker;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
 import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
-import org.yakindu.base.types.typesystem.DefaultTypeSystem;
-import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.sgraph.resource.SCTLinker;
 import org.yakindu.sct.model.sgraph.resource.provider.SCTResourceDescriptionStrategy;
 import org.yakindu.sct.model.stext.conversion.StextValueConverterService;
@@ -55,10 +53,6 @@ public class STextRuntimeModule extends org.yakindu.sct.model.stext.AbstractSTex
 		return StextValueConverterService.class;
 	}
 
-	public Class<? extends ITypeSystem> bindITypeSystem() {
-		return DefaultTypeSystem.class;
-	}
-
 	public Class<? extends ITypeSystemInferrer> bindITypeSystemInferrer() {
 		return STextTypeInferrer.class;
 	}

+ 16 - 1
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/scoping/STextGlobalScopeProvider.java

@@ -14,6 +14,7 @@ import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
 import org.eclipse.xtext.resource.IEObjectDescription;
 import org.eclipse.xtext.scoping.IScope;
@@ -21,6 +22,8 @@ import org.eclipse.xtext.scoping.impl.DefaultGlobalScopeProvider;
 import org.eclipse.xtext.scoping.impl.FilteringScope;
 import org.yakindu.base.types.ITypeSystemRegistry;
 import org.yakindu.base.types.typesystem.ITypeSystem;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.model.sgraph.Statechart;
 
 import com.google.common.base.Predicate;
 import com.google.inject.Inject;
@@ -47,9 +50,21 @@ public class STextGlobalScopeProvider extends DefaultGlobalScopeProvider {
 		IScope parentScope = super.getScope(context, reference, filter);
 		parentScope = filterExternalDeclarations(context, parentScope);
 		parentScope = new TypeSystemAwareScope(parentScope, typeSystem, qualifiedNameProvider,
-				reference.getEReferenceType());
+				reference.getEReferenceType(),getStatechart(context).getTypesystemURI());
 		return parentScope;
 	}
+	
+	private Statechart getStatechart(Resource context) {
+		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(
+				context, ContextElementAdapter.class);
+
+		if (provider == null) {
+			return (Statechart) EcoreUtil2.getObjectByType(context.getContents(), SGraphPackage.Literals.STATECHART);
+		} else {
+			return (Statechart) EcoreUtil.getObjectByType(provider.getElement().eResource().getContents(),
+					SGraphPackage.Literals.STATECHART);
+		}
+	}
 
 	/**
 	 * Filter all Elements that are part of an SCT file bug from another

+ 8 - 3
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/scoping/TypeSystemAwareScope.java

@@ -28,24 +28,29 @@ import com.google.common.collect.Lists;
 
 public class TypeSystemAwareScope extends AbstractScope {
 
+	private static final String DEFAULT_TYPE_SYSTEM = "Default";
+
 	private final ITypeSystemRegistry typeSystemAccess;
 
 	private final IQualifiedNameProvider qualifiedNameProvider;
 
 	private EClass eClass;
 
+	private String typesystemURI;
+
 	public TypeSystemAwareScope(IScope parent, ITypeSystemRegistry typeSystemAccess,
-			IQualifiedNameProvider qualifiedNameProvider, EClass eClass) {
+			IQualifiedNameProvider qualifiedNameProvider, EClass eClass, String typesystemURI) {
 		super(parent, false);
 		this.typeSystemAccess = typeSystemAccess;
 		this.qualifiedNameProvider = qualifiedNameProvider;
 		this.eClass = eClass;
+		this.typesystemURI = typesystemURI != null ? typesystemURI : DEFAULT_TYPE_SYSTEM;
 	}
 
 	@Override
 	protected Iterable<IEObjectDescription> getAllLocalElements() {
 		List<IEObjectDescription> result = Lists.newArrayList();
-		Iterable<ITypeSystem> allTypeSystems = typeSystemAccess.getAllTypeSystems();
+		Iterable<ITypeSystem> allTypeSystems = typeSystemAccess.getTypeSystems(typesystemURI);
 		for (ITypeSystem iTypeSystem : allTypeSystems) {
 			Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor(
 					EcoreUtil2.<EObject> getObjectsByType(iTypeSystem.getTypes(), eClass), qualifiedNameProvider);
@@ -53,4 +58,4 @@ public class TypeSystemAwareScope extends AbstractScope {
 		}
 		return result;
 	}
-}
+} 

+ 2 - 0
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -131,6 +131,8 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 
 	@Check
 	public void checkExpression(VariableDefinition expression) {
+		if (expression.getType() == null || expression.getType().eIsProxy())
+			return;
 		typeInferrer.inferType(expression, this);
 	}
 

+ 0 - 7
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/util/STextRuntimeTestModule.java

@@ -12,8 +12,6 @@ package org.yakindu.sct.model.stext.test.util;
 
 import org.eclipse.xtext.scoping.IScopeProvider;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
-import org.yakindu.base.types.typesystem.DefaultTypeSystem;
-import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.stext.STextRuntimeModule;
 import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
 
@@ -29,11 +27,6 @@ public class STextRuntimeTestModule extends STextRuntimeModule {
 		return STextTestScopeProvider.class;
 	}
 	
-	@Override
-	public Class<? extends ITypeSystem> bindITypeSystem() {
-		return DefaultTypeSystem.class;
-	}
-	
 	@Override
 	public Class<? extends ITypeSystemInferrer> bindITypeSystemInferrer() {
 		return STextTypeInferrer.class;