Search in sources :

Example 96 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class AnnexHandler method getCanonicalReference.

@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
    final Object bo = ctx.getBusinessObject();
    if (bo instanceof AnnexLibrary) {
        final AnnexLibrary annexLibrary = (AnnexLibrary) bo;
        final AadlPackage annexPkg = getAnnexLibraryPackage(annexLibrary);
        if (annexPkg == null) {
            throw new RuntimeException("Unable to retrieve package.");
        }
        final int index = getAnnexLibraryIndex(annexLibrary);
        return new CanonicalBusinessObjectReference(DeclarativeReferenceType.ANNEX_LIBRARY.getId(), annexPkg.getQualifiedName(), annexLibrary.getName(), Integer.toString(index));
    } else if (bo instanceof AnnexSubclause) {
        final AnnexSubclause annexSubclause = (AnnexSubclause) bo;
        if (annexSubclause.getContainingClassifier() == null) {
            throw new RuntimeException("Unable to retrieve containing classifier.");
        }
        final Classifier annexSubclauseClassifier = annexSubclause.getContainingClassifier();
        final int index = getAnnexSubclauseIndex(annexSubclause, false);
        return new CanonicalBusinessObjectReference(DeclarativeReferenceType.ANNEX_SUBCLAUSE.getId(), ctx.getReferenceBuilder().getCanonicalReference(annexSubclauseClassifier).encode(), annexSubclause.getName(), Integer.toString(index));
    }
    throw new RuntimeException("Unexpected business object " + bo);
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) Classifier(org.osate.aadl2.Classifier) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 97 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class DeclarativeReferenceResolver method getClassifierByQualifiedName.

private Classifier getClassifierByQualifiedName(final String qualifiedName) {
    final String[] qualifiedNameSegs = qualifiedName.split("::");
    final String packageName = StringUtil.join(qualifiedNameSegs, 0, qualifiedNameSegs.length - 1, "::");
    final String classifierName = qualifiedNameSegs[qualifiedNameSegs.length - 1];
    final AadlPackage pkg = getAadlPackage(packageName);
    if (pkg == null) {
        return null;
    }
    // Return the package if that is the element that was being retrieved
    Classifier classifier = findClassifierByName(pkg.getPublicSection(), classifierName);
    if (classifier == null) {
        classifier = findClassifierByName(pkg.getPrivateSection(), classifierName);
    }
    return classifier;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) Classifier(org.osate.aadl2.Classifier)

Example 98 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class SetFeatureClassifierPropertySection method setFeatureClassifier.

private static void setFeatureClassifier(final NamedElement feature, final Object classifier) {
    if (classifier != null) {
        // Import its package if necessary
        final AadlPackage pkg = (AadlPackage) feature.getElementRoot();
        if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
            final PackageSection section = pkg.getPublicSection();
            final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
            if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
                AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
            }
        }
        // If the feature is an abstract feature, need to reset the feature prototype. Only a prototype or a classifier may be set.
        if (feature instanceof AbstractFeature) {
            ((AbstractFeature) feature).setFeaturePrototype(null);
        }
    }
    final FeatureClassifierMetadata setterInfo = featureTypeToMetadataMap.get(feature.eClass());
    try {
        final Method method = feature.getClass().getMethod(setterInfo.setterName, setterInfo.classifierClass);
        method.invoke(feature, classifier);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) AbstractFeature(org.osate.aadl2.AbstractFeature) AbstractFeatureClassifier(org.osate.aadl2.AbstractFeatureClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) BusFeatureClassifier(org.osate.aadl2.BusFeatureClassifier) FeatureClassifier(org.osate.aadl2.FeatureClassifier) DataClassifier(org.osate.aadl2.DataClassifier) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 99 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class GoToPackageDiagramHandler method setEnabled.

@Override
public void setEnabled(final Object evaluationContext) {
    boolean enabled = false;
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 1) {
        final Object selectedBo = selectedBusinessObjectContexts.get(0).getBusinessObject();
        if (!(selectedBo instanceof AadlPackage)) {
            final AadlPackage pkg = getPackage(selectedBo);
            enabled = pkg != null && ProjectUtil.getProjectForBo(pkg).isPresent();
        }
    }
    setBaseEnabled(enabled);
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 100 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class PasteAction method getDestinationEObject.

private EObject getDestinationEObject(final DiagramNode dstDiagramNode) {
    if (!(dstDiagramNode instanceof DiagramElement)) {
        return null;
    }
    final DiagramElement dstDiagramElement = (DiagramElement) dstDiagramNode;
    if (!(dstDiagramElement.getBusinessObject() instanceof EObject)) {
        return null;
    }
    EObject dstBo = (EObject) dstDiagramElement.getBusinessObject();
    final Collection<CopiedDiagramElement> copiedDiagramElements = getCopiedDiagramElements();
    if (copiedDiagramElements.size() == 0) {
        return null;
    }
    // Determine the business object inside which to copy the copied business objects
    while (dstBo != null) {
        // Check if all copied business objects may be copied to the potential destination business object
        final EClass dstBoEClass = dstBo.eClass();
        final boolean allElementsAreCompatible = copiedDiagramElements.stream().allMatch(copiedDiagramElement -> !(copiedDiagramElement.getCopiedBusinessObject() instanceof EObject) || getCompatibleStructuralFeature(copiedDiagramElement.getContainingFeature(), dstBoEClass) != null);
        if (allElementsAreCompatible) {
            break;
        }
        // Select a new destination business object.
        if (dstBo instanceof ComponentImplementation) {
            dstBo = ((ComponentImplementation) dstBo).getType();
        } else if (dstBo instanceof Subcomponent) {
            dstBo = ((Subcomponent) dstBo).getAllClassifier();
        } else if (dstBo instanceof AadlPackage) {
            dstBo = ((AadlPackage) dstBo).getPublicSection();
        } else {
            dstBo = null;
        }
    }
    // Only allow pasting of the destination has a valid XtextResource
    if (dstBo != null && !(dstBo.eResource() instanceof XtextResource)) {
        return null;
    }
    return dstBo;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ComponentImplementation(org.osate.aadl2.ComponentImplementation) EClass(org.eclipse.emf.ecore.EClass) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) XtextResource(org.eclipse.xtext.resource.XtextResource)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)106 EObject (org.eclipse.emf.ecore.EObject)45 Classifier (org.osate.aadl2.Classifier)39 NamedElement (org.osate.aadl2.NamedElement)26 ArrayList (java.util.ArrayList)22 ComponentImplementation (org.osate.aadl2.ComponentImplementation)20 PackageSection (org.osate.aadl2.PackageSection)18 Element (org.osate.aadl2.Element)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)13 Optional (java.util.Optional)11 Test (org.junit.Test)11 SystemInstance (org.osate.aadl2.instance.SystemInstance)11 List (java.util.List)10 URI (org.eclipse.emf.common.util.URI)10 Subcomponent (org.osate.aadl2.Subcomponent)10 Inject (com.google.inject.Inject)9 IFile (org.eclipse.core.resources.IFile)9