Search in sources :

Example 36 with ReplaceRegion

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

the class AbstractSmokeTest method testSkipNodesInBetween.

@Test
public void testSkipNodesInBetween() throws Exception {
    for (String string : smokeTestModels) {
        LazyLinkingResource resource = createResource(string);
        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);
                doParseAndCheckForSmoke(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 37 with ReplaceRegion

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

the class AbstractRewritableImportSectionTest method assertEquals.

protected void assertEquals(final RewritableImportSection section, final CharSequence sectionAsString) {
    final StringBuilder builder = new StringBuilder(this.model);
    final List<ReplaceRegion> changes = section.rewrite();
    final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
        return Integer.valueOf(it.getOffset());
    };
    List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
    for (final ReplaceRegion it : _reverse) {
        int _offset = it.getOffset();
        int _offset_1 = it.getOffset();
        int _length = it.getLength();
        int _plus = (_offset_1 + _length);
        builder.replace(_offset, _plus, it.getText());
    }
    Assert.assertEquals(this.processLinebreaks(this.getExpectedModel(sectionAsString.toString())), this.processLinebreaks(builder));
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion)

Example 38 with ReplaceRegion

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

the class OrganizeImportsTest method assertIsOrganizedTo.

protected void assertIsOrganizedTo(final CharSequence model, final String fileName, final CharSequence expected) {
    try {
        Assert.assertFalse(expected.toString().contains("$"));
        final XtendFile xtendFile = this._workbenchTestHelper.xtendFile(fileName, model.toString());
        Resource _eResource = xtendFile.eResource();
        final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
        final StringBuilder builder = new StringBuilder(model);
        final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
            return Integer.valueOf(it.getOffset());
        };
        List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
        for (final ReplaceRegion it : _reverse) {
            int _offset = it.getOffset();
            int _offset_1 = it.getOffset();
            int _length = it.getLength();
            int _plus = (_offset_1 + _length);
            builder.replace(_offset, _plus, it.getText());
        }
        Assert.assertEquals(expected.toString(), builder.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 39 with ReplaceRegion

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

the class OrganizeImportsTest method assertIsOrganizedWithErrorsTo.

protected void assertIsOrganizedWithErrorsTo(final CharSequence model, final CharSequence expected) {
    try {
        Assert.assertFalse(expected.toString().contains("$"));
        final XtendFile xtendFile = this.xtendFileWithError(model.toString());
        Resource _eResource = xtendFile.eResource();
        final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
        final StringBuilder builder = new StringBuilder(model);
        final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
            return Integer.valueOf(it.getOffset());
        };
        List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
        for (final ReplaceRegion it : _reverse) {
            int _offset = it.getOffset();
            int _offset_1 = it.getOffset();
            int _length = it.getLength();
            int _plus = (_offset_1 + _length);
            builder.replace(_offset, _plus, it.getText());
        }
        Assert.assertEquals(expected.toString(), builder.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 40 with ReplaceRegion

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

the class XtendValidator method checkJavaDocRefs.

@Check
public void checkJavaDocRefs(XtendMember member) {
    if (isIgnored(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC))
        return;
    List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) documentationProvider).getDocumentationNodes(member);
    for (INode node : documentationNodes) {
        for (ReplaceRegion region : javaDocTypeReferenceProvider.computeTypeRefRegions(node)) {
            String typeRefString = region.getText();
            if (typeRefString != null && typeRefString.length() > 0) {
                IScope scope = scopeProvider.getScope(member, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
                IEObjectDescription candidate = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(typeRefString));
                if (candidate == null) {
                    Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC);
                    if (severity != null)
                        getChain().add(createDiagnostic(severity, "javaDoc: " + typeRefString + " cannot be resolved to a type", member, region.getOffset(), region.getLength(), IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC));
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) IScope(org.eclipse.xtext.scoping.IScope) Severity(org.eclipse.xtext.diagnostics.Severity) RichString(org.eclipse.xtend.core.xtend.RichString) IEObjectDocumentationProviderExtension(org.eclipse.xtext.documentation.IEObjectDocumentationProviderExtension) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Check(org.eclipse.xtext.validation.Check)

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