use of org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration in project xtext-xtend by eclipse.
the class JvmExecutableDeclarationImpl method addParameter.
public MutableParameterDeclaration addParameter(final String name, final TypeReference type) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
Preconditions.checkArgument((type != null), "type cannot be null");
boolean _isInferred = type.isInferred();
if (_isInferred) {
throw new IllegalArgumentException("Cannot use inferred type as parameter type.");
}
final JvmFormalParameter param = TypesFactory.eINSTANCE.createJvmFormalParameter();
param.setName(name);
param.setParameterType(this.getCompilationUnit().toJvmTypeReference(type));
this.getDelegate().getParameters().add(param);
ParameterDeclaration _parameterDeclaration = this.getCompilationUnit().toParameterDeclaration(param);
return ((MutableParameterDeclaration) _parameterDeclaration);
}
use of org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration in project xtext-xtend by eclipse.
the class JvmTypeDeclarationImpl method findDeclaredConstructor.
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
ConstructorDeclaration _xblockexpression = null;
{
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(parameterTypes)), "parameterTypes");
final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
return it.getType();
};
List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>) Conversions.doWrapArray(parameterTypes)));
return Boolean.valueOf(Objects.equal(_list, _list_1));
};
_xblockexpression = IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration in project xtext-xtend by eclipse.
the class DeclarationsTest method testXtendClassWithMethodFieldAndConstructor.
@Test
public void testXtendClassWithMethodFieldAndConstructor() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass<T extends CharSequence> {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("String myField");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("new(String initial) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this.myField = initial");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T2 extends CharSequence> MyClass myMethod(T2 a, T b) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("myField = myField + a + b");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return this");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertEquals("foo", it.getPackageName());
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration clazz = ((ClassDeclaration) _head);
final MutableClassDeclaration genClazz = it.getTypeLookup().findClass("foo.MyClass");
Assert.assertEquals("foo.MyClass", clazz.getQualifiedName());
Assert.assertNull(clazz.getExtendedClass());
Assert.assertTrue(IterableExtensions.isEmpty(clazz.getImplementedInterfaces()));
Assert.assertEquals(3, IterableExtensions.size(clazz.getDeclaredMembers()));
Assert.assertEquals("T", IterableExtensions.head(clazz.getTypeParameters()).getSimpleName());
Assert.assertEquals("CharSequence", IterableExtensions.head(IterableExtensions.head(clazz.getTypeParameters()).getUpperBounds()).toString());
Assert.assertSame(clazz, IterableExtensions.head(clazz.getTypeParameters()).getTypeParameterDeclarator());
final FieldDeclaration field = IterableExtensions.head(clazz.getDeclaredFields());
Assert.assertSame(clazz, field.getDeclaringType());
Assert.assertEquals("myField", field.getSimpleName());
Assert.assertEquals("String", field.getType().toString());
Assert.assertFalse(field.isFinal());
final ConstructorDeclaration constructor = IterableExtensions.head(clazz.getDeclaredConstructors());
Assert.assertSame(clazz, constructor.getDeclaringType());
Assert.assertEquals("MyClass", constructor.getSimpleName());
Assert.assertEquals("initial", IterableExtensions.head(constructor.getParameters()).getSimpleName());
Assert.assertEquals("String", IterableExtensions.head(constructor.getParameters()).getType().toString());
final MethodDeclaration method = IterableExtensions.head(clazz.getDeclaredMethods());
final MutableMethodDeclaration genMethod = IterableExtensions.head(genClazz.getDeclaredMethods());
Assert.assertSame(clazz, method.getDeclaringType());
Assert.assertEquals("a", IterableExtensions.head(method.getParameters()).getSimpleName());
Assert.assertEquals("T2", IterableExtensions.head(method.getParameters()).getType().toString());
Assert.assertSame(IterableExtensions.head(genMethod.getTypeParameters()), IterableExtensions.head(method.getParameters()).getType().getType());
Assert.assertEquals("T", ((ParameterDeclaration[]) Conversions.unwrapArray(method.getParameters(), ParameterDeclaration.class))[1].getType().toString());
Assert.assertSame(IterableExtensions.head(genClazz.getTypeParameters()), ((ParameterDeclaration[]) Conversions.unwrapArray(method.getParameters(), ParameterDeclaration.class))[1].getType().getType());
Assert.assertSame(genClazz, method.getReturnType().getType());
Assert.assertEquals("T2", IterableExtensions.head(method.getTypeParameters()).getSimpleName());
Assert.assertEquals("CharSequence", IterableExtensions.head(IterableExtensions.head(method.getTypeParameters()).getUpperBounds()).toString());
Assert.assertSame(IterableExtensions.head(method.getTypeParameters()), IterableExtensions.head(method.getTypeParameters()));
Assert.assertSame(method, IterableExtensions.head(method.getTypeParameters()).getTypeParameterDeclarator());
Assert.assertSame(field, ((Object[]) Conversions.unwrapArray(clazz.getDeclaredMembers(), Object.class))[0]);
Assert.assertSame(constructor, ((Object[]) Conversions.unwrapArray(clazz.getDeclaredMembers(), Object.class))[1]);
Assert.assertSame(method, ((Object[]) Conversions.unwrapArray(clazz.getDeclaredMembers(), Object.class))[2]);
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration in project xtext-xtend by eclipse.
the class ResolvedExecutableImpl method getResolvedParameters.
@Override
public Iterable<? extends ResolvedParameter> getResolvedParameters() {
Iterable<? extends ResolvedParameter> _xblockexpression = null;
{
if ((this.resolvedParameters == null)) {
int _size = this.getDelegate().getDeclaration().getParameters().size();
final Function1<Integer, ResolvedParameterImpl> _function = (Integer i) -> {
ParameterDeclaration _parameterDeclaration = this.getCompilationUnit().toParameterDeclaration(this.getDelegate().getDeclaration().getParameters().get((i).intValue()));
TypeReference _typeReference = this.getCompilationUnit().toTypeReference(this.getDelegate().getResolvedParameterTypes().get((i).intValue()));
return new ResolvedParameterImpl(_parameterDeclaration, _typeReference);
};
this.resolvedParameters = IterableExtensions.<Integer, ResolvedParameterImpl>map(new ExclusiveRange(0, _size, true), _function);
}
_xblockexpression = this.resolvedParameters;
}
return _xblockexpression;
}
Aggregations