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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations