Java Code Examples for proguard.classfile.util.ClassUtil#internalArrayTypeDimensionCount()

The following examples show how to use proguard.classfile.util.ClassUtil#internalArrayTypeDimensionCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReferenceValue.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the type is an instance of the given type.
 */
public int instanceOf(String otherType, Clazz otherReferencedClass)
{
    String thisType = this.type;

    // If this type is null, it is never an instance of any class.
    if (thisType == null)
    {
        return NEVER;
    }

    // Start taking into account the type dimensions.
    int thisDimensionCount   = ClassUtil.internalArrayTypeDimensionCount(thisType);
    int otherDimensionCount  = ClassUtil.internalArrayTypeDimensionCount(otherType);
    int commonDimensionCount = Math.min(thisDimensionCount, otherDimensionCount);

    // Strip any common array prefixes.
    thisType  = thisType.substring(commonDimensionCount);
    otherType = otherType.substring(commonDimensionCount);

    // If either stripped type is a primitive type, we can tell right away.
    if (commonDimensionCount > 0 &&
        (ClassUtil.isInternalPrimitiveType(thisType.charAt(0)) ||
         ClassUtil.isInternalPrimitiveType(otherType.charAt(0))))
    {
        return !thisType.equals(otherType) ? NEVER :
               mayBeNull                   ? MAYBE :
                                             ALWAYS;
    }

    // Strip the class type prefix and suffix of this type, if any.
    if (thisDimensionCount == commonDimensionCount)
    {
        thisType = ClassUtil.internalClassNameFromClassType(thisType);
    }

    // Strip the class type prefix and suffix of the other type, if any.
    if (otherDimensionCount == commonDimensionCount)
    {
        otherType = ClassUtil.internalClassNameFromClassType(otherType);
    }

    // If this type is an array type, and the other type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount > otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(otherType))
    {
        return NEVER;
    }

    // If the other type is an array type, and this type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount < otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(thisType))
    {
        return NEVER;
    }

    // If this type may be null, it might not be an instance of any class.
    if (mayBeNull)
    {
        return MAYBE;
    }

    // If this type is equal to the other type, or if the other type is
    // java.lang.Object, this type is always an instance.
    if (thisType.equals(otherType) ||
        ClassConstants.INTERNAL_NAME_JAVA_LANG_OBJECT.equals(otherType))
    {
        return ALWAYS;
    }

    // If this type is an array type, it's ok.
    if (thisDimensionCount > otherDimensionCount)
    {
        return ALWAYS;
    }

    // If the other type is an array type, it might be ok.
    if (thisDimensionCount < otherDimensionCount)
    {
        return MAYBE;
    }

    // If the value extends the type, we're sure.
    return referencedClass      != null &&
           otherReferencedClass != null &&
           referencedClass.extendsOrImplements(otherReferencedClass) ?
               ALWAYS :
               MAYBE;
}
 
Example 2
Source File: TypedReferenceValue.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public int instanceOf(String otherType, Clazz otherReferencedClass)
{
    String thisType = this.type;

    // If this type is null, it is never an instance of any class.
    if (thisType == null)
    {
        return NEVER;
    }

    // Start taking into account the type dimensions.
    int thisDimensionCount   = ClassUtil.internalArrayTypeDimensionCount(thisType);
    int otherDimensionCount  = ClassUtil.internalArrayTypeDimensionCount(otherType);
    int commonDimensionCount = Math.min(thisDimensionCount, otherDimensionCount);

    // Strip any common array prefixes.
    thisType  = thisType.substring(commonDimensionCount);
    otherType = otherType.substring(commonDimensionCount);

    // If either stripped type is a primitive type, we can tell right away.
    if (commonDimensionCount > 0 &&
        (ClassUtil.isInternalPrimitiveType(thisType.charAt(0)) ||
         ClassUtil.isInternalPrimitiveType(otherType.charAt(0))))
    {
        return !thisType.equals(otherType) ? NEVER :
               mayBeNull                   ? MAYBE :
                                             ALWAYS;
    }

    // Strip the class type prefix and suffix of this type, if any.
    if (thisDimensionCount == commonDimensionCount)
    {
        thisType = ClassUtil.internalClassNameFromClassType(thisType);
    }

    // Strip the class type prefix and suffix of the other type, if any.
    if (otherDimensionCount == commonDimensionCount)
    {
        otherType = ClassUtil.internalClassNameFromClassType(otherType);
    }

    // If this type is an array type, and the other type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount > otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(otherType))
    {
        return NEVER;
    }

    // If the other type is an array type, and this type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount < otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(thisType))
    {
        return NEVER;
    }

    // If this type may be null, it might not be an instance of any class.
    if (mayBeNull)
    {
        return MAYBE;
    }

    // If this type is equal to the other type, or if the other type is
    // java.lang.Object, this type is always an instance.
    if (thisType.equals(otherType) ||
        ClassConstants.NAME_JAVA_LANG_OBJECT.equals(otherType))
    {
        return ALWAYS;
    }

    // If this type is an array type, it's ok.
    if (thisDimensionCount > otherDimensionCount)
    {
        return ALWAYS;
    }

    // If the other type is an array type, it might be ok.
    if (thisDimensionCount < otherDimensionCount)
    {
        return MAYBE;
    }

    // If the value extends the type, we're sure.
    return referencedClass      != null &&
           otherReferencedClass != null &&
           referencedClass.extendsOrImplements(otherReferencedClass) ?
               ALWAYS :
               MAYBE;
}
 
Example 3
Source File: TypedReferenceValue.java    From bazel with Apache License 2.0 4 votes vote down vote up
public int instanceOf(String otherType, Clazz otherReferencedClass)
{
    String thisType = this.type;

    // If this type is null, it is never an instance of any class.
    if (thisType == null)
    {
        return NEVER;
    }

    // Start taking into account the type dimensions.
    int thisDimensionCount   = ClassUtil.internalArrayTypeDimensionCount(thisType);
    int otherDimensionCount  = ClassUtil.internalArrayTypeDimensionCount(otherType);
    int commonDimensionCount = Math.min(thisDimensionCount, otherDimensionCount);

    // Strip any common array prefixes.
    thisType  = thisType.substring(commonDimensionCount);
    otherType = otherType.substring(commonDimensionCount);

    // If either stripped type is a primitive type, we can tell right away.
    if (commonDimensionCount > 0 &&
        (ClassUtil.isInternalPrimitiveType(thisType.charAt(0)) ||
         ClassUtil.isInternalPrimitiveType(otherType.charAt(0))))
    {
        return !thisType.equals(otherType) ? NEVER :
               mayBeNull                   ? MAYBE :
                                             ALWAYS;
    }

    // Strip the class type prefix and suffix of this type, if any.
    if (thisDimensionCount == commonDimensionCount)
    {
        thisType = ClassUtil.internalClassNameFromClassType(thisType);
    }

    // Strip the class type prefix and suffix of the other type, if any.
    if (otherDimensionCount == commonDimensionCount)
    {
        otherType = ClassUtil.internalClassNameFromClassType(otherType);
    }

    // If this type is an array type, and the other type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount > otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(otherType))
    {
        return NEVER;
    }

    // If the other type is an array type, and this type is not
    // java.lang.Object, java.lang.Cloneable, or java.io.Serializable,
    // this type can never be an instance.
    if (thisDimensionCount < otherDimensionCount &&
        !ClassUtil.isInternalArrayInterfaceName(thisType))
    {
        return NEVER;
    }

    // If this type may be null, it might not be an instance of any class.
    if (mayBeNull)
    {
        return MAYBE;
    }

    // If this type is equal to the other type, or if the other type is
    // java.lang.Object, this type is always an instance.
    if (thisType.equals(otherType) ||
        ClassConstants.NAME_JAVA_LANG_OBJECT.equals(otherType))
    {
        return ALWAYS;
    }

    // If this type is an array type, it's ok.
    if (thisDimensionCount > otherDimensionCount)
    {
        return ALWAYS;
    }

    // If the other type is an array type, it might be ok.
    if (thisDimensionCount < otherDimensionCount)
    {
        return MAYBE;
    }

    // If the value extends the type, we're sure.
    return referencedClass      != null &&
           otherReferencedClass != null &&
           referencedClass.extendsOrImplements(otherReferencedClass) ?
               ALWAYS :
               MAYBE;
}