You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2014/05/31 00:51:30 UTC
svn commit: r1598766 [2/12] - in /commons/proper/bcel/trunk/src:
main/java/org/apache/bcel/ main/java/org/apache/bcel/classfile/
main/java/org/apache/bcel/generic/ main/java/org/apache/bcel/util/
main/java/org/apache/bcel/verifier/exc/ main/java/org/ap...
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java Fri May 30 22:51:27 2014
@@ -44,7 +44,7 @@ public abstract class FieldOrMethod exte
private String signatureAttributeString = null;
private boolean searchedForSignatureAttribute = false;
-
+
// Annotations are collected from certain attributes, don't do it more than necessary!
private boolean annotationsOutOfDate = true;
@@ -204,7 +204,7 @@ public abstract class FieldOrMethod exte
* @return deep copy of this field
*/
protected FieldOrMethod copy_( ConstantPool _constant_pool ) {
- FieldOrMethod c = null;
+ FieldOrMethod c = null;
try {
c = (FieldOrMethod)clone();
@@ -219,73 +219,73 @@ public abstract class FieldOrMethod exte
return c;
}
-
+
+ /**
+ * Ensure we have unpacked any attributes that contain annotations.
+ * We don't remove these annotation attributes from the attributes list, they
+ * remain there.
+ */
+ private void ensureAnnotationsUpToDate()
+ {
+ if (annotationsOutOfDate)
+ {
+ // Find attributes that contain annotation data
+ Attribute[] attrs = getAttributes();
+ List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
+ for (Attribute attribute : attrs) {
+ if (attribute instanceof Annotations)
+ {
+ Annotations annotations = (Annotations) attribute;
+ for (int j = 0; j < annotations.getAnnotationEntries().length; j++)
+ {
+ accumulatedAnnotations.add(annotations
+ .getAnnotationEntries()[j]);
+ }
+ }
+ }
+ annotationEntries = accumulatedAnnotations
+ .toArray(new AnnotationEntry[accumulatedAnnotations.size()]);
+ annotationsOutOfDate = false;
+ }
+ }
+
+ public AnnotationEntry[] getAnnotationEntries()
+ {
+ ensureAnnotationsUpToDate();
+ return annotationEntries;
+ }
+
+ public void addAnnotationEntry(AnnotationEntry a)
+ {
+ ensureAnnotationsUpToDate();
+ int len = annotationEntries.length;
+ AnnotationEntry[] newAnnotations = new AnnotationEntry[len + 1];
+ System.arraycopy(annotationEntries, 0, newAnnotations, 0, len);
+ newAnnotations[len] = a;
+ annotationEntries = newAnnotations;
+ }
+
/**
- * Ensure we have unpacked any attributes that contain annotations.
- * We don't remove these annotation attributes from the attributes list, they
- * remain there.
- */
- private void ensureAnnotationsUpToDate()
- {
- if (annotationsOutOfDate)
- {
- // Find attributes that contain annotation data
- Attribute[] attrs = getAttributes();
- List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
- for (Attribute attribute : attrs) {
- if (attribute instanceof Annotations)
- {
- Annotations annotations = (Annotations) attribute;
- for (int j = 0; j < annotations.getAnnotationEntries().length; j++)
- {
- accumulatedAnnotations.add(annotations
- .getAnnotationEntries()[j]);
- }
- }
- }
- annotationEntries = accumulatedAnnotations
- .toArray(new AnnotationEntry[accumulatedAnnotations.size()]);
- annotationsOutOfDate = false;
- }
- }
-
- public AnnotationEntry[] getAnnotationEntries()
- {
- ensureAnnotationsUpToDate();
- return annotationEntries;
- }
-
- public void addAnnotationEntry(AnnotationEntry a)
- {
- ensureAnnotationsUpToDate();
- int len = annotationEntries.length;
- AnnotationEntry[] newAnnotations = new AnnotationEntry[len + 1];
- System.arraycopy(annotationEntries, 0, newAnnotations, 0, len);
- newAnnotations[len] = a;
- annotationEntries = newAnnotations;
- }
-
- /**
- * Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature
- * may be (Ljava/util/Vector;)V the signature attribute may in fact say 'Ljava/lang/Vector<Ljava/lang/String>;'
- * Coded for performance - searches for the attribute only when requested - only searches for it once.
- */
- public final String getGenericSignature()
- {
- if (!searchedForSignatureAttribute)
- {
- boolean found = false;
- for (int i = 0; !found && i < attributes_count; i++)
- {
- if (attributes[i] instanceof Signature)
- {
- signatureAttributeString = ((Signature) attributes[i])
- .getSignature();
- found = true;
- }
- }
- searchedForSignatureAttribute = true;
- }
- return signatureAttributeString;
- }
+ * Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature
+ * may be (Ljava/util/Vector;)V the signature attribute may in fact say 'Ljava/lang/Vector<Ljava/lang/String>;'
+ * Coded for performance - searches for the attribute only when requested - only searches for it once.
+ */
+ public final String getGenericSignature()
+ {
+ if (!searchedForSignatureAttribute)
+ {
+ boolean found = false;
+ for (int i = 0; !found && i < attributes_count; i++)
+ {
+ if (attributes[i] instanceof Signature)
+ {
+ signatureAttributeString = ((Signature) attributes[i])
+ .getSignature();
+ found = true;
+ }
+ }
+ searchedForSignatureAttribute = true;
+ }
+ return signatureAttributeString;
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java Fri May 30 22:51:27 2014
@@ -73,10 +73,10 @@ public class JavaClass extends AccessFla
public static final byte ZIP = 3;
static boolean debug = false; // Debugging on/off
static char sep = '/'; // directory separator
-
+
// Annotations are collected from certain attributes, don't do it more than necessary!
private boolean annotationsOutOfDate = true;
-
+
private static BCELComparator _cmp = new BCELComparator() {
public boolean equals( Object o1, Object o2 ) {
@@ -336,24 +336,24 @@ public class JavaClass extends AccessFla
public Attribute[] getAttributes() {
return attributes;
}
-
+
public AnnotationEntry[] getAnnotationEntries() {
- if (annotationsOutOfDate) {
- // Find attributes that contain annotation data
- Attribute[] attrs = getAttributes();
- List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
- for (Attribute attribute : attrs) {
- if (attribute instanceof Annotations) {
- Annotations runtimeAnnotations = (Annotations)attribute;
- for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++) {
+ if (annotationsOutOfDate) {
+ // Find attributes that contain annotation data
+ Attribute[] attrs = getAttributes();
+ List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
+ for (Attribute attribute : attrs) {
+ if (attribute instanceof Annotations) {
+ Annotations runtimeAnnotations = (Annotations)attribute;
+ for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++) {
accumulatedAnnotations.add(runtimeAnnotations.getAnnotationEntries()[j]);
}
- }
- }
- annotations = accumulatedAnnotations.toArray(new AnnotationEntry[accumulatedAnnotations.size()]);
- annotationsOutOfDate = false;
- }
- return annotations;
+ }
+ }
+ annotations = accumulatedAnnotations.toArray(new AnnotationEntry[accumulatedAnnotations.size()]);
+ annotationsOutOfDate = false;
+ }
+ return annotations;
}
/**
* @return Class name.
@@ -649,8 +649,8 @@ public class JavaClass extends AccessFla
}
AnnotationEntry[] annotations = getAnnotationEntries();
if (annotations!=null && annotations.length>0) {
- buf.append("\nAnnotation(s):\n");
- for (AnnotationEntry annotation : annotations) {
+ buf.append("\nAnnotation(s):\n");
+ for (AnnotationEntry annotation : annotations) {
buf.append(indent(annotation));
}
}
@@ -716,42 +716,42 @@ public class JavaClass extends AccessFla
public final boolean isClass() {
return (access_flags & Constants.ACC_INTERFACE) == 0;
}
-
+
public final boolean isAnonymous() {
- computeNestedTypeStatus();
- return this.isAnonymous;
+ computeNestedTypeStatus();
+ return this.isAnonymous;
}
-
+
public final boolean isNested() {
- computeNestedTypeStatus();
- return this.isNested;
+ computeNestedTypeStatus();
+ return this.isNested;
}
-
+
private void computeNestedTypeStatus() {
- if (computedNestedTypeStatus) {
+ if (computedNestedTypeStatus) {
return;
}
- for (Attribute attribute : this.attributes) {
- if (attribute instanceof InnerClasses) {
- InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses();
- for (InnerClass innerClasse : innerClasses) {
- boolean innerClassAttributeRefersToMe = false;
- String inner_class_name = constant_pool.getConstantString(innerClasse.getInnerClassIndex(),
- Constants.CONSTANT_Class);
- inner_class_name = Utility.compactClassName(inner_class_name);
- if (inner_class_name.equals(getClassName())) {
- innerClassAttributeRefersToMe = true;
- }
- if (innerClassAttributeRefersToMe) {
- this.isNested = true;
- if (innerClasse.getInnerNameIndex() == 0) {
- this.isAnonymous = true;
- }
- }
- }
- }
- }
- this.computedNestedTypeStatus = true;
+ for (Attribute attribute : this.attributes) {
+ if (attribute instanceof InnerClasses) {
+ InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses();
+ for (InnerClass innerClasse : innerClasses) {
+ boolean innerClassAttributeRefersToMe = false;
+ String inner_class_name = constant_pool.getConstantString(innerClasse.getInnerClassIndex(),
+ Constants.CONSTANT_Class);
+ inner_class_name = Utility.compactClassName(inner_class_name);
+ if (inner_class_name.equals(getClassName())) {
+ innerClassAttributeRefersToMe = true;
+ }
+ if (innerClassAttributeRefersToMe) {
+ this.isNested = true;
+ if (innerClasse.getInnerNameIndex() == 0) {
+ this.isAnonymous = true;
+ }
+ }
+ }
+ }
+ }
+ this.computedNestedTypeStatus = true;
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java Fri May 30 22:51:27 2014
@@ -22,16 +22,16 @@ import java.io.*;
// The new table is used when generic types are about...
//LocalVariableTable_attribute {
-// u2 attribute_name_index;
-// u4 attribute_length;
-// u2 local_variable_table_length;
-// { u2 start_pc;
-// u2 length;
-// u2 name_index;
-// u2 descriptor_index;
-// u2 index;
-// } local_variable_table[local_variable_table_length];
-// }
+// u2 attribute_name_index;
+// u4 attribute_length;
+// u2 local_variable_table_length;
+// { u2 start_pc;
+// u2 length;
+// u2 name_index;
+// u2 descriptor_index;
+// u2 index;
+// } local_variable_table[local_variable_table_length];
+// }
//LocalVariableTypeTable_attribute {
// u2 attribute_name_index;
@@ -53,12 +53,12 @@ private int local_variable_t
public LocalVariableTypeTable(LocalVariableTypeTable c) {
this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(),
- c.getConstantPool());
+ c.getConstantPool());
}
public LocalVariableTypeTable(int name_index, int length,
- LocalVariable[] local_variable_table,
- ConstantPool constant_pool)
+ LocalVariable[] local_variable_table,
+ ConstantPool constant_pool)
{
super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
setLocalVariableTable(local_variable_table);
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java Fri May 30 22:51:27 2014
@@ -72,7 +72,7 @@ public class MethodParameter implements
} else {
return ((ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8)).getBytes();
}
- }
+ }
public int getAccessFlags() {
return access_flags;
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java Fri May 30 22:51:27 2014
@@ -78,9 +78,9 @@ public class MethodParameters extends At
* @throws IOException
*/
@Override
- public void dump(DataOutputStream file) throws IOException {
- super.dump(file);
- file.writeByte(parameters.length);
+ public void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeByte(parameters.length);
for (MethodParameter parameter : parameters) {
parameter.dump(file);
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java Fri May 30 22:51:27 2014
@@ -115,7 +115,7 @@ public abstract class ParameterAnnotatio
public final int getNumParameterAnnotation() {
return num_parameters;
}
-
+
@Override
public void dump(DataOutputStream dos) throws IOException
{
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java Fri May 30 22:51:27 2014
@@ -32,40 +32,40 @@ import org.apache.bcel.Constants;
*/
public class RuntimeInvisibleAnnotations extends Annotations
{
- private static final long serialVersionUID = 5274986004117955967L;
+ private static final long serialVersionUID = 5274986004117955967L;
/**
- * @param name_index
- * Index pointing to the name <em>Code</em>
- * @param length
- * Content length in bytes
- * @param file
- * Input stream
- * @param constant_pool
- * Array of constants
- */
- RuntimeInvisibleAnnotations(int name_index, int length,
- DataInputStream file, ConstantPool constant_pool)
- throws IOException
- {
- super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, name_index, length,
- file, constant_pool, false);
- }
+ * @param name_index
+ * Index pointing to the name <em>Code</em>
+ * @param length
+ * Content length in bytes
+ * @param file
+ * Input stream
+ * @param constant_pool
+ * Array of constants
+ */
+ RuntimeInvisibleAnnotations(int name_index, int length,
+ DataInputStream file, ConstantPool constant_pool)
+ throws IOException
+ {
+ super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, name_index, length,
+ file, constant_pool, false);
+ }
- /**
- * @return deep copy of this attribute
- */
- @Override
+ /**
+ * @return deep copy of this attribute
+ */
+ @Override
public Attribute copy(ConstantPool constant_pool)
- {
- Annotations c = (Annotations) clone();
- return c;
- }
+ {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
- @Override
+ @Override
public final void dump(DataOutputStream dos) throws IOException
- {
- super.dump(dos);
- writeAnnotations(dos);
- }
+ {
+ super.dump(dos);
+ writeAnnotations(dos);
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java Fri May 30 22:51:27 2014
@@ -32,40 +32,40 @@ import org.apache.bcel.Constants;
*/
public class RuntimeVisibleAnnotations extends Annotations
{
- private static final long serialVersionUID = 8992333017010665281L;
+ private static final long serialVersionUID = 8992333017010665281L;
/**
- * @param name_index
- * Index pointing to the name <em>Code</em>
- * @param length
- * Content length in bytes
- * @param file
- * Input stream
- * @param constant_pool
- * Array of constants
- */
- public RuntimeVisibleAnnotations(int name_index, int length,
- DataInputStream file, ConstantPool constant_pool)
- throws IOException
- {
- super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length,
- file, constant_pool, true);
- }
+ * @param name_index
+ * Index pointing to the name <em>Code</em>
+ * @param length
+ * Content length in bytes
+ * @param file
+ * Input stream
+ * @param constant_pool
+ * Array of constants
+ */
+ public RuntimeVisibleAnnotations(int name_index, int length,
+ DataInputStream file, ConstantPool constant_pool)
+ throws IOException
+ {
+ super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length,
+ file, constant_pool, true);
+ }
- /**
- * @return deep copy of this attribute
- */
- @Override
+ /**
+ * @return deep copy of this attribute
+ */
+ @Override
public Attribute copy(ConstantPool constant_pool)
- {
- Annotations c = (Annotations) clone();
- return c;
- }
+ {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
- @Override
+ @Override
public final void dump(DataOutputStream dos) throws IOException
- {
- super.dump(dos);
- writeAnnotations(dos);
- }
+ {
+ super.dump(dos);
+ writeAnnotations(dos);
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java Fri May 30 22:51:27 2014
@@ -23,201 +23,201 @@ import org.apache.bcel.Constants;
public class SimpleElementValue extends ElementValue
{
- private int index;
+ private int index;
- public SimpleElementValue(int type, int index, ConstantPool cpool)
- {
- super(type, cpool);
- this.index = index;
- }
+ public SimpleElementValue(int type, int index, ConstantPool cpool)
+ {
+ super(type, cpool);
+ this.index = index;
+ }
- /**
- * @return Value entry index in the cpool
- */
- public int getIndex()
- {
- return index;
- }
+ /**
+ * @return Value entry index in the cpool
+ */
+ public int getIndex()
+ {
+ return index;
+ }
- public void setIndex(int index)
- {
- this.index = index;
- }
+ public void setIndex(int index)
+ {
+ this.index = index;
+ }
- public String getValueString()
- {
- if (type != STRING) {
+ public String getValueString()
+ {
+ if (type != STRING) {
throw new RuntimeException(
- "Dont call getValueString() on a non STRING ElementValue");
+ "Dont call getValueString() on a non STRING ElementValue");
}
- ConstantUtf8 c = (ConstantUtf8) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Utf8);
- return c.getBytes();
- }
+ ConstantUtf8 c = (ConstantUtf8) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Utf8);
+ return c.getBytes();
+ }
- public int getValueInt()
- {
- if (type != PRIMITIVE_INT) {
+ public int getValueInt()
+ {
+ if (type != PRIMITIVE_INT) {
throw new RuntimeException(
- "Dont call getValueString() on a non STRING ElementValue");
+ "Dont call getValueString() on a non STRING ElementValue");
}
- ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return c.getBytes();
- }
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return c.getBytes();
+ }
- public byte getValueByte()
- {
- if (type != PRIMITIVE_BYTE) {
+ public byte getValueByte()
+ {
+ if (type != PRIMITIVE_BYTE) {
throw new RuntimeException(
- "Dont call getValueByte() on a non BYTE ElementValue");
+ "Dont call getValueByte() on a non BYTE ElementValue");
}
- ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return (byte) c.getBytes();
- }
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return (byte) c.getBytes();
+ }
- public char getValueChar()
- {
- if (type != PRIMITIVE_CHAR) {
+ public char getValueChar()
+ {
+ if (type != PRIMITIVE_CHAR) {
throw new RuntimeException(
- "Dont call getValueChar() on a non CHAR ElementValue");
+ "Dont call getValueChar() on a non CHAR ElementValue");
}
- ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return (char) c.getBytes();
- }
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return (char) c.getBytes();
+ }
- public long getValueLong()
- {
- if (type != PRIMITIVE_LONG) {
+ public long getValueLong()
+ {
+ if (type != PRIMITIVE_LONG) {
throw new RuntimeException(
- "Dont call getValueLong() on a non LONG ElementValue");
+ "Dont call getValueLong() on a non LONG ElementValue");
}
- ConstantLong j = (ConstantLong) cpool.getConstant(getIndex());
- return j.getBytes();
- }
+ ConstantLong j = (ConstantLong) cpool.getConstant(getIndex());
+ return j.getBytes();
+ }
- public float getValueFloat()
- {
- if (type != PRIMITIVE_FLOAT) {
+ public float getValueFloat()
+ {
+ if (type != PRIMITIVE_FLOAT) {
throw new RuntimeException(
- "Dont call getValueFloat() on a non FLOAT ElementValue");
+ "Dont call getValueFloat() on a non FLOAT ElementValue");
}
- ConstantFloat f = (ConstantFloat) cpool.getConstant(getIndex());
- return f.getBytes();
- }
+ ConstantFloat f = (ConstantFloat) cpool.getConstant(getIndex());
+ return f.getBytes();
+ }
- public double getValueDouble()
- {
- if (type != PRIMITIVE_DOUBLE) {
+ public double getValueDouble()
+ {
+ if (type != PRIMITIVE_DOUBLE) {
throw new RuntimeException(
- "Dont call getValueDouble() on a non DOUBLE ElementValue");
+ "Dont call getValueDouble() on a non DOUBLE ElementValue");
}
- ConstantDouble d = (ConstantDouble) cpool.getConstant(getIndex());
- return d.getBytes();
- }
+ ConstantDouble d = (ConstantDouble) cpool.getConstant(getIndex());
+ return d.getBytes();
+ }
- public boolean getValueBoolean()
- {
- if (type != PRIMITIVE_BOOLEAN) {
+ public boolean getValueBoolean()
+ {
+ if (type != PRIMITIVE_BOOLEAN) {
throw new RuntimeException(
- "Dont call getValueBoolean() on a non BOOLEAN ElementValue");
+ "Dont call getValueBoolean() on a non BOOLEAN ElementValue");
}
- ConstantInteger bo = (ConstantInteger) cpool.getConstant(getIndex());
- return (bo.getBytes() != 0);
- }
+ ConstantInteger bo = (ConstantInteger) cpool.getConstant(getIndex());
+ return (bo.getBytes() != 0);
+ }
- public short getValueShort()
- {
- if (type != PRIMITIVE_SHORT) {
+ public short getValueShort()
+ {
+ if (type != PRIMITIVE_SHORT) {
throw new RuntimeException(
- "Dont call getValueShort() on a non SHORT ElementValue");
+ "Dont call getValueShort() on a non SHORT ElementValue");
}
- ConstantInteger s = (ConstantInteger) cpool.getConstant(getIndex());
- return (short) s.getBytes();
- }
+ ConstantInteger s = (ConstantInteger) cpool.getConstant(getIndex());
+ return (short) s.getBytes();
+ }
- @Override
+ @Override
public String toString()
- {
- return stringifyValue();
- }
+ {
+ return stringifyValue();
+ }
- // Whatever kind of value it is, return it as a string
- @Override
+ // Whatever kind of value it is, return it as a string
+ @Override
public String stringifyValue()
- {
- switch (type)
- {
- case PRIMITIVE_INT:
- ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return Integer.toString(c.getBytes());
- case PRIMITIVE_LONG:
- ConstantLong j = (ConstantLong) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Long);
- return Long.toString(j.getBytes());
- case PRIMITIVE_DOUBLE:
- ConstantDouble d = (ConstantDouble) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Double);
- return Double.toString(d.getBytes());
- case PRIMITIVE_FLOAT:
- ConstantFloat f = (ConstantFloat) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Float);
- return Float.toString(f.getBytes());
- case PRIMITIVE_SHORT:
- ConstantInteger s = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return Integer.toString(s.getBytes());
- case PRIMITIVE_BYTE:
- ConstantInteger b = (ConstantInteger) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Integer);
- return Integer.toString(b.getBytes());
- case PRIMITIVE_CHAR:
- ConstantInteger ch = (ConstantInteger) cpool.getConstant(
- getIndex(), Constants.CONSTANT_Integer);
- return String.valueOf((char)ch.getBytes());
- case PRIMITIVE_BOOLEAN:
- ConstantInteger bo = (ConstantInteger) cpool.getConstant(
- getIndex(), Constants.CONSTANT_Integer);
- if (bo.getBytes() == 0) {
+ {
+ switch (type)
+ {
+ case PRIMITIVE_INT:
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return Integer.toString(c.getBytes());
+ case PRIMITIVE_LONG:
+ ConstantLong j = (ConstantLong) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Long);
+ return Long.toString(j.getBytes());
+ case PRIMITIVE_DOUBLE:
+ ConstantDouble d = (ConstantDouble) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Double);
+ return Double.toString(d.getBytes());
+ case PRIMITIVE_FLOAT:
+ ConstantFloat f = (ConstantFloat) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Float);
+ return Float.toString(f.getBytes());
+ case PRIMITIVE_SHORT:
+ ConstantInteger s = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return Integer.toString(s.getBytes());
+ case PRIMITIVE_BYTE:
+ ConstantInteger b = (ConstantInteger) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Integer);
+ return Integer.toString(b.getBytes());
+ case PRIMITIVE_CHAR:
+ ConstantInteger ch = (ConstantInteger) cpool.getConstant(
+ getIndex(), Constants.CONSTANT_Integer);
+ return String.valueOf((char)ch.getBytes());
+ case PRIMITIVE_BOOLEAN:
+ ConstantInteger bo = (ConstantInteger) cpool.getConstant(
+ getIndex(), Constants.CONSTANT_Integer);
+ if (bo.getBytes() == 0) {
return "false";
} else {
return "true";
}
- case STRING:
- ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(getIndex(),
- Constants.CONSTANT_Utf8);
- return cu8.getBytes();
- default:
- throw new RuntimeException(
- "SimpleElementValue class does not know how to stringify type "
- + type);
- }
- }
+ case STRING:
+ ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(getIndex(),
+ Constants.CONSTANT_Utf8);
+ return cu8.getBytes();
+ default:
+ throw new RuntimeException(
+ "SimpleElementValue class does not know how to stringify type "
+ + type);
+ }
+ }
- @Override
+ @Override
public void dump(DataOutputStream dos) throws IOException
- {
- dos.writeByte(type); // u1 kind of value
- switch (type)
- {
- case PRIMITIVE_INT:
- case PRIMITIVE_BYTE:
- case PRIMITIVE_CHAR:
- case PRIMITIVE_FLOAT:
- case PRIMITIVE_LONG:
- case PRIMITIVE_BOOLEAN:
- case PRIMITIVE_SHORT:
- case PRIMITIVE_DOUBLE:
- case STRING:
- dos.writeShort(getIndex());
- break;
- default:
- throw new RuntimeException(
- "SimpleElementValue doesnt know how to write out type "
- + type);
- }
- }
+ {
+ dos.writeByte(type); // u1 kind of value
+ switch (type)
+ {
+ case PRIMITIVE_INT:
+ case PRIMITIVE_BYTE:
+ case PRIMITIVE_CHAR:
+ case PRIMITIVE_FLOAT:
+ case PRIMITIVE_LONG:
+ case PRIMITIVE_BOOLEAN:
+ case PRIMITIVE_SHORT:
+ case PRIMITIVE_DOUBLE:
+ case STRING:
+ dos.writeShort(getIndex());
+ break;
+ default:
+ throw new RuntimeException(
+ "SimpleElementValue doesnt know how to write out type "
+ + type);
+ }
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java Fri May 30 22:51:27 2014
@@ -36,7 +36,7 @@ import org.apache.bcel.Constants;
*/
public final class StackMapTableEntry implements Cloneable, Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
private int frame_type;
private int byte_code_offset_delta;
@@ -54,45 +54,45 @@ public final class StackMapTableEntry im
*/
StackMapTableEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
this(file.read(), -1, -1, null, -1, null, constant_pool);
-
+
if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
- byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
+ byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
} else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
- byte_code_offset_delta = frame_type - Constants.SAME_LOCALS_1_STACK_ITEM_FRAME;
- number_of_stack_items = 1;
- types_of_stack_items = new StackMapType[1];
- types_of_stack_items[0] = new StackMapType(file, constant_pool);
+ byte_code_offset_delta = frame_type - Constants.SAME_LOCALS_1_STACK_ITEM_FRAME;
+ number_of_stack_items = 1;
+ types_of_stack_items = new StackMapType[1];
+ types_of_stack_items[0] = new StackMapType(file, constant_pool);
} else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
- byte_code_offset_delta = file.readShort();
- number_of_stack_items = 1;
- types_of_stack_items = new StackMapType[1];
- types_of_stack_items[0] = new StackMapType(file, constant_pool);
+ byte_code_offset_delta = file.readShort();
+ number_of_stack_items = 1;
+ types_of_stack_items = new StackMapType[1];
+ types_of_stack_items[0] = new StackMapType(file, constant_pool);
} else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) {
- byte_code_offset_delta = file.readShort();
+ byte_code_offset_delta = file.readShort();
} else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
- byte_code_offset_delta = file.readShort();
+ byte_code_offset_delta = file.readShort();
} else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) {
- byte_code_offset_delta = file.readShort();
- number_of_locals = frame_type - 251;
- types_of_locals = new StackMapType[number_of_locals];
- for (int i = 0; i < number_of_locals; i++) {
- types_of_locals[i] = new StackMapType(file, constant_pool);
- }
+ byte_code_offset_delta = file.readShort();
+ number_of_locals = frame_type - 251;
+ types_of_locals = new StackMapType[number_of_locals];
+ for (int i = 0; i < number_of_locals; i++) {
+ types_of_locals[i] = new StackMapType(file, constant_pool);
+ }
} else if (frame_type == Constants.FULL_FRAME) {
- byte_code_offset_delta = file.readShort();
- number_of_locals = file.readShort();
- types_of_locals = new StackMapType[number_of_locals];
- for (int i = 0; i < number_of_locals; i++) {
- types_of_locals[i] = new StackMapType(file, constant_pool);
- }
- number_of_stack_items = file.readShort();
- types_of_stack_items = new StackMapType[number_of_stack_items];
- for (int i = 0; i < number_of_stack_items; i++) {
- types_of_stack_items[i] = new StackMapType(file, constant_pool);
- }
+ byte_code_offset_delta = file.readShort();
+ number_of_locals = file.readShort();
+ types_of_locals = new StackMapType[number_of_locals];
+ for (int i = 0; i < number_of_locals; i++) {
+ types_of_locals[i] = new StackMapType(file, constant_pool);
+ }
+ number_of_stack_items = file.readShort();
+ types_of_stack_items = new StackMapType[number_of_stack_items];
+ for (int i = 0; i < number_of_stack_items; i++) {
+ types_of_stack_items[i] = new StackMapType(file, constant_pool);
+ }
} else {
- /* Can't happen */
- throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
+ /* Can't happen */
+ throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
}
}
@@ -100,7 +100,7 @@ public final class StackMapTableEntry im
public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals,
StackMapType[] types_of_locals, int number_of_stack_items,
StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
- this.frame_type = tag;
+ this.frame_type = tag;
this.byte_code_offset_delta = byte_code_offset_delta;
this.number_of_locals = number_of_locals;
this.types_of_locals = types_of_locals;
@@ -117,23 +117,23 @@ public final class StackMapTableEntry im
* @throws IOException
*/
public final void dump( DataOutputStream file ) throws IOException {
- file.write(frame_type);
- if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
- // nothing to be done
- } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
- types_of_stack_items[0].dump(file);
+ file.write(frame_type);
+ if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
+ // nothing to be done
+ } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
+ types_of_stack_items[0].dump(file);
} else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
file.writeShort(byte_code_offset_delta);
- types_of_stack_items[0].dump(file);
+ types_of_stack_items[0].dump(file);
} else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) {
file.writeShort(byte_code_offset_delta);
} else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
file.writeShort(byte_code_offset_delta);
} else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) {
file.writeShort(byte_code_offset_delta);
- for (int i = 0; i < number_of_locals; i++) {
- types_of_locals[i].dump(file);
- }
+ for (int i = 0; i < number_of_locals; i++) {
+ types_of_locals[i].dump(file);
+ }
} else if (frame_type == Constants.FULL_FRAME) {
file.writeShort(byte_code_offset_delta);
file.writeShort(number_of_locals);
@@ -145,8 +145,8 @@ public final class StackMapTableEntry im
types_of_stack_items[i].dump(file);
}
} else {
- /* Can't happen */
- throw new ClassFormatException ("Invalid Stack map table tag: " + frame_type);
+ /* Can't happen */
+ throw new ClassFormatException ("Invalid Stack map table tag: " + frame_type);
}
}
@@ -159,21 +159,21 @@ public final class StackMapTableEntry im
StringBuilder buf = new StringBuilder(64);
buf.append("(");
if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
- buf.append("SAME");
+ buf.append("SAME");
} else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
- buf.append("SAME_LOCALS_1_STACK");
+ buf.append("SAME_LOCALS_1_STACK");
} else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
- buf.append("SAME_LOCALS_1_STACK_EXTENDED");
+ buf.append("SAME_LOCALS_1_STACK_EXTENDED");
} else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) {
- buf.append("CHOP "+(251-frame_type));
+ buf.append("CHOP "+(251-frame_type));
} else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
- buf.append("SAME_EXTENDED");
+ buf.append("SAME_EXTENDED");
} else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) {
- buf.append("APPEND "+(frame_type-251));
+ buf.append("APPEND "+(frame_type-251));
} else if (frame_type == Constants.FULL_FRAME) {
- buf.append("FULL");
+ buf.append("FULL");
} else {
- buf.append("UNKNOWN");
+ buf.append("UNKNOWN");
}
buf.append(", offset delta=").append(byte_code_offset_delta);
if (number_of_locals > 0) {
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java Fri May 30 22:51:27 2014
@@ -1395,50 +1395,50 @@ public abstract class Utility {
* @param vec A list of AnnotationGen objects
*/
public static Attribute[] getAnnotationAttributes(ConstantPoolGen cp,List<AnnotationEntryGen> vec) {
-
- if (vec.isEmpty()) {
+
+ if (vec.isEmpty()) {
return new Attribute[0];
}
-
- try {
- int countVisible = 0;
- int countInvisible = 0;
-
- // put the annotations in the right output stream
- for (AnnotationEntryGen a : vec) {
- if (a.isRuntimeVisible()) {
+
+ try {
+ int countVisible = 0;
+ int countInvisible = 0;
+
+ // put the annotations in the right output stream
+ for (AnnotationEntryGen a : vec) {
+ if (a.isRuntimeVisible()) {
countVisible++;
} else {
countInvisible++;
}
- }
-
- ByteArrayOutputStream rvaBytes = new ByteArrayOutputStream();
- ByteArrayOutputStream riaBytes = new ByteArrayOutputStream();
- DataOutputStream rvaDos = new DataOutputStream(rvaBytes);
- DataOutputStream riaDos = new DataOutputStream(riaBytes);
-
- rvaDos.writeShort(countVisible);
- riaDos.writeShort(countInvisible);
-
- // put the annotations in the right output stream
- for (AnnotationEntryGen a : vec) {
- if (a.isRuntimeVisible()) {
+ }
+
+ ByteArrayOutputStream rvaBytes = new ByteArrayOutputStream();
+ ByteArrayOutputStream riaBytes = new ByteArrayOutputStream();
+ DataOutputStream rvaDos = new DataOutputStream(rvaBytes);
+ DataOutputStream riaDos = new DataOutputStream(riaBytes);
+
+ rvaDos.writeShort(countVisible);
+ riaDos.writeShort(countInvisible);
+
+ // put the annotations in the right output stream
+ for (AnnotationEntryGen a : vec) {
+ if (a.isRuntimeVisible()) {
a.dump(rvaDos);
} else {
a.dump(riaDos);
}
- }
+ }
rvaDos.close();
riaDos.close();
-
+
byte[] rvaData = rvaBytes.toByteArray();
byte[] riaData = riaBytes.toByteArray();
-
+
int rvaIndex = -1;
int riaIndex = -1;
-
+
if (rvaData.length>2) {
rvaIndex = cp.addUtf8("RuntimeVisibleAnnotations");
}
@@ -1446,112 +1446,112 @@ public abstract class Utility {
riaIndex = cp.addUtf8("RuntimeInvisibleAnnotations");
}
- List<Attribute> newAttributes = new ArrayList<Attribute>();
- if (rvaData.length>2) {
-
- newAttributes.add(
- new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,new DataInputStream(new ByteArrayInputStream(rvaData)),cp.getConstantPool()));
- }
- if (riaData.length>2) {
- newAttributes.add(
- new RuntimeInvisibleAnnotations(riaIndex,riaData.length,new DataInputStream(new ByteArrayInputStream(riaData)),cp.getConstantPool()));
- }
-
- return newAttributes.toArray(new Attribute[newAttributes.size()]);
- } catch (IOException e) {
- System.err.println("IOException whilst processing annotations");
- e.printStackTrace();
- }
- return null;
+ List<Attribute> newAttributes = new ArrayList<Attribute>();
+ if (rvaData.length>2) {
+
+ newAttributes.add(
+ new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,new DataInputStream(new ByteArrayInputStream(rvaData)),cp.getConstantPool()));
+ }
+ if (riaData.length>2) {
+ newAttributes.add(
+ new RuntimeInvisibleAnnotations(riaIndex,riaData.length,new DataInputStream(new ByteArrayInputStream(riaData)),cp.getConstantPool()));
+ }
+
+ return newAttributes.toArray(new Attribute[newAttributes.size()]);
+ } catch (IOException e) {
+ System.err.println("IOException whilst processing annotations");
+ e.printStackTrace();
+ }
+ return null;
}
/**
- * Annotations against a class are stored in one of four attribute kinds:
- * - RuntimeVisibleParameterAnnotations
- * - RuntimeInvisibleParameterAnnotations
- */
- public static Attribute[] getParameterAnnotationAttributes(
- ConstantPoolGen cp,
- List<AnnotationEntryGen>[] /*Array of lists, array size depends on #params */vec)
- {
- int visCount[] = new int[vec.length];
- int totalVisCount = 0;
- int invisCount[] = new int[vec.length];
- int totalInvisCount = 0;
- try {
- for (int i = 0; i < vec.length; i++) {
- if (vec[i] != null) {
- for (AnnotationEntryGen element : vec[i]) {
- if (element.isRuntimeVisible()) {
- visCount[i]++;
- totalVisCount++;
- }
- else {
- invisCount[i]++;
- totalInvisCount++;
- }
- }
- }
- }
- // Lets do the visible ones
- ByteArrayOutputStream rvaBytes = new ByteArrayOutputStream();
- DataOutputStream rvaDos = new DataOutputStream(rvaBytes);
- rvaDos.writeByte(vec.length); // First goes number of parameters
- for (int i = 0; i < vec.length; i++) {
- rvaDos.writeShort(visCount[i]);
- if (visCount[i] > 0) {
- for (AnnotationEntryGen element : vec[i]) {
- if (element.isRuntimeVisible()) {
+ * Annotations against a class are stored in one of four attribute kinds:
+ * - RuntimeVisibleParameterAnnotations
+ * - RuntimeInvisibleParameterAnnotations
+ */
+ public static Attribute[] getParameterAnnotationAttributes(
+ ConstantPoolGen cp,
+ List<AnnotationEntryGen>[] /*Array of lists, array size depends on #params */vec)
+ {
+ int visCount[] = new int[vec.length];
+ int totalVisCount = 0;
+ int invisCount[] = new int[vec.length];
+ int totalInvisCount = 0;
+ try {
+ for (int i = 0; i < vec.length; i++) {
+ if (vec[i] != null) {
+ for (AnnotationEntryGen element : vec[i]) {
+ if (element.isRuntimeVisible()) {
+ visCount[i]++;
+ totalVisCount++;
+ }
+ else {
+ invisCount[i]++;
+ totalInvisCount++;
+ }
+ }
+ }
+ }
+ // Lets do the visible ones
+ ByteArrayOutputStream rvaBytes = new ByteArrayOutputStream();
+ DataOutputStream rvaDos = new DataOutputStream(rvaBytes);
+ rvaDos.writeByte(vec.length); // First goes number of parameters
+ for (int i = 0; i < vec.length; i++) {
+ rvaDos.writeShort(visCount[i]);
+ if (visCount[i] > 0) {
+ for (AnnotationEntryGen element : vec[i]) {
+ if (element.isRuntimeVisible()) {
element.dump(rvaDos);
}
- }
- }
- }
- rvaDos.close();
- // Lets do the invisible ones
- ByteArrayOutputStream riaBytes = new ByteArrayOutputStream();
- DataOutputStream riaDos = new DataOutputStream(riaBytes);
- riaDos.writeByte(vec.length); // First goes number of parameters
- for (int i = 0; i < vec.length; i++) {
- riaDos.writeShort(invisCount[i]);
- if (invisCount[i] > 0) {
- for (AnnotationEntryGen element : vec[i]) {
- if (!element.isRuntimeVisible()) {
+ }
+ }
+ }
+ rvaDos.close();
+ // Lets do the invisible ones
+ ByteArrayOutputStream riaBytes = new ByteArrayOutputStream();
+ DataOutputStream riaDos = new DataOutputStream(riaBytes);
+ riaDos.writeByte(vec.length); // First goes number of parameters
+ for (int i = 0; i < vec.length; i++) {
+ riaDos.writeShort(invisCount[i]);
+ if (invisCount[i] > 0) {
+ for (AnnotationEntryGen element : vec[i]) {
+ if (!element.isRuntimeVisible()) {
element.dump(riaDos);
}
- }
- }
- }
- riaDos.close();
- byte[] rvaData = rvaBytes.toByteArray();
- byte[] riaData = riaBytes.toByteArray();
- int rvaIndex = -1;
- int riaIndex = -1;
- if (totalVisCount > 0) {
+ }
+ }
+ }
+ riaDos.close();
+ byte[] rvaData = rvaBytes.toByteArray();
+ byte[] riaData = riaBytes.toByteArray();
+ int rvaIndex = -1;
+ int riaIndex = -1;
+ if (totalVisCount > 0) {
rvaIndex = cp.addUtf8("RuntimeVisibleParameterAnnotations");
}
- if (totalInvisCount > 0) {
+ if (totalInvisCount > 0) {
riaIndex = cp.addUtf8("RuntimeInvisibleParameterAnnotations");
}
- List<Attribute> newAttributes = new ArrayList<Attribute>();
- if (totalVisCount > 0) {
- newAttributes
- .add(new RuntimeVisibleParameterAnnotations(rvaIndex,
- rvaData.length, new DataInputStream(new ByteArrayInputStream(rvaData)), cp.getConstantPool()));
- }
- if (totalInvisCount > 0) {
- newAttributes
- .add(new RuntimeInvisibleParameterAnnotations(riaIndex,
- riaData.length, new DataInputStream(new ByteArrayInputStream(riaData)), cp.getConstantPool()));
- }
- return newAttributes.toArray(new Attribute[newAttributes.size()]);
- }
- catch (IOException e) {
- System.err
- .println("IOException whilst processing parameter annotations");
- e.printStackTrace();
- }
- return null;
- }
+ List<Attribute> newAttributes = new ArrayList<Attribute>();
+ if (totalVisCount > 0) {
+ newAttributes
+ .add(new RuntimeVisibleParameterAnnotations(rvaIndex,
+ rvaData.length, new DataInputStream(new ByteArrayInputStream(rvaData)), cp.getConstantPool()));
+ }
+ if (totalInvisCount > 0) {
+ newAttributes
+ .add(new RuntimeInvisibleParameterAnnotations(riaIndex,
+ riaData.length, new DataInputStream(new ByteArrayInputStream(riaData)), cp.getConstantPool()));
+ }
+ return newAttributes.toArray(new Attribute[newAttributes.size()]);
+ }
+ catch (IOException e) {
+ System.err
+ .println("IOException whilst processing parameter annotations");
+ e.printStackTrace();
+ }
+ return null;
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java Fri May 30 22:51:27 2014
@@ -27,87 +27,87 @@ package org.apache.bcel.classfile;
*/
public interface Visitor
{
- void visitCode(Code obj);
+ void visitCode(Code obj);
- void visitCodeException(CodeException obj);
+ void visitCodeException(CodeException obj);
- void visitConstantClass(ConstantClass obj);
+ void visitConstantClass(ConstantClass obj);
- void visitConstantDouble(ConstantDouble obj);
+ void visitConstantDouble(ConstantDouble obj);
- void visitConstantFieldref(ConstantFieldref obj);
+ void visitConstantFieldref(ConstantFieldref obj);
- void visitConstantFloat(ConstantFloat obj);
+ void visitConstantFloat(ConstantFloat obj);
- void visitConstantInteger(ConstantInteger obj);
+ void visitConstantInteger(ConstantInteger obj);
- void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj);
+ void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj);
- void visitConstantLong(ConstantLong obj);
+ void visitConstantLong(ConstantLong obj);
- void visitConstantMethodref(ConstantMethodref obj);
+ void visitConstantMethodref(ConstantMethodref obj);
- void visitConstantNameAndType(ConstantNameAndType obj);
+ void visitConstantNameAndType(ConstantNameAndType obj);
- void visitConstantPool(ConstantPool obj);
+ void visitConstantPool(ConstantPool obj);
- void visitConstantString(ConstantString obj);
+ void visitConstantString(ConstantString obj);
- void visitConstantUtf8(ConstantUtf8 obj);
+ void visitConstantUtf8(ConstantUtf8 obj);
- void visitConstantValue(ConstantValue obj);
+ void visitConstantValue(ConstantValue obj);
- void visitDeprecated(Deprecated obj);
+ void visitDeprecated(Deprecated obj);
- void visitExceptionTable(ExceptionTable obj);
+ void visitExceptionTable(ExceptionTable obj);
- void visitField(Field obj);
+ void visitField(Field obj);
- void visitInnerClass(InnerClass obj);
+ void visitInnerClass(InnerClass obj);
- void visitInnerClasses(InnerClasses obj);
+ void visitInnerClasses(InnerClasses obj);
- void visitJavaClass(JavaClass obj);
+ void visitJavaClass(JavaClass obj);
- void visitLineNumber(LineNumber obj);
+ void visitLineNumber(LineNumber obj);
- void visitLineNumberTable(LineNumberTable obj);
+ void visitLineNumberTable(LineNumberTable obj);
- void visitLocalVariable(LocalVariable obj);
+ void visitLocalVariable(LocalVariable obj);
- void visitLocalVariableTable(LocalVariableTable obj);
+ void visitLocalVariableTable(LocalVariableTable obj);
- void visitMethod(Method obj);
+ void visitMethod(Method obj);
- void visitSignature(Signature obj);
+ void visitSignature(Signature obj);
- void visitSourceFile(SourceFile obj);
+ void visitSourceFile(SourceFile obj);
- void visitSynthetic(Synthetic obj);
+ void visitSynthetic(Synthetic obj);
- void visitUnknown(Unknown obj);
+ void visitUnknown(Unknown obj);
- void visitStackMap(StackMap obj);
+ void visitStackMap(StackMap obj);
- void visitStackMapEntry(StackMapEntry obj);
+ void visitStackMapEntry(StackMapEntry obj);
- void visitStackMapTable(StackMapTable obj);
+ void visitStackMapTable(StackMapTable obj);
- void visitStackMapTableEntry(StackMapTableEntry obj);
+ void visitStackMapTableEntry(StackMapTableEntry obj);
- void visitAnnotation(Annotations obj);
+ void visitAnnotation(Annotations obj);
- void visitParameterAnnotation(ParameterAnnotations obj);
+ void visitParameterAnnotation(ParameterAnnotations obj);
- void visitAnnotationEntry(AnnotationEntry obj);
+ void visitAnnotationEntry(AnnotationEntry obj);
- void visitAnnotationDefault(AnnotationDefault obj);
+ void visitAnnotationDefault(AnnotationDefault obj);
- void visitLocalVariableTypeTable(LocalVariableTypeTable obj);
+ void visitLocalVariableTypeTable(LocalVariableTypeTable obj);
- void visitEnclosingMethod(EnclosingMethod obj);
+ void visitEnclosingMethod(EnclosingMethod obj);
void visitBootstrapMethods(BootstrapMethods obj);
-
+
void visitMethodParameters(MethodParameters obj);
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationElementValueGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationElementValueGen.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationElementValueGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationElementValueGen.java Fri May 30 22:51:27 2014
@@ -24,58 +24,58 @@ import org.apache.bcel.classfile.Element
public class AnnotationElementValueGen extends ElementValueGen
{
- // For annotation element values, this is the annotation
- private AnnotationEntryGen a;
+ // For annotation element values, this is the annotation
+ private AnnotationEntryGen a;
- public AnnotationElementValueGen(AnnotationEntryGen a, ConstantPoolGen cpool)
- {
- super(ANNOTATION, cpool);
- this.a = a;
- }
-
- public AnnotationElementValueGen(int type, AnnotationEntryGen annotation,
- ConstantPoolGen cpool)
- {
- super(type, cpool);
- if (type != ANNOTATION) {
+ public AnnotationElementValueGen(AnnotationEntryGen a, ConstantPoolGen cpool)
+ {
+ super(ANNOTATION, cpool);
+ this.a = a;
+ }
+
+ public AnnotationElementValueGen(int type, AnnotationEntryGen annotation,
+ ConstantPoolGen cpool)
+ {
+ super(type, cpool);
+ if (type != ANNOTATION) {
throw new RuntimeException(
- "Only element values of type annotation can be built with this ctor - type specified: " + type);
+ "Only element values of type annotation can be built with this ctor - type specified: " + type);
}
- this.a = annotation;
- }
+ this.a = annotation;
+ }
- public AnnotationElementValueGen(AnnotationElementValue value,
- ConstantPoolGen cpool, boolean copyPoolEntries)
- {
- super(ANNOTATION, cpool);
- a = new AnnotationEntryGen(value.getAnnotationEntry(), cpool, copyPoolEntries);
- }
+ public AnnotationElementValueGen(AnnotationElementValue value,
+ ConstantPoolGen cpool, boolean copyPoolEntries)
+ {
+ super(ANNOTATION, cpool);
+ a = new AnnotationEntryGen(value.getAnnotationEntry(), cpool, copyPoolEntries);
+ }
- @Override
+ @Override
public void dump(DataOutputStream dos) throws IOException
- {
- dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
- a.dump(dos);
- }
+ {
+ dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
+ a.dump(dos);
+ }
- @Override
+ @Override
public String stringifyValue()
- {
- throw new RuntimeException("Not implemented yet");
- }
-
- /**
- * Return immutable variant of this AnnotationElementValueGen
- */
- @Override
+ {
+ throw new RuntimeException("Not implemented yet");
+ }
+
+ /**
+ * Return immutable variant of this AnnotationElementValueGen
+ */
+ @Override
public ElementValue getElementValue()
- {
- return new AnnotationElementValue(this.type, a.getAnnotation(), cpGen
- .getConstantPool());
- }
-
- public AnnotationEntryGen getAnnotation()
- {
- return a;
- }
+ {
+ return new AnnotationElementValue(this.type, a.getAnnotation(), cpGen
+ .getConstantPool());
+ }
+
+ public AnnotationEntryGen getAnnotation()
+ {
+ return a;
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java Fri May 30 22:51:27 2014
@@ -30,177 +30,177 @@ import org.apache.bcel.classfile.Element
public class AnnotationEntryGen
{
- private int typeIndex;
+ private int typeIndex;
- private List<ElementValuePairGen> evs;
+ private List<ElementValuePairGen> evs;
- private ConstantPoolGen cpool;
+ private ConstantPoolGen cpool;
- private boolean isRuntimeVisible = false;
+ private boolean isRuntimeVisible = false;
- /**
- * Here we are taking a fixed annotation of type Annotation and building a
- * modifiable AnnotationGen object. If the pool passed in is for a different
- * class file, then copyPoolEntries should have been passed as true as that
- * will force us to do a deep copy of the annotation and move the cpool
- * entries across. We need to copy the type and the element name value pairs
- * and the visibility.
- */
- public AnnotationEntryGen(AnnotationEntry a, ConstantPoolGen cpool,
- boolean copyPoolEntries)
- {
- this.cpool = cpool;
- if (copyPoolEntries)
- {
- typeIndex = cpool.addUtf8(a.getAnnotationType());
- }
- else
- {
- typeIndex = a.getAnnotationTypeIndex();
- }
- isRuntimeVisible = a.isRuntimeVisible();
- evs = copyValues(a.getElementValuePairs(), cpool, copyPoolEntries);
- }
-
- private List<ElementValuePairGen> copyValues(ElementValuePair[] in, ConstantPoolGen cpool,
- boolean copyPoolEntries)
- {
- List<ElementValuePairGen> out = new ArrayList<ElementValuePairGen>();
- int l = in.length;
+ /**
+ * Here we are taking a fixed annotation of type Annotation and building a
+ * modifiable AnnotationGen object. If the pool passed in is for a different
+ * class file, then copyPoolEntries should have been passed as true as that
+ * will force us to do a deep copy of the annotation and move the cpool
+ * entries across. We need to copy the type and the element name value pairs
+ * and the visibility.
+ */
+ public AnnotationEntryGen(AnnotationEntry a, ConstantPoolGen cpool,
+ boolean copyPoolEntries)
+ {
+ this.cpool = cpool;
+ if (copyPoolEntries)
+ {
+ typeIndex = cpool.addUtf8(a.getAnnotationType());
+ }
+ else
+ {
+ typeIndex = a.getAnnotationTypeIndex();
+ }
+ isRuntimeVisible = a.isRuntimeVisible();
+ evs = copyValues(a.getElementValuePairs(), cpool, copyPoolEntries);
+ }
+
+ private List<ElementValuePairGen> copyValues(ElementValuePair[] in, ConstantPoolGen cpool,
+ boolean copyPoolEntries)
+ {
+ List<ElementValuePairGen> out = new ArrayList<ElementValuePairGen>();
+ int l = in.length;
for (ElementValuePair nvp : in)
{
out.add(new ElementValuePairGen(nvp, cpool, copyPoolEntries));
}
- return out;
- }
+ return out;
+ }
+
+ private AnnotationEntryGen(ConstantPoolGen cpool)
+ {
+ this.cpool = cpool;
+ }
+
+ /**
+ * Retrieve an immutable version of this AnnotationGen
+ */
+ public AnnotationEntry getAnnotation()
+ {
+ AnnotationEntry a = new AnnotationEntry(typeIndex, cpool.getConstantPool(),
+ isRuntimeVisible);
+ for (ElementValuePairGen element : evs) {
+ a.addElementNameValuePair(element.getElementNameValuePair());
+ }
+ return a;
+ }
- private AnnotationEntryGen(ConstantPoolGen cpool)
- {
- this.cpool = cpool;
- }
-
- /**
- * Retrieve an immutable version of this AnnotationGen
- */
- public AnnotationEntry getAnnotation()
- {
- AnnotationEntry a = new AnnotationEntry(typeIndex, cpool.getConstantPool(),
- isRuntimeVisible);
- for (ElementValuePairGen element : evs) {
- a.addElementNameValuePair(element.getElementNameValuePair());
- }
- return a;
- }
-
- public AnnotationEntryGen(ObjectType type,
- List<ElementValuePairGen> elements, boolean vis,
- ConstantPoolGen cpool)
- {
- this.cpool = cpool;
- this.typeIndex = cpool.addUtf8(type.getSignature());
- evs = elements;
- isRuntimeVisible = vis;
- }
-
- public static AnnotationEntryGen read(DataInputStream dis,
- ConstantPoolGen cpool, boolean b) throws IOException
- {
- AnnotationEntryGen a = new AnnotationEntryGen(cpool);
- a.typeIndex = dis.readUnsignedShort();
- int elemValuePairCount = dis.readUnsignedShort();
- for (int i = 0; i < elemValuePairCount; i++)
- {
- int nidx = dis.readUnsignedShort();
- a.addElementNameValuePair(new ElementValuePairGen(nidx,
- ElementValueGen.readElementValue(dis, cpool), cpool));
- }
- a.isRuntimeVisible(b);
- return a;
- }
-
- public void dump(DataOutputStream dos) throws IOException
- {
- dos.writeShort(typeIndex); // u2 index of type name in cpool
- dos.writeShort(evs.size()); // u2 element_value pair count
+ public AnnotationEntryGen(ObjectType type,
+ List<ElementValuePairGen> elements, boolean vis,
+ ConstantPoolGen cpool)
+ {
+ this.cpool = cpool;
+ this.typeIndex = cpool.addUtf8(type.getSignature());
+ evs = elements;
+ isRuntimeVisible = vis;
+ }
+
+ public static AnnotationEntryGen read(DataInputStream dis,
+ ConstantPoolGen cpool, boolean b) throws IOException
+ {
+ AnnotationEntryGen a = new AnnotationEntryGen(cpool);
+ a.typeIndex = dis.readUnsignedShort();
+ int elemValuePairCount = dis.readUnsignedShort();
+ for (int i = 0; i < elemValuePairCount; i++)
+ {
+ int nidx = dis.readUnsignedShort();
+ a.addElementNameValuePair(new ElementValuePairGen(nidx,
+ ElementValueGen.readElementValue(dis, cpool), cpool));
+ }
+ a.isRuntimeVisible(b);
+ return a;
+ }
+
+ public void dump(DataOutputStream dos) throws IOException
+ {
+ dos.writeShort(typeIndex); // u2 index of type name in cpool
+ dos.writeShort(evs.size()); // u2 element_value pair count
for (ElementValuePairGen envp : evs)
{
envp.dump(dos);
}
- }
+ }
- public void addElementNameValuePair(ElementValuePairGen evp)
- {
- if (evs == null) {
+ public void addElementNameValuePair(ElementValuePairGen evp)
+ {
+ if (evs == null) {
evs = new ArrayList<ElementValuePairGen>();
}
- evs.add(evp);
- }
+ evs.add(evp);
+ }
- public int getTypeIndex()
- {
- return typeIndex;
- }
-
- public final String getTypeSignature()
- {
- // ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex);
- ConstantUtf8 utf8 = (ConstantUtf8) cpool
- .getConstant(typeIndex/* c.getNameIndex() */);
- return utf8.getBytes();
- }
-
- public final String getTypeName()
- {
- return getTypeSignature();// BCELBUG: Should I use this instead?
- // Utility.signatureToString(getTypeSignature());
- }
-
- /**
- * Returns list of ElementNameValuePair objects
- */
- public List<ElementValuePairGen> getValues()
- {
- return evs;
- }
+ public int getTypeIndex()
+ {
+ return typeIndex;
+ }
+
+ public final String getTypeSignature()
+ {
+ // ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex);
+ ConstantUtf8 utf8 = (ConstantUtf8) cpool
+ .getConstant(typeIndex/* c.getNameIndex() */);
+ return utf8.getBytes();
+ }
+
+ public final String getTypeName()
+ {
+ return getTypeSignature();// BCELBUG: Should I use this instead?
+ // Utility.signatureToString(getTypeSignature());
+ }
+
+ /**
+ * Returns list of ElementNameValuePair objects
+ */
+ public List<ElementValuePairGen> getValues()
+ {
+ return evs;
+ }
- @Override
+ @Override
public String toString()
- {
- StringBuilder s = new StringBuilder(32);
- s.append("AnnotationGen:[" + getTypeName() + " #" + evs.size() + " {");
- for (int i = 0; i < evs.size(); i++)
- {
- s.append(evs.get(i));
- if (i + 1 < evs.size()) {
+ {
+ StringBuilder s = new StringBuilder(32);
+ s.append("AnnotationGen:[" + getTypeName() + " #" + evs.size() + " {");
+ for (int i = 0; i < evs.size(); i++)
+ {
+ s.append(evs.get(i));
+ if (i + 1 < evs.size()) {
s.append(",");
}
- }
- s.append("}]");
- return s.toString();
- }
-
- public String toShortString()
- {
- StringBuilder s = new StringBuilder();
- s.append("@" + getTypeName() + "(");
- for (int i = 0; i < evs.size(); i++)
- {
- s.append(evs.get(i));
- if (i + 1 < evs.size()) {
+ }
+ s.append("}]");
+ return s.toString();
+ }
+
+ public String toShortString()
+ {
+ StringBuilder s = new StringBuilder();
+ s.append("@" + getTypeName() + "(");
+ for (int i = 0; i < evs.size(); i++)
+ {
+ s.append(evs.get(i));
+ if (i + 1 < evs.size()) {
s.append(",");
}
- }
- s.append(")");
- return s.toString();
- }
-
- private void isRuntimeVisible(boolean b)
- {
- isRuntimeVisible = b;
- }
-
- public boolean isRuntimeVisible()
- {
- return isRuntimeVisible;
- }
+ }
+ s.append(")");
+ return s.toString();
+ }
+
+ private void isRuntimeVisible(boolean b)
+ {
+ isRuntimeVisible = b;
+ }
+
+ public boolean isRuntimeVisible()
+ {
+ return isRuntimeVisible;
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java Fri May 30 22:51:27 2014
@@ -27,97 +27,97 @@ import org.apache.bcel.classfile.Element
public class ArrayElementValueGen extends ElementValueGen
{
- // J5TODO: Should we make this an array or a list? A list would be easier to
- // modify ...
- private List<ElementValueGen> evalues;
-
- public ArrayElementValueGen(ConstantPoolGen cp)
- {
- super(ARRAY, cp);
- evalues = new ArrayList<ElementValueGen>();
- }
-
- public ArrayElementValueGen(int type, ElementValue[] datums,
- ConstantPoolGen cpool)
- {
- super(type, cpool);
- if (type != ARRAY) {
+ // J5TODO: Should we make this an array or a list? A list would be easier to
+ // modify ...
+ private List<ElementValueGen> evalues;
+
+ public ArrayElementValueGen(ConstantPoolGen cp)
+ {
+ super(ARRAY, cp);
+ evalues = new ArrayList<ElementValueGen>();
+ }
+
+ public ArrayElementValueGen(int type, ElementValue[] datums,
+ ConstantPoolGen cpool)
+ {
+ super(type, cpool);
+ if (type != ARRAY) {
throw new RuntimeException(
- "Only element values of type array can be built with this ctor - type specified: " + type);
+ "Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.evalues = new ArrayList<ElementValueGen>();
- for (ElementValue datum : datums) {
- evalues.add(ElementValueGen.copy(datum, cpool, true));
- }
- }
-
- /**
- * Return immutable variant of this ArrayElementValueGen
- */
- @Override
+ this.evalues = new ArrayList<ElementValueGen>();
+ for (ElementValue datum : datums) {
+ evalues.add(ElementValueGen.copy(datum, cpool, true));
+ }
+ }
+
+ /**
+ * Return immutable variant of this ArrayElementValueGen
+ */
+ @Override
public ElementValue getElementValue()
- {
- ElementValue[] immutableData = new ElementValue[evalues.size()];
- int i = 0;
- for (ElementValueGen element : evalues) {
- immutableData[i++] = element.getElementValue();
- }
- return new ArrayElementValue(type, immutableData, cpGen
- .getConstantPool());
- }
-
- /**
- * @param value
- * @param cpool
- */
- public ArrayElementValueGen(ArrayElementValue value, ConstantPoolGen cpool,
- boolean copyPoolEntries)
- {
- super(ARRAY, cpool);
- evalues = new ArrayList<ElementValueGen>();
- ElementValue[] in = value.getElementValuesArray();
- for (ElementValue element : in) {
- evalues.add(ElementValueGen.copy(element, cpool, copyPoolEntries));
- }
- }
+ {
+ ElementValue[] immutableData = new ElementValue[evalues.size()];
+ int i = 0;
+ for (ElementValueGen element : evalues) {
+ immutableData[i++] = element.getElementValue();
+ }
+ return new ArrayElementValue(type, immutableData, cpGen
+ .getConstantPool());
+ }
+
+ /**
+ * @param value
+ * @param cpool
+ */
+ public ArrayElementValueGen(ArrayElementValue value, ConstantPoolGen cpool,
+ boolean copyPoolEntries)
+ {
+ super(ARRAY, cpool);
+ evalues = new ArrayList<ElementValueGen>();
+ ElementValue[] in = value.getElementValuesArray();
+ for (ElementValue element : in) {
+ evalues.add(ElementValueGen.copy(element, cpool, copyPoolEntries));
+ }
+ }
- @Override
+ @Override
public void dump(DataOutputStream dos) throws IOException
- {
- dos.writeByte(type); // u1 type of value (ARRAY == '[')
- dos.writeShort(evalues.size());
- for (ElementValueGen element : evalues) {
- element.dump(dos);
- }
- }
+ {
+ dos.writeByte(type); // u1 type of value (ARRAY == '[')
+ dos.writeShort(evalues.size());
+ for (ElementValueGen element : evalues) {
+ element.dump(dos);
+ }
+ }
- @Override
+ @Override
public String stringifyValue()
- {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- String comma = "";
- for (ElementValueGen element : evalues) {
- sb.append(comma);
- comma = ",";
- sb.append(element.stringifyValue());
- }
- sb.append("]");
- return sb.toString();
- }
-
- public List<ElementValueGen> getElementValues()
- {
- return evalues;
- }
-
- public int getElementValuesSize()
- {
- return evalues.size();
- }
-
- public void addElement(ElementValueGen gen)
- {
- evalues.add(gen);
- }
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ String comma = "";
+ for (ElementValueGen element : evalues) {
+ sb.append(comma);
+ comma = ",";
+ sb.append(element.stringifyValue());
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ public List<ElementValueGen> getElementValues()
+ {
+ return evalues;
+ }
+
+ public int getElementValuesSize()
+ {
+ return evalues.size();
+ }
+
+ public void addElement(ElementValueGen gen)
+ {
+ evalues.add(gen);
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassElementValueGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassElementValueGen.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassElementValueGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassElementValueGen.java Fri May 30 22:51:27 2014
@@ -28,73 +28,73 @@ import org.apache.bcel.generic.ElementVa
public class ClassElementValueGen extends ElementValueGen
{
- // For primitive types and string type, this points to the value entry in
- // the cpool
- // For 'class' this points to the class entry in the cpool
- private int idx;
-
- protected ClassElementValueGen(int typeIdx, ConstantPoolGen cpool)
- {
- super(ElementValueGen.CLASS, cpool);
- this.idx = typeIdx;
- }
-
- public ClassElementValueGen(ObjectType t, ConstantPoolGen cpool)
- {
- super(ElementValueGen.CLASS, cpool);
- // this.idx = cpool.addClass(t);
- idx = cpool.addUtf8(t.getSignature());
- }
-
- /**
- * Return immutable variant of this ClassElementValueGen
- */
- @Override
+ // For primitive types and string type, this points to the value entry in
+ // the cpool
+ // For 'class' this points to the class entry in the cpool
+ private int idx;
+
+ protected ClassElementValueGen(int typeIdx, ConstantPoolGen cpool)
+ {
+ super(ElementValueGen.CLASS, cpool);
+ this.idx = typeIdx;
+ }
+
+ public ClassElementValueGen(ObjectType t, ConstantPoolGen cpool)
+ {
+ super(ElementValueGen.CLASS, cpool);
+ // this.idx = cpool.addClass(t);
+ idx = cpool.addUtf8(t.getSignature());
+ }
+
+ /**
+ * Return immutable variant of this ClassElementValueGen
+ */
+ @Override
public ElementValue getElementValue()
- {
- return new ClassElementValue(type, idx, cpGen.getConstantPool());
- }
-
- public ClassElementValueGen(ClassElementValue value, ConstantPoolGen cpool,
- boolean copyPoolEntries)
- {
- super(CLASS, cpool);
- if (copyPoolEntries)
- {
- // idx = cpool.addClass(value.getClassString());
- idx = cpool.addUtf8(value.getClassString());
- }
- else
- {
- idx = value.getIndex();
- }
- }
-
- public int getIndex()
- {
- return idx;
- }
-
- public String getClassString()
- {
- ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
- return cu8.getBytes();
- // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
- // ConstantUtf8 utf8 =
- // (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
- // return utf8.getBytes();
- }
+ {
+ return new ClassElementValue(type, idx, cpGen.getConstantPool());
+ }
+
+ public ClassElementValueGen(ClassElementValue value, ConstantPoolGen cpool,
+ boolean copyPoolEntries)
+ {
+ super(CLASS, cpool);
+ if (copyPoolEntries)
+ {
+ // idx = cpool.addClass(value.getClassString());
+ idx = cpool.addUtf8(value.getClassString());
+ }
+ else
+ {
+ idx = value.getIndex();
+ }
+ }
+
+ public int getIndex()
+ {
+ return idx;
+ }
+
+ public String getClassString()
+ {
+ ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
+ return cu8.getBytes();
+ // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
+ // ConstantUtf8 utf8 =
+ // (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
+ // return utf8.getBytes();
+ }
- @Override
+ @Override
public String stringifyValue()
- {
- return getClassString();
- }
+ {
+ return getClassString();
+ }
- @Override
+ @Override
public void dump(DataOutputStream dos) throws IOException
- {
- dos.writeByte(type); // u1 kind of value
- dos.writeShort(idx);
- }
+ {
+ dos.writeByte(type); // u1 kind of value
+ dos.writeShort(idx);
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java Fri May 30 22:51:27 2014
@@ -58,7 +58,7 @@ public class ClassGen extends AccessFlag
private List<Attribute> attribute_vec = new ArrayList<Attribute>();
private List<String> interface_vec = new ArrayList<String>();
private List<AnnotationEntryGen> annotation_vec = new ArrayList<AnnotationEntryGen>();
-
+
private static BCELComparator _cmp = new BCELComparator() {
public boolean equals( Object o1, Object o2 ) {
@@ -159,36 +159,36 @@ public class ClassGen extends AccessFlag
addField(field);
}
}
-
+
/**
- * Look for attributes representing annotations and unpack them.
- */
- private AnnotationEntryGen[] unpackAnnotations(Attribute[] attrs)
- {
- List<AnnotationEntryGen> annotationGenObjs = new ArrayList<AnnotationEntryGen>();
- for (Attribute attr : attrs) {
- if (attr instanceof RuntimeVisibleAnnotations)
- {
- RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
- AnnotationEntry[] annos = rva.getAnnotationEntries();
- for (AnnotationEntry a : annos) {
- annotationGenObjs.add(new AnnotationEntryGen(a,
- getConstantPool(), false));
- }
- }
- else
- if (attr instanceof RuntimeInvisibleAnnotations)
- {
- RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
- AnnotationEntry[] annos = ria.getAnnotationEntries();
- for (AnnotationEntry a : annos) {
- annotationGenObjs.add(new AnnotationEntryGen(a,
- getConstantPool(), false));
- }
- }
- }
- return annotationGenObjs.toArray(new AnnotationEntryGen[annotationGenObjs.size()]);
- }
+ * Look for attributes representing annotations and unpack them.
+ */
+ private AnnotationEntryGen[] unpackAnnotations(Attribute[] attrs)
+ {
+ List<AnnotationEntryGen> annotationGenObjs = new ArrayList<AnnotationEntryGen>();
+ for (Attribute attr : attrs) {
+ if (attr instanceof RuntimeVisibleAnnotations)
+ {
+ RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
+ AnnotationEntry[] annos = rva.getAnnotationEntries();
+ for (AnnotationEntry a : annos) {
+ annotationGenObjs.add(new AnnotationEntryGen(a,
+ getConstantPool(), false));
+ }
+ }
+ else
+ if (attr instanceof RuntimeInvisibleAnnotations)
+ {
+ RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
+ AnnotationEntry[] annos = ria.getAnnotationEntries();
+ for (AnnotationEntry a : annos) {
+ annotationGenObjs.add(new AnnotationEntryGen(a,
+ getConstantPool(), false));
+ }
+ }
+ }
+ return annotationGenObjs.toArray(new AnnotationEntryGen[annotationGenObjs.size()]);
+ }
/**
@@ -200,9 +200,9 @@ public class ClassGen extends AccessFlag
Method[] methods = getMethods();
Attribute[] attributes = null;
if (annotation_vec.isEmpty()) {
- attributes = getAttributes();
+ attributes = getAttributes();
} else {
- // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
+ // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
Attribute[] annAttributes = Utility.getAnnotationAttributes(cp,annotation_vec);
attributes = new Attribute[attribute_vec.size()+annAttributes.length];
attribute_vec.toArray(attributes);
@@ -272,9 +272,9 @@ public class ClassGen extends AccessFlag
public void addAttribute( Attribute a ) {
attribute_vec.add(a);
}
-
+
public void addAnnotationEntry(AnnotationEntryGen a) {
- annotation_vec.add(a);
+ annotation_vec.add(a);
}
@@ -478,10 +478,10 @@ public class ClassGen extends AccessFlag
public Attribute[] getAttributes() {
return attribute_vec.toArray(new Attribute[attribute_vec.size()]);
}
-
+
// J5TODO: Should we make calling unpackAnnotations() lazy and put it in here?
public AnnotationEntryGen[] getAnnotationEntries() {
- return annotation_vec.toArray(new AnnotationEntryGen[annotation_vec.size()]);
+ return annotation_vec.toArray(new AnnotationEntryGen[annotation_vec.size()]);
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGenException.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGenException.java?rev=1598766&r1=1598765&r2=1598766&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGenException.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGenException.java Fri May 30 22:51:27 2014
@@ -36,8 +36,8 @@ public class ClassGenException extends R
public ClassGenException(String s) {
super(s);
}
-
+
public ClassGenException(String s, Throwable initCause) {
- super(s, initCause);
+ super(s, initCause);
}
}