use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class VarArgFeatureCallArgumentsTest method test_03.
@Test
public void test_03() {
final IFeatureCallArguments arguments = this.toArgumentsWithoutReceiver("String s", "\"\"");
Assert.assertTrue(arguments.hasUnprocessedArguments());
Assert.assertEquals(1, arguments.getArgumentCount());
final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertTrue(singleSlot.isVarArg());
Assert.assertFalse(singleSlot.isSuperfluous());
XExpression _argumentExpression = singleSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
Assert.assertEquals("String", singleSlot.getDeclaredType().getSimpleName());
singleSlot.markProcessed();
Assert.assertFalse(arguments.hasUnprocessedArguments());
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class VarArgFeatureCallArgumentsTest method test_08.
@Test
public void test_08() {
final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int i", "\"\", 1");
Assert.assertEquals(3, arguments.getArgumentCount());
Assert.assertTrue(arguments.hasUnprocessedArguments());
final IFeatureCallArgumentSlot firstSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertFalse(firstSlot.isVarArg());
Assert.assertFalse(firstSlot.isSuperfluous());
XExpression _argumentExpression = firstSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
Assert.assertEquals("String", firstSlot.getDeclaredType().getSimpleName());
Assert.assertTrue(arguments.isProcessed(0));
Assert.assertFalse(arguments.isProcessed(1));
firstSlot.markProcessed();
Assert.assertTrue(arguments.isProcessed(1));
Assert.assertTrue(arguments.hasUnprocessedArguments());
final IFeatureCallArgumentSlot secondSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertTrue(secondSlot.isVarArg());
Assert.assertFalse(secondSlot.isSuperfluous());
XExpression _argumentExpression_1 = secondSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression_1 instanceof XNumberLiteral));
Assert.assertEquals("int", secondSlot.getDeclaredType().getSimpleName());
Assert.assertFalse(arguments.isProcessed(2));
secondSlot.markProcessed();
Assert.assertTrue(arguments.isProcessed(2));
Assert.assertFalse(arguments.hasUnprocessedArguments());
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference.
@Test
public void testOverriddenMethodTypeArgumentInference() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Iterable<String>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFunction function = this.function(_builder.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
Assert.assertEquals("Iterable<String>", resolvedTypes.getActualType(operation).toString());
XExpression _expression = function.getExpression();
XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
Assert.assertEquals("Iterator<String>", resolvedTypes.getActualType(overriding).toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference_2.
@Test
public void testOverriddenMethodTypeArgumentInference_2() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def <T> foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Iterable<T>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFunction function = this.function(_builder.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
Assert.assertEquals("Iterable<T>", resolvedTypes.getActualType(operation).toString());
XExpression _expression = function.getExpression();
XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
Assert.assertEquals("Iterator<T>", resolvedTypes.getActualType(overriding).toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class AmbiguityValidationTest method assertAmbiguous.
protected void assertAmbiguous(final CharSequence contents, final String... messageParts) {
final XtendFile file = this.getParsedXtendFile(contents);
final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
Assert.assertEquals(errors.toString(), 1, errors.size());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
Assert.assertEquals(singleError.getMessage(), IssueCodes.AMBIGUOUS_FEATURE_CALL, singleError.getCode());
final Function1<String, String> _function = (String it) -> {
return Strings.toUnixLineSeparator(it);
};
final Consumer<String> _function_1 = (String it) -> {
final String message = singleError.getMessage();
boolean _contains = message.contains(it);
boolean _not = (!_contains);
if (_not) {
Assert.assertEquals(it, message);
}
};
ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
final XtendFunction firstMember = ((XtendFunction) _head_1);
XExpression _expression = firstMember.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
Assert.assertTrue((linkingCandidate instanceof IAmbiguousLinkingCandidate));
}
Aggregations