use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class TypeProviderTest method testExpectationRelevantExpressionType_06.
@Test
public void testExpectationRelevantExpressionType_06() throws Exception {
String clazzString = "class C<T> {\n" + " def String m(String s, Class<? extends T>[] types) {\n" + " this.m('', newArrayList)\n" + " }\n" + "}";
XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) function.getExpression();
XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
assertEquals("Class<? extends T>[]", getExpectedType(newArrayList).getSimpleName());
assertEquals("ArrayList<Class<? extends T>>", getType(newArrayList).getSimpleName());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class TypeProviderTest method testExpectationRelevantExpressionType_04.
@Test
public void testExpectationRelevantExpressionType_04() throws Exception {
String clazzString = "class C<T> {\n" + " def String m(String s, Class<T>[] types) {\n" + " this.m('', newArrayList)\n" + " }\n" + "}";
XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) function.getExpression();
XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
assertEquals("Class<T>[]", getExpectedType(newArrayList).getSimpleName());
assertEquals("ArrayList<Class<T>>", getType(newArrayList).getSimpleName());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class TypeProviderTest method testExpectationRelevantExpressionType_02.
@Test
public void testExpectationRelevantExpressionType_02() throws Exception {
String clazzString = "import java.util.Set\n" + "import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor\n" + "import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference\n" + "class C<T> extends TypeParameterSubstitutor<Set<T>> {\n" + " override substitute(LightweightTypeReference original) {\n" + " original.accept(this, newHashSet)\n" + " }" + "}";
XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) function.getExpression();
XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
XFeatureCall newHashSet = (XFeatureCall) invocation.getActualArguments().get(1);
assertEquals("newHashSet", newHashSet.getFeature().getSimpleName());
assertEquals("HashSet<T>", getType(newHashSet).getSimpleName());
assertEquals("Set<T>", getExpectedType(newHashSet).getSimpleName());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ReorderedFeatureCallArgumentsTest method toArguments.
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def void m(");
_builder.append(signature);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("m(");
_builder.append(invocation, "\t");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
final String functionString = _builder.toString();
final XtendFunction function = this.function(functionString);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XFeatureCall featureCall = ((XFeatureCall) _head);
final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
Class<? extends IFeatureCallArguments> _class = result.getClass();
boolean _equals = Objects.equal(_class, ReorderedFeatureCallArguments.class);
Assert.assertTrue(_equals);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ReorderedVarArgFeatureCallArgumentsTest method toArguments.
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def void m(");
_builder.append(signature);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("m(");
_builder.append(invocation, "\t");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
final String functionString = _builder.toString();
final XtendFunction function = this.function(functionString);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XFeatureCall featureCall = ((XFeatureCall) _head);
final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
Class<? extends IFeatureCallArguments> _class = result.getClass();
boolean _equals = Objects.equal(_class, ReorderedVarArgFeatureCallArguments.class);
Assert.assertTrue(_equals);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations