Java Code Examples for proguard.classfile.constant.RefConstant

The following examples show how to use proguard.classfile.constant.RefConstant. These examples are extracted from open source projects. 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
public void visitAnyMethodrefConstant(Clazz clazz, RefConstant methodrefConstant)
{
    String type = methodrefConstant.getType(clazz);

    // Count the number of parameters.
    int parameterCount = ClassUtil.internalMethodParameterCount(type);
    if (!isStatic)
    {
        parameterCount++;
    }

    // Pop the parameters and the class reference, in reverse order.
    for (int parameterIndex = parameterCount-1; parameterIndex >= 0; parameterIndex--)
    {
        setMethodParameterValue(clazz, methodrefConstant, parameterIndex, stack.pop());
    }

    // Push the return value, if applicable.
    String returnType = ClassUtil.internalMethodReturnType(type);
    if (returnType.charAt(0) != ClassConstants.INTERNAL_TYPE_VOID)
    {
        stack.push(getMethodReturnValue(clazz, methodrefConstant, returnType));
    }
}
 
Example 2
Source Project: java-n-IDE-for-Android   Source File: UsageMarker.java    License: Apache License 2.0 6 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    if (shouldBeMarkedAsUsed(refConstant))
    {
        markAsUsed(refConstant);

        markConstant(clazz, refConstant.u2classIndex);
        markConstant(clazz, refConstant.u2nameAndTypeIndex);

        // When compiled with "-target 1.2" or higher, the class or
        // interface actually containing the referenced class member may
        // be higher up the hierarchy. Make sure it's marked, in case it
        // isn't used elsewhere.
        refConstant.referencedClassAccept(this);

        // Mark the referenced class member itself.
        refConstant.referencedMemberAccept(this);
    }
}
 
Example 3
public void visitAnyMethodrefConstant(Clazz clazz, RefConstant refConstant)
{
    // Remember the referenced class. Note that we're interested in the
    // class of the method reference, not in the class in which the
    // method was actually found, unless it is an array type.
    //
    if (ClassUtil.isInternalArrayType(refConstant.getClassName(clazz)))
    {
        // For an array type, the class will be java.lang.Object.
        referencedClass = refConstant.referencedClass;
    }
    else
    {
        clazz.constantPoolEntryAccept(refConstant.u2classIndex, this);
    }

    // Remember the referenced method.
    referencedMethodClass = refConstant.referencedClass;
    referencedMethod      = refConstant.referencedMember;
}
 
Example 4
protected Value getFieldClassValue(Clazz       clazz,
                                   RefConstant refConstant,
                                   String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field class value.
            ReferenceValue value = StoringInvocationUnit.getFieldClassValue((Field)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getFieldClassValue(clazz, refConstant, type);
}
 
Example 5
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field value.
            Value value = StoringInvocationUnit.getFieldValue((Field)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getFieldValue(clazz, refConstant, type);
}
 
Example 6
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    if (loadMethodReturnValues)
    {
        // Do we know this method?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored method return value.
            Value value = StoringInvocationUnit.getMethodReturnValue((Method)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getMethodReturnValue(clazz,
                                      refConstant,
                                      type);
}
 
Example 7
protected void setMethodParameterValue(Clazz       clazz,
                                       RefConstant refConstant,
                                       int         parameterIndex,
                                       Value value)
{
    if (storeMethodParameterValues)
    {
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            generalizeMethodParameterValue((Method)referencedMember,
                                           parameterIndex,
                                           value);
        }
    }
}
 
Example 8
protected Value getFieldClassValue(Clazz       clazz,
                                   RefConstant refConstant,
                                   String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field class value.
            ReferenceValue value = StoringInvocationUnit.getFieldClassValue((Field)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getFieldClassValue(clazz, refConstant, type);
}
 
Example 9
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field value.
            Value value = StoringInvocationUnit.getFieldValue((Field)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getFieldValue(clazz, refConstant, type);
}
 
Example 10
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    if (loadMethodReturnValues)
    {
        // Do we know this method?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored method return value.
            Value value = StoringInvocationUnit.getMethodReturnValue((Method)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getMethodReturnValue(clazz,
                                      refConstant,
                                      type);
}
 
Example 11
protected void setMethodParameterValue(Clazz       clazz,
                                       RefConstant refConstant,
                                       int         parameterIndex,
                                       Value       value)
{
    if (storeMethodParameterValues)
    {
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            generalizeMethodParameterValue((Method)referencedMember,
                                           parameterIndex,
                                           value);
        }
    }
}
 
Example 12
Source Project: bazel   Source File: LoadingInvocationUnit.java    License: Apache License 2.0 6 votes vote down vote up
protected Value getFieldClassValue(Clazz       clazz,
                                   RefConstant refConstant,
                                   String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field class value.
            ReferenceValue value = StoringInvocationUnit.getFieldClassValue((Field)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getFieldClassValue(clazz, refConstant, type);
}
 
Example 13
Source Project: bazel   Source File: LoadingInvocationUnit.java    License: Apache License 2.0 6 votes vote down vote up
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field value.
            Value value = StoringInvocationUnit.getFieldValue((Field)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getFieldValue(clazz, refConstant, type);
}
 
Example 14
Source Project: bazel   Source File: LoadingInvocationUnit.java    License: Apache License 2.0 6 votes vote down vote up
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    if (loadMethodReturnValues)
    {
        // Do we know this method?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored method return value.
            Value value = StoringInvocationUnit.getMethodReturnValue((Method)referencedMember);
            if (value != null)
            {
                return value;
            }
        }
    }

    return super.getMethodReturnValue(clazz,
                                      refConstant,
                                      type);
}
 
Example 15
Source Project: bazel   Source File: StoringInvocationUnit.java    License: Apache License 2.0 6 votes vote down vote up
protected void setMethodParameterValue(Clazz       clazz,
                                       RefConstant refConstant,
                                       int         parameterIndex,
                                       Value       value)
{
    if (storeMethodParameterValues)
    {
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            generalizeMethodParameterValue((Method)referencedMember,
                                           parameterIndex,
                                           value);
        }
    }
}
 
Example 16
/**
 * Sets the class through which the specified field is accessed.
 */
protected void setFieldClassValue(Clazz          clazz,
                                  RefConstant refConstant,
                                  ReferenceValue value)
{
    // We don't care about the new value.
}
 
Example 17
/**
 * Returns the class though which the specified field is accessed.
 */
protected Value getFieldClassValue(Clazz       clazz,
                                   RefConstant refConstant,
                                   String      type)
{
    // Try to figure out the class of the return type.
    returnTypeClass = null;
    refConstant.referencedMemberAccept(this);

    return valueFactory.createValue(type,
                                    returnTypeClass,
                                    true);
}
 
Example 18
/**
 * Sets the value of the specified field.
 */
protected void setFieldValue(Clazz       clazz,
                             RefConstant refConstant,
                             Value value)
{
    // We don't care about the new field value.
}
 
Example 19
/**
 * Returns the value of the specified field.
 */
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    // Try to figure out the class of the return type.
    returnTypeClass = null;
    refConstant.referencedMemberAccept(this);

    return valueFactory.createValue(type,
                                    returnTypeClass,
                                    true);
}
 
Example 20
/**
 * Sets the value of the specified method parameter.
 */
protected void setMethodParameterValue(Clazz       clazz,
                                       RefConstant refConstant,
                                       int         parameterIndex,
                                       Value value)
{
    // We don't care about the parameter value.
}
 
Example 21
/**
 * Returns the return value of the specified method.
 */
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    // Try to figure out the class of the return type.
    returnTypeClass = null;
    refConstant.referencedMemberAccept(this);

    return valueFactory.createValue(type,
                                    returnTypeClass,
                                    true);
}
 
Example 22
private void visitRefConstant(Clazz clazz, RefConstant methodrefConstant)
{
    String type = methodrefConstant.getType(clazz);

    parameterStackDelta = ClassUtil.internalMethodParameterSize(type);
    typeStackDelta      = ClassUtil.internalTypeSize(ClassUtil.internalMethodReturnType(type));
}
 
Example 23
Source Project: java-n-IDE-for-Android   Source File: StringSharer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    Member referencedMember = refConstant.referencedMember;
    if (referencedMember != null)
    {
        Clazz referencedClass = refConstant.referencedClass;

        // Put the actual class member's name and type strings in the class
        // pool.
        name = referencedMember.getName(referencedClass);
        type = referencedMember.getDescriptor(referencedClass);
        clazz.constantPoolEntryAccept(refConstant.u2nameAndTypeIndex, this);
    }
}
 
Example 24
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    RefConstant refPatternConstant = (RefConstant)patternConstant;

    // Check the class and the name and type.
    matchingConstant =
        matchingConstantIndices(clazz,
                                refConstant.getClassIndex(),
                                refPatternConstant.getClassIndex()) &&
        matchingConstantIndices(clazz,
                                refConstant.getNameAndTypeIndex(),
                                refPatternConstant.getNameAndTypeIndex());
}
 
Example 25
Source Project: java-n-IDE-for-Android   Source File: ComparableConstant.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    RefConstant otherRefConstant = (RefConstant)otherConstant;
    result = (refConstant.getClassName(clazz) + ' ' +
              refConstant.getName(clazz)      + ' ' +
              refConstant.getType(clazz))
             .compareTo
             (otherRefConstant.getClassName(clazz) + ' ' +
              otherRefConstant.getName(clazz)      + ' ' +
              otherRefConstant.getType(clazz));
}
 
Example 26
private void debug(Clazz       clazz,
                   RefConstant refConstant,
                   Clazz       referencedClass,
                   Member referencedMember)
{
    System.out.println("MemberReferenceFixer:");
    System.out.println("  Class file      = "+clazz.getName());
    System.out.println("  Ref class       = "+referencedClass.getName());
    System.out.println("  Ref member name = "+refConstant.getName(clazz));
    System.out.println("                 -> "+referencedMember.getName(referencedClass));
    System.out.println("  Ref descriptor  = "+refConstant.getType(clazz));
    System.out.println("                 -> "+referencedMember.getDescriptor(referencedClass));
}
 
Example 27
Source Project: java-n-IDE-for-Android   Source File: AccessFixer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    referencingClass = clazz;

    // Remember the specified class, since it might be different from
    // the referenced class that actually contains the class member.
    clazz.constantPoolEntryAccept(refConstant.u2classIndex, referencedClassFinder);

    // Make sure the access flags of the referenced class member are
    // acceptable.
    refConstant.referencedMemberAccept(this);
}
 
Example 28
Source Project: java-n-IDE-for-Android   Source File: AccessMethodMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    // Check the referenced class.
    clazz.constantPoolEntryAccept(refConstant.u2classIndex, this);

    // Check the referenced class member itself.
    refConstant.referencedClassAccept(this);
    refConstant.referencedMemberAccept(this);
}
 
Example 29
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    // Check the referenced class and class member.
    if (refConstant.referencedClass != clazz)
    {
        referencingClass = clazz;

        refConstant.referencedClassAccept(this);
        refConstant.referencedMemberAccept(this);
    }
}
 
Example 30
public void visitAnyMethodrefConstant(Clazz clazz, RefConstant refConstant)
{
    // Pass the referencing class.
    referencingClass = clazz;

    // We'll have to assume invoking an unknown method has side effects.
    hasSideEffects = true;

    // Check the referenced method, if known.
    refConstant.referencedMemberAccept(this);
}