Search in sources :

Example 1 with Ignore

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

the class Array method $set$.

@Ignore
@Override
public void $set$(ReachableReference reference, java.lang.Object instance) {
    if (reference instanceof Member && getArraySize().equals(((Member) reference).getAttribute())) {
        int size = toSize(((ceylon.language.Integer) instance).value);
        try {
            Lookup lookup = MethodHandles.lookup();
            Util.setter(lookup, "size").invokeExact(this, size);
            java.lang.Object array = createArrayWithElement($reifiedElement, size, null);
            Util.setter(lookup, "array").invokeExact(this, array);
            if (elementType.fieldName != null) {
                MethodHandle fieldSetter = Util.setter(lookup, elementType.fieldName);
                switch(elementType) {
                    case CeylonInteger:
                        fieldSetter.invokeExact(this, (long[]) array);
                        break;
                    case CeylonFloat:
                        fieldSetter.invokeExact(this, (double[]) array);
                        break;
                    case CeylonCharacter:
                        fieldSetter.invokeExact(this, (int[]) array);
                        break;
                    case CeylonByte:
                        fieldSetter.invokeExact(this, (byte[]) array);
                        break;
                    case CeylonBoolean:
                        fieldSetter.invokeExact(this, (boolean[]) array);
                        break;
                    case CeylonString:
                        fieldSetter.invokeExact(this, (java.lang.String[]) array);
                        break;
                    case Other:
                        fieldSetter.invokeExact(this, (java.lang.Object[]) array);
                        break;
                    default:
                        fieldSetter.invoke(this, array);
                        break;
                }
            }
        } catch (java.lang.Throwable t) {
            rethrow_.rethrow(t);
        }
    } else {
        ceylon.language.serialization.Element index = (ceylon.language.serialization.Element) reference;
        set(index.getIndex(), (Element) instance);
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Member(ceylon.language.serialization.Member) MethodHandle(java.lang.invoke.MethodHandle) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 2 with Ignore

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

the class ValueDeclarationImpl method $getJavaAnnotations$.

@Override
@Ignore
public java.lang.annotation.Annotation[] $getJavaAnnotations$() {
    Class<?> javaClass = Metamodel.getJavaClass(declaration);
    ArrayList<java.lang.annotation.Annotation> result = new ArrayList<>();
    HashSet<Class<? extends java.lang.annotation.Annotation>> cls = new HashSet<>();
    if (javaClass != null) {
        // FIXME: pretty sure this doesn't work with interop and fields
        Method declaredGetter = Reflection.getDeclaredGetter(javaClass, NamingBase.getGetterName(declaration));
        if (declaredGetter != null) {
            addToList(result, cls, declaredGetter.getAnnotations());
        }
        if (!((Value) declaration).isTransient()) {
            // TODO only include those which are java annotations
            Field field = Reflection.getDeclaredField(javaClass, declaration.getName());
            if (field != null) {
                Annotation[] fieldAnnos = field.getAnnotations();
                addToList(result, cls, fieldAnnos);
            }
            Method setter = Reflection.getDeclaredSetter(javaClass, NamingBase.getSetterName(declaration.getName()));
            if (setter != null) {
                Annotation[] setterAnnos = setter.getAnnotations();
                addToList(result, cls, setterAnnos);
            }
        }
    }
    // one last chance
    if (parameter != null && !parameter.getModel().isShared()) {
        // get the annotations from the parameter itself
        Annotation[][] parameterAnnotations;
        Scope container = parameter.getModel().getContainer();
        if (container instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
            parameterAnnotations = Metamodel.getJavaMethod((org.eclipse.ceylon.model.typechecker.model.Function) container).getParameterAnnotations();
        } else if (container instanceof org.eclipse.ceylon.model.typechecker.model.ClassAlias) {
            parameterAnnotations = Reflection.findClassAliasInstantiator(Metamodel.getJavaClass((org.eclipse.ceylon.model.typechecker.model.Class) container), (org.eclipse.ceylon.model.typechecker.model.ClassAlias) container).getParameterAnnotations();
        } else if (container instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
            // FIXME: pretty sure that's wrong because of synthetic params. See ReflectionMethod.getParameters
            parameterAnnotations = Reflection.findConstructor(Metamodel.getJavaClass((org.eclipse.ceylon.model.typechecker.model.Class) container)).getParameterAnnotations();
        } else {
            throw Metamodel.newModelError("Unsupported parameter container");
        }
        // now find the right parameter
        List<Parameter> parameters = ((org.eclipse.ceylon.model.typechecker.model.Functional) container).getFirstParameterList().getParameters();
        int index = parameters.indexOf(parameter);
        if (index == -1)
            throw Metamodel.newModelError("Parameter " + parameter + " not found in container " + parameter.getModel().getContainer());
        if (index >= parameterAnnotations.length)
            throw Metamodel.newModelError("Parameter " + parameter + " index is greater than JVM parameters for " + parameter.getModel().getContainer());
        addToList(result, cls, parameterAnnotations[index]);
    }
    // nope
    return result.toArray(new java.lang.annotation.Annotation[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) Field(java.lang.reflect.Field) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) HashSet(java.util.HashSet) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.compiler.java.metadata.TypeParameter) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 3 with Ignore

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

the class SetterDeclarationImpl method $isAnnotated$.

@Override
@Ignore
public boolean $isAnnotated$(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) {
    checkInit();
    final AnnotatedElement element = declaredSetter;
    return element != null ? element.isAnnotationPresent(annotationType) : false;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 4 with Ignore

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

the class Tuple method $references$.

@Ignore
@Override
public java.util.Collection<ReachableReference> $references$() {
    // could put the elements with int indexes and the rest as a String!
    ArrayList<ReachableReference> s = new ArrayList<ReachableReference>(2);
    ClassDeclaration cd = (ClassDeclaration) Metamodel.getOrCreateMetamodel(Tuple.class);
    s.add(new MemberImpl(Util.assertExists(cd.<ValueDeclaration>getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "first"))));
    s.add(new MemberImpl(Util.assertExists(cd.<ValueDeclaration>getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, "rest"))));
    return s;
}
Also used : ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) MemberImpl(ceylon.language.impl.MemberImpl) ArrayList(java.util.ArrayList) ReachableReference(ceylon.language.serialization.ReachableReference) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 5 with Ignore

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

the class ValueTypeTests method validateVTMethod.

// Check if the given method should have a static companion method
// and if so check that it exists and adheres to all the rules
private void validateVTMethod(Class<?> clazz, Method classMethod) {
    if (classMethod.getAnnotation(Ignore.class) != null || (classMethod.getModifiers() & Modifier.STATIC) != 0 || (classMethod.getModifiers() & Modifier.VOLATILE) != 0 || classMethod.getDeclaringClass() == Object.class) {
        // And finally we skip all methods defined on Object
        return;
    }
    validateVTMethodUnchecked(clazz, classMethod, classMethod);
    // See if it has any overloads that need checking
    Method[] overloads = findVTMethodOverloads(clazz, classMethod);
    for (Method m : overloads) {
        if (m.getAnnotation(Ignore.class) == null || (m.getModifiers() & Modifier.STATIC) != 0 || (m.getModifiers() & Modifier.VOLATILE) != 0) {
            // and those NOT marked with @Ignore
            continue;
        }
        validateVTMethodUnchecked(clazz, m, classMethod);
    }
}
Also used : Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore) Method(java.lang.reflect.Method)

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