Search in sources :

Example 1 with Triple

use of org.eclipse.xtext.util.Triple in project xtext-core by eclipse.

the class OverriddenValueInspectorTest method testFragment_03.

@Test
public void testFragment_03() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("First : Named;");
    _builder.newLine();
    _builder.append("fragment Named: name=ID Named;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function).toString(), 0, this.warnings.size());
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
    final ParserRule fragment = ((ParserRule) _findRuleForName_1);
    this.validateRule(fragment);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function_1 = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function_1).toString(), 2, this.warnings.size());
}
Also used : Triple(org.eclipse.xtext.util.Triple) ParserRule(org.eclipse.xtext.ParserRule) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Example 2 with Triple

use of org.eclipse.xtext.util.Triple in project xtext-core by eclipse.

the class LazyLinkingResourceTest method testEObjectReference.

@Test
public void testEObjectReference() throws Exception {
    final EAnnotation source = EcoreFactory.eINSTANCE.createEAnnotation();
    final EObject referencedObject = XtextFactory.eINSTANCE.createGrammar();
    LazyLinkingResource res = new LazyLinkingResource();
    res.setLinkingHelper(new LinkingHelper() {

        @Override
        public String getCrossRefNodeAsString(INode node, boolean convert) {
            return node.getText();
        }
    });
    res.setEncoder(new LazyURIEncoder() {

        @Override
        public boolean isCrossLinkFragment(Resource res, String s) {
            return "foo".equals(s);
        }

        @Override
        public Triple<EObject, EReference, INode> decode(Resource res, String uriFragment) {
            return Tuples.create((EObject) source, EcorePackage.Literals.EANNOTATION__REFERENCES, (INode) new LeafNode());
        }
    });
    res.setLinkingService(new ILinkingService() {

        @Override
        public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
            return Lists.newArrayList(referencedObject);
        }
    });
    res.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
    assertEquals(referencedObject, res.getEObject("foo"));
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Resource(org.eclipse.emf.ecore.resource.Resource) Triple(org.eclipse.xtext.util.Triple) EAnnotation(org.eclipse.emf.ecore.EAnnotation) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) IllegalNodeException(org.eclipse.xtext.linking.impl.IllegalNodeException) ILinkingService(org.eclipse.xtext.linking.ILinkingService) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) List(java.util.List) InternalEList(org.eclipse.emf.ecore.util.InternalEList) LinkingHelper(org.eclipse.xtext.linking.impl.LinkingHelper) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 3 with Triple

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

the class ActualTypeArgumentCollectorTest method assertMapping.

public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> assertMapping(final Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mapping, final String typeParamName, final Triple<String, VarianceInfo, VarianceInfo>... mappedTypes) {
    final Set<JvmTypeParameter> allKeys = mapping.keySet();
    for (final JvmTypeParameter key : allKeys) {
        String _simpleName = key.getSimpleName();
        boolean _equals = Objects.equal(_simpleName, typeParamName);
        if (_equals) {
            Assert.assertNotNull(mappedTypes);
            final List<LightweightBoundTypeArgument> mappingData = mapping.get(key);
            final Function1<LightweightBoundTypeArgument, String> _function = (LightweightBoundTypeArgument it) -> {
                StringConcatenation _builder = new StringConcatenation();
                LightweightTypeReference _typeReference = it.getTypeReference();
                _builder.append(_typeReference);
                _builder.append("(");
                VarianceInfo _declaredVariance = it.getDeclaredVariance();
                _builder.append(_declaredVariance);
                _builder.append("/");
                VarianceInfo _actualVariance = it.getActualVariance();
                _builder.append(_actualVariance);
                _builder.append(")");
                return _builder.toString();
            };
            Assert.assertEquals(ListExtensions.<LightweightBoundTypeArgument, String>map(mappingData, _function).toString(), ((List<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)).size(), mappingData.size());
            final Function1<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>> _function_1 = (LightweightBoundTypeArgument it) -> {
                return Tuples.<String, VarianceInfo, VarianceInfo>create(it.getTypeReference().toString(), it.getDeclaredVariance(), it.getActualVariance());
            };
            Assert.assertEquals(IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes))), IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(ListExtensions.<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>>map(mappingData, _function_1)));
            return mapping;
        }
    }
    if ((mappedTypes != null)) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("No mapping for ");
        _builder.append(typeParamName);
        _builder.append(" in ");
        final Function1<JvmTypeParameter, String> _function_2 = (JvmTypeParameter it) -> {
            return it.getSimpleName();
        };
        Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function_2);
        _builder.append(_map);
        Assert.fail(_builder.toString());
    }
    return mapping;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Triple(org.eclipse.xtext.util.Triple) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 4 with Triple

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

the class DeferredTypeParameterHintCollectorTest method like.

public List<LightweightBoundTypeArgument> like(final List<LightweightBoundTypeArgument> mappingData, final Triple<String, VarianceInfo, VarianceInfo>... mappedTypes) {
    final Function1<LightweightBoundTypeArgument, String> _function = (LightweightBoundTypeArgument it) -> {
        StringConcatenation _builder = new StringConcatenation();
        String _string = it.getTypeReference().toString();
        _builder.append(_string);
        _builder.append("(");
        VarianceInfo _declaredVariance = it.getDeclaredVariance();
        _builder.append(_declaredVariance);
        _builder.append("/");
        VarianceInfo _actualVariance = it.getActualVariance();
        _builder.append(_actualVariance);
        _builder.append(")");
        return _builder.toString();
    };
    Assert.assertEquals(ListExtensions.<LightweightBoundTypeArgument, String>map(mappingData, _function).toString(), ((List<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)).size(), mappingData.size());
    List<Triple<String, VarianceInfo, VarianceInfo>> _list = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)));
    final Function1<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>> _function_1 = (LightweightBoundTypeArgument it) -> {
        return Tuples.<String, VarianceInfo, VarianceInfo>create(it.getTypeReference().toString(), it.getDeclaredVariance(), it.getActualVariance());
    };
    Assert.assertEquals(((Object) _list), IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(ListExtensions.<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>>map(mappingData, _function_1)));
    return mappingData;
}
Also used : Triple(org.eclipse.xtext.util.Triple) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 5 with Triple

use of org.eclipse.xtext.util.Triple in project xtext-core by eclipse.

the class OverriddenValueInspectorTest method testFragment_04.

@Test
public void testFragment_04() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate metamodel \'foo.sample\'");
    _builder.newLine();
    _builder.append("First : Named;");
    _builder.newLine();
    _builder.append("fragment Named: name=ID NamedAgain;");
    _builder.newLine();
    _builder.append("fragment NamedAgain returns Named: Named;");
    _builder.newLine();
    String grammarAsString = _builder.toString();
    final Grammar grammar = this.getGrammar(grammarAsString);
    AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
    final ParserRule rule = ((ParserRule) _findRuleForName);
    this.validateRule(rule);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function).toString(), 0, this.warnings.size());
    AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
    final ParserRule fragment = ((ParserRule) _findRuleForName_1);
    this.validateRule(fragment);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function_1 = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function_1).toString(), 2, this.warnings.size());
    AbstractRule _findRuleForName_2 = GrammarUtil.findRuleForName(grammar, "NamedAgain");
    final ParserRule otherFragment = ((ParserRule) _findRuleForName_2);
    this.validateRule(otherFragment);
    final Function1<Triple<String, EObject, EStructuralFeature>, String> _function_2 = (Triple<String, EObject, EStructuralFeature> it) -> {
        return it.getFirst();
    };
    Assert.assertEquals(ListExtensions.<Triple<String, EObject, EStructuralFeature>, String>map(this.warnings, _function_2).toString(), 0, this.warnings.size());
}
Also used : Triple(org.eclipse.xtext.util.Triple) ParserRule(org.eclipse.xtext.ParserRule) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test) AbstractXtextRuleInspectorTest(org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)

Aggregations

Triple (org.eclipse.xtext.util.Triple)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 EObject (org.eclipse.emf.ecore.EObject)4 LightweightBoundTypeArgument (org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)4 VarianceInfo (org.eclipse.xtext.xbase.typesystem.util.VarianceInfo)4 Test (org.junit.Test)4 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)3 List (java.util.List)2 EAnnotation (org.eclipse.emf.ecore.EAnnotation)2 EReference (org.eclipse.emf.ecore.EReference)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 Grammar (org.eclipse.xtext.Grammar)2 ParserRule (org.eclipse.xtext.ParserRule)2 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2