Search in sources :

Example 1 with Wrapping

use of org.eclipse.ceylon.compiler.java.wrapping.Wrapping in project ceylon by eclipse.

the class Wrappings method elementMapping.

static <Java, Ceylon> Wrapping<Java, Ceylon> elementMapping(TypeDescriptor $reified$Element) {
    boolean allowNull = false;
    if ($reified$Element.containsNull()) {
        allowNull = true;
        if ($reified$Element instanceof TypeDescriptor.Union && ((TypeDescriptor.Union) $reified$Element).getMembers().length == 2) {
            Union union = (TypeDescriptor.Union) $reified$Element;
            if (union.getMembers()[0].containsNull()) {
                $reified$Element = union.getMembers()[1];
            } else if (union.getMembers()[1].containsNull()) {
                $reified$Element = union.getMembers()[0];
            }
        }
    }
    Wrapping<Java, Ceylon> elementWrapping;
    if ($reified$Element == ceylon.language.Integer.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_INTEGER_OR_NULL : TO_CEYLON_INTEGER);
    } else if ($reified$Element == ceylon.language.Float.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_FLOAT_OR_NULL : TO_CEYLON_FLOAT);
    } else if ($reified$Element == ceylon.language.Byte.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_BYTE_OR_NULL : TO_CEYLON_BYTE);
    } else if ($reified$Element == ceylon.language.Boolean.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_BOOLEAN_OR_NULL : TO_CEYLON_BOOLEAN);
    } else if ($reified$Element == ceylon.language.Character.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_CHARACTER_OR_NULL : TO_CEYLON_CHARACTER);
    } else if ($reified$Element == ceylon.language.String.$TypeDescriptor$) {
        elementWrapping = (Wrapping) (allowNull ? TO_CEYLON_STRING_OR_NULL : TO_CEYLON_STRING);
    } else if ($reified$Element instanceof TypeDescriptor.Class) {
        TypeDescriptor.Class classDescriptor = (TypeDescriptor.Class) $reified$Element;
        if (classDescriptor.getKlass() == ceylon.language.List.class) {
            elementWrapping = (Wrapping) toCeylonList(classDescriptor.getTypeArgument(0), allowNull);
        } else if (classDescriptor.getKlass() == ceylon.language.Set.class) {
            elementWrapping = (Wrapping) toCeylonSet(classDescriptor.getTypeArgument(0), allowNull);
        } else if (classDescriptor.getKlass() == ceylon.language.Map.class) {
            elementWrapping = (Wrapping) toCeylonMap(classDescriptor.getTypeArgument(0), classDescriptor.getTypeArgument(1), allowNull);
        } else {
            elementWrapping = allowNull ? MAYBE_IDENTITY : DEFINITE_IDENTITY;
        }
    } else {
        elementWrapping = allowNull ? MAYBE_IDENTITY : DEFINITE_IDENTITY;
    }
    return elementWrapping;
}
Also used : WrappedJavaSet(org.eclipse.ceylon.compiler.java.wrapping.WrappedJavaSet) WrappedCeylonSet(org.eclipse.ceylon.compiler.java.wrapping.WrappedCeylonSet) Union(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor.Union) Wrapping(org.eclipse.ceylon.compiler.java.wrapping.Wrapping) Union(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor.Union) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)

Aggregations

TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)1 Union (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor.Union)1 WrappedCeylonSet (org.eclipse.ceylon.compiler.java.wrapping.WrappedCeylonSet)1 WrappedJavaSet (org.eclipse.ceylon.compiler.java.wrapping.WrappedJavaSet)1 Wrapping (org.eclipse.ceylon.compiler.java.wrapping.Wrapping)1