Search in sources :

Example 1 with DefaultLinkingService

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);
}
Also used : DefaultLinkingService(org.eclipse.xtext.linking.impl.DefaultLinkingService) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) LinkingHelper(org.eclipse.xtext.linking.impl.LinkingHelper) Linker(org.eclipse.xtext.linking.impl.Linker)

Example 2 with DefaultLinkingService

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;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Keyword(org.eclipse.xtext.Keyword) DefaultLinkingService(org.eclipse.xtext.linking.impl.DefaultLinkingService) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

DefaultLinkingService (org.eclipse.xtext.linking.impl.DefaultLinkingService)2 EObject (org.eclipse.emf.ecore.EObject)1 CrossReference (org.eclipse.xtext.CrossReference)1 Keyword (org.eclipse.xtext.Keyword)1 RuleCall (org.eclipse.xtext.RuleCall)1 Linker (org.eclipse.xtext.linking.impl.Linker)1 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)1 LinkingHelper (org.eclipse.xtext.linking.impl.LinkingHelper)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 INode (org.eclipse.xtext.nodemodel.INode)1