Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unable to fetch data type information if defined in an imported AADL file:
Unable to fetch data type information if defined in an imported AADL file: [message #1831784] Fri, 28 August 2020 22:34 Go to next message
vrg 123 is currently offline vrg 123Friend
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?
Re: Unable to fetch data type information if defined in an imported AADL file: [message #1831793 is a reply to message #1831784] Sat, 29 August 2020 16:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Don't use the resolve alll load options
Add all resources to the resourceset
Then call resolveAll (ecoreutil)

In general you cannot get anything from an import that is not use
An import is just a Special Name that makes stuff visible under a shorter name (or at all if you use import uri global scoping )


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unable to fetch data type information if defined in an imported AADL file: [message #1831794 is a reply to message #1831793] Sat, 29 August 2020 18:09 Go to previous messageGo to next message
vrg 123 is currently offline vrg 123Friend
Messages: 2
Registered: August 2020
Junior Member
I changed the code as below, i.e. removed the resolve all options while loading and added resolveall after loading. But it still fetches the type of "target_picture" as "AbstractTypeImpl" instead of "DataTypeImpl".
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<>();
// Obtain all AADL files contents in the project
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
for (final Resource resource : rs.getResources()) {
	try {
		EcorePlugin.ExtensionProcessor.process(null);
		resource.load(null);
		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);
	} 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);
}		
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##########");
						}
					}
				}
			}
		}
	}
}

I noticed that if I added the "Base_Types.aadl" file to the same folder as the "DeliveryDrone.aadl" file, then I am able to fetch the information right.
However, "Base_Types.aadl" is part of the standard AADL library. Could the project setup be the actual issue?
Re: Unable to fetch data type information if defined in an imported AADL file: [message #1831795 is a reply to message #1831794] Sat, 29 August 2020 18:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
does the resource.getErrors contain anything for any of the resources?
There should not be any could not resolve issues
If there are you miss some files


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 29 August 2020 20:16]

Report message to a moderator

Re: Unable to fetch data type information if defined in an imported AADL file: [message #1831807 is a reply to message #1831795] Sun, 30 August 2020 15:30 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6874
Registered: July 2009
Senior Member
HI

EMF XML loading creates objects for references twice, once as a proxy with a 'stupid' often abstract type, and then properly once the proxy is resolved.

Debug EcoreUtil.resolveProxy failures in accordance with the ResourceSet.resources.errors.

Regards

Ed Willink
Previous Topic:Add an ID (hidden) in the metamodel associated with the xtext grammar
Next Topic:Integrate Xtend with runtime EMF Instances
Goto Forum:
  


Current Time: Thu Oct 22 18:59:03 GMT 2020

Powered by FUDForum. Page generated in 0.01395 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top