use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class DefaultAadlModificationService method getParsedAnnexRootIndices.
/**
* Return indices that indicate the location of an object within a parsed annex element.
* @param obj
* @return
*/
private Deque<Integer> getParsedAnnexRootIndices(final EObject obj) {
assert !(obj instanceof DefaultAnnexLibrary || obj instanceof DefaultAnnexSubclause);
final Deque<Integer> indices = new ArrayDeque<>();
// Find the root of the parsed annex
EObject tmp = obj;
while (tmp != null && !(tmp instanceof AnnexLibrary || tmp instanceof AnnexSubclause)) {
final int newIndex = ECollections.indexOf(tmp.eContainer().eContents(), tmp, 0);
if (newIndex == -1) {
throw new GraphicalEditorException("Unable to get index inside of container contents");
}
indices.push(newIndex);
;
tmp = tmp.eContainer();
}
return indices;
}
use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class DefaultAadlModificationService method modifyAnnexInXtextDocument.
private <TagType, BusinessObjectType extends EObject> ModifySafelyResults modifyAnnexInXtextDocument(final XtextResource resource, final EObject defaultAnnexElement, final TagType tag, final BusinessObjectType bo, final Modifier<TagType, BusinessObjectType> modifier) {
// Make a copy of the resource
final EObject parsedAnnexElement = getParsedAnnexElement(defaultAnnexElement);
final ResourceSet tmpResourceSet = new ResourceSetImpl();
final Resource tmpResource = tmpResourceSet.createResource(resource.getURI());
tmpResource.getContents().addAll(EcoreUtil.copyAll(resource.getContents()));
// Clone the bo specified by the modification
final EObject parsedAnnexRootClone = tmpResourceSet.getEObject(EcoreUtil.getURI(parsedAnnexElement), false);
final Deque<Integer> indexStack = getParsedAnnexRootIndices(bo);
EObject tmpClonedObject = parsedAnnexRootClone;
while (!indexStack.isEmpty()) {
tmpClonedObject = tmpClonedObject.eContents().get(indexStack.pop());
}
@SuppressWarnings("unchecked") final BusinessObjectType clonedUserObject = (BusinessObjectType) tmpClonedObject;
// Modify the annex by modifying the cloned object, unparsing, and then updating the source text of the original default annex element.
return modifySafely(resource, tag, defaultAnnexElement, (unusedTag, defaultAnnexElement1) -> {
// Modify the cloned object
modifier.modify(tag, clonedUserObject);
// Unparse the annex text of the cloned object and update the Xtext document
if (parsedAnnexRootClone instanceof AnnexLibrary) {
final DefaultAnnexLibrary defaultAnnexLibrary = (DefaultAnnexLibrary) defaultAnnexElement1;
final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexLibrary.getName()).unparseAnnexLibrary((AnnexLibrary) parsedAnnexRootClone, " ");
final String sourceTxt1 = alignAnnexTextToCore(resource, annexText, 1);
EcoreUtil.delete(defaultAnnexLibrary.getParsedAnnexLibrary());
defaultAnnexLibrary.setSourceText(sourceTxt1);
} else if (parsedAnnexRootClone instanceof AnnexSubclause) {
final DefaultAnnexSubclause defaultAnnexSubclause = (DefaultAnnexSubclause) defaultAnnexElement1;
final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexSubclause.getName()).unparseAnnexSubclause((AnnexSubclause) parsedAnnexRootClone, " ");
final String sourceTxt2 = alignAnnexTextToCore(resource, annexText, 2);
EcoreUtil.delete(defaultAnnexSubclause.getParsedAnnexSubclause());
defaultAnnexSubclause.setSourceText(sourceTxt2);
} else {
throw new GraphicalEditorException("Unhandled case, parsedAnnexRoot is of type: " + parsedAnnexRootClone.getClass());
}
}, false);
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeAnnexContentAssist method annexCompletionSuggestions.
@Override
public List<String> annexCompletionSuggestions(EObject defaultAnnex, int offset) {
// get one character back
offset = (offset <= 0) ? 0 : offset - 1;
EObjectAtOffsetHelper helper = getOffsetHelper();
EObject grammerObject = null;
// EObjectAtOffsetHelper
if (defaultAnnex instanceof DefaultAnnexLibrary) {
AnnexLibrary annexLib = ((DefaultAnnexLibrary) defaultAnnex).getParsedAnnexLibrary();
XtextResource resource = (XtextResource) annexLib.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
} else if (defaultAnnex instanceof DefaultAnnexSubclause) {
AnnexSubclause annexSub = ((DefaultAnnexSubclause) defaultAnnex).getParsedAnnexSubclause();
XtextResource resource = (XtextResource) annexSub.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
}
List<String> results = new ArrayList<>();
if (grammerObject instanceof SelectionExpr) {
results.addAll(getNestedDotIDCandidates((SelectionExpr) grammerObject));
}
return results;
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeAnnexContentAssist method getNestedDotIDCandidates.
private List<String> getNestedDotIDCandidates(AadlPackage aadlPackage) {
AgreeContract contract = null;
List<String> results = new ArrayList<>();
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
if (annex instanceof AgreeLibrary) {
contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
}
}
if (contract != null) {
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof ConstStatement) {
results.add(((ConstStatement) spec).getName());
}
}
}
return results;
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeValidator method checkEqStatement.
@Check(CheckType.FAST)
public void checkEqStatement(EqStatement eqStat) {
AnnexLibrary library = EcoreUtil2.getContainerOfType(eqStat, AnnexLibrary.class);
if (library != null) {
error(eqStat, "Equation statments are allowed only in component annexes");
}
checkMultiAssignEq(eqStat, eqStat.getLhs(), eqStat.getExpr());
}
Aggregations