Search in sources :

Example 21 with JvmTypeReference

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

the class CompilationUnitImpl method toJvmTypeReference.

public JvmTypeReference toJvmTypeReference(final TypeReference typeRef) {
    this.checkCanceled();
    JvmTypeReference _switchResult = null;
    boolean _matched = false;
    if (typeRef instanceof TypeReferenceImpl) {
        _matched = true;
        _switchResult = ((TypeReferenceImpl) typeRef).getLightweightTypeReference().toJavaCompliantTypeReference();
    }
    if (!_matched) {
        if (typeRef instanceof InferredTypeReferenceImpl) {
            _matched = true;
            _switchResult = EcoreUtil.<XComputedTypeReferenceImplCustom>copy(((InferredTypeReferenceImpl) typeRef).getDelegate());
        }
    }
    return _switchResult;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 22 with JvmTypeReference

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

the class CompilationUnitImpl method toTypeReference.

public TypeReference toTypeReference(final JvmTypeReference delegate) {
    TypeReference _xblockexpression = null;
    {
        if ((delegate == null)) {
            return null;
        }
        TypeReference _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof XComputedTypeReferenceImplCustom) {
            boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) delegate).isEquivalentComputed();
            boolean _not = (!_isEquivalentComputed);
            if (_not) {
                _matched = true;
                InferredTypeReferenceImpl _inferredTypeReferenceImpl = new InferredTypeReferenceImpl();
                final Procedure1<InferredTypeReferenceImpl> _function = (InferredTypeReferenceImpl it) -> {
                    it.setDelegate(((XComputedTypeReferenceImplCustom) delegate));
                    it.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<InferredTypeReferenceImpl>operator_doubleArrow(_inferredTypeReferenceImpl, _function);
            }
        }
        if (!_matched) {
            _switchResult = this.toTypeReference(this.typeRefFactory.toLightweightReference(delegate), delegate);
        }
        _xblockexpression = _switchResult;
    }
    return _xblockexpression;
}
Also used : XComputedTypeReferenceImplCustom(org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)

Example 23 with JvmTypeReference

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

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

the class TypeReferenceProviderImpl method createTypeRef.

public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) {
    if ((type == null)) {
        throw new NullPointerException("type");
    }
    final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
    reference.setType(type);
    for (final JvmTypeReference typeArg : typeArgs) {
        reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg));
    }
    if ((type instanceof JvmGenericType)) {
        final EList<JvmTypeParameter> list = ((JvmGenericType) type).getTypeParameters();
        if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) {
            String _identifier = ((JvmGenericType) type).getIdentifier();
            String _plus = ("The type " + _identifier);
            String _plus_1 = (_plus + " expects ");
            int _size = list.size();
            String _plus_2 = (_plus_1 + Integer.valueOf(_size));
            String _plus_3 = (_plus_2 + " type arguments, but was ");
            int _size_1 = reference.getArguments().size();
            String _plus_4 = (_plus_3 + Integer.valueOf(_size_1));
            String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number.");
            throw new IllegalArgumentException(_plus_5);
        }
    }
    return reference;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 25 with JvmTypeReference

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

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