Search in sources :

Example 26 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class MutableJvmInterfaceDeclarationImpl method setExtendedInterfaces.

@Override
public void setExtendedInterfaces(final Iterable<? extends TypeReference> superinterfaces) {
    this.checkMutable();
    ConditionUtils.checkIterable(superinterfaces, "superinterfaces");
    this.getDelegate().getSuperTypes().clear();
    for (final TypeReference typeRef : superinterfaces) {
        {
            boolean _isInferred = typeRef.isInferred();
            if (_isInferred) {
                throw new IllegalArgumentException("Cannot use inferred type as extended interface.");
            }
            EList<JvmTypeReference> _superTypes = this.getDelegate().getSuperTypes();
            JvmTypeReference _jvmTypeReference = this.getCompilationUnit().toJvmTypeReference(typeRef);
            _superTypes.add(_jvmTypeReference);
        }
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 27 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference 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 28 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class AnnotationValidation method isValidAnnotationValueType.

public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
    JvmTypeReference _switchResult = null;
    boolean _matched = false;
    if (reference instanceof JvmGenericArrayTypeReference) {
        _matched = true;
        _switchResult = ((JvmGenericArrayTypeReference) reference).getComponentType();
    }
    if (!_matched) {
        _switchResult = reference;
    }
    final JvmTypeReference toCheck = _switchResult;
    if ((toCheck == null)) {
        return true;
    }
    JvmType _type = toCheck.getType();
    if ((_type instanceof JvmPrimitiveType)) {
        return true;
    }
    JvmType _type_1 = toCheck.getType();
    if ((_type_1 instanceof JvmEnumerationType)) {
        return true;
    }
    JvmType _type_2 = toCheck.getType();
    if ((_type_2 instanceof JvmAnnotationType)) {
        return true;
    }
    if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
        return true;
    }
    return false;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmPrimitiveType(org.eclipse.xtext.common.types.JvmPrimitiveType) JvmType(org.eclipse.xtext.common.types.JvmType) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Example 29 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference 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());
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 30 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
    inferredJvmType.setAbstract(true);
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField) {
            XtendField field = (XtendField) member;
            if (!Strings.isEmpty(field.getName())) {
                JvmOperation operation = typesFactory.createJvmOperation();
                associator.associatePrimary(member, operation);
                operation.setSimpleName(field.getName());
                JvmTypeReference returnType = null;
                XExpression initialValue = field.getInitialValue();
                if (field.getType() != null) {
                    returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
                } else if (initialValue != null) {
                    returnType = jvmTypesBuilder.inferredType(initialValue);
                }
                operation.setReturnType(returnType);
                if (initialValue != null) {
                    JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
                    if (jvmAnnotationValue != null) {
                        operation.setDefaultValue(jvmAnnotationValue);
                        jvmAnnotationValue.setOperation(operation);
                    }
                    jvmTypesBuilder.setBody(operation, initialValue);
                }
                operation.setVisibility(JvmVisibility.PUBLIC);
                translateAnnotationsTo(member.getAnnotations(), operation);
                jvmTypesBuilder.copyDocumentationTo(member, operation);
                inferredJvmType.getMembers().add(operation);
            }
        }
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)194 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)68 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)22 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12