org.eclipse.xtext.linking.impl.DefaultLinkingService Java Examples

The following examples show how to use org.eclipse.xtext.linking.impl.DefaultLinkingService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseTreeUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: PartialLinkingTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: DefaultRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends ILinkingService> bindILinkingService() {
	return DefaultLinkingService.class;
}
 
Example #4
Source File: EObjectUtil.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns a scope provider given a {@link org.eclipse.xtext.linking.lazy.LazyLinkingResource LazyLinkingResource}.
 *
 * @param resource
 *          the resource
 * @return the scope provider by resource
 */
public static IScopeProvider getScopeProviderByResource(final LazyLinkingResource resource) {
  return ((DefaultLinkingService) resource.getLinkingService()).getScopeProvider();
}