use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class ContentAssistFragment2 method handleAssignmentOptions.
private StringConcatenationClient handleAssignmentOptions(final Iterable<AbstractElement> terminals) {
StringConcatenationClient _xblockexpression = null;
{
final HashSet<EClass> processedTerminals = CollectionLiterals.<EClass>newHashSet();
final Function2<ArrayList<AbstractElement>, AbstractElement, ArrayList<AbstractElement>> _function = (ArrayList<AbstractElement> candidates, AbstractElement terminal) -> {
ArrayList<AbstractElement> _xblockexpression_1 = null;
{
boolean _contains = processedTerminals.contains(terminal.eClass());
boolean _not = (!_contains);
if (_not) {
EClass _eClass = terminal.eClass();
processedTerminals.add(_eClass);
candidates.add(terminal);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractElement> candidates = IterableExtensions.<AbstractElement, ArrayList<AbstractElement>>fold(terminals, CollectionLiterals.<AbstractElement>newArrayList(), _function);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
for (final AbstractElement terminal : candidates) {
_builder.append("if (assignment.getTerminal() instanceof ");
Class<?> _instanceClass = terminal.eClass().getInstanceClass();
_builder.append(_instanceClass);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("assignment.getTerminal()");
}
};
StringConcatenationClient _assignmentTerminal = ContentAssistFragment2.this.assignmentTerminal(terminal, _client);
_builder.append(_assignmentTerminal, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class DefaultEcoreElementFactoryTest method testNullInput.
@Test
public void testNullInput() throws Exception {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
final ILeafNode node = new LeafNode();
Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {
@Override
public Object apply(String lexerRule, INode nodeParam) {
if ("foo".equals(lexerRule) && nodeParam.equals(node)) {
return null;
}
fail();
return null;
}
};
DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
factory.setConverterService(new MockedConverterService(toValueImpl));
try {
factory.set(eClass, "abstract", null, "foo", node);
fail("Expected ValueConverterException");
} catch (ValueConverterException ex) {
assertNull(ex.getCause());
assertTrue(ex.getMessage().indexOf("ValueConverter returned null for") >= 0);
assertSame(node, ex.getNode());
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class DefaultEcoreElementFactoryTest method testValueConverterException.
@Test
public void testValueConverterException() throws Exception {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
final ILeafNode node = new LeafNode();
final ValueConverterException expected = new ValueConverterException("Foo", node, null);
Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {
@Override
public Object apply(String lexerRule, INode nodeParam) {
if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
throw expected;
}
fail();
return null;
}
};
DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
factory.setConverterService(new MockedConverterService(toValueImpl));
try {
factory.set(eClass, "abstract", null, "foo", node);
fail("Expected ValueConverterException");
} catch (ValueConverterException ex) {
assertSame(expected, ex);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class DefaultEcoreElementFactoryTest method testConvertNullInput.
@Test
public void testConvertNullInput() throws Exception {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {
@Override
public Object apply(String lexerRule, INode node) {
if ("foo".equals(lexerRule)) {
return "FOO";
}
return null;
}
};
DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
factory.setConverterService(new MockedConverterService(toValueImpl));
factory.set(eClass, "name", null, "foo", null);
assertEquals("FOO", eClass.getName());
}
Aggregations