瀏覽代碼

#965 provide infrastructure for extension operations and properties

Andreas Muelder 9 年之前
父節點
當前提交
27b17fe567

+ 1 - 1
plugins/org.yakindu.base.types.test/src/org/yakindu/base/types/test/AbstractTypeSystemTest.java

@@ -41,7 +41,7 @@ public class AbstractTypeSystemTest extends AbstractTypeSystem {
 	private Type conversionSubType;
 
 	@Override
-	protected void initBuiltInTypes() {
+	protected void initRegistries() {
 		// SubType extends SuperType
 		superType = createPrimitive(SUPER_TYPE);
 		declareType(superType, SUPER_TYPE);

+ 34 - 7
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/AbstractTypeSystem.java

@@ -23,7 +23,9 @@ import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.yakindu.base.types.ComplexType;
+import org.yakindu.base.types.Operation;
 import org.yakindu.base.types.PrimitiveType;
+import org.yakindu.base.types.Property;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.TypesFactory;
 import org.yakindu.base.types.annotations.TypeAnnotations;
@@ -42,18 +44,21 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 
 	protected Map<String, Type> typeRegistry = new HashMap<String, Type>();
 	protected ListMultimap<Type, Type> extendsRegistry = ArrayListMultimap.create();
+	protected ListMultimap<Type, Operation> extensionOperationRegistry = ArrayListMultimap.create();
+	protected ListMultimap<Type, Property> extensionPropertyRegistry = ArrayListMultimap.create();
+
 	protected Map<Type, Type> conversionRegistry = new HashMap<Type, Type>();
 
-	protected abstract void initBuiltInTypes();
+	protected abstract void initRegistries();
 
 	protected Resource resource;
-	
+
 	protected TypeAnnotations typeAnnotations;
 
 	public AbstractTypeSystem() {
 		resource = new ResourceImpl(URI.createURI("types"));
 		typeAnnotations = new TypeAnnotations();
-		initBuiltInTypes();
+		initRegistries();
 	}
 
 	protected void reset() {
@@ -81,7 +86,7 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 			ComplexType complexType = (ComplexType) type;
 			superTypes.addAll(complexType.getSuperTypes());
 		}
-		
+
 		return superTypes;
 	}
 
@@ -99,7 +104,7 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 	private void collectSupertypes(Type subtypeClass, List<Type> typeHierachy) {
 		if (subtypeClass == null)
 			return;
-		
+
 		List<Type> superTypes = getSuperTypes(subtypeClass);
 		for (Type superType : superTypes) {
 			typeHierachy.add(superType);
@@ -217,13 +222,35 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 	protected Type getConversionType(Type sourceType) {
 		return conversionRegistry.get(sourceType);
 	}
-	
+
 	public Resource getResource() {
 		return resource;
 	}
-	
+
 	@Override
 	public boolean isBuiltInType(Type type) {
 		return typeAnnotations.hasBuiltInTypeAnnotation(type);
 	}
+
+	@Override
+	public List<Operation> getOperationExtensions(Type type) {
+		List<Operation> result = new ArrayList<>();
+		result.addAll(extensionOperationRegistry.get(type));
+		List<Type> superTypes = getSuperTypes(type);
+		for (Type superType : superTypes) {
+			result.addAll(extensionOperationRegistry.get(superType));
+		}
+		return result;
+	}
+
+	@Override
+	public List<Property> getPropertyExtensions(Type type) {
+		List<Property> result = new ArrayList<>();
+		result.addAll(extensionPropertyRegistry.get(type));
+		List<Type> superTypes = getSuperTypes(type);
+		for (Type superType : superTypes) {
+			result.addAll(extensionPropertyRegistry.get(superType));
+		}
+		return result;
+	}
 }

+ 1 - 1
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/GenericTypeSystem.java

@@ -30,7 +30,7 @@ public class GenericTypeSystem extends AbstractTypeSystem {
 	}
 
 	@Override
-	protected void initBuiltInTypes() {
+	protected void initRegistries() {
 		declarePrimitive(STRING);
 		declarePrimitive(REAL);
 		declarePrimitive(INTEGER);

+ 11 - 5
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/ITypeSystem.java

@@ -13,6 +13,8 @@ package org.yakindu.base.types.typesystem;
 import java.util.Collection;
 import java.util.List;
 
+import org.yakindu.base.types.Operation;
+import org.yakindu.base.types.Property;
 import org.yakindu.base.types.Type;
 
 /**
@@ -23,7 +25,7 @@ import org.yakindu.base.types.Type;
  * 
  */
 public interface ITypeSystem {
-	
+
 	public static final String STRING = "string";
 	public static final String REAL = "real";
 	public static final String INTEGER = "integer";
@@ -32,11 +34,11 @@ public interface ITypeSystem {
 	public static final String NULL = "null";
 
 	public Collection<Type> getTypes();
-	
+
 	public Collection<Type> getConcreteTypes();
 
 	public Type getType(String name);
-	
+
 	public boolean isSame(Type type1, Type type2);
 
 	public boolean haveCommonType(Type type1, Type type2);
@@ -46,11 +48,15 @@ public interface ITypeSystem {
 	public boolean haveCommonTypeWithConversion(Type type1, Type type2);
 
 	public Type getCommonTypeWithConversion(Type type1, Type type2);
-	
+
 	public List<Type> getSuperTypes(Type type);
 
 	public boolean isSuperType(Type subtype, Type supertype);
-	
+
 	public boolean isBuiltInType(Type type);
 
+	public List<Operation> getOperationExtensions(Type type);
+
+	public List<Property> getPropertyExtensions(Type type);
+
 }

+ 1 - 2
plugins/org.yakindu.sct.domain.generic/META-INF/MANIFEST.MF

@@ -12,5 +12,4 @@ Require-Bundle: org.eclipse.core.runtime,
  org.yakindu.sct.model.stext
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
-Export-Package: org.yakindu.sct.domain.generic,
- org.yakindu.sct.domain.generic.modules
+Export-Package: org.yakindu.sct.domain.generic

+ 0 - 8
plugins/org.yakindu.sct.domain.generic/plugin.xml

@@ -10,12 +10,4 @@
             name="Default">
       </Domain>
    </extension>
-<extension
-      point="org.yakindu.sct.domain.modules">
-   <Module
-         domainID="org.yakindu.domain.default"
-         feature="org.yakindu.sct.resource"
-         moduleProvider="org.yakindu.sct.domain.generic.modules.ResourceModuleProvider">
-   </Module>
-</extension>
 </plugin>

+ 0 - 43
plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/modules/ResourceModuleProvider.java

@@ -1,43 +0,0 @@
-/** 
- * Copyright (c) 2016 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
- *
-*/
-package org.yakindu.sct.domain.generic.modules;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.yakindu.sct.domain.extension.IModuleProvider;
-import org.yakindu.sct.model.stext.STextRuntimeModule;
-import org.yakindu.sct.model.stext.resource.StextResource;
-
-import com.google.inject.Binder;
-import com.google.inject.Module;
-import com.google.inject.util.Modules;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class ResourceModuleProvider implements IModuleProvider {
-
-	@Override
-	public Module getModule(String... options) {
-		return Modules.combine(getLanguageRuntimeModule(), new Module() {
-			@Override
-			public void configure(Binder binder) {
-				binder.bind(Resource.class).to(StextResource.class);
-			}
-		});
-	}
-
-	protected Module getLanguageRuntimeModule() {
-		return new STextRuntimeModule();
-	}
-
-}

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

@@ -34,6 +34,7 @@ import org.yakindu.base.types.ComplexType;
 import org.yakindu.base.types.EnumerationType;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
+import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.Scope;
 import org.yakindu.sct.model.sgraph.Statechart;
@@ -58,6 +59,8 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
 
 	@Inject
 	private ITypeSystemInferrer typeInferrer;
+	@Inject 
+	private ITypeSystem typeSystem;
 	
 	private static class ErrorHandlerDelegate<T> implements ErrorHandler<T> {
 
@@ -130,13 +133,16 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
 		}
 
 		IScope scope = IScope.NULLSCOPE;
+		Type ownerType = typeInferrer.inferType(owner, null);
 
 		if (element instanceof Scope) {
 			scope = Scopes.scopeFor(((Scope) element).getDeclarations());
 			return new FilteringScope(scope, predicate);
+		}else{
+			scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
+			scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType),scope);
 		}
-
-		Type ownerType = typeInferrer.inferType(owner, null);
+		
 		if (ownerType instanceof ComplexType) {
 			return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
 		}

+ 1 - 0
releng/org.yakindu.sct.releng/pom.xml

@@ -394,6 +394,7 @@
 		<module>../../plugins/org.yakindu.sct.domain.generic.editor</module>
 		<module>../../plugins/org.yakindu.sct.domain.generic.generator</module>
 		<module>../../plugins/org.yakindu.sct.domain.generic.simulation</module>
+		<module>../../plugins/org.yakindu.sct.domain.generic.resource</module>
 		<module>../../plugins/org.yakindu.sct.doc.user</module>
 		<module>../../plugins/org.yakindu.sct.generator.core</module>
 		<module>../../plugins/org.yakindu.sct.generator.builder</module>