use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.
the class STextTaskFinder method findTasks.
public List<Task> findTasks(StextResource resource) {
TaskTags taskTags = taskTagProvider.getTaskTags(resource);
List<Task> result = Lists.newArrayList();
TreeIterator<EObject> allContents = resource.getAllContents();
while (allContents.hasNext()) {
EObject eObject = (EObject) allContents.next();
if (eObject instanceof SpecificationElement) {
List<Task> parseTasks = parseTasks(eObject, SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION, taskTags);
result.addAll(parseTasks);
}
if (eObject instanceof DocumentedElement) {
result.addAll(parseTasks(eObject, BasePackage.Literals.DOCUMENTED_ELEMENT__DOCUMENTATION, taskTags));
}
}
return result;
}
use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.
the class STextExpressionParser method parseExpression.
public EObject parseExpression(String expression, String ruleName, String specification) {
StextResource resource = getResource();
resource.setURI(URI.createURI(getUri(), true));
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName(ruleName);
IParseResult result = parser.parse(parserRule, new StringReader(expression));
EObject rootASTElement = result.getRootASTElement();
resource.getContents().add(rootASTElement);
ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
Statechart sc = SGraphFactory.eINSTANCE.createStatechart();
sc.setDomainID(domainId);
sc.setName("sc");
if (specification != null) {
sc.setSpecification(specification);
}
resource.getContents().add(sc);
resource.getLinkingDiagnostics().clear();
linker.linkModel(sc, diagnosticsConsumer);
linker.linkModel(rootASTElement, diagnosticsConsumer);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics();
if (diagnostics.size() > 0) {
throw new LinkingException(diagnostics.toString());
}
if (result.hasSyntaxErrors()) {
StringBuilder errorMessages = new StringBuilder();
Iterable<INode> syntaxErrors = result.getSyntaxErrors();
for (INode iNode : syntaxErrors) {
errorMessages.append(iNode.getSyntaxErrorMessage());
errorMessages.append("\n");
}
throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages);
}
if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
}
return rootASTElement;
}
use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.
the class AbstractSCTResource method attachedHelper.
@Override
protected void attachedHelper(EObject eObject) {
super.attachedHelper(eObject);
if (eObject instanceof SpecificationElement) {
Adapter parseAdapter = EcoreUtil.getExistingAdapter(eObject, ParseAdapter.class);
if (parseAdapter == null) {
parseSpecificationElement((SpecificationElement) eObject);
linkSpecificationElement((SpecificationElement) eObject);
eObject.eAdapters().add(new ParseAdapter());
}
Adapter serializeAdapter = EcoreUtil.getExistingAdapter(eObject, SerializeAdapter.class);
if (serializeAdapter == null) {
eObject.eAdapters().add(new SerializeAdapter());
}
}
}
use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.
the class AbstractSCTResource method createDiagnostic.
protected void createDiagnostic(Triple<EObject, EReference, INode> triple) {
SpecificationElement specificationElement = EcoreUtil2.getContainerOfType(triple.getFirst(), SpecificationElement.class);
DiagnosticMessage message = createDiagnosticMessage(triple);
Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData());
linkingDiagnostics.put(specificationElement, diagnostic);
}
use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.
the class STextScopeProvider method getActiveStateNormalizer.
protected List<ImportNormalizer> getActiveStateNormalizer(EObject context) {
List<ImportNormalizer> normalizer = Lists.newArrayList();
SpecificationElement contextElement = getContextElement(context);
if (contextElement == null)
return normalizer;
Region containingRegion = EcoreUtil2.getContainerOfType(contextElement, Region.class);
if (containingRegion == null)
return normalizer;
QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(containingRegion);
while (!fullyQualifiedName.getSegments().isEmpty()) {
normalizer.add(new ImportNormalizer(fullyQualifiedName, true, false));
fullyQualifiedName = fullyQualifiedName.skipLast(1);
}
return normalizer;
}
Aggregations