use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class AnnexParserAgent method processAnnexSection.
/**
* Common functionality for processing either a {@link DefaultAnnexLibrary} or a {@link DefaultAnnexSubclause}.
* Processing involves parsing the text, attaching the resulting {@link AnnexLibrary} or {@link AnnexSubclause} to
* the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}, setting the modes for the resulting
* {@link AnnexSubclause}, and either running the resolver or the linking service, depending upon which one if
* available. If the resolver produces errors, then the {@link AnnexLibrary} or {@link AnnexSubclause} will be
* detached from the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}. All error, warning, and info
* messages that are produced from the parser, resolver, or linker will be passed along to
* {@code diagnosticsConsumer}.
*
* @param <A> Type of the resulting annex section. Expected to be {@link AnnexLibrary} or {@link AnnexSubclause}.
* @param <D> Type of the default annex section. Expected to be {@link DefaultAnnexLibrary} or
* {@link DefaultAnnexSubclause}.
* @param defaultAnnexSection Either the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}.
* @param annexText Either the value of {@link DefaultAnnexLibrary#getSourceText()} or
* {@link DefaultAnnexSubclause#getSourceText()}.
* @param filename Name of the AADL file containing the annex section.
* @param diagnosticsConsumer Used for handling error, warning, and info messages.
* @param parserFunction Either
* {@link AnnexParser#parseAnnexLibrary(String, String, String, int, int, ParseErrorReporter)}
* or
* {@link AnnexParser#parseAnnexSubclause(String, String, String, int, int, ParseErrorReporter)}.
* @param setParsedAnnexSection Either {@link DefaultAnnexLibrary#setSourceText(String)} or
* {@link DefaultAnnexSubclause#setSourceText(String)}.
* @param copyModes Function for copying modes from the {@link DefaultAnnexSubclause} into the newly created
* {@link AnnexSubclause}. When processing an annex library, {@code copyModes} is expected to be a
* no-op {@link Consumer}.
*/
private <A extends NamedElement, D extends A> void processAnnexSection(D defaultAnnexSection, String annexText, String filename, IDiagnosticConsumer diagnosticsConsumer, ParserFunction<A> parserFunction, Consumer<A> setParsedAnnexSection, Consumer<A> copyModes) {
INode node = NodeModelUtils.findActualNodeFor(defaultAnnexSection);
int line = node.getStartLine() + computeLineOffset(node);
int offset = AnnexUtil.getAnnexOffset(defaultAnnexSection);
// look for plug-in parser
String annexName = defaultAnnexSection.getName();
if (annexText != null && annexText.length() > 6 && annexName != null) {
// strip {** **} from annex text
if (annexText.startsWith("{**")) {
annexText = annexText.substring(3, annexText.length() - 3);
}
annexName = AnnexModel.filterDisabledAnnexes(defaultAnnexSection, annexName);
AnnexParser ap = PARSER_REGISTRY.getAnnexParser(annexName);
try {
QueuingParseErrorReporter parseErrReporter = new QueuingParseErrorReporter();
parseErrReporter.setContextResource(defaultAnnexSection.eResource());
if (defaultAnnexSection instanceof AnnexSubclause) {
AnnexUtil.setCurrentAnnexSubclause((AnnexSubclause) defaultAnnexSection);
}
A annexSection = parserFunction.parse(ap, annexName, annexText, filename, line, offset, parseErrReporter);
if (defaultAnnexSection instanceof AnnexSubclause) {
AnnexUtil.setCurrentAnnexSubclause(null);
}
if (ParseResultHolder.Factory.INSTANCE.adapt(defaultAnnexSection).getParseResult() == null) {
// Only consume messages for non-Xtext annexes
consumeMessages(parseErrReporter, diagnosticsConsumer, annexText, line, offset);
}
if (annexSection != null) {
annexSection.setName(annexName);
setParsedAnnexSection.accept(annexSection);
// copy in modes list
copyModes.accept(annexSection);
// now resolve reference so we get messages if we have references to undefined items
AnnexResolver resolver = RESOLVER_REGISTRY.getAnnexResolver(annexName);
AnnexLinkingService linkingService = LINKING_SERVICE_REGISTRY.getAnnexLinkingService(annexName);
if (resolver != null && parseErrReporter.getNumErrors() == 0) {
// Don't resolve any annex with parsing errors.
QueuingParseErrorReporter resolveErrReporter = new QueuingParseErrorReporter();
AnalysisErrorReporterManager resolveErrManager = new AnalysisErrorReporterManager(new AnalysisToParseErrorReporterAdapter.Factory(aadlRsrc -> resolveErrReporter));
resolver.resolveAnnex(annexName, Collections.singletonList(annexSection), resolveErrManager);
consumeMessages(resolveErrReporter, diagnosticsConsumer, annexText, line, offset);
if (resolveErrReporter.getNumErrors() != 0) {
AnnexValidator.setNoValidation(defaultAnnexSection, annexName);
}
} else if (linkingService != null) {
try {
XtextResource res = (XtextResource) defaultAnnexSection.eResource();
ILinker linker = res.getLinker();
linker.linkModel(annexSection, diagnosticsConsumer);
} catch (Exception e) {
String message = "Linking Service error in " + filename + " at line " + line;
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, e);
Activator.getDefault().getLog().log(status);
}
}
}
if (parseErrReporter.getNumErrors() > 0) {
AnnexValidator.setNoValidation(defaultAnnexSection, annexName);
}
} catch (RecognitionException e) {
String message = "Major parsing error in " + filename + " at line " + line;
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, e);
Activator.getDefault().getLog().log(status);
}
}
}
use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class AadlBusinessObjectProvider method populateChildren.
private static void populateChildren(final PackageSection ps, final Set<Object> children, final ExtensionRegistryService extRegistryService) {
if (ps == null) {
return;
}
children.addAll(ps.getOwnedClassifiers());
for (final AnnexLibrary annexLibrary : ps.getOwnedAnnexLibraries()) {
final NamedElement parsedAnnexLibrary = getParsedAnnexLibrary(annexLibrary);
final boolean specializedHandling = parsedAnnexLibrary != null && extRegistryService.getApplicableBusinessObjectHandler(parsedAnnexLibrary) != null;
// Only contribute the annex object if a BOH for the annex does not exist. The annex plugin is expected to contribute the object as needed.
if (!specializedHandling) {
children.add(annexLibrary);
}
}
}
use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class AnnexHandler method getAnnexLibraryIndex.
/**
* Returns a 0 based index for referencing an annex library in a list that contains only annex libraries with the same type and owner
* @param annexLibrary
* @return
*/
private static int getAnnexLibraryIndex(AnnexLibrary annexLibrary) {
// Get the default annex library if a parsed annex library was specified. This is needed for the comparison later in the function.
if (!(annexLibrary instanceof DefaultAnnexLibrary)) {
if (annexLibrary.eContainer() instanceof DefaultAnnexLibrary) {
annexLibrary = (AnnexLibrary) annexLibrary.eContainer();
} else {
return -1;
}
}
final String annexName = annexLibrary.getName();
if (annexName == null) {
return -1;
}
// Get the Aadl Package
Element tmp = annexLibrary.getOwner();
while (tmp != null && !(tmp instanceof AadlPackage)) {
tmp = tmp.getOwner();
}
int index = 0;
if (tmp instanceof AadlPackage) {
for (final AnnexLibrary tmpLibrary : AnnexUtil.getAllDefaultAnnexLibraries((AadlPackage) tmp)) {
if (tmpLibrary == annexLibrary) {
return index;
} else if (annexName.equalsIgnoreCase(tmpLibrary.getName())) {
index++;
}
}
}
return -1;
}
use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class AnnexAwareEntryPointFinder method findEntryPoint.
@Override
public ICompositeNode findEntryPoint(IParseResult parseResult, int offset) {
ICompositeNode rootNode = parseResult.getRootNode();
EObject semanticObject = rootNode.getSemanticElement();
if (semanticObject instanceof AnnexSubclause || semanticObject instanceof AnnexLibrary) {
return rootNode;
}
return super.findEntryPoint(parseResult, offset);
}
use of org.osate.aadl2.AnnexLibrary in project osate2 by osate.
the class AadlElementContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
Stream<EObject> children;
final ResourceSetImpl resourceSet = new ResourceSetImpl();
if (parentElement instanceof IFile) {
String path = ((IFile) parentElement).getFullPath().toString();
URI uri = URI.createPlatformResourceURI(path, true);
Resource resource = resourceSet.getResource(uri, true);
children = resource.getContents().stream();
} else if (parentElement instanceof ContributedAadlStorage) {
URI uri = ((ContributedAadlStorage) parentElement).getUri();
Resource resource = resourceSet.getResource(uri, true);
children = resource.getContents().stream();
} else {
EObjectURIWrapper wrapper = (EObjectURIWrapper) parentElement;
EObject eObject = resourceSet.getEObject(wrapper.getUri(), true);
if (eObject instanceof AadlPackage || eObject instanceof PropertySet || eObject instanceof ComponentInstance) {
children = eObject.eContents().stream().filter(element -> !(element instanceof SystemOperationMode || element instanceof PropertyAssociation));
} else if (eObject instanceof PackageSection) {
children = eObject.eContents().stream().filter(element -> element instanceof Classifier || element instanceof AnnexLibrary);
} else if (eObject instanceof Classifier) {
children = eObject.eContents().stream().filter(element -> element instanceof ClassifierFeature || element instanceof PropertyAssociation);
} else {
children = Stream.empty();
}
}
final EObjectURIWrapper.Factory factory = new EObjectURIWrapper.Factory(UiUtil.getModelElementLabelProvider());
// Issue 2430: limit the number of children to 150
return children.limit(150).map(element -> factory.createWrapperFor(element)).toArray();
}
Aggregations