Search in sources :

Example 26 with Element

use of org.osate.aadl2.Element in project sonar-cxx by SonarOpenCommunity.

the class CxxSquidConfiguration method getValues.

/**
 * Used to read multi-valued properties.
 *
 * Collects all found values over all levels. It starts with the given level and further found values in parent levels
 * are added to the end of the list. The method can return an empty list if the property is not set.
 *
 * @param level level at which the search is started
 * @param property key that is searched for
 * @return the values with the specified key value
 */
public List<String> getValues(String level, String key) {
    List<String> result = new ArrayList<>();
    Element eLevel = findLevel(level, parentList.getFirst());
    do {
        if (eLevel != null) {
            Element eKey = eLevel.getChild(key);
            if (eKey != null) {
                for (var value : eKey.getChildren("Value")) {
                    result.add(value.getText());
                }
            }
        }
        eLevel = getParentElement(eLevel);
    } while (eLevel != null);
    return result;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 27 with Element

use of org.osate.aadl2.Element in project VERDICT by ge-high-assurance.

the class Aadl2CsvTranslator method buildScnBusBindingsTable.

/**
 * Build the scenario bus bindings table
 */
Table buildScnBusBindingsTable() {
    Table scnBusBindingsTable = new Table("Scenario", "Comp", "Impl", "ActualConnectionBindingSrcComp", "ActualConnectionBindingSrcImpl", "ActualConnectionBindingSrcCompInst", "ActualConnectionBindingSrcBusInst", "ActualConnectionBindingDestConnComp", "ActualConnectionBindingDestConnImpl", "ActualConnectionBindingDestConnCompInst", "ActualConnectionBindingDestConn");
    for (ComponentImplementation sysImpl : compImpls) {
        for (PropertyAssociation propAssoc : sysImpl.getOwnedPropertyAssociations()) {
            if (propAssoc.getOwnedValues().size() != 1) {
                throw new RuntimeException("Unexpected number of property owned values: " + propAssoc.getOwnedValues().size());
            }
            PropertyExpression expr = propAssoc.getOwnedValues().get(0).getOwnedValue();
            // Obtain the bus reference values
            String[] compImplInstBusNames = getStrRepofExpr(expr);
            // We only consider the case where the length of compImplInstBusNames is 4
            if (compImplInstBusNames.length != 4) {
                throw new RuntimeException("Unexpected number of values in property expression: " + compImplInstBusNames.length);
            }
            // property: bus connection binding applies to connections
            for (ContainedNamedElement appliesToImpl : propAssoc.getAppliesTos()) {
                PortConnection appliesToConn = null;
                SystemSubcomponent appliesToSubcomp = null;
                scnBusBindingsTable.addValue(scenario);
                scnBusBindingsTable.addValue(sysImpl.getTypeName());
                scnBusBindingsTable.addValue(sysImpl.getName());
                scnBusBindingsTable.addValue(compImplInstBusNames[0]);
                scnBusBindingsTable.addValue(compImplInstBusNames[1]);
                scnBusBindingsTable.addValue(compImplInstBusNames[2]);
                scnBusBindingsTable.addValue(compImplInstBusNames[3]);
                if (appliesToImpl.getContainmentPathElements().size() > 2) {
                    throw new RuntimeException("Unexpected number of values in ContainedNamedElement: " + appliesToImpl.getContainmentPathElements().size());
                }
                for (ContainmentPathElement element : appliesToImpl.getContainmentPathElements()) {
                    NamedElement namedElement = element.getNamedElement();
                    if (namedElement instanceof SystemSubcomponent) {
                        appliesToSubcomp = (SystemSubcomponent) namedElement;
                    } else if (namedElement instanceof PortConnection) {
                        appliesToConn = (PortConnection) namedElement;
                    } else {
                        throw new RuntimeException("Unexpected value: " + namedElement);
                    }
                }
                if (appliesToSubcomp != null) {
                    ComponentImplementation compImpl = appliesToSubcomp.getComponentImplementation();
                    scnBusBindingsTable.addValue(compImpl.getTypeName());
                    scnBusBindingsTable.addValue(compImpl.getName());
                    scnBusBindingsTable.addValue(appliesToSubcomp.getName());
                } else {
                    scnBusBindingsTable.addValue(sysImpl.getTypeName());
                    scnBusBindingsTable.addValue(sysImpl.getName());
                    scnBusBindingsTable.addValue("");
                }
                scnBusBindingsTable.addValue(appliesToConn.getName());
                scnBusBindingsTable.capRow();
            }
        }
    }
    return scnBusBindingsTable;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) PortConnection(org.osate.aadl2.PortConnection)

Example 28 with Element

use of org.osate.aadl2.Element in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method createVdmPort.

/**
 * @author Vidhya Tekken Valapil
 * Creates a new Vdm Port object and returns
 * Populates "name", "mode" and "type"
 * @param eventdataport
 * @return vdm port
 */
private Port createVdmPort(EventDataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
    String modeString = "in";
    if (dataPort.isIn()) {
        modeString = "in";
    } else if (dataPort.isOut()) {
        modeString = "out";
    }
    // fetching data type information
    DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
    verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
    if (dSubCompType != null) {
        verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
        if (dSubCompType instanceof DataTypeImpl) {
            org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
            dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
        } else if (dSubCompType instanceof DataImplementationImpl) {
            org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
            dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
        } else {
            System.out.println("Unresolved/unexpected Named Element.");
        }
        newPort.setType(dtype);
    }
    newPort.setProbe(false);
    newPort.setId(dataPort.getQualifiedName());
    newPort.setName(dataPort.getName());
    newPort.setMode(convertToVdmPortMode(modeString));
    newPort.setEvent(true);
    return newPort;
}
Also used : DataImplementationImpl(org.osate.aadl2.impl.DataImplementationImpl) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) DataImplementation(org.osate.aadl2.DataImplementation) Port(verdict.vdm.vdm_model.Port) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataType(org.osate.aadl2.DataType) DataType(org.osate.aadl2.DataType)

Example 29 with Element

use of org.osate.aadl2.Element in project VERDICT by ge-high-assurance.

the class ThreatModelUtil method getTypes.

/**
 * Build a map from type names to types. Traverses all files
 * in the current project looking for property declarations, which
 * are used to populate fields for the built-in types.
 *
 * Built-in types are system, connection, and port (also portDirection).
 *
 * This method is not very efficient, and it gets called several times
 * on every keystroke. Fortunately there still seems to be reasonably fast.
 * A crucial optimization will be caching the results because the set of
 * properties does not change that frequently.
 *
 * @param obj an AST node context, used to get access to project files
 * @param indexProvider an index provider, may be obtained through Guice
 * @return the constructed type map
 */
public static LinkedHashMap<String, VerdictType> getTypes(EObject obj, ResourceDescriptionsProvider indexProvider) {
    LinkedHashMap<String, VerdictType> types = new LinkedHashMap<>();
    // Three main built-in types
    BuiltInType connection = new BuiltInType("connection");
    BuiltInType port = new BuiltInType("port");
    BuiltInType system = new BuiltInType("system");
    addBuiltin(types, connection);
    addBuiltin(types, port);
    addBuiltin(types, system);
    // Connection fields
    connection.addField("inPort", port);
    connection.addField("outPort", port);
    connection.addField("source", system);
    connection.addField("dest", system);
    // Port direction
    BuiltInType portDir = new BuiltInType("portDirection");
    portDir.addValue("in");
    portDir.addValue("out");
    // Port fields
    port.addField("direction", portDir);
    port.addField("connections", connection.getListType());
    // System fields
    system.addField("subcomponents", system.getListType());
    system.addField("connections", connection.getListType());
    system.addField("ports", port.getListType());
    // Get the path to the current resource, used to get the project path
    String[] resSegments = obj.eResource().getURI().segments();
    // Iterate through all resources
    IResourceDescriptions index = indexProvider.getResourceDescriptions(obj.eResource());
    descLoop: for (IEObjectDescription desc : index.getExportedObjectsByType(Aadl2Package.eINSTANCE.getPropertySet())) {
        // Get the path to the resource we are examining
        String[] propsResSegments = desc.getEObjectURI().segments();
        // The project is determined by the first two URI segments
        for (int i = 0; i < Math.min(2, Math.min(resSegments.length, propsResSegments.length)); i++) {
            if (!resSegments[i].equals(propsResSegments[i])) {
                continue descLoop;
            }
        }
        // Load the resource into EMF-land; dynamically loads if necessary
        Resource res = obj.eResource().getResourceSet().getResource(desc.getEObjectURI(), true);
        if (res != null) {
            // Search the AST
            TreeIterator<EObject> it = res.getAllContents();
            while (it.hasNext()) {
                EObject next = it.next();
                if (next instanceof PropertySet) {
                    PropertySet props = (PropertySet) next;
                    // Iterate the declared properties
                    for (Element elem : props.getOwnedElements()) {
                        if (elem instanceof Property) {
                            Property prop = (Property) elem;
                            // Make sure type information is present
                            if (prop.getPropertyType() != null) {
                                // the types for which the property is a field
                                for (MetaclassReference meta : prop.getAppliesToMetaclasses()) {
                                    // Get type name, lowercase it because it is a class name
                                    String appliesToMetaclass = meta.getMetaclass().getName().toLowerCase();
                                    // Hopefully this is a type that we have accounted for
                                    if (types.containsKey(appliesToMetaclass)) {
                                        ((BuiltInType) types.get(appliesToMetaclass)).addField(prop.getName(), new AadlTypeWrapper(prop.getName(), prop.getPropertyType()));
                                    } else {
                                        // If we get this error message, then perhaps need to add
                                        // some built-in types
                                        System.err.println("could not find built in type: " + appliesToMetaclass);
                                    }
                                }
                            }
                        }
                    }
                    // Discard all children of the property set
                    it.prune();
                }
            }
        }
    }
    // Prevent synchronization issues
    portDir.lock();
    connection.lock();
    port.lock();
    system.lock();
    return types;
}
Also used : Element(org.osate.aadl2.Element) Resource(org.eclipse.emf.ecore.resource.Resource) AadlTypeWrapper(com.ge.research.osate.verdict.dsl.type.AadlTypeWrapper) BuiltInType(com.ge.research.osate.verdict.dsl.type.BuiltInType) LinkedHashMap(java.util.LinkedHashMap) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) VerdictType(com.ge.research.osate.verdict.dsl.type.VerdictType) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) EObject(org.eclipse.emf.ecore.EObject) PropertySet(org.osate.aadl2.PropertySet) MetaclassReference(org.osate.aadl2.MetaclassReference) TreeIterator(org.eclipse.emf.common.util.TreeIterator) Property(org.osate.aadl2.Property)

Example 30 with Element

use of org.osate.aadl2.Element in project VERDICT by ge-high-assurance.

the class VerdictUtil method getHostingSystemType.

public static ComponentType getHostingSystemType(EObject element) {
    ComponentType hostingSysType = null;
    EObject container = element;
    while (!(container instanceof ComponentType)) {
        if (container == null) {
            break;
        }
        container = container.eContainer();
    }
    if (container instanceof ComponentType) {
        hostingSysType = (ComponentType) container;
    }
    return hostingSysType;
}
Also used : ComponentType(org.osate.aadl2.ComponentType) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Element (org.jdom2.Element)3601 Document (org.jdom2.Document)589 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)393 IOException (java.io.IOException)320 JDOMException (org.jdom2.JDOMException)230 Attribute (org.jdom2.Attribute)217 SAXBuilder (org.jdom2.input.SAXBuilder)169 Namespace (org.jdom2.Namespace)157 List (java.util.List)156 File (java.io.File)143 Element (org.osate.aadl2.Element)143 NamedElement (org.osate.aadl2.NamedElement)138 XMLOutputter (org.jdom2.output.XMLOutputter)136 HashMap (java.util.HashMap)134 Test (org.junit.jupiter.api.Test)134 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 StringReader (java.io.StringReader)85 Iterator (java.util.Iterator)73