Java Code Examples for proguard.util.ArrayUtil#add()

The following examples show how to use proguard.util.ArrayUtil#add() . 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: CodeAttributeComposer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Appends the given line number to the line number table.
 * @param lineNumberInfo the line number to be appended.
 */
public void appendLineNumber(LineNumberInfo lineNumberInfo)
{
    if (DEBUG)
    {
        print("         ", "Line number ["+lineNumberInfo.u2startPC+"]");
    }

    // Remap the line number right away.
    visitLineNumberInfo(null, null, null, lineNumberInfo);

    if (DEBUG)
    {
        System.out.println(" -> ["+lineNumberInfo.u2startPC+"] line "+lineNumberInfo.u2lineNumber+(lineNumberInfo.getSource()==null ? "":" ["+lineNumberInfo.getSource()+"]"));
    }

    // Add the line number.
    lineNumberTable =
        (LineNumberInfo[])ArrayUtil.add(lineNumberTable,
                                        lineNumberTableLength++,
                                        lineNumberInfo);
}
 
Example 2
Source File: CodeAttributeComposer.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Appends the given line number to the line number table.
 * @param lineNumberInfo the line number to be appended.
 */
public void appendLineNumber(LineNumberInfo lineNumberInfo)
{
    if (DEBUG)
    {
        print("         ", "Line number ["+lineNumberInfo.u2startPC+"]");
    }

    // Remap the line number right away.
    visitLineNumberInfo(null, null, null, lineNumberInfo);

    if (DEBUG)
    {
        System.out.println(" -> ["+lineNumberInfo.u2startPC+"] line "+lineNumberInfo.u2lineNumber+(lineNumberInfo.getSource()==null ? "":" ["+lineNumberInfo.getSource()+"]"));
    }

    // Add the line number.
    lineNumberTable =
        (LineNumberInfo[])ArrayUtil.add(lineNumberTable,
                                        lineNumberTableLength++,
                                        lineNumberInfo);
}
 
Example 3
Source File: LocalVariableTableAttributeEditor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a given line number to the line number table attribute.
 */
public void addLocalVariableInfo(LocalVariableInfo localVariableInfo)
{
    targetLocalVariableTableAttribute.localVariableTable =
        (LocalVariableInfo[])ArrayUtil.add(targetLocalVariableTableAttribute.localVariableTable,
                                           targetLocalVariableTableAttribute.u2localVariableTableLength++,
                                           localVariableInfo);
}
 
Example 4
Source File: CodeAttributeComposer.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Appends the given exception to the exception table.
 * @param exceptionInfo the exception to be appended.
 */
public void appendException(ExceptionInfo exceptionInfo)
{
    if (DEBUG)
    {
        print("         ", "Exception ["+exceptionInfo.u2startPC+" -> "+exceptionInfo.u2endPC+": "+exceptionInfo.u2handlerPC+"]");
    }

    // Remap the exception right away.
    visitExceptionInfo(null, null, null, exceptionInfo);

    if (DEBUG)
    {
        System.out.println(" -> ["+exceptionInfo.u2startPC+" -> "+exceptionInfo.u2endPC+": "+exceptionInfo.u2handlerPC+"]");
    }

    // Don't add the exception if its instruction range is empty.
    if (exceptionInfo.u2startPC == exceptionInfo.u2endPC)
    {
        if (DEBUG)
        {
            println("         ", "  (not added because of empty instruction range)");
        }

        return;
    }

    // Add the exception.
    exceptionTable =
        (ExceptionInfo[])ArrayUtil.add(exceptionTable,
                                       exceptionTableLength++,
                                       exceptionInfo);
}
 
Example 5
Source File: LocalVariableTypeTableAttributeEditor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a given local variable type to the local variable type table attribute.
 */
public void addLocalVariableTypeInfo(LocalVariableTypeInfo localVariableTypeInfo)
{
    targetLocalVariableTypeTableAttribute.localVariableTypeTable =
        (LocalVariableTypeInfo[])ArrayUtil.add(targetLocalVariableTypeTableAttribute.localVariableTypeTable,
                                               targetLocalVariableTypeTableAttribute.u2localVariableTypeTableLength++,
                                               localVariableTypeInfo);
}
 
Example 6
Source File: ParameterAnnotationsAttributeEditor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a given annotation to the annotations attribute.
 */
public void addAnnotation(int parameterIndex, Annotation annotation)
{
    ArrayUtil.add(targetParameterAnnotationsAttribute.parameterAnnotations[parameterIndex],
                  targetParameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex]++,
                  annotation);
}
 
Example 7
Source File: BootstrapMethodsAttributeEditor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a given bootstrap method to the bootstrap methods attribute.
 * @return the index of the bootstrap method.
 */
public int addBootstrapMethodInfo(BootstrapMethodInfo bootstrapMethodInfo)
{
    targetBootstrapMethodsAttribute.bootstrapMethods =
        (BootstrapMethodInfo[])ArrayUtil.add(targetBootstrapMethodsAttribute.bootstrapMethods,
                                             targetBootstrapMethodsAttribute.u2bootstrapMethodsCount,
                                             bootstrapMethodInfo);

    return targetBootstrapMethodsAttribute.u2bootstrapMethodsCount++;
}
 
Example 8
Source File: InterfacesEditor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds the specified interface to the target class, if it isn't present yet.
 */
public void addInterface(int interfaceConstantIndex)
{
    // Is the interface not yet present?
    if (findInterfaceIndex(interfaceConstantIndex) < 0)
    {
        // Append the interface.
        targetClass.u2interfaces =
            ArrayUtil.add(targetClass.u2interfaces,
                          targetClass.u2interfacesCount++,
                          interfaceConstantIndex);
    }
}
 
Example 9
Source File: LocalVariableTableAttributeEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given line number to the line number table attribute.
 */
public void addLocalVariableInfo(LocalVariableInfo localVariableInfo)
{
    targetLocalVariableTableAttribute.localVariableTable =
        (LocalVariableInfo[])ArrayUtil.add(targetLocalVariableTableAttribute.localVariableTable,
                                           targetLocalVariableTableAttribute.u2localVariableTableLength++,
                                           localVariableInfo);
}
 
Example 10
Source File: CodeAttributeComposer.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the given exception to the exception table.
 * @param exceptionInfo the exception to be appended.
 */
public void appendException(ExceptionInfo exceptionInfo)
{
    if (DEBUG)
    {
        print("         ", "Exception ["+exceptionInfo.u2startPC+" -> "+exceptionInfo.u2endPC+": "+exceptionInfo.u2handlerPC+"]");
    }

    // Remap the exception right away.
    visitExceptionInfo(null, null, null, exceptionInfo);

    if (DEBUG)
    {
        System.out.println(" -> ["+exceptionInfo.u2startPC+" -> "+exceptionInfo.u2endPC+": "+exceptionInfo.u2handlerPC+"]");
    }

    // Don't add the exception if its instruction range is empty.
    if (exceptionInfo.u2startPC == exceptionInfo.u2endPC)
    {
        if (DEBUG)
        {
            println("         ", "  (not added because of empty instruction range)");
        }

        return;
    }

    // Add the exception.
    exceptionTable =
        (ExceptionInfo[])ArrayUtil.add(exceptionTable,
                                       exceptionTableLength++,
                                       exceptionInfo);
}
 
Example 11
Source File: LocalVariableTypeTableAttributeEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given local variable type to the local variable type table attribute.
 */
public void addLocalVariableTypeInfo(LocalVariableTypeInfo localVariableTypeInfo)
{
    targetLocalVariableTypeTableAttribute.localVariableTypeTable =
        (LocalVariableTypeInfo[])ArrayUtil.add(targetLocalVariableTypeTableAttribute.localVariableTypeTable,
                                               targetLocalVariableTypeTableAttribute.u2localVariableTypeTableLength++,
                                               localVariableTypeInfo);
}
 
Example 12
Source File: ParameterAnnotationsAttributeEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given annotation to the annotations attribute.
 */
public void addAnnotation(int parameterIndex, Annotation annotation)
{
    ArrayUtil.add(targetParameterAnnotationsAttribute.parameterAnnotations[parameterIndex],
                  targetParameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex]++,
                  annotation);
}
 
Example 13
Source File: BootstrapMethodsAttributeEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given bootstrap method to the bootstrap methods attribute.
 * @return the index of the bootstrap method.
 */
public int addBootstrapMethodInfo(BootstrapMethodInfo bootstrapMethodInfo)
{
    targetBootstrapMethodsAttribute.bootstrapMethods =
        (BootstrapMethodInfo[])ArrayUtil.add(targetBootstrapMethodsAttribute.bootstrapMethods,
                                             targetBootstrapMethodsAttribute.u2bootstrapMethodsCount,
                                             bootstrapMethodInfo);

    return targetBootstrapMethodsAttribute.u2bootstrapMethodsCount++;
}
 
Example 14
Source File: InterfacesEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the specified interface to the target class, if it isn't present yet.
 */
public void addInterface(int interfaceConstantIndex)
{
    // Is the interface not yet present?
    if (findInterfaceIndex(interfaceConstantIndex) < 0)
    {
        // Append the interface.
        targetClass.u2interfaces =
            ArrayUtil.add(targetClass.u2interfaces,
                          targetClass.u2interfacesCount++,
                          interfaceConstantIndex);
    }
}
 
Example 15
Source File: LambdaExpressionCollector.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitBootstrapMethodInfo(Clazz clazz, BootstrapMethodInfo bootstrapMethodInfo)
{
    ProgramClass programClass = (ProgramClass) clazz;

    MethodHandleConstant bootstrapMethodHandle =
        (MethodHandleConstant) programClass.getConstant(bootstrapMethodInfo.u2methodHandleIndex);

    if (isLambdaMetaFactory(bootstrapMethodHandle.getClassName(clazz)))
    {
        String factoryMethodDescriptor =
            referencedInvokeDynamicConstant.getType(clazz);

        String interfaceClassName =
            ClassUtil.internalClassNameFromClassType(ClassUtil.internalMethodReturnType(factoryMethodDescriptor));

        // Find the actual method that is being invoked.
        MethodHandleConstant invokedMethodHandle =
            (MethodHandleConstant) programClass.getConstant(bootstrapMethodInfo.u2methodArguments[1]);

        referencedInvokedClass  = null;
        referencedInvokedMethod = null;
        clazz.constantPoolEntryAccept(invokedMethodHandle.u2referenceIndex, this);

        // Collect all the useful information.
        LambdaExpression lambdaExpression =
            new LambdaExpression(programClass,
                                 referencedBootstrapMethodIndex,
                                 bootstrapMethodInfo,
                                 factoryMethodDescriptor,
                                 new String[] { interfaceClassName },
                                 new String[0],
                                 referencedInvokeDynamicConstant.getName(clazz),
                                 getMethodTypeConstant(programClass, bootstrapMethodInfo.u2methodArguments[0]).getType(clazz),
                                 invokedMethodHandle.getReferenceKind(),
                                 invokedMethodHandle.getClassName(clazz),
                                 invokedMethodHandle.getName(clazz),
                                 invokedMethodHandle.getType(clazz),
                                 referencedInvokedClass,
                                 referencedInvokedMethod);

        if (isAlternateFactoryMethod(bootstrapMethodHandle.getName(clazz)))
        {
            int flags =
                getIntegerConstant(programClass,
                                   bootstrapMethodInfo.u2methodArguments[3]);

            // For the alternate metafactory, the optional arguments start
            // at index 4.
            int argumentIndex = 4;

            if ((flags & BootstrapMethodInfo.FLAG_MARKERS) != 0)
            {
                int markerInterfaceCount =
                    getIntegerConstant(programClass,
                                       bootstrapMethodInfo.u2methodArguments[argumentIndex++]);

                for (int i = 0; i < markerInterfaceCount; i++)
                {
                    String interfaceName =
                        programClass.getClassName(bootstrapMethodInfo.u2methodArguments[argumentIndex++]);

                    lambdaExpression.interfaces =
                        ArrayUtil.add(lambdaExpression.interfaces,
                                      lambdaExpression.interfaces.length,
                                      interfaceName);
                }
            }

            if ((flags & BootstrapMethodInfo.FLAG_BRIDGES) != 0)
            {
                int bridgeMethodCount =
                    getIntegerConstant(programClass,
                                       bootstrapMethodInfo.u2methodArguments[argumentIndex++]);

                for (int i = 0; i < bridgeMethodCount; i++)
                {
                    MethodTypeConstant methodTypeConstant =
                        getMethodTypeConstant(programClass,
                                              bootstrapMethodInfo.u2methodArguments[argumentIndex++]);

                    lambdaExpression.bridgeMethodDescriptors =
                        ArrayUtil.add(lambdaExpression.bridgeMethodDescriptors,
                                      lambdaExpression.bridgeMethodDescriptors.length,
                                      methodTypeConstant.getType(programClass));
                }
            }

            if ((flags & BootstrapMethodInfo.FLAG_SERIALIZABLE) != 0)
            {
                lambdaExpression.interfaces =
                    ArrayUtil.add(lambdaExpression.interfaces,
                                  lambdaExpression.interfaces.length,
                                  ClassConstants.NAME_JAVA_IO_SERIALIZABLE);
            }
        }

        lambdaExpressions.put(referencedBootstrapMethodIndex, lambdaExpression);
    }
}
 
Example 16
Source File: TypeArgumentFinder.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitVariableInstruction(Clazz               clazz,
                                     Method              method,
                                     CodeAttribute       codeAttribute,
                                     int                 offset,
                                     VariableInstruction variableInstruction)
{
    if (variableInstruction.canonicalOpcode() == Instruction.OP_ALOAD)
    {
        // Find the operation that stored the loaded Type.
        LastStoreFinder lastStoreFinder = new LastStoreFinder(variableInstruction.variableIndex);
        codeAttribute.instructionsAccept(clazz, method, 0, offset, lastStoreFinder);

        if (lastStoreFinder.lastStore != null)
        {
            // Find out which instruction produced the stored Type.
            TracedStack stackBeforeStore = partialEvaluator.getStackBefore(lastStoreFinder.lastStoreOffset);
            InstructionOffsetValue instructionOffsetValue = stackBeforeStore.getTopProducerValue(0).instructionOffsetValue();

            // Derive the signature of the subclass of TypeToken from which the Type is retrieved.
            TypeTokenSignatureFinder typeTokenFinder = new TypeTokenSignatureFinder();
            for (int offsetIndex = 0; offsetIndex < instructionOffsetValue.instructionOffsetCount(); offsetIndex++)
            {
                int instructionOffset = instructionOffsetValue.instructionOffset(offsetIndex);
                codeAttribute.instructionAccept(clazz, method, instructionOffset, typeTokenFinder);
            }

            // Derive the classes from the signature of the TypeToken subclass.
            if (typeTokenFinder.typeTokenSignature != null)
            {
                typeArgumentClasses = new String[0];
                Clazz[] referencedClasses = typeTokenFinder.typeTokenSignature.referencedClasses;
                for (Clazz referencedClass : referencedClasses)
                {
                    if (referencedClass!= null &&
                        !referencedClass.getName().equals(GsonClassConstants.NAME_TYPE_TOKEN))
                    {
                        typeArgumentClasses = ArrayUtil.add(typeArgumentClasses,
                                                            typeArgumentClasses.length,
                                                            referencedClass.getName());
                    }
                }
            }
        }
    }
}