Search in sources :

Example 6 with Triple

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

the class LazyLinkingResourceTest method testWarningInsteadOfError.

@Test
public void testWarningInsteadOfError() throws Exception {
    final EAnnotation source = EcoreFactory.eINSTANCE.createEAnnotation();
    LazyLinkingResource res = new LazyLinkingResource();
    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 Collections.emptyList();
        }
    });
    res.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider() {

        @Override
        public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
            return new DiagnosticMessage("myMessage", Severity.WARNING, null);
        }
    });
    assertTrue(res.getWarnings().isEmpty());
    assertNull(res.getEObject("foo"));
    assertEquals(1, res.getWarnings().size());
    assertTrue(res.getErrors().isEmpty());
    assertEquals("myMessage", res.getWarnings().get(0).getMessage());
}
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) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) 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) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 7 with Triple

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

the class ImportsAwareClipboardAction method createClipboardData.

private XbaseClipboardData createClipboardData() {
    try {
        IEditorInput editorInput = getTextEditor().getEditorInput();
        final String sourceIdentifier = editorInput != null ? editorInput.toString() : "nullEditorInput";
        IXtextDocument document = getXtextDocument();
        final ISelection selection = getTextEditor().getSelectionProvider().getSelection();
        if (selection instanceof ITextSelection && !selection.isEmpty()) {
            final ITextSelection textSelection = (ITextSelection) selection;
            return document.readOnly(new IUnitOfWork<XbaseClipboardData, XtextResource>() {

                @Override
                public XbaseClipboardData exec(XtextResource state) throws Exception {
                    ITextRegion region = new TextRegion(textSelection.getOffset(), textSelection.getLength() - 1);
                    Triple<Set<String>, Set<String>, Set<String>> imports = importsUtil.collectImports(state, region);
                    XbaseClipboardData clipboardData = new XbaseClipboardData(sourceIdentifier, Iterables.toArray(imports.getFirst(), String.class), Iterables.toArray(imports.getSecond(), String.class), Iterables.toArray(imports.getThird(), String.class));
                    return clipboardData;
                }
            });
        }
    } catch (Exception e) {
        // TODO Log exception
        return null;
    }
    return null;
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) Triple(org.eclipse.xtext.util.Triple) ITextRegion(org.eclipse.xtext.util.ITextRegion) ISelection(org.eclipse.jface.viewers.ISelection) IEditorInput(org.eclipse.ui.IEditorInput) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 8 with Triple

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

the class BoundTypeArgumentMergerTest method mergeSuccessive.

public LightweightMergedBoundTypeArgument mergeSuccessive(final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
    try {
        int _length = mergeUs.length;
        boolean _greaterThan = (_length > 2);
        Assert.assertTrue(_greaterThan);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void method(");
        final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
            return it.getFirst();
        };
        String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function);
        _builder.append(_join);
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
        final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
            final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
            Object _object = new Object();
            VarianceInfo _second = input.getSecond();
            VarianceInfo _third = input.getThird();
            LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _object, _second, _third);
            mergable.add(_lightweightBoundTypeArgument);
        };
        IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
        final Iterator<LightweightBoundTypeArgument> iterator = mergable.iterator();
        LightweightBoundTypeArgument first = iterator.next();
        LightweightBoundTypeArgument second = iterator.next();
        LightweightMergedBoundTypeArgument merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
        while (iterator.hasNext()) {
            {
                LightweightTypeReference _typeReference = merged.getTypeReference();
                Object _object = new Object();
                VarianceInfo _variance = merged.getVariance();
                VarianceInfo _variance_1 = merged.getVariance();
                LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_typeReference, null, _object, _variance, _variance_1);
                first = _lightweightBoundTypeArgument;
                second = iterator.next();
                merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
            }
        }
        return merged;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Triple(org.eclipse.xtext.util.Triple) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightMergedBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 9 with Triple

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

the class BoundTypeArgumentMergerTest method mergeWithSource.

public LightweightMergedBoundTypeArgument mergeWithSource(final Object source, final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void method(");
        final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
            return it.getFirst();
        };
        String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function);
        _builder.append(_join);
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
        final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
            final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
            Object _elvis = null;
            if (source != null) {
                _elvis = source;
            } else {
                Object _object = new Object();
                _elvis = _object;
            }
            VarianceInfo _second = input.getSecond();
            VarianceInfo _third = input.getThird();
            LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _elvis, _second, _third);
            mergable.add(_lightweightBoundTypeArgument);
        };
        IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
        return this.merger.merge(mergable, this.getOwner());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Triple(org.eclipse.xtext.util.Triple) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

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