Search in sources :

Example 26 with ICompositeNode

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

the class JavaDocTypeReferenceProviderTest method testComputation_7.

@Test
public void testComputation_7() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* {@link    String}");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        _builder.append("class Foo{}");
        _builder.newLine();
        final String input = _builder.toString();
        Resource _eResource = this.clazz(input).eResource();
        final XtextResource resource = ((XtextResource) _eResource);
        final ICompositeNode rootNode = resource.getParseResult().getRootNode();
        final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode);
        Assert.assertEquals(1, regions.size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 27 with ICompositeNode

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

the class ParserTest method testAllGrammarElementsUniqueAfterReparse.

@Test
public void testAllGrammarElementsUniqueAfterReparse() throws Exception {
    String text = "class Foo { def m() { newArrayList() } }";
    XtendClass clazz = clazz(text);
    XtextResource resource = (XtextResource) clazz.eResource();
    resource.update(text.indexOf('m'), 0, "m");
    ICompositeNode root = resource.getParseResult().getRootNode();
    assertSame(root, root.getRootNode());
    Set<EObject> grammarElements = Sets.newHashSet();
    for (INode node : root.getAsTreeIterable()) {
        if (node instanceof ICompositeNode) {
            if (node.getGrammarElement() == null) {
                fail("node without grammar element");
            }
            if (!grammarElements.add(node.getGrammarElement())) {
                fail(node.getGrammarElement().toString());
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 28 with ICompositeNode

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

the class ParserTest method testAllGrammarElementsUnique.

@Test
public void testAllGrammarElementsUnique() throws Exception {
    XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
    XtextResource resource = (XtextResource) clazz.eResource();
    ICompositeNode root = resource.getParseResult().getRootNode();
    new InvariantChecker().checkInvariant(root);
    assertSame(root, root.getRootNode());
    Set<EObject> grammarElements = Sets.newHashSet();
    for (INode node : root.getAsTreeIterable()) {
        if (node instanceof ICompositeNode) {
            if (node.getGrammarElement() == null) {
                fail("node without grammar element");
            }
            if (!grammarElements.add(node.getGrammarElement())) {
                fail(node.getGrammarElement().toString());
            }
        }
    }
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 29 with ICompositeNode

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

the class XtendHoverSerializer method computeArguments.

public String computeArguments(XAbstractFeatureCall featureCall) {
    StringBuilder stringBuilder = new StringBuilder("(");
    if (featureCall != null) {
        XExpression implicitFirstArgument = featureCall.getImplicitFirstArgument();
        List<XExpression> arguments = featureCall.getActualArguments();
        if (implicitFirstArgument != null) {
            XbaseSwitch<String> xbaseSwitch = new XtendHoverXbaseSwitch();
            String doSwitch = xbaseSwitch.doSwitch(implicitFirstArgument).trim();
            if (doSwitch != null)
                stringBuilder.append(doSwitch);
        }
        int start = implicitFirstArgument != null ? 1 : 0;
        for (int i = start; i < arguments.size(); i++) {
            if (i != 0) {
                stringBuilder.append(SEPARATOR);
            }
            XExpression expression = arguments.get(i);
            ICompositeNode node = NodeModelUtils.findActualNodeFor(expression);
            if (node != null)
                stringBuilder.append(node.getText().trim());
        }
    }
    stringBuilder.append(")");
    return stringBuilder.toString();
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 30 with ICompositeNode

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

the class XtendOutlineNodeFactory method configureNode.

private void configureNode(IOutlineNode parentNode, EObject modelElement, int inheritanceDepth, XtendEObjectNode featureNode) {
    EObject primarySourceElement = associations.getPrimarySourceElement(modelElement);
    ICompositeNode parserNode = NodeModelUtils.getNode(primarySourceElement == null ? modelElement : primarySourceElement);
    if (parserNode != null)
        featureNode.setTextRegion(parserNode.getTextRegion());
    if (isLocalElement(parentNode, modelElement))
        featureNode.setShortTextRegion(getLocationInFileProvider().getSignificantTextRegion(primarySourceElement == null ? modelElement : primarySourceElement));
    featureNode.setStatic(isStatic(modelElement));
    featureNode.setInheritanceDepth(inheritanceDepth);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

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