summaryrefslogtreecommitdiff
path: root/src/proguard/classfile/io/ProgramClassWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/classfile/io/ProgramClassWriter.java')
-rw-r--r--src/proguard/classfile/io/ProgramClassWriter.java144
1 files changed, 141 insertions, 3 deletions
diff --git a/src/proguard/classfile/io/ProgramClassWriter.java b/src/proguard/classfile/io/ProgramClassWriter.java
index dbf1de3..bcc3403 100644
--- a/src/proguard/classfile/io/ProgramClassWriter.java
+++ b/src/proguard/classfile/io/ProgramClassWriter.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -23,6 +23,8 @@ package proguard.classfile.io;
import proguard.classfile.*;
import proguard.classfile.attribute.*;
import proguard.classfile.attribute.annotation.*;
+import proguard.classfile.attribute.annotation.target.*;
+import proguard.classfile.attribute.annotation.target.visitor.*;
import proguard.classfile.attribute.annotation.visitor.*;
import proguard.classfile.attribute.preverification.*;
import proguard.classfile.attribute.preverification.visitor.*;
@@ -289,9 +291,14 @@ implements ClassVisitor,
StackMapFrameVisitor,
VerificationTypeVisitor,
LineNumberInfoVisitor,
+ ParameterInfoVisitor,
LocalVariableInfoVisitor,
LocalVariableTypeInfoVisitor,
AnnotationVisitor,
+ TypeAnnotationVisitor,
+ TargetInfoVisitor,
+ TypePathInfoVisitor,
+ LocalVariableTargetElementVisitor,
ElementValueVisitor
{
// Implementations for AttributeVisitor.
@@ -364,6 +371,15 @@ implements ClassVisitor,
}
+ public void visitMethodParametersAttribute(Clazz clazz, Method method, MethodParametersAttribute methodParametersAttribute)
+ {
+ // Write the parameter information.
+ dataOutput.writeByte(methodParametersAttribute.u1parametersCount);
+
+ methodParametersAttribute.parametersAccept(clazz, method, this);
+ }
+
+
public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
{
// Write the exceptions.
@@ -456,9 +472,9 @@ implements ClassVisitor,
public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
{
// Write the parameter annotations.
- dataOutput.writeByte(parameterAnnotationsAttribute.u2parametersCount);
+ dataOutput.writeByte(parameterAnnotationsAttribute.u1parametersCount);
- for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++)
+ for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u1parametersCount; parameterIndex++)
{
// Write the parameter annotations of the given parameter.
int u2annotationsCount = parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex];
@@ -475,6 +491,15 @@ implements ClassVisitor,
}
+ public void visitAnyTypeAnnotationsAttribute(Clazz clazz, TypeAnnotationsAttribute typeAnnotationsAttribute)
+ {
+ // Write the type annotations.
+ dataOutput.writeShort(typeAnnotationsAttribute.u2annotationsCount);
+
+ typeAnnotationsAttribute.typeAnnotationsAccept(clazz, this);
+ }
+
+
public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
{
// Write the default element value.
@@ -541,6 +566,15 @@ implements ClassVisitor,
}
+ // Implementations for ParameterInfoVisitor.
+
+ public void visitParameterInfo(Clazz clazz, Method method, int parameterIndex, ParameterInfo parameterInfo)
+ {
+ dataOutput.writeShort(parameterInfo.u2nameIndex);
+ dataOutput.writeShort(parameterInfo.u2accessFlags);
+ }
+
+
// Implementations for LocalVariableInfoVisitor.
public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
@@ -579,6 +613,110 @@ implements ClassVisitor,
}
+ // Implementations for TypeAnnotationVisitor.
+
+ public void visitTypeAnnotation(Clazz clazz, TypeAnnotation typeAnnotation)
+ {
+ // Write the target info.
+ dataOutput.writeByte(typeAnnotation.targetInfo.u1targetType);
+
+ typeAnnotation.targetInfoAccept(clazz, this);
+
+ // Write the type path.
+ dataOutput.writeByte(typeAnnotation.typePath.length);
+
+ typeAnnotation.typePathInfosAccept(clazz, this);
+
+ // Write the actual annotation.
+ visitAnnotation(clazz, typeAnnotation);
+ }
+
+
+ // Implementations for TargetInfoVisitor.
+
+ public void visitTypeParameterTargetInfo(Clazz clazz, TypeAnnotation typeAnnotation, TypeParameterTargetInfo typeParameterTargetInfo)
+ {
+ dataOutput.writeByte(typeParameterTargetInfo.u1typeParameterIndex);
+ }
+
+
+ public void visitSuperTypeTargetInfo(Clazz clazz, TypeAnnotation typeAnnotation, SuperTypeTargetInfo superTypeTargetInfo)
+ {
+ dataOutput.writeShort(superTypeTargetInfo.u2superTypeIndex);
+ }
+
+
+ public void visitTypeParameterBoundTargetInfo(Clazz clazz, TypeAnnotation typeAnnotation, TypeParameterBoundTargetInfo typeParameterBoundTargetInfo)
+ {
+ dataOutput.writeByte(typeParameterBoundTargetInfo.u1typeParameterIndex);
+ dataOutput.writeByte(typeParameterBoundTargetInfo.u1boundIndex);
+ }
+
+
+ public void visitEmptyTargetInfo(Clazz clazz, Member member, TypeAnnotation typeAnnotation, EmptyTargetInfo emptyTargetInfo)
+ {
+ }
+
+
+ public void visitFormalParameterTargetInfo(Clazz clazz, Method method, TypeAnnotation typeAnnotation, FormalParameterTargetInfo formalParameterTargetInfo)
+ {
+ dataOutput.writeByte(formalParameterTargetInfo.u1formalParameterIndex);
+ }
+
+
+ public void visitThrowsTargetInfo(Clazz clazz, Method method, TypeAnnotation typeAnnotation, ThrowsTargetInfo throwsTargetInfo)
+ {
+ dataOutput.writeShort(throwsTargetInfo.u2throwsTypeIndex);
+ }
+
+
+ public void visitLocalVariableTargetInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, TypeAnnotation typeAnnotation, LocalVariableTargetInfo localVariableTargetInfo)
+ {
+ // Write the local variable target elements.
+ dataOutput.writeShort(localVariableTargetInfo.u2tableLength);
+
+ localVariableTargetInfo.targetElementsAccept(clazz, method, codeAttribute, typeAnnotation, this);
+ }
+
+
+ public void visitCatchTargetInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, TypeAnnotation typeAnnotation, CatchTargetInfo catchTargetInfo)
+ {
+ dataOutput.writeShort(catchTargetInfo.u2exceptionTableIndex);
+ }
+
+
+ public void visitOffsetTargetInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, TypeAnnotation typeAnnotation, OffsetTargetInfo offsetTargetInfo)
+ {
+ dataOutput.writeShort(offsetTargetInfo.u2offset);
+ }
+
+
+ public void visitTypeArgumentTargetInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, TypeAnnotation typeAnnotation, TypeArgumentTargetInfo typeArgumentTargetInfo)
+ {
+ dataOutput.writeShort(typeArgumentTargetInfo.u2offset);
+ dataOutput.writeByte(typeArgumentTargetInfo.u1typeArgumentIndex);
+ }
+
+
+ // Implementations for TypePathInfoVisitor.
+
+ public void visitTypePathInfo(Clazz clazz, TypeAnnotation typeAnnotation, TypePathInfo typePathInfo)
+ {
+ dataOutput.writeByte(typePathInfo.u1typePathKind);
+ dataOutput.writeByte(typePathInfo.u1typeArgumentIndex);
+ }
+
+
+ // Implementations for LocalVariableTargetElementVisitor.
+
+ public void visitLocalVariableTargetElement(Clazz clazz, Method method, CodeAttribute codeAttribute, TypeAnnotation typeAnnotation, LocalVariableTargetInfo localVariableTargetInfo, LocalVariableTargetElement localVariableTargetElement)
+ {
+ dataOutput.writeShort(localVariableTargetElement.u2startPC);
+ dataOutput.writeShort(localVariableTargetElement.u2length);
+ dataOutput.writeShort(localVariableTargetElement.u2index);
+ }
+
+
// Implementations for ElementValueVisitor.
public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue)