Java Code Examples for proguard.classfile.constant.Utf8Constant

The following examples show how to use proguard.classfile.constant.Utf8Constant. 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: java-n-IDE-for-Android   Source File: ConstantPoolEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Finds or creates a Utf8Constant constant pool entry for the given string.
 * @return the constant pool index of the Utf8Constant.
 */
public int addUtf8Constant(String string)
{
    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_Utf8)
        {
            Utf8Constant utf8Constant = (Utf8Constant)constant;
            if (utf8Constant.getString().equals(string))
            {
                return index;
            }
        }
    }

    return addConstant(new Utf8Constant(string));
}
 
Example 2
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 3
Source Project: java-n-IDE-for-Android   Source File: ProgramClassReader.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 4
Source Project: java-n-IDE-for-Android   Source File: UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    if (shouldBeMarkedAsUsed(utf8Constant))
    {
        markAsUsed(utf8Constant);
    }
}
 
Example 5
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    if (!usageMarker.isUsed(utf8Constant))
    {
        usageMarker.markAsUsed(utf8Constant);
    }
}
 
Example 6
Source Project: java-n-IDE-for-Android   Source File: ProgramClass.java    License: Apache License 2.0 5 votes vote down vote up
public String getString(int constantIndex)
{
    try
    {
        return ((Utf8Constant)constantPool[constantIndex]).getString();
    }
    catch (ClassCastException ex)
    {
        throw new ClassCastException("Expected Utf8Constant at index ["+constantIndex+"] in class ["+getName()+"], found ["+ex.getMessage()+"]");
    }
}
 
Example 7
Source Project: java-n-IDE-for-Android   Source File: StringSharer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    // Do we have a new string to put into this constant?
    if (name != null)
    {
        // Replace the string, if it's actually the same.
        if (name.equals(utf8Constant.getString()))
        {
            utf8Constant.setString(name);
        }

        name = null;
    }
}
 
Example 8
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    Utf8Constant utf8PatternConstant = (Utf8Constant)patternConstant;

    // Compare the actual strings.
    matchingConstant = utf8Constant.getString().equals(
                       utf8PatternConstant.getString());
}
 
Example 9
Source Project: java-n-IDE-for-Android   Source File: ProgramClassWriter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    byte[] bytes = utf8Constant.getBytes();

    dataOutput.writeShort(bytes.length);
    dataOutput.write(bytes);
}
 
Example 10
Source Project: java-n-IDE-for-Android   Source File: LibraryClassReader.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    int u2length = dataInput.readUnsignedShort();

    // Read the UTF-8 bytes.
    byte[] bytes = new byte[u2length];
    dataInput.readFully(bytes);
    utf8Constant.setBytes(bytes);
}
 
Example 11
Source Project: java-n-IDE-for-Android   Source File: ProgramClassReader.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    int u2length = dataInput.readUnsignedShort();

    // Read the UTF-8 bytes.
    byte[] bytes = new byte[u2length];
    dataInput.readFully(bytes);
    utf8Constant.setBytes(bytes);
}
 
Example 12
Source Project: java-n-IDE-for-Android   Source File: ClassShrinker.java    License: Apache License 2.0 4 votes vote down vote up
public void visitSignatureAttribute(Clazz clazz, SignatureAttribute  signatureAttribute)
{
    Clazz[] referencedClasses = signatureAttribute.referencedClasses;
    if (referencedClasses != null)
    {
        // Go over the generic definitions, superclass and implemented interfaces.
        String signature = clazz.getString(signatureAttribute.u2signatureIndex);

        InternalTypeEnumeration internalTypeEnumeration =
            new InternalTypeEnumeration(signature);

        StringBuffer newSignatureBuffer = new StringBuffer();

        int referencedClassIndex    = 0;
        int newReferencedClassIndex = 0;

        while (internalTypeEnumeration.hasMoreTypes())
        {
            // Consider the classes referenced by this signature.
            String type       = internalTypeEnumeration.nextType();
            int    classCount = new DescriptorClassEnumeration(type).classCount();

            Clazz referencedClass = referencedClasses[referencedClassIndex];
            if (referencedClass == null ||
                usageMarker.isUsed(referencedClass))
            {
                // Append the superclass or interface.
                newSignatureBuffer.append(type);

                // Copy the referenced classes.
                for (int counter = 0; counter < classCount; counter++)
                {
                    referencedClasses[newReferencedClassIndex++] =
                        referencedClasses[referencedClassIndex++];
                }
            }
            else
            {
                // Skip the referenced classes.
                referencedClassIndex += classCount;
            }
        }

        if (newReferencedClassIndex < referencedClassIndex)
        {
            // Update the signature.
            ((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());

            // Clear the unused entries.
            while (newReferencedClassIndex < referencedClassIndex)
            {
                referencedClasses[newReferencedClassIndex++] = null;
            }
        }
    }
}
 
Example 13
Source Project: java-n-IDE-for-Android   Source File: InnerUsageMarker.java    License: Apache License 2.0 4 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    usageMarker.markAsUsed(utf8Constant);
}
 
Example 14
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 4 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    println(visitorInfo(utf8Constant) + " Utf8 [" +
            utf8Constant.getString() + "]");
}
 
Example 15
Source Project: java-n-IDE-for-Android   Source File: SimplifiedVisitor.java    License: Apache License 2.0 4 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    visitAnyConstant(clazz, utf8Constant);
}
 
Example 16
Source Project: java-n-IDE-for-Android   Source File: ConstantAdder.java    License: Apache License 2.0 4 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    constantIndex =
        constantPoolEditor.addUtf8Constant(utf8Constant.getString());
}
 
Example 17
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    // Nothing to do.
}
 
Example 18
Source Project: java-n-IDE-for-Android   Source File: ComparableConstant.java    License: Apache License 2.0 4 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    result = utf8Constant.getString().compareTo(((Utf8Constant)otherConstant).getString());
}
 
Example 19
Source Project: java-n-IDE-for-Android   Source File: LibraryClassReader.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the string of the Utf8Constant at the specified index in the
 * reusable constant pool.
 */
private String getString(int constantIndex)
{
    return ((Utf8Constant)constantPool[constantIndex]).getString();
}
 
Example 20
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Marks the given UTF-8 constant pool entry of the given class.
 */
private void markCpUtf8Entry(Clazz clazz, int index)
{
     markAsUsed((Utf8Constant)((ProgramClass)clazz).getConstant(index));
}
 
Example 21
Source Project: atlas   Source File: AbstractClasslVisitor.java    License: Apache License 2.0 2 votes vote down vote up
@Override
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) {

}
 
Example 22
Source Project: java-n-IDE-for-Android   Source File: ConstantVisitor.java    License: Apache License 2.0 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant); 
Example 23
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) {}