Search in sources :

Example 6 with ReplaceRegion

use of org.eclipse.xtext.util.ReplaceRegion in project n4js by eclipse.

the class OutlineXpectMethod method skipNodesInBetween.

private void skipNodesInBetween(Script script) throws Exception {
    if (script != null) {
        XtextResource resource = (XtextResource) script.eResource();
        ICompositeNode rootNode = resource.getParseResult().getRootNode();
        ReplaceRegion region = null;
        for (INode node : rootNode.getAsTreeIterable()) {
            if (node instanceof ICompositeNode && !(node instanceof SyntheticCompositeNode)) {
                ICompositeNode casted = (ICompositeNode) node;
                int offset = node.getTotalOffset();
                int length = node.getTotalLength();
                if (length != 0) {
                    if (casted.getFirstChild().equals(casted.getLastChild())) {
                        if (region == null || region.getOffset() != offset || region.getLength() != length) {
                            region = new ReplaceRegion(offset, length, "");
                            StringBuilder builder = new StringBuilder(rootNode.getText());
                            region.applyTo(builder);
                            processFile(builder.toString(), "skipNodesInBetween");
                        }
                    }
                }
            }
        }
    }
}
Also used : SyntheticCompositeNode(org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode) INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 7 with ReplaceRegion

use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.

the class JavaDocTypeReferenceProviderTest method testComputation_3.

@Test
public void testComputation_3() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* {@link java.util.ArrayList");
        _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(0, 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 8 with ReplaceRegion

use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.

the class JavaDocTypeReferenceProviderTest method testComputation_8.

@Test
public void testComputation_8() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @see    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 9 with ReplaceRegion

use of org.eclipse.xtext.util.ReplaceRegion 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 10 with ReplaceRegion

use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.

the class JavaDocTypeReferenceProviderTest method testComputation_5.

@Test
public void testComputation_5() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo{");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param string - a fancy string");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param anotherString-even more fancy");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param zonk");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String string, String anotherString, Integer zonk){}");
        _builder.newLine();
        _builder.append("}");
        _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.computeParameterTypeRefRegions(rootNode);
        Assert.assertEquals(3, regions.size());
        Assert.assertEquals("string", IterableExtensions.<ReplaceRegion>head(regions).getText());
        Assert.assertEquals(input.indexOf("string"), IterableExtensions.<ReplaceRegion>head(regions).getOffset());
        Assert.assertEquals("string".length(), IterableExtensions.<ReplaceRegion>head(regions).getLength());
        Assert.assertEquals("anotherString", regions.get(1).getText());
        Assert.assertEquals(input.indexOf("anotherString"), regions.get(1).getOffset());
        Assert.assertEquals("anotherString".length(), regions.get(1).getLength());
        Assert.assertEquals("zonk", regions.get(2).getText());
        Assert.assertEquals(input.indexOf("zonk"), regions.get(2).getOffset());
        Assert.assertEquals("zonk".length(), regions.get(2).getLength());
    } 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)

Aggregations

ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)52 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)20 Test (org.junit.Test)19 XtextResource (org.eclipse.xtext.resource.XtextResource)18 Resource (org.eclipse.emf.ecore.resource.Resource)13 INode (org.eclipse.xtext.nodemodel.INode)11 IParseResult (org.eclipse.xtext.parser.IParseResult)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 EObject (org.eclipse.emf.ecore.EObject)7 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)6 StringReader (java.io.StringReader)5 SyntheticCompositeNode (org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode)4 TextRegion (org.eclipse.xtext.util.TextRegion)4 List (java.util.List)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 TextEdit (org.eclipse.text.edits.TextEdit)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 PartialParsingPointers (org.eclipse.xtext.parser.impl.PartialParsingPointers)3 ITextRegion (org.eclipse.xtext.util.ITextRegion)3 ArrayList (java.util.ArrayList)2