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());
}
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;
}
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);
}
}
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);
}
}
Aggregations