Search in sources :

Example 31 with AnnexLibrary

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) ArrayDeque(java.util.ArrayDeque) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 32 with AnnexLibrary

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);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 33 with AnnexLibrary

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;
}
Also used : EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 34 with AnnexLibrary

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;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) AgreeLibrary(com.rockwellcollins.atc.agree.agree.AgreeLibrary) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary)

Example 35 with AnnexLibrary

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());
}
Also used : AnnexLibrary(org.osate.aadl2.AnnexLibrary) Check(org.eclipse.xtext.validation.Check)

Aggregations

AnnexLibrary (org.osate.aadl2.AnnexLibrary)32 DefaultAnnexLibrary (org.osate.aadl2.DefaultAnnexLibrary)16 AadlPackage (org.osate.aadl2.AadlPackage)15 EObject (org.eclipse.emf.ecore.EObject)14 AnnexSubclause (org.osate.aadl2.AnnexSubclause)14 DefaultAnnexSubclause (org.osate.aadl2.DefaultAnnexSubclause)8 NamedElement (org.osate.aadl2.NamedElement)8 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)7 ArrayList (java.util.ArrayList)7 Classifier (org.osate.aadl2.Classifier)6 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 Check (org.eclipse.xtext.validation.Check)5 Element (org.osate.aadl2.Element)5 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 INode (org.eclipse.xtext.nodemodel.INode)4 PropertySet (org.osate.aadl2.PropertySet)4 AgreeContractLibrary (com.rockwellcollins.atc.agree.agree.AgreeContractLibrary)3 HashMap (java.util.HashMap)3