use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class ReorderedVarArgFeatureCallArgumentsTest method test_01.
@Test
public void test_01() {
final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s, int i", "[], 1");
Assert.assertEquals(2, arguments.getArgumentCount());
Assert.assertTrue(arguments.hasUnprocessedArguments());
final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertTrue(firstSlot.isVarArg());
Assert.assertFalse(firstSlot.isSuperfluous());
XExpression _argumentExpression = firstSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression instanceof XNumberLiteral));
Assert.assertEquals("int", firstSlot.getDeclaredType().getSimpleName());
Assert.assertFalse(arguments.isProcessed(0));
firstSlot.markProcessed();
Assert.assertTrue(arguments.isProcessed(0));
Assert.assertTrue(arguments.hasUnprocessedArguments());
final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertFalse(secondSlot.isVarArg());
Assert.assertFalse(secondSlot.isSuperfluous());
XExpression _argumentExpression_1 = secondSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression_1 instanceof XClosure));
Assert.assertEquals("String", secondSlot.getDeclaredType().getSimpleName());
Assert.assertFalse(arguments.isProcessed(1));
secondSlot.markProcessed();
Assert.assertTrue(arguments.isProcessed(1));
Assert.assertFalse(arguments.hasUnprocessedArguments());
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForForXClosureVariable.
@Test
public void testSignatureForForXClosureVariable() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\t");
_builder.append("package testPackage");
_builder.newLine();
_builder.append("\t");
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("def zonk(){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("bar(s | s + \"42\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("def bar((String)=>String fun){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction xtendFunction = ((XtendFunction) _get);
XExpression _expression = xtendFunction.getExpression();
XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
XExpression _get_2 = ((XFeatureCall) _get_1).getFeatureCallArguments().get(0);
final XClosure closure = ((XClosure) _get_2);
final JvmFormalParameter param = closure.getDeclaredFormalParameters().get(0);
final String signature = this.signatureProvider.getSignature(param);
Assert.assertEquals("String s", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_017.
@Test
public void testErrorModel_017() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static extension Throwables.*");
_builder.newLine();
_builder.append("import java.net.URI");
_builder.newLine();
_builder.newLine();
_builder.append("class Throwables {");
_builder.newLine();
_builder.append("\t");
_builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("proc.apply");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch(Exception e) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw handler.apply(e)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class Client {");
_builder.newLine();
_builder.append("\t");
_builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
final XtendField field = ((XtendField) _head);
XExpression _initialValue = field.getInitialValue();
final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
final XClosure closure = ((XClosure) _head_1);
final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
Assert.assertNotNull(implicit);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_019.
@Test
public void testErrorModel_019() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package x");
_builder.newLine();
_builder.append("import bug396879.*");
_builder.newLine();
_builder.append("class Z {");
_builder.newLine();
_builder.append(" \t");
_builder.append("def addListeners(BooleanProperty prop) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val ChangeListenerBoolean> listener = [ p, oldValue, newValue | ]\t\tprop.addListener(listener)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration z = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _get = z.getMembers().get(1);
final XtendField field = ((XtendField) _get);
XExpression _initialValue = field.getInitialValue();
final XClosure closure = ((XClosure) _initialValue);
final JvmFormalParameter param = IterableExtensions.<JvmFormalParameter>head(closure.getDeclaredFormalParameters());
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(param);
Assert.assertNotNull(resolvedTypes.getActualType(param));
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class Oven method fireproof.
public void fireproof(final String input) throws Exception {
try {
final EObject file = this._parseHelper.parse(input);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
Assert.assertNotNull(resolvedTypes);
if ((file != null)) {
Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
for (final EObject content : _iterable) {
boolean _matched = false;
if (content instanceof XAbstractFeatureCall) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
boolean _tripleNotEquals = (_implicitReceiver != null);
if (_tripleNotEquals) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
}
XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
if (_tripleNotEquals_1) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof XClosure) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
};
((XClosure) content).getImplicitFormalParameters().forEach(_function);
}
}
if (!_matched) {
if (content instanceof XExpression) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof JvmIdentifiableElement) {
_matched = true;
this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
}
}
}
}
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
String _message = e.getMessage();
final ComparisonFailure error = new ComparisonFailure(_message, input, "");
error.setStackTrace(e.getStackTrace());
throw error;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
Aggregations