Search in sources :

Example 1 with TypeParameterDeclaration

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);
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 2 with 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);
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 3 with 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);
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 4 with 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;
}
Also used : TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) TypeParameterDeclarator(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclarator) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 5 with TypeParameterDeclaration

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);
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Aggregations

TypeParameterDeclaration (org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration)6 MutableTypeParameterDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration)5 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)3 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)2 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)2 Type (org.eclipse.xtend.lib.macro.declaration.Type)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 Test (org.junit.Test)2 TypeParameterDeclarator (org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclarator)1 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)1