use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class ModelLoadingAdapter method getAdapter.
/**
* XXX: Notice - the methods dealing with EMF Index operations has been moved to the EMFIndexRetrieval Class in org.osate.xtext.aadl2.properties.util
*/
/*
* * Usage: ModelUnit target = (ModelUnit)Platform.getAdapterManager().getAdapter(f, ModelUnit.class);
*/
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == ModelUnit.class || adapterType == Element.class || adapterType == InstanceObject.class || adapterType == SystemInstance.class) {
if (adaptableObject instanceof ISelection) {
final ISelection sel = (ISelection) adaptableObject;
if (!(sel instanceof IStructuredSelection)) {
return null;
}
final IStructuredSelection selection = (IStructuredSelection) sel;
if (!(selection.getFirstElement() instanceof IFile)) {
return null;
}
adaptableObject = selection.getFirstElement();
}
if (adaptableObject instanceof IFile) {
final IFile file = (IFile) adaptableObject;
String ext = file.getFileExtension();
if (ext == null) {
return null;
}
if (ext.toLowerCase().equals(FileNameConstants.SOURCE_FILE_EXT)) {
ModelUnit model;
ResourceSet resourceSet = new ResourceSetImpl();
String sp = file.getFullPath().toString();
Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(sp, false), true);
if (!resource.getContents().isEmpty()) {
model = (ModelUnit) resource.getContents().get(0);
} else {
model = null;
}
return model;
} else if (ext.toLowerCase().equals("aaxl2")) {
SystemInstance model;
ResourceSet resourceSet = new ResourceSetImpl();
String sp = file.getFullPath().toString();
Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(sp, false), true);
if (!resource.getContents().isEmpty()) {
model = (SystemInstance) resource.getContents().get(0);
} else {
model = null;
}
return model;
}
}
}
return null;
}
use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class PropertiesLinkingDiagnosticMessageProvider method getUnresolvedProxyMessage.
@Override
public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
EClass referenceType = context.getReference().getEReferenceType();
String targetName = null;
if (Aadl2Package.eINSTANCE.getAbstractNamedValue() == referenceType) {
targetName = "Property Constant, Property Definition, Enumeration or Unit literal";
String msg = "Couldn't resolve reference to " + targetName + " '" + context.getLinkText() + "'." + " For classifier references use classifier( <ref> ).";
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
boolean suppressError = false;
if (Aadl2Package.eINSTANCE.getProperty() == referenceType) {
boolean showWarningInstead = false;
if (context.getLinkText().indexOf("::") > 0) {
// get preferences ~ same as org.osate.ui.utils.PropertySetModel
String[] ignoredPerPreference = getIgnoredPropertySetPreference();
showWarningInstead = getIgnoredPropertySetAlertPreference();
// FIXME - should process property set name only
for (String propSetName : context.getLinkText().split("::")) {
if (!suppressError) {
// check against preference
for (String pref : ignoredPerPreference) {
if (pref.equalsIgnoreCase(propSetName)) {
suppressError = true;
break;
}
}
}
}
}
String msg = "Couldn't resolve reference to property definition '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
if (suppressError) {
if (showWarningInstead) {
return new DiagnosticMessage(msg, Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
} else {
return null;
}
} else {
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
}
if (Aadl2Package.eINSTANCE.getPropertyType() == referenceType) {
String msg = "Couldn't resolve reference to property type '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
if (Aadl2Package.eINSTANCE.getPropertyConstant() == referenceType) {
String msg = "Couldn't resolve reference to property constant '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
if (Aadl2Package.eINSTANCE.getNamedElement() == referenceType) {
EObject obj = context.getContext();
if (obj instanceof ContainmentPathElement) {
Subcomponent sub = AadlUtil.getContainingSubcomponent(obj);
INode node = NodeModelUtils.findActualNodeFor(obj);
String name = NodeModelUtils.getTokenText(node);
if (sub != null && !(obj.eContainer() instanceof ContainmentPathElement)) {
String msg = "Could not find path element " + name + " in subcomponent " + sub.getName();
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
}
String msg = "Couldn't resolve reference to '" + context.getLinkText() + "'.";
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
if (Aadl2Package.eINSTANCE.getMode() == referenceType) {
EObject cxt = context.getContext();
PropertyAssociation pa = AadlUtil.getContainingPropertyAssociation(cxt);
boolean iscontainedPA = (pa != null && !pa.getAppliesTos().isEmpty());
String msg = "Couldn't resolve reference to mode '" + context.getLinkText() + "'";
if (iscontainedPA) {
EList<ContainedNamedElement> appl = pa.getAppliesTos();
ContainedNamedElement path = appl.get(appl.size() - 1);
msg = msg + " in applies to '" + Aadl2Util.getPrintablePathName(path) + "'.";
} else {
msg = msg + ".";
}
return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
DiagnosticMessage msg = super.getUnresolvedProxyMessage(context);
if (referenceType.getName().equals("ModelUnit")) {
// check against preference
for (String inIgnoredPrefList : getIgnoredPropertySetPreference()) {
if (inIgnoredPrefList.equalsIgnoreCase(context.getLinkText())) {
return new DiagnosticMessage(context.getLinkText() + " property set is missing. Install additional plug-ins that have this property set", Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
}
}
}
return msg;
}
use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class OrganizeWithHandler method findMissingWiths.
private List<ModelUnit> findMissingWiths(PackageSection pkgSection) {
List<ModelUnit> currentWiths = pkgSection.getImportedUnits();
List<ModelUnit> missingWiths = new ArrayList<ModelUnit>();
TreeIterator<EObject> packageContents = pkgSection.eAllContents();
while (packageContents.hasNext()) {
EObject nextObject = packageContents.next();
EList<EObject> crossReferences = nextObject.eCrossReferences();
for (EObject crossReference : crossReferences) {
EObject container = crossReference.eContainer();
while (container != null) {
if ((container instanceof PropertySet || container instanceof AadlPackage) && (!AadlUtil.isPredeclaredPropertySet(((ModelUnit) container).getName())) && (!((ModelUnit) container).equals(pkgSection.eContainer()))) {
if (!currentWiths.contains(container) && !missingWiths.contains(container)) {
missingWiths.add((ModelUnit) container);
}
}
container = container.eContainer();
}
}
}
return missingWiths;
}
use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class OrganizeWithHandler method organizeWithClauses.
private void organizeWithClauses(PackageSection pkgSection) {
List<ModelUnit> workingImportedUnits = new ArrayList<ModelUnit>();
for (ModelUnit nextImportedUnit : pkgSection.getImportedUnits()) {
workingImportedUnits.add(nextImportedUnit);
}
List<ModelUnit> unusedImportedUnits = getUnusedWiths(pkgSection);
workingImportedUnits.removeAll(unusedImportedUnits);
List<ModelUnit> missingWiths = findMissingWiths(pkgSection);
workingImportedUnits.addAll(missingWiths);
Collections.sort(workingImportedUnits, new Comparator<ModelUnit>() {
@Override
public int compare(ModelUnit obj1, ModelUnit obj2) {
return obj1.getName().toLowerCase().compareTo(obj2.getName().toLowerCase());
}
});
pkgSection.getImportedUnits().removeAll(pkgSection.getImportedUnits());
pkgSection.getImportedUnits().addAll(workingImportedUnits);
}
use of org.osate.aadl2.ModelUnit in project AGREE by loonwerks.
the class AgreeFileUtil method collectResourceFiles.
/**
* Recursive function to recursively collect all referenced files of the current resource.
* @param resource - The resource representing the file.
* @param files - Set of resource path/file names.
* @throws Exception
*/
private static void collectResourceFiles(Resource resource, Set<IFile> files) throws Exception {
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
URI uri = resource.getURI();
IFile file = workspaceRoot.getFile(new Path(uri.toPlatformString(true)));
if (uri.segment(0).equals("plugin")) {
// We're going to ignore these
return;
} else if (!file.isAccessible() || !file.exists()) {
throw new Exception("Unable to access file " + file.getName() + ".");
} else {
files.add(file);
}
// Get the resources that are referred to (via the 'with' statement)
EList<EObject> resourceContents = resource.getContents();
for (EObject eObj : resourceContents) {
if (eObj instanceof AadlPackage) {
AadlPackage aadlPackage = (AadlPackage) eObj;
// Resources included in the public section
if (aadlPackage.getOwnedPublicSection() != null) {
final EList<ModelUnit> importedUnits = aadlPackage.getPublicSection().getImportedUnits();
for (ModelUnit mUnit : importedUnits) {
IFile resourceFile = workspaceRoot.getFile(new Path(mUnit.eResource().getURI().toPlatformString(true)));
if (!files.contains(resourceFile)) {
collectResourceFiles(mUnit.eResource(), files);
}
}
}
// Resources included in the private section
if (aadlPackage.getOwnedPrivateSection() != null) {
final EList<ModelUnit> importedUnits = aadlPackage.getPrivateSection().getImportedUnits();
for (ModelUnit mUnit : importedUnits) {
IFile resourceFile = workspaceRoot.getFile(new Path(mUnit.eResource().getURI().toPlatformString(true)));
if (!files.contains(resourceFile)) {
collectResourceFiles(mUnit.eResource(), files);
}
}
}
}
}
return;
}
Aggregations