Search in sources :

Example 6 with Feature

use of org.osate.aadl2.Feature in project AGREE by loonwerks.

the class AgreeValidator method checkLiftContract.

@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
    Classifier comp = lcst.getContainingClassifier();
    if (comp instanceof ComponentImplementation) {
        ComponentType ct = ((ComponentImplementation) comp).getType();
        List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (agreeAnnexes.size() > 0) {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
        }
        List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
        if (subcomps.size() == 1) {
            Subcomponent subcomp = subcomps.get(0);
            Classifier subCls = subcomp.getClassifier();
            ComponentType subCt = null;
            if (subCls instanceof ComponentImplementation) {
                subCt = ((ComponentImplementation) subCls).getType();
            } else if (subCls instanceof ComponentType) {
                subCt = (ComponentType) subCls;
            } else {
                throw new RuntimeException();
            }
            {
                Set<String> usedParentInPorts = new HashSet<>();
                Set<String> usedParentOutPorts = new HashSet<>();
                Set<String> usedChildInPorts = new HashSet<>();
                Set<String> usedChildOutPorts = new HashSet<>();
                EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
                EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
                for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
                    {
                        NamedElement sourceNe = conn.getSource().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedChildOutPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
                            }
                            usedChildOutPorts.add(sourceNe.getName());
                        }
                        if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedParentInPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
                            }
                            usedParentInPorts.add(sourceNe.getName());
                        }
                    }
                    {
                        NamedElement destNe = conn.getDestination().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedChildInPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
                            }
                            usedChildInPorts.add(destNe.getName());
                        }
                        if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedParentOutPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
                            }
                            usedParentOutPorts.add(destNe.getName());
                        }
                    }
                }
                for (Feature feat : comp.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedParentInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedParentOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
                        }
                    }
                }
                for (Feature feat : subCt.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedChildInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedChildOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
                        }
                    }
                }
            }
        } else {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
        }
    } else {
        error(lcst, "'lift contract;' statement is not allowed in component interface.");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Set(java.util.Set) HashSet(java.util.HashSet) Connection(org.osate.aadl2.Connection) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EList(org.eclipse.emf.common.util.EList) EventPort(org.osate.aadl2.EventPort) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause) Check(org.eclipse.xtext.validation.Check)

Example 7 with Feature

use of org.osate.aadl2.Feature in project AGREE by loonwerks.

the class AgreeValidator method getFieldTypes.

private Map<String, TypeDef> getFieldTypes(DoubleDotRef recType) {
    NamedElement rec = recType.getElm();
    Map<String, TypeDef> typeMap = new HashMap<>();
    if (rec instanceof RecordDef) {
        RecordDef recDef = (RecordDef) rec;
        for (Arg arg : recDef.getArgs()) {
            typeMap.put(arg.getName(), AgreeTypeSystem.typeDefFromType(arg.getType()));
        }
    } else if (rec instanceof DataImplementation) {
        DataImplementation dataImpl = (DataImplementation) rec;
        for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
            typeMap.put(sub.getName(), AgreeTypeSystem.typeDefFromClassifier((sub.getClassifier())));
        }
    } else {
        error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
    }
    return typeMap;
}
Also used : AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) HashMap(java.util.HashMap) Arg(com.rockwellcollins.atc.agree.agree.Arg) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DataImplementation(org.osate.aadl2.DataImplementation) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 8 with Feature

use of org.osate.aadl2.Feature in project AGREE by loonwerks.

the class AgreeValidator method checkRecordDefExpr.

// =======
// //    private List<AgreeType> getArgTypes(NestedDotID recId){
// //
// //    	NamedElement rec = getFinalNestId(recId);
// //    	List<AgreeType> types = new ArrayList<AgreeType>();
// //
// //    	if(rec instanceof RecordDefExpr){
// //    		RecordDefExpr recDef = (RecordDefExpr)rec;
// //    		for(Arg arg : recDef.getArgs()){
// //    			types.add(getAgreeType(arg.getType()));
// //    		}
// //    	}else if(rec instanceof FeatureGroupType){
// //    		FeatureGroupType featGroup = (FeatureGroupType)rec;
// //    		for(Feature feat : featGroup.getAllFeatures()){
// //    			types.add(getAgreeType(feat));
// //    		}
// //    	}
// //
// //    	return types;
// //    }
// 
// private void dataImplCycleCheck(NestedDotID dataID) {
// NamedElement finalId = dataID.getBase();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
// 
// private void dataImplCycleCheck(DoubleDotRef dataID) {
// NamedElement finalId = dataID.getElm();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
// 
// 
// private void dataImplCycleCheck(DataImplementation dataImpl, EObject errorSource) {
// Set<DataImplementation> dataClosure = new HashSet<>();
// Set<DataImplementation> prevClosure = null;
// 
// for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
// ComponentImplementation subImpl = sub.getComponentImplementation();
// if (subImpl != null) {
// dataClosure.add((DataImplementation) subImpl);
// }
// }
// 
// do {
// prevClosure = new HashSet<>(dataClosure);
// for (DataImplementation subImpl : prevClosure) {
// if (subImpl == dataImpl) {
// error(errorSource, "The component implementation '" + dataImpl.getName()
// + "' has a cyclic definition.  This cannot be reasoned about by AGREE.");
// break;
// }
// for (Subcomponent subSub : subImpl.getAllSubcomponents()) {
// ComponentImplementation subSubImpl = subSub.getComponentImplementation();
// if (subSubImpl != null) {
// dataClosure.add((DataImplementation) subSubImpl);
// }
// }
// 
// }
// 
// } while (!prevClosure.equals(dataClosure));
// 
// }
// >>>>>>> origin/develop
@Check(CheckType.FAST)
public void checkRecordDefExpr(RecordDef recordDef) {
    Set<RecordDef> recordClosure = new HashSet<>();
    Set<RecordDef> prevClosure = null;
    for (Arg arg : recordDef.getArgs()) {
        Type type = arg.getType();
        if (type instanceof DoubleDotRef) {
            NamedElement finalId = ((DoubleDotRef) type).getElm();
            if (finalId instanceof RecordDef) {
                recordClosure.add((RecordDef) finalId);
            }
        }
    }
    do {
        prevClosure = new HashSet<>(recordClosure);
        for (RecordDef subRecDef : prevClosure) {
            if (subRecDef == recordDef) {
                error(recordDef, "The definition of type '" + recordDef.getName() + "' is involved in a cyclic definition");
                break;
            }
            for (Arg arg : subRecDef.getArgs()) {
                Type type = arg.getType();
                if (type instanceof DoubleDotRef) {
                    NamedElement subFinalEl = ((DoubleDotRef) type).getElm();
                    if (subFinalEl instanceof RecordDef) {
                        recordClosure.add((RecordDef) subFinalEl);
                    // =======
                    // if (type instanceof RecordType) {
                    // DoubleDotRef subRecId = ((RecordType) type).getRecord();
                    // NamedElement subFinalEl = subRecId.getElm();
                    // if (subFinalEl instanceof RecordDefExpr) {
                    // recordClosure.add((RecordDefExpr) subFinalEl);
                    // >>>>>>> origin/develop
                    }
                }
            }
        }
    } while (!prevClosure.equals(recordClosure));
}
Also used : PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) CheckType(org.eclipse.xtext.validation.CheckType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentType(org.osate.aadl2.ComponentType) Type(com.rockwellcollins.atc.agree.agree.Type) DirectionType(org.osate.aadl2.DirectionType) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 9 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class Aadl2InstanceUtil method getIncomingConnection.

/**
 * find incoming connection that goes through the feature of the specified component instance
 * @param ci Component instance
 * @param fi Feature instance
 * @return list of connection instances going through the feature
 */
public static EList<ConnectionInstance> getIncomingConnection(ComponentInstance ci, FeatureInstance fi) {
    Feature f = fi.getFeature();
    EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
    // allEnclosingConnectionInstances();
    Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
    for (ConnectionInstance connectionInstance : it) {
        ConnectionInstanceEnd dest = connectionInstance.getDestination();
        ComponentInstance destci = dest.getContainingComponentInstance();
        if (containedIn(destci, ci)) {
            EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
            for (ConnectionReference connectionReference : connreflist) {
                ComponentInstance pci = connectionReference.getContext();
                Connection conn = connectionReference.getConnection();
                ConnectionEnd ce = conn.getAllSource();
                if (pci == ci.getContainingComponentInstance() && ce == f) {
                    result.add(connectionInstance);
                }
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BasicEList(org.eclipse.emf.common.util.BasicEList) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Connection(org.osate.aadl2.Connection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) Feature(org.osate.aadl2.Feature)

Example 10 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class Aadl2InstanceUtil method getOutgoingConnection.

/**
 * find outgoing connection that goes through the feature of the specified component instance
 * @param ci Component instance
 * @param fi Feature instance
 * @return list of connection instances going through the feature
 */
public static EList<ConnectionInstance> getOutgoingConnection(ComponentInstance ci, FeatureInstance fi) {
    Feature f = fi.getFeature();
    EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
    // allEnclosingConnectionInstances();
    Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
    for (ConnectionInstance connectionInstance : it) {
        ConnectionInstanceEnd src = connectionInstance.getSource();
        ComponentInstance srcci = src.getContainingComponentInstance();
        if (containedIn(srcci, ci)) {
            EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
            for (ConnectionReference connectionReference : connreflist) {
                ComponentInstance pci = connectionReference.getContext();
                Connection conn = connectionReference.getConnection();
                ConnectionEnd ce = conn.getAllSource();
                if (pci == ci.getContainingComponentInstance() && ce == f) {
                    // add connection if it goes through feature instance
                    result.add(connectionInstance);
                }
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BasicEList(org.eclipse.emf.common.util.BasicEList) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Connection(org.osate.aadl2.Connection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) Feature(org.osate.aadl2.Feature)

Aggregations

ArrayList (java.util.ArrayList)100 Feature (org.osate.aadl2.Feature)86 Feature (com.google.cloud.vision.v1.Feature)74 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)71 Image (com.google.cloud.vision.v1.Image)71 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)68 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)68 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)65 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)59 ByteString (com.google.protobuf.ByteString)48 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)47 Classifier (org.osate.aadl2.Classifier)45 NamedElement (org.osate.aadl2.NamedElement)42 ImageSource (com.google.cloud.vision.v1.ImageSource)39 Subcomponent (org.osate.aadl2.Subcomponent)39 FeatureGroup (org.osate.aadl2.FeatureGroup)33 FeatureGroupType (org.osate.aadl2.FeatureGroupType)33 FileInputStream (java.io.FileInputStream)30 ComponentClassifier (org.osate.aadl2.ComponentClassifier)30 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28