Search in sources :

Example 1 with AccessImpl

use of org.osate.aadl2.impl.AccessImpl in project osate-plugin by sireum.

the class Visitor method buildFeature.

private org.sireum.hamr.ir.Feature buildFeature(FeatureInstance featureInst, List<String> path) {
    final Feature f = featureInst.getFeature();
    final List<String> currentPath = VisitorUtil.add(path, featureInst.getName());
    org.sireum.hamr.ir.Classifier classifier = null;
    if (f.getFeatureClassifier() != null) {
        if (f.getFeatureClassifier() instanceof NamedElement) {
            if (((NamedElement) f.getFeatureClassifier()).getQualifiedName() != null) {
                classifier = factory.classifier(((NamedElement) f.getFeatureClassifier()).getQualifiedName().toString());
            } else {
                System.out.println("failing here");
            }
        } else {
            throw new RuntimeException("Unexepcted classifier " + f.getFeatureClassifier() + " for feature " + featureInst.getQualifiedName());
        }
    }
    final List<org.sireum.hamr.ir.Property> properties = featureInst.getOwnedPropertyAssociations().stream().map(pa -> buildProperty(pa, currentPath)).collect(Collectors.toList());
    AadlASTJavaFactory.FeatureCategory category = null;
    switch(featureInst.getCategory()) {
        case ABSTRACT_FEATURE:
            category = AadlASTJavaFactory.FeatureCategory.AbstractFeature;
            break;
        case BUS_ACCESS:
            category = AadlASTJavaFactory.FeatureCategory.BusAccess;
            break;
        case DATA_ACCESS:
            category = AadlASTJavaFactory.FeatureCategory.DataAccess;
            break;
        case DATA_PORT:
            category = AadlASTJavaFactory.FeatureCategory.DataPort;
            break;
        case EVENT_PORT:
            category = AadlASTJavaFactory.FeatureCategory.EventPort;
            break;
        case EVENT_DATA_PORT:
            category = AadlASTJavaFactory.FeatureCategory.EventDataPort;
            break;
        case FEATURE_GROUP:
            category = AadlASTJavaFactory.FeatureCategory.FeatureGroup;
            break;
        case PARAMETER:
            category = AadlASTJavaFactory.FeatureCategory.Parameter;
            break;
        case SUBPROGRAM_ACCESS:
            category = AadlASTJavaFactory.FeatureCategory.SubprogramAccess;
            break;
        case SUBPROGRAM_GROUP_ACCESS:
            category = AadlASTJavaFactory.FeatureCategory.SubprogramAccessGroup;
            break;
        default:
            throw new RuntimeException("Unexpected category: " + featureInst.getCategory());
    }
    switch(featureInst.getCategory()) {
        case DATA_ACCESS:
        case DATA_PORT:
        case EVENT_DATA_PORT:
        case PARAMETER:
            if (f.getClassifier() instanceof DataClassifier) {
                processDataType((DataClassifier) f.getClassifier());
            }
        // do nothing
        default:
    }
    org.sireum.hamr.ir.Name identifier = factory.name(currentPath, VisitorUtil.buildPosInfo(featureInst.getInstantiatedObjects().get(0)));
    final List<FeatureInstance> featureInstances = featureInst.getFeatureInstances();
    if (featureInstances.isEmpty()) {
        if (f instanceof AccessImpl) {
            final AccessImpl accessImpl = (AccessImpl) f;
            final AadlASTJavaFactory.AccessType accessType = accessImpl.getKind() == AccessType.PROVIDES ? AadlASTJavaFactory.AccessType.Provides : AadlASTJavaFactory.AccessType.Requires;
            AadlASTJavaFactory.AccessCategory accessCategory = null;
            switch(accessImpl.getCategory()) {
                case BUS:
                    accessCategory = AadlASTJavaFactory.AccessCategory.Bus;
                    break;
                case DATA:
                    accessCategory = AadlASTJavaFactory.AccessCategory.Data;
                    break;
                case SUBPROGRAM:
                    accessCategory = AadlASTJavaFactory.AccessCategory.Subprogram;
                    break;
                case SUBPROGRAM_GROUP:
                    accessCategory = AadlASTJavaFactory.AccessCategory.SubprogramGroup;
                    break;
                case VIRTUAL_BUS:
                    accessCategory = AadlASTJavaFactory.AccessCategory.VirtualBus;
                    break;
            }
            return factory.featureAccess(identifier, category, classifier, accessType, accessCategory, properties, VisitorUtil.getUriFragment(featureInst));
        } else if (f instanceof DirectedFeatureImpl) {
            final AadlASTJavaFactory.Direction direction = handleDirection(featureInst.getDirection());
            return factory.featureEnd(identifier, direction, category, classifier, properties, VisitorUtil.getUriFragment(featureInst));
        } else {
            throw new RuntimeException("Not expecting feature: " + featureInst);
        }
    } else {
        final boolean isInverse = ((FeatureGroupImpl) f).isInverse();
        final List<org.sireum.hamr.ir.Feature> features = featureInstances.stream().map(fi -> buildFeature(fi, currentPath)).collect(Collectors.toList());
        return factory.featureGroup(identifier, features, isInverse, category, properties, VisitorUtil.getUriFragment(featureInst));
    }
}
Also used : Arrays(java.util.Arrays) DataImplementation(org.osate.aadl2.DataImplementation) ListValue(org.osate.aadl2.ListValue) Element(org.osate.aadl2.Element) NamedValue(org.osate.aadl2.NamedValue) RangeValue(org.osate.aadl2.RangeValue) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) PropertyExpression(org.osate.aadl2.PropertyExpression) AnnexLib(org.sireum.hamr.ir.AnnexLib) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) FeatureConnection(org.osate.aadl2.FeatureConnection) AccessImpl(org.osate.aadl2.impl.AccessImpl) Map(java.util.Map) ParameterConnection(org.osate.aadl2.ParameterConnection) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Bundle(org.osgi.framework.Bundle) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) Annex(org.sireum.hamr.ir.Annex) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) InstancePackage(org.osate.aadl2.instance.InstancePackage) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) Collectors(java.util.stream.Collectors) UnitLiteral(org.osate.aadl2.UnitLiteral) List(java.util.List) Property(org.osate.aadl2.Property) AccessType(org.osate.aadl2.AccessType) ReferenceValue(org.osate.aadl2.ReferenceValue) BusSubcomponentImpl(org.osate.aadl2.impl.BusSubcomponentImpl) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) StringLiteral(org.osate.aadl2.StringLiteral) Option(org.sireum.Option) Feature(org.osate.aadl2.Feature) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PreferenceValues(org.sireum.aadl.osate.PreferenceValues) DirectionType(org.osate.aadl2.DirectionType) Subcomponent(org.osate.aadl2.Subcomponent) Position(org.sireum.message.Position) FeatureGroup(org.osate.aadl2.FeatureGroup) NumberValue(org.osate.aadl2.NumberValue) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) ClassifierValue(org.osate.aadl2.ClassifierValue) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Some(org.sireum.Some) PropertyConstant(org.osate.aadl2.PropertyConstant) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataClassifier(org.osate.aadl2.DataClassifier) BooleanLiteral(org.osate.aadl2.BooleanLiteral) Platform(org.eclipse.core.runtime.Platform) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ConnectedElement(org.osate.aadl2.ConnectedElement) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) DataClassifier(org.osate.aadl2.DataClassifier) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) Feature(org.osate.aadl2.Feature) Property(org.osate.aadl2.Property) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) NamedElement(org.osate.aadl2.NamedElement) AccessImpl(org.osate.aadl2.impl.AccessImpl) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl)

Aggregations

Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Platform (org.eclipse.core.runtime.Platform)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 AccessConnection (org.osate.aadl2.AccessConnection)1 AccessType (org.osate.aadl2.AccessType)1 BooleanLiteral (org.osate.aadl2.BooleanLiteral)1 Classifier (org.osate.aadl2.Classifier)1 ClassifierValue (org.osate.aadl2.ClassifierValue)1 ConnectedElement (org.osate.aadl2.ConnectedElement)1 Connection (org.osate.aadl2.Connection)1 ConnectionEnd (org.osate.aadl2.ConnectionEnd)1