Search in sources :

Example 21 with ICompositeNode

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

the class XtendLocationInFileProvider method getSignificantTextRegion.

@Override
public ITextRegion getSignificantTextRegion(EObject element) {
    if (element instanceof RichStringLiteral) {
        ICompositeNode elementNode = findNodeFor(element);
        if (elementNode == null) {
            return ITextRegion.EMPTY_REGION;
        }
        ITextRegion result = ITextRegion.EMPTY_REGION;
        for (INode node : elementNode.getLeafNodes()) {
            if (isHidden(node)) {
                continue;
            }
            EObject grammarElement = node.getGrammarElement();
            if (!(grammarElement instanceof RuleCall)) {
                continue;
            }
            RuleCall ruleCall = (RuleCall) grammarElement;
            ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
            int offset = region.getOffset();
            int length = region.getLength();
            if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 6;
            } else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 2;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 5;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 3;
            } else {
                continue;
            }
            result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber())));
        }
        return result;
    }
    return super.getSignificantTextRegion(element);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) RuleCall(org.eclipse.xtext.RuleCall) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

Example 22 with ICompositeNode

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

the class XtendHighlightingCalculator method highlightDeprecatedXtendAnnotationTarget.

protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)) {
        if (target instanceof XtendConstructor) {
            ICompositeNode compositeNode = NodeModelUtils.getNode(target);
            for (ILeafNode leaf : compositeNode.getLeafNodes()) {
                if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) {
                    highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
                    highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID);
                    return;
                }
            }
        } else {
            EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name");
            if (nameFeature != null) {
                highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 23 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode 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)

Example 24 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode 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 25 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode 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)

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