Java Code Examples for proguard.classfile.constant.ClassConstant

The following examples show how to use proguard.classfile.constant.ClassConstant. 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
Source Project: proguard   Source File: ClassRenamer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Update the Class entry if required.
    String name    = clazz.getName();
    String newName = ClassObfuscator.newClassName(clazz);
    if (newName != null && !newName.equals(name))
    {
        // Refer to a new Utf8 entry.
        classConstant.u2nameIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newName);

        if (extraClassVisitor != null)
        {
            clazz.accept(extraClassVisitor);
        }
    }
}
 
Example 2
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    classUsed = usageMarker.isUsed(classConstant);

    // Is the class constant marked as being used?
    if (!classUsed)
    {
        // Check the referenced class.
        classUsed = true;
        classConstant.referencedClassAccept(this);

        // Is the referenced class marked as being used?
        if (classUsed)
        {
            // Mark the class constant and its Utf8 constant.
            usageMarker.markAsUsed(classConstant);

            markConstant(clazz, classConstant.u2nameIndex);
        }
    }
}
 
Example 3
Source Project: java-n-IDE-for-Android   Source File: InnerUsageMarker.java    License: Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    classUsed = usageMarker.isUsed(classConstant);

    // Is the class constant marked as being used?
    if (!classUsed)
    {
        // Check the referenced class.
        classUsed = true;
        classConstant.referencedClassAccept(this);

        // Is the referenced class marked as being used?
        if (classUsed)
        {
            // Mark the class constant and its Utf8 constant.
            usageMarker.markAsUsed(classConstant);

            markConstant(clazz, classConstant.u2nameIndex);
        }
    }
}
 
Example 4
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    boolean classUsed = usageMarker.isUsed(classConstant);

    if (!classUsed)
    {
        // The ClassConstant isn't marked as being used yet. But maybe it
        // should be included as an interface, so check the actual class.
        classConstant.referencedClassAccept(this);
        classUsed = used;

        if (classUsed)
        {
            // The class is being used. Mark the ClassConstant as being used
            // as well.
            usageMarker.markAsUsed(classConstant);

            clazz.constantPoolEntryAccept(classConstant.u2nameIndex, this);
        }
    }

    // The return values.
    used    =  classUsed;
    anyUsed |= classUsed;
}
 
Example 5
/**
 * Prints out a note about the class cast to this class, if applicable.
 */
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Print out a note about the class cast.
    if (noteExceptionMatcher == null ||
        !noteExceptionMatcher.matches(classConstant.getName(clazz)))
    {
        notePrinter.print(clazz.getName(),
                          classConstant.getName(clazz),
                          "Note: " +
                          ClassUtil.externalClassName(clazz.getName()) +
                          " calls '(" +
                          ClassUtil.externalClassName(classConstant.getName(clazz)) +
                          ")Class.forName(variable).newInstance()'");
    }
}
 
Example 6
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Check if this class entry is an array type.
    if (ClassUtil.isInternalArrayType(classConstant.getName(clazz)))
    {
        isInterfaceMethod = false;
    }
    else
    {
        // Check if this class entry refers to an interface class.
        Clazz referencedClass = classConstant.referencedClass;
        if (referencedClass != null)
        {
            isInterfaceMethod = (referencedClass.getAccessFlags() & ClassConstants.INTERNAL_ACC_INTERFACE) != 0;
        }
    }
}
 
Example 7
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Do we know the referenced class?
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass != null)
    {
        // Has the class name changed?
        String className    = classConstant.getName(clazz);
        String newClassName = newClassName(className, referencedClass);
        if (!className.equals(newClassName))
        {
            // Refer to a new Utf8 entry.
            classConstant.u2nameIndex =
                new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newClassName);
        }
    }
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: LibraryClassReader.java    License: Apache License 2.0 6 votes vote down vote up
private Constant createConstant()
{
    int u1tag = dataInput.readUnsignedByte();

    switch (u1tag)
    {
        case ClassConstants.CONSTANT_Utf8:               return new Utf8Constant();
        case ClassConstants.CONSTANT_Integer:            return new IntegerConstant();
        case ClassConstants.CONSTANT_Float:              return new FloatConstant();
        case ClassConstants.CONSTANT_Long:               return new LongConstant();
        case ClassConstants.CONSTANT_Double:             return new DoubleConstant();
        case ClassConstants.CONSTANT_String:             return new StringConstant();
        case ClassConstants.CONSTANT_Fieldref:           return new FieldrefConstant();
        case ClassConstants.CONSTANT_Methodref:          return new MethodrefConstant();
        case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant();
        case ClassConstants.CONSTANT_Class:              return new ClassConstant();
        case ClassConstants.CONSTANT_NameAndType:        return new NameAndTypeConstant();

        default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool");
    }
}
 
Example 9
Source Project: java-n-IDE-for-Android   Source File: TargetClassChanger.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Explicitly adds a new class constant for the given class in the given
 * program class.
 */
private int addNewClassConstant(ProgramClass programClass,
                                String       className,
                                Clazz        referencedClass)
{
    ConstantPoolEditor constantPoolEditor =
        new ConstantPoolEditor(programClass);

    int nameIndex =
        constantPoolEditor.addUtf8Constant(className);

    int classConstantIndex =
        constantPoolEditor.addConstant(new ClassConstant(nameIndex,
                                                         referencedClass));
    return classConstantIndex;
}
 
Example 10
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Create a Class reference instead of a reference to the class.
    value = valueFactory.createReferenceValue(ClassConstants.INTERNAL_NAME_JAVA_LANG_CLASS,
                                              classConstant.javaLangClassClass,
                                              false);
}
 
Example 11
Source Project: java-n-IDE-for-Android   Source File: UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (shouldBeMarkedAsUsed(classConstant))
    {
        markAsUsed(classConstant);

        markConstant(clazz, classConstant.u2nameIndex);

        // Mark the referenced class itself.
        classConstant.referencedClassAccept(this);
    }
}
 
Example 12
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (!classConstant.getName(clazz).equals(exceptClassName))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example 13
Source Project: java-n-IDE-for-Android   Source File: ProgramClass.java    License: Apache License 2.0 5 votes vote down vote up
public String getClassName(int constantIndex)
{
    try
    {
        return ((ClassConstant)constantPool[constantIndex]).getName(this);
    }
    catch (ClassCastException ex)
    {
        throw new ClassCastException("Expected ClassConstant at index ["+constantIndex+"] in class ["+getName()+"], found ["+ex.getMessage()+"]");
    }
}
 
Example 14
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !implementingClass.extendsOrImplements(referencedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example 15
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !referencedClass.extendsOrImplements(implementedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example 16
Source Project: bazel   Source File: ImplementedClassConstantFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !referencedClass.extendsOrImplements(implementedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example 17
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    String className = clazz.getName();

    // Fill out the referenced class.
    classConstant.referencedClass =
        findClass(className, ClassUtil.internalClassNameFromClassType(classConstant.getName(clazz)));

    // Fill out the Class class.
    classConstant.javaLangClassClass =
        findClass(className, ClassConstants.INTERNAL_NAME_JAVA_LANG_CLASS);
}
 
Example 18
Source Project: java-n-IDE-for-Android   Source File: StringSharer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass != null)
    {
        // Put the actual class's name string in the class pool.
        name = referencedClass.getName();
        clazz.constantPoolEntryAccept(classConstant.u2nameIndex, this);
    }
}
 
Example 19
/**
 * Remembers the referenced class.
 */
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (DEBUG)
    {
        System.out.println("DynamicMemberReferenceInitializer: ["+clazz.getName()+"] matched class ["+classConstant.getName(clazz)+"]");
    }

    // Remember the referenced class.
    referencedClass = ClassUtil.isInternalArrayType(classConstant.getName(clazz)) ?
        null :
        classConstant.referencedClass;
}
 
Example 20
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    ClassConstant classPatternConstant = (ClassConstant)patternConstant;

    // Check the class name.
    matchingConstant =
        matchingConstantIndices(clazz,
                                classConstant.u2nameIndex,
                                classPatternConstant.u2nameIndex);
}
 
Example 21
Source Project: java-n-IDE-for-Android   Source File: ExceptionAdder.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add a class constant to the constant pool.
    constantAdder.visitClassConstant(clazz, classConstant);

    // Add the index of the class constant to the list of exceptions.
    exceptionsAttributeEditor.addException(constantAdder.getConstantIndex());
}
 
Example 22
Source Project: java-n-IDE-for-Android   Source File: ConstantAdder.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add the class constant, with its referenced class..
    constantIndex =
        constantPoolEditor.addClassConstant(classConstant.getName(clazz),
                                            classConstant.referencedClass);
}
 
Example 23
Source Project: java-n-IDE-for-Android   Source File: ConstantPoolEditor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Finds or creates a ClassConstant constant pool entry with the given name.
 * @return the constant pool index of the ClassConstant.
 */
public int addClassConstant(String name,
                            Clazz  referencedClass)
{
    int        constantPoolCount = targetClass.u2constantPoolCount;
    Constant[] constantPool      = targetClass.constantPool;

    // Check if the entry already exists.
    for (int index = 1; index < constantPoolCount; index++)
    {
        Constant constant = constantPool[index];

        if (constant != null &&
            constant.getTag() == ClassConstants.CONSTANT_Class)
        {
            ClassConstant classConstant = (ClassConstant)constant;
            if (classConstant.getName(targetClass).equals(name))
            {
                return index;
            }
        }
    }

    int nameIndex = addUtf8Constant(name);

    return addConstant(new ClassConstant(nameIndex, referencedClass));
}
 
Example 24
Source Project: java-n-IDE-for-Android   Source File: AccessFixer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    referencingClass = clazz;

    // Make sure the access flags of the referenced class are acceptable.
    classConstant.referencedClassAccept(this);
}
 
Example 25
Source Project: java-n-IDE-for-Android   Source File: LibraryClassReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the class name of the ClassConstant at the specified index in the
 * reusable constant pool.
 */
private String getClassName(int constantIndex)
{
    ClassConstant classEntry = (ClassConstant)constantPool[constantIndex];

    return getString(classEntry.u2nameIndex);
}
 
Example 26
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Check the referenced class.
    if (classConstant.referencedClass != clazz)
    {
        referencingClass = clazz;

        classConstant.referencedClassAccept(this);
    }
}
 
Example 27
Source Project: bazel   Source File: ExceptionAdder.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add a class constant to the constant pool.
    constantAdder.visitClassConstant(clazz, classConstant);

    // Add the index of the class constant to the list of exceptions.
    exceptionsAttributeEditor.addException(constantAdder.getConstantIndex());
}
 
Example 28
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Create a Class reference instead of a reference to the class.
    value = valueFactory.createReferenceValue(ClassConstants.NAME_JAVA_LANG_CLASS,
                                              classConstant.javaLangClassClass,
                                              false);
}
 
Example 29
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (!classConstant.getName(clazz).equals(exceptClassName))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example 30
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !implementingClass.extendsOrImplements(referencedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}