use of org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration in project xtext-xtend by eclipse.
the class JvmExecutableDeclarationImpl method addTypeParameter.
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
param.setName(name);
this.getDelegate().getTypeParameters().add(param);
for (final TypeReference upper : upperBounds) {
{
final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
jvmUpperBound.setTypeReference(typeRef);
param.getConstraints().add(jvmUpperBound);
}
}
TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration in project xtext-xtend by eclipse.
the class MutableJvmClassDeclarationImpl method addTypeParameter.
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
param.setName(name);
this.getDelegate().getTypeParameters().add(param);
for (final TypeReference upper : upperBounds) {
{
final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
jvmUpperBound.setTypeReference(typeRef);
param.getConstraints().add(jvmUpperBound);
}
}
TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration in project xtext-xtend by eclipse.
the class MutableJvmInterfaceDeclarationImpl method addTypeParameter.
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
param.setName(name);
this.getDelegate().getTypeParameters().add(param);
for (final TypeReference upper : upperBounds) {
{
final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
jvmUpperBound.setTypeReference(typeRef);
param.getConstraints().add(jvmUpperBound);
}
}
TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration in project xtext-xtend by eclipse.
the class TypeReferenceProviderImpl method newSelfTypeReference.
@Override
public TypeReference newSelfTypeReference(final Type typeDeclaration) {
TypeReference _xifexpression = null;
if ((typeDeclaration instanceof TypeParameterDeclarator)) {
final Function1<TypeParameterDeclaration, TypeReference> _function = (TypeParameterDeclaration it) -> {
return this.newTypeReference(it);
};
_xifexpression = this.newTypeReference(typeDeclaration, ((TypeReference[]) Conversions.unwrapArray(IterableExtensions.map(((TypeParameterDeclarator) typeDeclaration).getTypeParameters(), _function), TypeReference.class)));
} else {
_xifexpression = this.newTypeReference(typeDeclaration);
}
return _xifexpression;
}
use of org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testBug441081.
@Test
public void testBug441081() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package bug441081");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.newLine();
_builder.append("interface GenericInterface {");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T> T m()");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(Bug441081Processor)");
_builder.newLine();
_builder.append("annotation Bug441081 {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class Bug441081Processor extends AbstractClassProcessor {");
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.implementedInterfaces = annotatedClass.implementedInterfaces + #[findTypeGlobally(GenericInterface).newTypeReference]");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.addMethod(\"m\") [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("returnType = addTypeParameter(\"T\", object).newTypeReference");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("body = \'");
_builder.append("\'\'return null;\'");
_builder.append("\'\'");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("primarySourceElement = annotatedClass");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("bug441081/Bug441081.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("import bug441081.Bug441081");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@Bug441081");
_builder_1.newLine();
_builder_1.append("class Bug441081Client {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("Bug441081Client.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration c = it.getTypeLookup().findClass("Bug441081Client");
Type _type = c.findDeclaredMethod("m").getReturnType().getType();
final TypeParameterDeclaration typeParam = ((TypeParameterDeclaration) _type);
Assert.assertFalse(IterableExtensions.isEmpty(typeParam.getUpperBounds()));
this.validator.assertNoIssues(it.getXtendFile());
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Aggregations