use of org.eclipse.xtext.linking.impl.DefaultLinkingService in project xtext-core by eclipse.
the class PartialLinkingTest method replaceLinker.
protected void replaceLinker(XtextResource resource) {
Linker linker = new Linker();
DefaultLinkingService linkingService = new DefaultLinkingService();
getInjector().injectMembers(linkingService);
linkingService.setScopeProvider(this);
linker.setLinkingService(linkingService);
linker.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
linker.setLinkingHelper(getInjector().getInstance(LinkingHelper.class));
resource.setLinker(linker);
}
use of org.eclipse.xtext.linking.impl.DefaultLinkingService in project dsl-devkit by dsldevkit.
the class ParseTreeUtil method getParsedStringUnchecked.
/**
* Returns the source text assigned to the given feature of the given object. Does not work for multi-valued features. Optionally also converts the source
* text using the corresponding value converter. Conversion is only performed for keywords, rule call or cross reference grammar rules.
* <p>
* This method does not perform a check to make sure the feature matches the given object.
*
* @param object
* the semantic object
* @param feature
* the feature to be considered when parsing the parse tree model
* @param convert
* {@code true} if the parsed string needs conversion using its value converter
* @return the parsed string from the node model
*/
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
if (node != null) {
if (convert) {
final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
EObject grammarElement = node.getGrammarElement();
if (res != null && (grammarElement instanceof Keyword || grammarElement instanceof RuleCall || grammarElement instanceof CrossReference)) {
final DefaultLinkingService linkingService = (DefaultLinkingService) res.getLinkingService();
return linkingService.getCrossRefNodeAsString(node);
}
}
// result may contain escape sequences or quotes
return NodeModelUtils.getTokenText(node);
}
return null;
}
Aggregations