Unable to fetch data type information if defined in an imported AADL file: [message #1831784] |
Fri, 28 August 2020 22:34 |
vrg 123 Messages: 2 Registered: August 2020 |
Junior Member |
|
|
I am trying to parse a specific annex defined in different model within a model. The main model is an AADL model. The xtext corresponding to the annex is here https://github.com/loonwerks/AGREE/blob/5eadb4956c52d69cb395473ed4b3fb7925a96785/com.rockwellcollins.atc.agree/src/com/rockwellcollins/atc/agree/Agree.xtext
A smaller version of the aadl file with the annex in it is below,
package DeliveryDrone
public
with Base_Types;
system DeliveryPlanner
features
-- inputs
bus_in: in data port Data_Types::InputBus.impl;
annex agree {**
-- variables
eq recent_order: Data_Types::DeliveryOrder.impl = if init_mode then bus_in.order else bus_in.order -> pre(recent_order);
**};
end DeliveryPlanner;
end DeliveryDrone;
The definition of DeliveryOrder.impl is in the .aadl file below,
package Data_Types
public
with Data_Model, Base_Types;
data DeliveryOrder
end DeliveryOrder;
data implementation DeliveryOrder.impl
subcomponents
target_position: data Position.impl;
target_picture: data Base_Types::Integer;
item_value: data Base_Types::Float;
end DeliveryOrder.impl;
data Position
end Position;
data implementation Position.impl
subcomponents
x: data Base_Types::Float;
y: data Base_Types::Float;
end Position.impl;
end Data_Types;
I am parsing the aadl model using the java code below. My goal is to parse the contents of the annex.
The type of the second component i.e."target_picture" is fetched as AbstractTypeImplementation that has only null fields associated with it.
Ultimately, I would like to get the information that it is an integer.
I tried to add the definition corresponding to "Base_Types::Integer" in the same file as "DeliveryOrder.impl", then the type of "target_picture" is fetched as DataTypeImpl with non-null values for associated fields, i.e. I am able to get its name as "integer".
How can I get definitions from imported files correctly when loading the resources?
final Injector injector = new Aadl2StandaloneSetup().createInjectorAndDoEMFRegistration();
final XtextResourceSet rs = injector.getInstance(XtextResourceSet.class);
rs.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
List<String> aadlFileNames = new ArrayList<>();
List<EObject> objects = new ArrayList<>();
List<File> dirs = collectAllDirs(dir);
for(File subdir: dirs) {
for (File file : subdir.listFiles()) {
if (file.getAbsolutePath().endsWith(".aadl")) {
aadlFileNames.add(file.getAbsolutePath());
}
}
}
for (int i = 0; i < aadlFileNames.size(); i++) {
rs.getResource(URI.createFileURI(aadlFileNames.get(i)), true);
}
// Load the resources
Map<String,Boolean> options = new HashMap<String,Boolean>();
options.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
for (final Resource resource : rs.getResources()) {
try {
EcorePlugin.ExtensionProcessor.process(null);
resource.load(options);
IResourceValidator validator = ((XtextResource) resource).getResourceServiceProvider()
.getResourceValidator();
List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
System.out.println("Issues related to parsing "+resource);
for (Issue issue : issues) {
System.out.println(issue.getMessage());
}
//EcoreUtil2.resolveAll(resource);
//resource.load(null);
} catch (final IOException e) {
System.err.println("ERROR LOADING RESOURCE: " + e.getMessage());
}
}
//EcoreUtil2.resolveAll(rs);
for (final Resource resource : rs.getResources()) {
resource.getAllContents().forEachRemaining(objects::add);
}
//parsing individual objects in the annex
for(EObject obj : objects) {
if (obj instanceof SystemType) {
//obtaining system Types
SystemType sysType = (SystemType) obj;
// unpacking sysType
for(AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
if(annex.getName().equalsIgnoreCase("agree")) {
DefaultAnnexSubclause ddASC=(DefaultAnnexSubclause)annex;
AgreeContractSubclause agreeAnnex= (AgreeContractSubclause)ddASC.getParsedAnnexSubclause();
//Processing Agree Annex of the system
EList<EObject> annexContents= agreeAnnex.eContents();
for(EObject clause : annexContents) {
//mapping to AgreeContractclause
AgreeContract agreeContract = (AgreeContract)clause;
//getting specStatements
EList<SpecStatement> specStatements = agreeContract.getSpecs();
for(SpecStatement specStatement : specStatements) {
if (specStatement instanceof EqStatement) {
System.out.println("########Found type EqStatement#################");
EqStatement eqStmt = (EqStatement)specStatement;
//get left side of the equation
EList<Arg> lhsArgs = eqStmt.getLhs();
for(Arg lhsArg : lhsArgs) {//left side has the variable names along with their types
Type type = lhsArg.getType();
if(type instanceof DoubleDotRef) {
DoubleDotRef ddrefType = (DoubleDotRef)type;
NamedElement ddrefTypeElm = ddrefType.getElm();
if (ddrefTypeElm instanceof DataImplementation) {
DataImplementation elmDataImpl = (DataImplementation)ddrefTypeElm;
for (DataSubcomponent dataSubComp: elmDataImpl.getOwnedDataSubcomponents()) {
DataSubcomponentType dataSubcomponentType = dataSubComp.getDataSubcomponentType();
if (dataSubcomponentType instanceof AbstractTypeImpl) {
AbstractTypeImpl abstrType = (AbstractTypeImpl)dataSubcomponentType;
System.out.println(abstrType.getQualifiedName());
} else if (dataSubcomponentType instanceof DataImplementation) {
String ddrefTypeElmName = dataSubcomponentType.getName();
} else {}
}
}
}
}
System.out.println("########End of EqStatement processing##########");
}
}
}
}
}
}
}
To understand if the resources and cross-references are loaded correctly I tried to validate the resources I load and I get multiple errors, one of them being "Couldn't resolve reference to ModelUnit 'Base_Types'."
Another error was "AADL Enumerations must refer to a Data Type with "Enum" data representation property and have an "Enumerators' property value list.", which tells me that the contents in the annex are being treated as aadl elements.
How can I parse the contents in the annex correctly (i.e., as elements defined in the language corresponding to the annex and not as aadl elements), and also fetch any needed definitions defined in other imported .aadl files?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04519 seconds