Search in sources :

Example 1 with Pure

use of org.checkerframework.dataflow.qual.Pure in project checker-framework by typetools.

the class DelayQueue method size.

@Pure
public int size() {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        return q.size();
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Pure(org.checkerframework.dataflow.qual.Pure)

Example 2 with Pure

use of org.checkerframework.dataflow.qual.Pure in project checker-framework by typetools.

the class PropertyDescriptor method getReadMethod.

/**
 * Gets the method that should be used to read the property value.
 *
 * @return The method that should be used to read the property value.
 * May return null if the property can't be read.
 */
@Pure
@Nullable
public synchronized Method getReadMethod() {
    Method readMethod = this.readMethodRef.get();
    if (readMethod == null) {
        Class<?> cls = getClass0();
        if (cls == null || (readMethodName == null && !this.readMethodRef.isSet())) {
            // The read method was explicitly set to null.
            return null;
        }
        String nextMethodName = Introspector.GET_PREFIX + getBaseName();
        if (readMethodName == null) {
            Class<?> type = getPropertyType0();
            if (type == boolean.class || type == null) {
                readMethodName = Introspector.IS_PREFIX + getBaseName();
            } else {
                readMethodName = nextMethodName;
            }
        }
        // Since there can be multiple write methods but only one getter
        // method, find the getter method first so that you know what the
        // property type is.  For booleans, there can be "is" and "get"
        // methods.  If an "is" method exists, this is the official
        // reader method so look for this one first.
        readMethod = Introspector.findMethod(cls, readMethodName, 0);
        if ((readMethod == null) && !readMethodName.equals(nextMethodName)) {
            readMethodName = nextMethodName;
            readMethod = Introspector.findMethod(cls, readMethodName, 0);
        }
        try {
            setReadMethod(readMethod);
        } catch (IntrospectionException ex) {
        // fall
        }
    }
    return readMethod;
}
Also used : Method(java.lang.reflect.Method) Pure(org.checkerframework.dataflow.qual.Pure) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 3 with Pure

use of org.checkerframework.dataflow.qual.Pure in project checker-framework by typetools.

the class PropertyDescriptor method equals.

/**
 * Compares this <code>PropertyDescriptor</code> against the specified object.
 * Returns true if the objects are the same. Two <code>PropertyDescriptor</code>s
 * are the same if the read, write, property types, property editor and
 * flags  are equivalent.
 *
 * @since 1.4
 */
@Pure
public boolean equals(@Nullable Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj != null && obj instanceof PropertyDescriptor) {
        PropertyDescriptor other = (PropertyDescriptor) obj;
        Method otherReadMethod = other.getReadMethod();
        Method otherWriteMethod = other.getWriteMethod();
        if (!compareMethods(getReadMethod(), otherReadMethod)) {
            return false;
        }
        if (!compareMethods(getWriteMethod(), otherWriteMethod)) {
            return false;
        }
        if (getPropertyType() == other.getPropertyType() && getPropertyEditorClass() == other.getPropertyEditorClass() && bound == other.isBound() && constrained == other.isConstrained() && writeMethodName == other.writeMethodName && readMethodName == other.readMethodName) {
            return true;
        }
    }
    return false;
}
Also used : Method(java.lang.reflect.Method) Pure(org.checkerframework.dataflow.qual.Pure)

Example 4 with Pure

use of org.checkerframework.dataflow.qual.Pure 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

Pure (org.checkerframework.dataflow.qual.Pure)4 Method (java.lang.reflect.Method)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1