use of com.rockwellcollins.atc.agree.agree.RecordDef in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromNE.
public static TypeDef typeDefFromNE(NamedElement ne) {
if (ne instanceof Classifier) {
return typeDefFromClassifier((Classifier) ne);
} else if (ne instanceof RecordDef) {
EList<Arg> args = ((RecordDef) ne).getArgs();
Map<String, TypeDef> fields = new HashMap<>();
for (Arg arg : args) {
String key = arg.getName();
TypeDef typeDef = typeDefFromType(arg.getType());
fields.put(key, typeDef);
}
return new RecordTypeDef(ne.getQualifiedName(), fields, ne);
} else if (ne instanceof EnumStatement) {
String name = ne.getQualifiedName();
List<String> enumValues = new ArrayList<String>();
for (NamedID nid : ((EnumStatement) ne).getEnums()) {
String enumValue = name + "_" + nid.getName();
enumValues.add(enumValue);
}
return new EnumTypeDef(name, enumValues, ne);
} else if (ne instanceof Arg) {
return typeDefFromType(((Arg) ne).getType());
} else {
return Prim.ErrorTypeDef;
}
}
use of com.rockwellcollins.atc.agree.agree.RecordDef in project AGREE by loonwerks.
the class AgreeLinkingService method getElm.
private Element getElm(EObject context, EReference reference, String name) {
String[] segments = name.split("::");
if (segments.length >= 2) {
String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
String statementName = segments[segments.length - 1];
Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
if (propSet != null) {
Element elm = propSet.findNamedElement(statementName);
return elm;
}
AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
if (aadlPackage == null) {
for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
if (rename.getName() != null && pkgName.equals(rename.getName())) {
aadlPackage = rename.getRenamedPackage();
}
}
}
if (aadlPackage != null) {
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof RecordDef) {
if (((RecordDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof FnDef) {
if (((FnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LibraryFnDef) {
if (((LibraryFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof UninterpretedFnDef) {
if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof NodeDef) {
if (((NodeDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LinearizationDef) {
if (((LinearizationDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof ConstStatement) {
if (((ConstStatement) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof EnumStatement) {
if (((EnumStatement) spec).getName().equals(statementName)) {
return (spec);
}
EList<NamedID> enums = ((EnumStatement) spec).getEnums();
for (NamedID nid : enums) {
if (nid.getName().contentEquals(statementName)) {
return nid;
}
}
}
}
}
}
}
return null;
}
use of com.rockwellcollins.atc.agree.agree.RecordDef in project AMASE by loonwerks.
the class SafetyAnnexContentAssist method getNestedDotIDCandidates.
private List<String> getNestedDotIDCandidates(NamedElement namedEl) {
List<String> results = new ArrayList<>();
List<NamedElement> namedEls = new ArrayList<>();
if (namedEl instanceof ComponentImplementation) {
namedEls.addAll(((ComponentImplementation) namedEl).getAllSubcomponents());
} else if (namedEl instanceof RecordDef) {
namedEls.addAll(((RecordDef) namedEl).getArgs());
}
for (NamedElement el : namedEls) {
results.add(el.getName());
}
return results;
}
use of com.rockwellcollins.atc.agree.agree.RecordDef in project AMASE by loonwerks.
the class SafetyScopeProvider method scope_RecordLitExpr_args.
IScope scope_RecordLitExpr_args(RecordLitExpr ctx, EReference ref) {
IScope prevScope = prevScope(ctx, ref);
NamedElement recDef = ctx.getRecordType().getElm();
Set<Element> components = new HashSet<>();
if (recDef instanceof DataImplementation) {
components.addAll(((DataImplementation) recDef).getAllSubcomponents());
return Scopes.scopeFor(components, prevScope);
} else if (recDef instanceof RecordDef) {
components.addAll(((RecordDef) recDef).getArgs());
return Scopes.scopeFor(components, prevScope);
}
return prevScope;
}
use of com.rockwellcollins.atc.agree.agree.RecordDef in project AMASE by loonwerks.
the class SafetyLinkingService method getElm.
private Element getElm(EObject context, EReference reference, String name) {
String[] segments = name.split("::");
if (segments.length >= 2) {
String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
String statementName = segments[segments.length - 1];
Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
if (propSet != null) {
Element elm = propSet.findNamedElement(statementName);
return elm;
}
AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
if (aadlPackage == null) {
for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
if (rename.getName() != null && pkgName.equals(rename.getName())) {
aadlPackage = rename.getRenamedPackage();
}
}
}
if (aadlPackage != null) {
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
for (com.rockwellcollins.atc.agree.agree.SpecStatement spec : contract.getSpecs()) {
if (spec instanceof RecordDef) {
if (((RecordDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof FnDef) {
if (((FnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LibraryFnDef) {
if (((LibraryFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof NodeDef) {
if (((NodeDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LinearizationDef) {
if (((LinearizationDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof ConstStatement) {
if (((ConstStatement) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof EnumStatement) {
if (((EnumStatement) spec).getName().equals(statementName)) {
return (spec);
}
EList<NamedID> enums = ((EnumStatement) spec).getEnums();
for (NamedID nid : enums) {
if (nid.getName().contentEquals(statementName)) {
return nid;
}
}
}
}
}
}
}
return null;
}
Aggregations