static AnnotationInfo[] decodeAnnotations(int offset, boolean runtimeVisible, int numberOfAnnotations, MethodInfo methodInfo) { AnnotationInfo[] result = new AnnotationInfo[numberOfAnnotations]; int readOffset = offset; for (int i = 0; i < numberOfAnnotations; i++) { result[i] = new AnnotationInfo(methodInfo.reference, methodInfo.constantPoolOffsets, readOffset + methodInfo.structOffset, runtimeVisible, false); readOffset += result[i].readOffset; } return result; } static AnnotationInfo[] decodeMethodAnnotations(int offset, boolean runtimeVisible, MethodInfo methodInfo) {
/** * @param classFileBytes * @param offset the offset into <code>classFileBytes</code> for the "type_index" of the annotation attribute. * @param populate <code>true</code> to indicate to build out the annotation structure. */ AnnotationInfo(byte[] classFileBytes, int[] contantPoolOffsets, int offset, boolean runtimeVisible, boolean populate) { this(classFileBytes, contantPoolOffsets, offset); if (populate) decodeAnnotation(); else this.readOffset = scanAnnotation(0, runtimeVisible, true); } private void decodeAnnotation() {
private void decodeAnnotation() { this.readOffset = 0; int utf8Offset = this.constantPoolOffsets[u2At(0)] - this.structOffset; this.typename = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); int numberOfPairs = u2At(2); // u2 type_index + u2 num_member_value_pair this.readOffset += 4; this.pairs = numberOfPairs == 0 ? ElementValuePairInfo.NoMembers : new ElementValuePairInfo[numberOfPairs]; for (int i = 0; i < numberOfPairs; i++) { // u2 member_name_index; utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; char[] membername = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); this.readOffset += 2; Object value = decodeDefaultValue(); this.pairs[i] = new ElementValuePairInfo(membername, value); } } Object decodeDefaultValue() {
int tag = u1At(this.readOffset); this.readOffset++; int constValueOffset = -1; switch (tag) { case 'Z': // boolean constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = BooleanConstant.fromValue(i4At(constValueOffset + 1) == 1); this.readOffset += 2; break; case 'I': // integer constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = IntConstant.fromValue(i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'C': // char constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = CharConstant.fromValue((char) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'B': // byte constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ByteConstant.fromValue((byte) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'S': // short constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ShortConstant.fromValue((short) i4At(constValueOffset + 1)); this.readOffset += 2; break;
private int readTargetValue(int offset) { int currentOffset = offset; int tag = u1At(currentOffset); currentOffset++; switch (tag) { case 'e': int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); currentOffset += 2; if (typeName.length == 34 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) { utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); this.standardAnnotationTagBits |= Annotation.getTargetElementType(constName); currentOffset = scanAnnotation(currentOffset, false, false); break; case '[': int numberOfValues = u2At(currentOffset); currentOffset += 2; if (numberOfValues == 0) { } else { for (int i = 0; i < numberOfValues; i++) currentOffset = readTargetValue(currentOffset);
int utf8Offset = this.constantPoolOffsets[u2At(offset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); if (toplevel) this.typename = typeName; int numberOfPairs = u2At(offset + 2); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) { currentOffset += 2; return readTargetValue(currentOffset); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) { currentOffset += 2; return readRetentionPolicy(currentOffset); currentOffset = scanElementValue(currentOffset);
int tag = u1At(currentOffset); currentOffset++; switch (tag) { if ((this.standardAnnotationTagBits & TagBits.AnnotationDeprecated) != 0) { int constantOffset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset + 1; if (i4At(constantOffset) == 1) { this.standardAnnotationTagBits |= TagBits.AnnotationTerminallyDeprecated; currentOffset = scanAnnotation(currentOffset, false, false); break; case '[': int numberOfValues = u2At(currentOffset); currentOffset += 2; for (int i = 0; i < numberOfValues; i++) currentOffset = scanElementValue(currentOffset); break; default:
new AnnotationInfo(methodInfo.reference, methodInfo.constantPoolOffsets, readOffset + 6 + methodInfo.structOffset); defaultValue = info.decodeDefaultValue();
private void decodeAnnotation() { this.readOffset = 0; int utf8Offset = this.constantPoolOffsets[u2At(0)] - this.structOffset; this.typename = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); int numberOfPairs = u2At(2); while (i < numberOfPairs) { utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; char[] membername = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); this.readOffset += 2; Object value = decodeDefaultValue(); decodedPairs[i++] = new ElementValuePairInfo(membername, value); sanitizePairs(decodedPairs); StringBuilder newMessage = new StringBuilder(any.getMessage()); newMessage.append(" while decoding pair #").append(i).append(" of annotation @").append(this.typename); //$NON-NLS-1$ //$NON-NLS-2$
public IBinaryElementValuePair[] getElementValuePairs() { if (this.pairs == null) initialize(); return this.pairs; } public char[] getTypeName() {
void initialize() { if (this.pairs == null) decodeAnnotation(); } synchronized void lazyInitialize() {
int tag = u1At(this.readOffset); this.readOffset++; int constValueOffset = -1; switch (tag) { case 'Z': // boolean constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = BooleanConstant.fromValue(i4At(constValueOffset + 1) == 1); this.readOffset += 2; break; case 'I': // integer constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = IntConstant.fromValue(i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'C': // char constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = CharConstant.fromValue((char) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'B': // byte constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ByteConstant.fromValue((byte) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'S': // short constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ShortConstant.fromValue((short) i4At(constValueOffset + 1)); this.readOffset += 2; break;
private int readTargetValue(int offset) { int currentOffset = offset; int tag = u1At(currentOffset); currentOffset++; switch (tag) { case 'e': int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); currentOffset += 2; if (typeName.length == 34 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) { utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); this.standardAnnotationTagBits |= Annotation.getTargetElementType(constName); currentOffset = scanAnnotation(currentOffset, false, false); break; case '[': int numberOfValues = u2At(currentOffset); currentOffset += 2; if (numberOfValues == 0) { } else { for (int i = 0; i < numberOfValues; i++) currentOffset = readTargetValue(currentOffset);
int utf8Offset = this.constantPoolOffsets[u2At(offset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); if (toplevel) this.typename = typeName; int numberOfPairs = u2At(offset + 2); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) { currentOffset += 2; return readTargetValue(currentOffset); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) { currentOffset += 2; return readRetentionPolicy(currentOffset); currentOffset = scanElementValue(currentOffset);
new AnnotationInfo(methodInfo.reference, methodInfo.constantPoolOffsets, readOffset + 6 + methodInfo.structOffset); defaultValue = info.decodeDefaultValue();
public IBinaryElementValuePair[] getElementValuePairs() { if (this.pairs == null) initialize(); return this.pairs; } public char[] getTypeName() {
synchronized void lazyInitialize() { if (this.pairs == null) decodeAnnotation(); } private int readRetentionPolicy(int offset) {
int tag = u1At(this.readOffset); this.readOffset++; int constValueOffset = -1; switch (tag) { case 'Z': // boolean constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = BooleanConstant.fromValue(i4At(constValueOffset + 1) == 1); this.readOffset += 2; break; case 'I': // integer constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = IntConstant.fromValue(i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'C': // char constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = CharConstant.fromValue((char) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'B': // byte constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ByteConstant.fromValue((byte) i4At(constValueOffset + 1)); this.readOffset += 2; break; case 'S': // short constant constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - this.structOffset; value = ShortConstant.fromValue((short) i4At(constValueOffset + 1)); this.readOffset += 2; break;
private int readTargetValue(int offset) { int currentOffset = offset; int tag = u1At(currentOffset); currentOffset++; switch (tag) { case 'e': int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); currentOffset += 2; if (typeName.length == 34 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) { utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset; char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); this.standardAnnotationTagBits |= Annotation.getTargetElementType(constName); currentOffset = scanAnnotation(currentOffset, false, false); break; case '[': int numberOfValues = u2At(currentOffset); currentOffset += 2; if (numberOfValues == 0) { } else { for (int i = 0; i < numberOfValues; i++) currentOffset = readTargetValue(currentOffset);
int utf8Offset = this.constantPoolOffsets[u2At(offset)] - this.structOffset; char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); if (toplevel) this.typename = typeName; int numberOfPairs = u2At(offset + 2); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) { currentOffset += 2; return readTargetValue(currentOffset); if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) { currentOffset += 2; return readRetentionPolicy(currentOffset); currentOffset = scanElementValue(currentOffset);