Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions kerml/src/examples/Simple Tests/MetadataTest.kerml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ package MetadataTest {
}
}

class CC;
struct SS {
feature cc : CC;
}

metaclass M :> Metaobjects::SemanticMetadata {
:>> annotatedElement : KerML::Class;
:>> baseType = if annotatedElement istype KerML::Structure ?
SS meta KerML::Type else CC meta KerML::Class;
}

#M struct T {
feature :>> cc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
File {from ="/library/Performances.kerml"}
File {from ="/library/Metaobjects.kerml"}
File {from ="/library/KerML.kerml"}
File {from ="/library/BaseFunctions.kerml"}
File {from ="/library/ControlFunctions.kerml"}
}
Workspace {
JavaProject {
Expand All @@ -20,6 +22,8 @@
File {from ="/library/Performances.kerml"}
File {from ="/library/Metaobjects.kerml"}
File {from ="/library/KerML.kerml"}
File {from ="/library/BaseFunctions.kerml"}
File {from ="/library/ControlFunctions.kerml"}
}
}
}
Expand Down Expand Up @@ -54,4 +58,19 @@ package Metadata {
#A #B metadata C;
#A #B @C;
}

class CC;
struct SS {
feature cc : CC;
}

metaclass M :> Metaobjects::SemanticMetadata {
:>> annotatedElement : KerML::Class;
:>> baseType = if annotatedElement istype KerML::Structure ?
SS meta KerML::Type else CC meta KerML::Class;
}

#M struct T {
feature :>> cc;
}
}
50 changes: 41 additions & 9 deletions org.omg.sysml/src/org/omg/sysml/adapter/FeatureAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.omg.sysml.lang.sysml.Association;
import org.omg.sysml.lang.sysml.BindingConnector;
import org.omg.sysml.lang.sysml.Connector;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.omg.sysml.util.ElementUtil;
import org.omg.sysml.util.ExpressionUtil;
import org.omg.sysml.util.FeatureUtil;
import org.omg.sysml.util.NonNotifyingEObjectEList;
import org.omg.sysml.util.TypeUtil;

public class FeatureAdapter extends TypeAdapter {
Expand Down Expand Up @@ -112,15 +114,6 @@ public String getEffectiveShortName() {
return storedEffectiveShortName;
}

public EList<Type> getTypes() {
return types;
}

public EList<Type> setTypes(EList<Type> types) {
this.types = types;
return types;
}

Set<Feature> allRedefinedFeatures = null;

@Override
Expand Down Expand Up @@ -549,6 +542,45 @@ public boolean isComputeRedefinitions() {
target.getOwnedRedefinition().isEmpty());
}

public EList<Type> getAllTypes() {
if (types == null) {
types = new NonNotifyingEObjectEList<Type>(Type.class, (InternalEObject)getTarget(), SysMLPackage.FEATURE__TYPE);
getTypes(types, new HashSet<Feature>());
removeRedundantTypes(types);
}
return types;
}

public void getTypes(List<Type> types, Set<Feature> visitedFeatures) {
Feature feature = getTarget();
visitedFeatures.add(feature);
computeImplicitGeneralTypes();
getFeatureTypes(types, visitedFeatures);
for (Feature typingFeature : feature.typingFeatures()) {
if (!visitedFeatures.contains(typingFeature)) {
FeatureUtil.getTypesOf(typingFeature, types, visitedFeatures);
}
}
}

public void getFeatureTypes(List<Type> types, Set<Feature> visitedFeatures) {
Feature feature = getTarget();
feature.getOwnedTyping().stream().
map(typing->typing.getType()).
filter(type->type != null).
forEachOrdered(types::add);
types.addAll(getImplicitGeneralTypes(SysMLPackage.eINSTANCE.getFeatureTyping()));
}

protected static void removeRedundantTypes(List<Type> types) {
for (int i = types.size() - 1; i >= 0 ; i--) {
Type type = types.get(i);
if (types.stream().anyMatch(otherType->otherType != type && TypeUtil.specializes(otherType, type))) {
types.remove(i);
}
}
}

/**
* Compute relevant implicit Redefinitions, as appropriate.
*/
Expand Down
5 changes: 3 additions & 2 deletions org.omg.sysml/src/org/omg/sysml/adapter/TypeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ protected List<Type> getBaseTypes() {
filter(f->TypeUtil.specializes(f, getBaseTypeFeature(metadataFeature))).
map(FeatureUtil::getValueExpressionFor).
filter(expr->expr != null).
map(expr->expr.evaluate(target)).
map(expr->
expr.evaluate(metadataFeature)).
filter(results->results != null && !results.isEmpty()).
map(results->results.get(0)).
map(EvaluationUtil::getMetaclassReferenceOf).
Expand All @@ -456,7 +457,7 @@ protected List<Type> getBaseTypes() {
return baseTypes;
}

protected Feature getBaseTypeFeature(Element element) {
protected static Feature getBaseTypeFeature(Element element) {
return (Feature)SysMLLibraryUtil.getLibraryType(element,
ImplicitGeneralizationMap.getDefaultSupertypeFor(element.getClass(), "baseType"));
}
Expand Down
42 changes: 3 additions & 39 deletions org.omg.sysml/src/org/omg/sysml/util/FeatureUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -58,7 +57,6 @@
import org.omg.sysml.lang.sysml.Step;
import org.omg.sysml.lang.sysml.Subsetting;
import org.omg.sysml.lang.sysml.SysMLFactory;
import org.omg.sysml.lang.sysml.SysMLPackage;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.lang.sysml.TypeFeaturing;

Expand Down Expand Up @@ -120,12 +118,6 @@ public static boolean checkIsOrdered(Feature feature, Set<Feature> visited) {

// Typing

public static EList<Type> cacheTypesOf(Feature feature, Supplier<EList<Type>> supplier) {
FeatureAdapter adapter = getFeatureAdapter(feature);
EList<Type> types = adapter.getTypes();
return types == null? adapter.setTypes(supplier.get()): types;
}

public static <T> T getFirstTypeOf(Feature feature, Class<T> kind) {
return FeatureUtil.getAllTypesOf(feature).stream().
filter(kind::isInstance).
Expand All @@ -144,39 +136,11 @@ public static <T> EList<T> getAllTypesOf(Feature feature, Class<T> kind, int fea
}

public static EList<Type> getAllTypesOf(Feature feature) {
return FeatureUtil.cacheTypesOf(feature, ()->{
EList<Type> types = new NonNotifyingEObjectEList<Type>(Type.class, (InternalEObject)feature, SysMLPackage.FEATURE__TYPE);
getTypesOf(feature, types, new HashSet<Feature>());
removeRedundantTypes(types);
return types;
});
return getFeatureAdapter(feature).getAllTypes();
}

private static void getTypesOf(Feature feature, List<Type> types, Set<Feature> visitedFeatures) {
visitedFeatures.add(feature);
getFeatureTypesOf(feature, types, visitedFeatures);
for (Feature typingFeature : feature.typingFeatures()) {
if (!visitedFeatures.contains(typingFeature)) {
getTypesOf(typingFeature, types, visitedFeatures);
}
}
}

private static void getFeatureTypesOf(Feature feature, List<Type> types, Set<Feature> visitedFeatures) {
feature.getOwnedTyping().stream().
map(typing->typing.getType()).
filter(type->type != null).
forEachOrdered(types::add);
types.addAll(TypeUtil.getImplicitGeneralTypesFor(feature, SysMLPackage.eINSTANCE.getFeatureTyping()));
}

protected static void removeRedundantTypes(List<Type> types) {
for (int i = types.size() - 1; i >= 0 ; i--) {
Type type = types.get(i);
if (types.stream().anyMatch(otherType->otherType != type && TypeUtil.specializes(otherType, type))) {
types.remove(i);
}
}
public static void getTypesOf(Feature feature, List<Type> types, Set<Feature> visitedFeatures) {
getFeatureAdapter(feature).getTypes(types, visitedFeatures);
}

public static FeatureTyping addFeatureTypingTo(Feature feature) {
Expand Down