use of org.eclipse.xtext.resource.XtextResource in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method getScope.
/**
* Returns a scope for a given context object and EReference, using a named scope definition. If none is found
* tries to find a scope (using the same name) for the type of the reference.
*
* @param context
* the context
* @param reference
* the reference
* @param scopeName
* the scope name
* @param originalResource
* the original resource
* @return the scope
*/
public IScope getScope(final EObject context, final EReference reference, final String scopeName, final Resource originalResource) {
if (context.eResource() != originalResource && context.eResource() instanceof XtextResource) {
registerForeignObject(context, (XtextResource) context.eResource(), originalResource);
}
String nameToFind = scopeName == null ? SCOPE_STRING : scopeName;
IScope scope = internalGetScope(context, reference, nameToFind, originalResource);
if (scope == null) {
scope = internalGetScope(context, reference.getEReferenceType(), nameToFind, originalResource);
}
return (scope == null) ? IScope.NULLSCOPE : scope;
}
use of org.eclipse.xtext.resource.XtextResource in project statecharts by Yakindu.
the class AsyncXtextContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
if (getContentProposalProvider() == null)
return null;
IXtextDocument document = (IXtextDocument) viewer.getDocument();
final CancelableCompletionProposalComputer computer = createCompletionProposalComputer(viewer, offset);
ICompletionProposal[] result = document.readOnly(new CancelableUnitOfWork<ICompletionProposal[], XtextResource>() {
@Override
public ICompletionProposal[] exec(XtextResource state, CancelIndicator cancelIndicator) throws Exception {
computer.setCancelIndicator(cancelIndicator);
try {
return computer.exec(state);
} catch (Throwable t) {
return new ICompletionProposal[] {};
}
}
});
Arrays.sort(result, getCompletionProposalComparator());
result = getCompletionProposalPostProcessor().postProcess(result);
return result;
}
use of org.eclipse.xtext.resource.XtextResource in project statecharts by Yakindu.
the class AbstractSGenTest method parseExpression.
protected EObject parseExpression(String expression, String ruleName) {
XtextResource resource = resourceProvider.get();
resource.setURI(URI.createPlatformPluginURI("path", 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();
linker.linkModel(result.getRootASTElement(), diagnosticsConsumer);
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 RuntimeException("Could not parse expression, syntax errors: " + errorMessages);
}
if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
throw new RuntimeException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
}
return rootASTElement;
}
use of org.eclipse.xtext.resource.XtextResource in project statecharts by Yakindu.
the class XtextStyledTextSelectionProvider method getSelection.
public ISelection getSelection() {
if (styledText.isDisposed())
return StructuredSelection.EMPTY;
int offset = styledText.getCaretOffset() - 1;
XtextResource fakeResource = xtextResource;
IParseResult parseResult = fakeResource.getParseResult();
if (parseResult == null)
return StructuredSelection.EMPTY;
ICompositeNode rootNode = parseResult.getRootNode();
ILeafNode selectedNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
final EObject selectedObject = NodeModelUtils.findActualSemanticObjectFor(selectedNode);
if (selectedObject == null) {
return StructuredSelection.EMPTY;
}
return new StructuredSelection(selectedObject);
}
use of org.eclipse.xtext.resource.XtextResource in project dsl-devkit by dsldevkit.
the class CatalogFromExtensionPointScope method getAllLocalElements.
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
loadDefinitions();
if (loadedModel == null) {
return ImmutableList.of();
}
XtextResource resource = (XtextResource) loadedModel.eResource();
IQualifiedNameProvider nameProvider = resource.getResourceServiceProvider().get(IQualifiedNameProvider.class);
return Scopes.scopedElementsFor(ImmutableList.of(loadedModel), nameProvider);
}
Aggregations