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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations