Search in sources :

Example 1 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.

the class AbstractSmokeTest method testSkipNodesInBetween.

@Test
public void testSkipNodesInBetween() throws Exception {
    for (String string : getSmokeTestModels()) {
        LazyLinkingResource resource = createResource(string);
        if (resource != null) {
            ICompositeNode rootNode = resource.getParseResult().getRootNode();
            ReplaceRegion replaceRegion = null;
            for (INode node : rootNode.getAsTreeIterable()) {
                int offset = node.getTotalOffset();
                int length = node.getTotalLength();
                if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
                    replaceRegion = new ReplaceRegion(offset, length, "");
                    StringBuilder builder = new StringBuilder(string);
                    replaceRegion.applyTo(builder);
                    processModel(builder.toString());
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 2 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.

the class DefaultTextEditComposer method beginRecording.

@Override
public void beginRecording(Resource newResource) {
    reset();
    if (newResource != resource) {
        if (resource != null)
            resource.eAdapters().remove(this);
        newResource.eAdapters().add(this);
        resource = newResource;
    }
    if (resource.getContents().isEmpty()) {
        resourceSize = 0;
    } else {
        final EObject root = resource.getContents().get(0);
        ICompositeNode rootNode = NodeModelUtils.getNode(root);
        if (rootNode == null) {
            throw new IllegalStateException("Cannot find root node in resource " + resource.getURI());
        }
        resourceSize = rootNode.getTotalLength();
    }
    recording = true;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 3 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.

the class XbaseProposalProvider method completeXFeatureCall_Feature.

@Override
public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model != null) {
        if (typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN)) {
            return;
        }
    }
    if (model instanceof XMemberFeatureCall) {
        ICompositeNode node = NodeModelUtils.getNode(model);
        int endOffset = node.getEndOffset();
        if (isInMemberFeatureCall(model, endOffset, context)) {
            return;
        }
    }
    createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
Also used : XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 4 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.

the class XtextOutlineTreeProvider method createRuleNode.

protected void createRuleNode(IOutlineNode parentNode, AbstractRule rule, boolean isShowGrammar, boolean isLocalRule) {
    StyledString text = (StyledString) textDispatcher.invoke(rule);
    if (isShowGrammar) {
        EObject grammar = rule.eContainer();
        if (grammar instanceof Grammar)
            text.append(new StyledString(" (" + ((Grammar) grammar).getName() + ")", StyledString.COUNTER_STYLER));
    }
    Image image = imageDispatcher.invoke(rule);
    RuleNode ruleNode = new RuleNode(rule, parentNode, image, text, isLeafDispatcher.invoke(rule));
    ruleNode.setFullText(new StyledString().append(text).append(getReturnTypeText(rule)));
    if (isLocalRule) {
        ICompositeNode parserNode = NodeModelUtils.getNode(rule);
        if (parserNode != null)
            ruleNode.setTextRegion(parserNode.getTextRegion());
        ruleNode.setShortTextRegion(locationInFileProvider.getSignificantTextRegion(rule));
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) StyledString(org.eclipse.jface.viewers.StyledString) Grammar(org.eclipse.xtext.Grammar) Image(org.eclipse.swt.graphics.Image)

Example 5 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.

the class XtextGrammarQuickfixProvider method fixUnresolvedRule.

@Fix(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE)
public void fixUnresolvedRule(final Issue issue, IssueResolutionAcceptor acceptor) {
    final String ruleName = issue.getData()[0];
    acceptor.accept(issue, "Create rule '" + ruleName + "'", "Create rule '" + ruleName + "'", NULL_QUICKFIX_IMAGE, new ISemanticModification() {

        @Override
        public void apply(final EObject element, IModificationContext context) throws BadLocationException {
            AbstractRule abstractRule = EcoreUtil2.getContainerOfType(element, ParserRule.class);
            ICompositeNode node = NodeModelUtils.getNode(abstractRule);
            int offset = node.getEndOffset();
            StringBuilder builder = new StringBuilder("\n\n");
            if (abstractRule instanceof TerminalRule)
                builder.append("terminal ");
            String newRule = builder.append(ruleName).append(":\n\t\n;").toString();
            context.getXtextDocument().replace(offset, 0, newRule);
        }
    });
    createLinkingIssueResolutions(issue, acceptor);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule) BadLocationException(org.eclipse.jface.text.BadLocationException) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)263 Test (org.junit.Test)87 INode (org.eclipse.xtext.nodemodel.INode)79 EObject (org.eclipse.emf.ecore.EObject)70 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)57 XtextResource (org.eclipse.xtext.resource.XtextResource)41 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)24 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)20 Resource (org.eclipse.emf.ecore.resource.Resource)19 Model (org.eclipse.xtext.valueconverter.bug250313.Model)15 IParseResult (org.eclipse.xtext.parser.IParseResult)14 ParserRule (org.eclipse.xtext.ParserRule)12 ITextRegion (org.eclipse.xtext.util.ITextRegion)12 RuleCall (org.eclipse.xtext.RuleCall)11 CrossReference (org.eclipse.xtext.CrossReference)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)8 AbstractRule (org.eclipse.xtext.AbstractRule)8 Keyword (org.eclipse.xtext.Keyword)8