use of org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testSetUpperBoundsForMutableTypeParameterDeclaration.
@Test
public void testSetUpperBoundsForMutableTypeParameterDeclaration() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.List");
_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.TransformationParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclarator");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(MyAnnotationProcessor)");
_builder.newLine();
_builder.append("annotation MyAnnotation {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class MyAnnotationProcessor implements TransformationParticipant<MutableTypeParameterDeclarator> {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(List<? extends MutableTypeParameterDeclarator> annotatedTargetElements,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("for (annotatedTargetElement : annotatedTargetElements) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("doTransform(annotatedTargetElement, context)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("def doTransform(MutableTypeParameterDeclarator it, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("typeParameters.head.upperBounds = #[String.newTypeReference]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/MyAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.MyAnnotation");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("class MyClass<T extends CharSequence> {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("interface MyInterface<T extends CharSequence> {");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("abstract def <T extends CharSequence> void foo();");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final Procedure1<MutableTypeParameterDeclarator> _function_1 = (MutableTypeParameterDeclarator it_1) -> {
Assert.assertEquals(1, IterableExtensions.size(it_1.getTypeParameters()));
final MutableTypeParameterDeclaration typeParameter = IterableExtensions.head(it_1.getTypeParameters());
Assert.assertEquals(1, IterableExtensions.size(typeParameter.getUpperBounds()));
Assert.assertEquals("java.lang.String", IterableExtensions.head(typeParameter.getUpperBounds()).getName());
};
final Procedure1<? super MutableTypeParameterDeclarator> assertMyAnnotationChanges = _function_1;
assertMyAnnotationChanges.apply(it.getTypeLookup().findClass("myusercode.MyClass"));
final MutableInterfaceDeclaration myInterface = it.getTypeLookup().findInterface("myusercode.MyInterface");
assertMyAnnotationChanges.apply(myInterface);
assertMyAnnotationChanges.apply(IterableExtensions.head(myInterface.getDeclaredMethods()));
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration 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.MutableTypeParameterDeclaration 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.MutableTypeParameterDeclaration 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.MutableTypeParameterDeclaration in project xtext-xtend by eclipse.
the class InferredTypeReferencesCheckProcessor method doTransform.
@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
final TypeReference type = it.findDeclaredField("foo").getType();
Assert.assertTrue(type.isInferred());
final Procedure0 _function = () -> {
it.setExtendedClass(type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as extended class.", _function);
final Procedure0 _function_1 = () -> {
Iterable<? extends TypeReference> _implementedInterfaces = it.getImplementedInterfaces();
Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_implementedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
it.setImplementedInterfaces(_plus);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as implemented interface.", _function_1);
final Procedure1<MutableMethodDeclaration> _function_2 = (MutableMethodDeclaration it_1) -> {
it_1.setReturnType(type);
final Procedure0 _function_3 = () -> {
it_1.addParameter("bar", type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_3);
final Procedure0 _function_4 = () -> {
it_1.setExceptions(type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as exception type.", _function_4);
final Procedure0 _function_5 = () -> {
it_1.addTypeParameter("T", type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_5);
MutableTypeParameterDeclaration _addTypeParameter = it_1.addTypeParameter("T");
final Procedure1<MutableTypeParameterDeclaration> _function_6 = (MutableTypeParameterDeclaration it_2) -> {
final Procedure0 _function_7 = () -> {
Iterable<? extends TypeReference> _upperBounds = it_2.getUpperBounds();
Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
it_2.setUpperBounds(_plus);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_7);
};
ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_6);
};
it.addMethod("bar", _function_2);
final Procedure1<MutableFieldDeclaration> _function_3 = (MutableFieldDeclaration field) -> {
field.setType(type);
};
it.addField("bar2", _function_3);
MutableInterfaceDeclaration _findInterface = context.findInterface("Bar");
final Procedure1<MutableInterfaceDeclaration> _function_4 = (MutableInterfaceDeclaration it_1) -> {
final Procedure0 _function_5 = () -> {
Iterable<? extends TypeReference> _extendedInterfaces = it_1.getExtendedInterfaces();
Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_extendedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
it_1.setExtendedInterfaces(_plus);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as extended interface.", _function_5);
final Procedure0 _function_6 = () -> {
it_1.addTypeParameter("T", type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_6);
MutableTypeParameterDeclaration _addTypeParameter = it_1.addTypeParameter("T");
final Procedure1<MutableTypeParameterDeclaration> _function_7 = (MutableTypeParameterDeclaration it_2) -> {
final Procedure0 _function_8 = () -> {
Iterable<? extends TypeReference> _upperBounds = it_2.getUpperBounds();
Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
it_2.setUpperBounds(_plus);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_8);
};
ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_7);
};
ObjectExtensions.<MutableInterfaceDeclaration>operator_doubleArrow(_findInterface, _function_4);
final Procedure0 _function_5 = () -> {
it.addTypeParameter("T", type);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_5);
MutableTypeParameterDeclaration _addTypeParameter = it.addTypeParameter("T");
final Procedure1<MutableTypeParameterDeclaration> _function_6 = (MutableTypeParameterDeclaration it_1) -> {
final Procedure0 _function_7 = () -> {
Iterable<? extends TypeReference> _upperBounds = it_1.getUpperBounds();
Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
it_1.setUpperBounds(_plus);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_7);
};
ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_6);
}
Aggregations