Search in sources :

Example 26 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class MethodRef method get.

@Nullable
Method get() {
    if (this.methodRef == null) {
        return null;
    }
    Method method = this.methodRef.get();
    if (method == null) {
        method = find(this.typeRef.get(), this.signature);
        if (method == null) {
            this.signature = null;
            this.methodRef = null;
            this.typeRef = null;
        } else {
            this.methodRef = new SoftReference<>(method);
        }
    }
    return isPackageAccessible(method.getDeclaringClass()) ? method : null;
}
Also used : Method(java.lang.reflect.Method) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 27 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class PropertyDescriptor method getWriteMethod.

/**
 * Gets the method that should be used to write the property value.
 *
 * @return The method that should be used to write the property value.
 * May return null if the property can't be written.
 */
@Pure
@Nullable
public synchronized Method getWriteMethod() {
    Method writeMethod = this.writeMethodRef.get();
    if (writeMethod == null) {
        Class<?> cls = getClass0();
        if (cls == null || (writeMethodName == null && !this.writeMethodRef.isSet())) {
            // The write method was explicitly set to null.
            return null;
        }
        // We need the type to fetch the correct method.
        Class<?> type = getPropertyType0();
        if (type == null) {
            try {
                // Can't use getPropertyType since it will lead to recursive loop.
                type = findPropertyType(getReadMethod(), null);
                setPropertyType(type);
            } catch (IntrospectionException ex) {
                // to find the correct method.
                return null;
            }
        }
        if (writeMethodName == null) {
            writeMethodName = Introspector.SET_PREFIX + getBaseName();
        }
        Class<?>[] args = (type == null) ? null : new Class<?>[] { type };
        writeMethod = Introspector.findMethod(cls, writeMethodName, 1, args);
        if (writeMethod != null) {
            if (!writeMethod.getReturnType().equals(void.class)) {
                writeMethod = null;
            }
        }
        try {
            setWriteMethod(writeMethod);
        } catch (IntrospectionException ex) {
        // fall through
        }
    }
    return writeMethod;
}
Also used : Method(java.lang.reflect.Method) Pure(org.checkerframework.dataflow.qual.Pure) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)27 TypeElement (javax.lang.model.element.TypeElement)7 VariableElement (javax.lang.model.element.VariableElement)4 TreePath (com.sun.source.util.TreePath)3 Method (java.lang.reflect.Method)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 Element (javax.lang.model.element.Element)3 ClassTree (com.sun.source.tree.ClassTree)2 MethodTree (com.sun.source.tree.MethodTree)2 VariableTree (com.sun.source.tree.VariableTree)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 PackageElement (javax.lang.model.element.PackageElement)2 Prefix (org.checkerframework.checker.units.qual.Prefix)2 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)2 Node (org.checkerframework.dataflow.cfg.node.Node)2 Pure (org.checkerframework.dataflow.qual.Pure)2 AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)2 AnnotationTree (com.sun.source.tree.AnnotationTree)1 AssignmentTree (com.sun.source.tree.AssignmentTree)1 BlockTree (com.sun.source.tree.BlockTree)1