Search in sources :

Example 6 with Ignore

use of org.eclipse.ceylon.compiler.java.metadata.Ignore in project ceylon by eclipse.

the class ValueConstructorImpl method getJavaMethod.

// /////////////////////////////////////////
/**
 * Gets the getter {@code java.lang.reflect.Method} for the
 * given value constructor.
 */
@Ignore
public static Method getJavaMethod(ValueConstructorDeclarationImpl declaration) {
    org.eclipse.ceylon.model.typechecker.model.Value decl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration.declaration;
    String getterName = "";
    try {
        if (decl instanceof JavaBeanValue) {
            java.lang.Class<?> javaClass = Metamodel.getJavaClass((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) decl.getContainer());
            getterName = ((JavaBeanValue) decl).getGetterName();
            java.lang.Class<?>[] params = NO_PARAMS;
            boolean isJavaArray = MethodHandleUtil.isJavaArray(javaClass);
            if (isJavaArray)
                params = MethodHandleUtil.getJavaArrayGetArrayParameterTypes(javaClass, getterName);
            // if it is shared we may want to get an inherited getter, but if it's private we need the declared method to return it
            Method m = decl.isShared() ? javaClass.getMethod(getterName, params) : javaClass.getDeclaredMethod(getterName, params);
            return m;
        } else if (decl instanceof LazyValue) {
            LazyValue lazyDecl = (LazyValue) decl;
            java.lang.Class<?> javaClass = ((ReflectionClass) lazyDecl.classMirror).klass;
            // FIXME: we should really save the getter name in the LazyDecl
            getterName = NamingBase.getGetterName(lazyDecl);
            // toplevels don't have inheritance
            Method m = javaClass.getDeclaredMethod(getterName);
            return m;
        } else if (ModelUtil.isEnumeratedConstructor(decl)) {
            java.lang.Class<?> javaClass = Metamodel.getJavaClass((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) decl.getContainer());
            Class constructedClass = ModelUtil.getConstructedClass(decl);
            if (constructedClass.isMember()) {
                // the getter for member classes is on the enclosing class.
                javaClass = javaClass.getEnclosingClass();
            } else if (ModelUtil.isLocalNotInitializer(constructedClass))
                // local class has no way to get the value
                return null;
            getterName = NamingBase.getGetterName(decl);
            java.lang.Class<?>[] params = NO_PARAMS;
            // if it is shared we may want to get an inherited getter, but if it's private we need the declared method to return it
            Method m = javaClass.getDeclaredMethod(getterName, params);
            return m;
        } else {
            throw new StorageException("Attribute " + decl.getName() + " is neither captured nor shared so it has no physical storage allocated and cannot be read by the metamodel");
        }
    } catch (NoSuchMethodException | SecurityException e) {
        throw Metamodel.newModelError("Failed to find getter method " + getterName + " for: " + decl, e);
    }
}
Also used : LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) Method(java.lang.reflect.Method) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) Class(org.eclipse.ceylon.model.typechecker.model.Class) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) StorageException(ceylon.language.meta.model.StorageException) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 7 with Ignore

use of org.eclipse.ceylon.compiler.java.metadata.Ignore in project ceylon by eclipse.

the class Array method instance.

@Ignore
public static <T> Array<T> instance(T[] array) {
    if (array == null) {
        return null;
    }
    java.lang.Class<?> componentType = array.getClass().getComponentType();
    TypeDescriptor optionalType = TypeDescriptor.union(Null.$TypeDescriptor$, TypeDescriptor.klass(componentType));
    return new Array<T>(optionalType, array);
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 8 with Ignore

use of org.eclipse.ceylon.compiler.java.metadata.Ignore in project ceylon by eclipse.

the class Tuple method $completeInit$.

@Ignore
public void $completeInit$(java.lang.Object first, java.lang.Object rest) {
    Lookup lookup = MethodHandles.lookup();
    try {
        java.lang.Object[] array = makeArray(first, (Sequential) rest);
        Util.setter(lookup, "array").invokeExact(this, array);
        Rest rest2 = (Rest) makeRest((Sequential) rest);
        Util.setter(lookup, "rest").invokeExact(this, rest2);
    } catch (java.lang.Throwable t) {
        rethrow_.rethrow(t);
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 9 with Ignore

use of org.eclipse.ceylon.compiler.java.metadata.Ignore in project ceylon by eclipse.

the class Tuple method $getType$.

@Override
@Ignore
public TypeDescriptor $getType$() {
    SoftReference<TypeDescriptor> cachedType = $cachedType;
    TypeDescriptor type = cachedType != null ? cachedType.get() : null;
    if (type == null) {
        synchronized (this) {
            cachedType = $cachedType;
            type = cachedType != null ? cachedType.get() : null;
            if (type == null) {
                type = computeType();
                $cachedType = new SoftReference<TypeDescriptor>(type);
            }
        }
    }
    return type;
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Metamodel.getTypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Aggregations

Ignore (org.eclipse.ceylon.compiler.java.metadata.Ignore)9 Method (java.lang.reflect.Method)3 Lookup (java.lang.invoke.MethodHandles.Lookup)2 ArrayList (java.util.ArrayList)2 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)2 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)2 MemberImpl (ceylon.language.impl.MemberImpl)1 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)1 StorageException (ceylon.language.meta.model.StorageException)1 Member (ceylon.language.serialization.Member)1 ReachableReference (ceylon.language.serialization.ReachableReference)1 Annotation (java.lang.annotation.Annotation)1 MethodHandle (java.lang.invoke.MethodHandle)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 TypeParameter (org.eclipse.ceylon.compiler.java.metadata.TypeParameter)1 Metamodel.getTypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor)1 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)1 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)1