use of org.eclipse.xtend.core.xtend.XtendParameter in project xtext-xtend by eclipse.
the class LinkingTest method testBug342848_02.
@Test
public void testBug342848_02() throws Exception {
String fileAsText = "import org.eclipse.xtext.xbase.lib.Functions\n" + "class Clazz { def void method(Functions.Function0<Integer> f) { f.apply } }";
XtendFile file = file(fileAsText, true);
XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
XtendParameter parameter = function.getParameters().get(0);
String identifier = parameter.getParameterType().getIdentifier();
assertEquals(Functions.Function0.class.getName() + "<java.lang.Integer>", identifier);
}
use of org.eclipse.xtend.core.xtend.XtendParameter in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_018.
@Test
public void testErrorModel_018() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def m(@");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction function = ((XtendFunction) _head);
final XtendParameter param = IterableExtensions.<XtendParameter>head(function.getParameters());
final XAnnotation annotation = IterableExtensions.<XAnnotation>head(param.getAnnotations());
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(annotation);
Assert.assertNotNull(resolvedTypes.getActualType(annotation));
}
use of org.eclipse.xtend.core.xtend.XtendParameter in project xtext-xtend by eclipse.
the class XtendCopyQualifiedNameService method toQualifiedName.
protected String toQualifiedName(final XtendConstructor it) {
StringConcatenation _builder = new StringConcatenation();
String _fullyQualifiedName = this.toFullyQualifiedName(it);
_builder.append(_fullyQualifiedName);
_builder.append("(");
final Function1<XtendParameter, String> _function = (XtendParameter it_1) -> {
return it_1.getParameterType().getSimpleName();
};
CharSequence _qualifiedNames = this.<XtendParameter>toQualifiedNames(it.getParameters(), _function);
_builder.append(_qualifiedNames);
_builder.append(")");
return _builder.toString();
}
use of org.eclipse.xtend.core.xtend.XtendParameter in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transformCreateExtension.
protected void transformCreateExtension(XtendFunction source, CreateExtensionInfo createExtensionInfo, JvmGenericType container, JvmOperation operation, /* @Nullable */
JvmTypeReference returnType) {
JvmField cacheVar = jvmTypesBuilder.toField(source, CREATE_CHACHE_VARIABLE_PREFIX + source.getName(), jvmTypesBuilder.inferredType());
if (cacheVar != null) {
cacheVar.setFinal(true);
jvmTypesBuilder.setInitializer(cacheVar, compileStrategies.forCacheVariable(source));
container.getMembers().add(cacheVar);
JvmOperation initializer = typesFactory.createJvmOperation();
container.getMembers().add(initializer);
initializer.setSimpleName(CREATE_INITIALIZER_PREFIX + source.getName());
initializer.setVisibility(JvmVisibility.PRIVATE);
initializer.setReturnType(typeReferences.getTypeForName(Void.TYPE, source));
for (JvmTypeReference exception : source.getExceptions()) {
initializer.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
}
jvmTypesBuilder.setBody(operation, compileStrategies.forCacheMethod(createExtensionInfo, cacheVar, initializer));
// the first parameter is the created object
JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
jvmParam.setName(createExtensionInfo.getName());
// TODO consider type parameters
jvmParam.setParameterType(jvmTypesBuilder.inferredType());
initializer.getParameters().add(jvmParam);
associator.associate(createExtensionInfo, jvmParam);
// add all others
for (XtendParameter parameter : source.getParameters()) {
jvmParam = typesFactory.createJvmFormalParameter();
jvmParam.setName(parameter.getName());
jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
initializer.getParameters().add(jvmParam);
associator.associate(parameter, jvmParam);
}
associator.associate(source, initializer);
setBody(operation, createExtensionInfo.getCreateExpression());
setBody(initializer, source.getExpression());
}
}
use of org.eclipse.xtend.core.xtend.XtendParameter in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunctionWithParameter.
@Test
public void testInferredFunctionWithParameter() throws Exception {
XtendFile xtendFile = file("class Foo { def bar(Boolean baz) { true } }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
assertEquals(1, jvmOperation.getParameters().size());
JvmFormalParameter jvmParameter = jvmOperation.getParameters().get(0);
XtendParameter xtendParameter = xtendFunction.getParameters().get(0);
assertEquals(xtendParameter.getName(), jvmParameter.getSimpleName());
assertEquals(xtendParameter.getParameterType().getType(), jvmParameter.getParameterType().getType());
}
Aggregations