/** * This method is used to fully initialize the contents of the receiver. All methodinfos, fields infos * will be therefore fully initialized and we can get rid of the bytes. */ protected void initialize() { getModifiers(); getSelector(); getMethodDescriptor(); getExceptionTypeNames(); getGenericSignature(); getArgumentNames(); reset(); } /**
static AnnotationInfo[][] decodeParamAnnotations(int offset, boolean runtimeVisible, MethodInfo methodInfo) { AnnotationInfo[][] allParamAnnotations = null; int numberOfParameters = methodInfo.u1At(offset + 6); if (numberOfParameters > 0) { // u2 attribute_name_index + u4 attribute_length + u1 num_parameters int readOffset = offset + 7; for (int i=0 ; i < numberOfParameters; i++) { int numberOfAnnotations = methodInfo.u2At(readOffset); readOffset += 2; if (numberOfAnnotations > 0) { if (allParamAnnotations == null) allParamAnnotations = new AnnotationInfo[numberOfParameters][]; AnnotationInfo[] annos = decodeAnnotations(readOffset, runtimeVisible, numberOfAnnotations, methodInfo); allParamAnnotations[i] = annos; for (int aIndex = 0; aIndex < annos.length; aIndex++) readOffset += annos[aIndex].readOffset; } } } return allParamAnnotations; }
public int compareTo(Object o) { MethodInfo otherMethod = (MethodInfo) o; int result = new String(getSelector()).compareTo(new String(otherMethod.getSelector())); if (result != 0) return result; return new String(getMethodDescriptor()).compareTo(new String(otherMethod.getMethodDescriptor())); } public boolean equals(Object o) {
if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; if (currentMethodInfo.getModifiers() != otherMethodInfo.getModifiers()) return true; if ((currentMethodInfo.getTagBits() & TagBits.AnnotationDeprecated) != (otherMethodInfo.getTagBits() & TagBits.AnnotationDeprecated)) return true; if (hasStructuralAnnotationChanges(currentMethodInfo.getAnnotations(), otherMethodInfo.getAnnotations())) return true; int currentAnnotatedParamsCount = currentMethodInfo.getAnnotatedParametersCount(); int otherAnnotatedParamsCount = otherMethodInfo.getAnnotatedParametersCount(); if (currentAnnotatedParamsCount != otherAnnotatedParamsCount) return true; for (int i=0; i<currentAnnotatedParamsCount; i++) { if (hasStructuralAnnotationChanges(currentMethodInfo.getParameterAnnotations(i), otherMethodInfo.getParameterAnnotations(i))) return true; if (!CharOperation.equals(currentMethodInfo.getSelector(), otherMethodInfo.getSelector())) return true; if (!CharOperation.equals(currentMethodInfo.getMethodDescriptor(), otherMethodInfo.getMethodDescriptor())) return true; if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; char[][] currentThrownExceptions = currentMethodInfo.getExceptionTypeNames(); char[][] otherThrownExceptions = otherMethodInfo.getExceptionTypeNames(); if (currentThrownExceptions != otherThrownExceptions) { // TypeConstants.NoExceptions int currentThrownExceptionsLength = currentThrownExceptions == null ? 0 : currentThrownExceptions.length;
public static MethodInfo createAnnotationMethod(byte classFileBytes[], int offsets[], int offset) { MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset); int attributesCount = methodInfo.u2At(6); int readOffset = 8; AnnotationInfo[] annotations = null; for (int i = 0; i < attributesCount; i++) { int utf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset)] - methodInfo.structOffset; char[] attributeName = methodInfo.utf8At(utf8Offset + 3, methodInfo.u2At(utf8Offset + 1)); if (attributeName.length > 0) { switch(attributeName[0]) { case 'S' : if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) methodInfo.signatureUtf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset + 6)] - methodInfo.structOffset; break; case 'R' : readOffset += (6 + methodInfo.u4At(readOffset + 2));
private boolean hasStructuralMethodChanges(MethodInfo currentMethodInfo, MethodInfo otherMethodInfo) { if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; if (currentMethodInfo.getModifiers() != otherMethodInfo.getModifiers()) return true; if ((currentMethodInfo.getTagBits() & TagBits.AnnotationDeprecated) != (otherMethodInfo.getTagBits() & TagBits.AnnotationDeprecated)) return true; if (hasStructuralAnnotationChanges(currentMethodInfo.getAnnotations(), otherMethodInfo.getAnnotations())) return true; if (!CharOperation.equals(currentMethodInfo.getSelector(), otherMethodInfo.getSelector())) return true; if (!CharOperation.equals(currentMethodInfo.getMethodDescriptor(), otherMethodInfo.getMethodDescriptor())) return true; if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; char[][] currentThrownExceptions = currentMethodInfo.getExceptionTypeNames(); char[][] otherThrownExceptions = otherMethodInfo.getExceptionTypeNames(); if (currentThrownExceptions != otherThrownExceptions) { // TypeConstants.NoExceptions int currentThrownExceptionsLength = currentThrownExceptions == null ? 0 : currentThrownExceptions.length;
public static MethodInfo createMethod(byte classFileBytes[], int offsets[], int offset) { MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset); int attributesCount = methodInfo.u2At(6); int readOffset = 8; AnnotationInfo[] annotations = null; int utf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset)] - methodInfo.structOffset; char[] attributeName = methodInfo.utf8At(utf8Offset + 3, methodInfo.u2At(utf8Offset + 1)); if (attributeName.length > 0) { switch(attributeName[0]) { case 'M' : if (CharOperation.equals(attributeName, AttributeNamesConstants.MethodParametersName)) { methodInfo.decodeMethodParameters(readOffset, methodInfo); methodInfo.signatureUtf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset + 6)] - methodInfo.structOffset; break; case 'R' : TypeAnnotationInfo[] methodTypeAnnotations = null; if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, false, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, false, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleTypeAnnotationsName)) { methodTypeAnnotations = decodeTypeAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleTypeAnnotationsName)) {
public static MethodInfo createMethod(byte classFileBytes[], int offsets[], int offset) { MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset); int attributesCount = methodInfo.u2At(6); int readOffset = 8; AnnotationInfo[] annotations = null; for (int i = 0; i < attributesCount; i++) { int utf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset)] - methodInfo.structOffset; char[] attributeName = methodInfo.utf8At(utf8Offset + 3, methodInfo.u2At(utf8Offset + 1)); if (attributeName.length > 0) { switch(attributeName[0]) { case 'S' : if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) methodInfo.signatureUtf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset + 6)] - methodInfo.structOffset; break; case 'R' : AnnotationInfo[][] paramAnnotations = null; if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, false, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, false, methodInfo); readOffset += (6 + methodInfo.u4At(readOffset + 2));
for (int i = 0, max = methods.length; i < max; i++) { MethodInfo method = methods[i]; if (checkAnnotations(typeReferencePattern, method.getAnnotations(), method.getTagBits())) { binaryTypeBinding = locator.cacheBinaryType(classFileBinaryType, binaryType); IMethod methodHandle = classFileBinaryType.getMethod( new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()), CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(method.getMethodDescriptor())))); TypeReferenceMatch match = new TypeReferenceMatch(methodHandle, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
protected void toStringContent(StringBuffer buffer) { int modifiers = getModifiers(); char[] desc = getGenericSignature(); if (desc == null) desc = getMethodDescriptor(); buffer .append('{') .append( ((modifiers & ClassFileConstants.AccDeprecated) != 0 ? "deprecated " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0001) == 1 ? "public " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0002) == 0x0002 ? "private " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0004) == 0x0004 ? "protected " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0008) == 0x000008 ? "static " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0010) == 0x0010 ? "final " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0040) == 0x0040 ? "bridge " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0080) == 0x0080 ? "varargs " : Util.EMPTY_STRING)) //$NON-NLS-1$ .append(getSelector()) .append(desc) .append('}'); } private void readCodeAttribute() {
this.methods[i] = isAnnotationType ? AnnotationMethodInfo.createAnnotationMethod(this.reference, this.constantPoolOffsets, readOffset) : MethodInfo.createMethod(this.reference, this.constantPoolOffsets, readOffset); readOffset += this.methods[i].sizeInBytes();
static AnnotationInfo[] decodeMethodAnnotations(int offset, boolean runtimeVisible, MethodInfo methodInfo) { int numberOfAnnotations = methodInfo.u2At(offset + 6); if (numberOfAnnotations > 0) { AnnotationInfo[] annos = decodeAnnotations(offset + 8, runtimeVisible, numberOfAnnotations, methodInfo); if (runtimeVisible){ int numStandardAnnotations = 0;
/** * Return true if the field is a synthetic method, false otherwise. * @return boolean */ public boolean isSynthetic() { return (getModifiers() & ClassFileConstants.AccSynthetic) != 0; } private void readExceptionAttributes() {
/** * Answer true if the method is a class initializer, false otherwise. * @return boolean */ public boolean isClinit() { char[] selector = getSelector(); return selector[0] == '<' && selector.length == 8; // Can only match <clinit> } /**
if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; if (currentMethodInfo.getModifiers() != otherMethodInfo.getModifiers()) return true; if ((currentMethodInfo.getTagBits() & TagBits.AnnotationDeprecated) != (otherMethodInfo.getTagBits() & TagBits.AnnotationDeprecated)) return true; if (hasStructuralAnnotationChanges(currentMethodInfo.getAnnotations(), otherMethodInfo.getAnnotations())) return true; int currentAnnotatedParamsCount = currentMethodInfo.getAnnotatedParametersCount(); int otherAnnotatedParamsCount = otherMethodInfo.getAnnotatedParametersCount(); if (currentAnnotatedParamsCount != otherAnnotatedParamsCount) return true; for (int i=0; i<currentAnnotatedParamsCount; i++) { if (hasStructuralAnnotationChanges(currentMethodInfo.getParameterAnnotations(i), otherMethodInfo.getParameterAnnotations(i))) return true; if (!CharOperation.equals(currentMethodInfo.getSelector(), otherMethodInfo.getSelector())) return true; if (!CharOperation.equals(currentMethodInfo.getMethodDescriptor(), otherMethodInfo.getMethodDescriptor())) return true; if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; char[][] currentThrownExceptions = currentMethodInfo.getExceptionTypeNames(); char[][] otherThrownExceptions = otherMethodInfo.getExceptionTypeNames(); if (currentThrownExceptions != otherThrownExceptions) { // TypeConstants.NoExceptions int currentThrownExceptionsLength = currentThrownExceptions == null ? 0 : currentThrownExceptions.length;
public static MethodInfo createAnnotationMethod(byte classFileBytes[], int offsets[], int offset) { MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset); int attributesCount = methodInfo.u2At(6); int readOffset = 8; AnnotationInfo[] annotations = null; for (int i = 0; i < attributesCount; i++) { int utf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset)] - methodInfo.structOffset; char[] attributeName = methodInfo.utf8At(utf8Offset + 3, methodInfo.u2At(utf8Offset + 1)); if (attributeName.length > 0) { switch(attributeName[0]) { case 'S' : if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) methodInfo.signatureUtf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset + 6)] - methodInfo.structOffset; break; case 'R' : readOffset += (6 + methodInfo.u4At(readOffset + 2));
private boolean hasStructuralMethodChanges(MethodInfo currentMethodInfo, MethodInfo otherMethodInfo) { if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; if (currentMethodInfo.getModifiers() != otherMethodInfo.getModifiers()) return true; if ((currentMethodInfo.getTagBits() & TagBits.AnnotationDeprecated) != (otherMethodInfo.getTagBits() & TagBits.AnnotationDeprecated)) return true; if (hasStructuralAnnotationChanges(currentMethodInfo.getAnnotations(), otherMethodInfo.getAnnotations())) return true; if (!CharOperation.equals(currentMethodInfo.getSelector(), otherMethodInfo.getSelector())) return true; if (!CharOperation.equals(currentMethodInfo.getMethodDescriptor(), otherMethodInfo.getMethodDescriptor())) return true; if (!CharOperation.equals(currentMethodInfo.getGenericSignature(), otherMethodInfo.getGenericSignature())) return true; char[][] currentThrownExceptions = currentMethodInfo.getExceptionTypeNames(); char[][] otherThrownExceptions = otherMethodInfo.getExceptionTypeNames(); if (currentThrownExceptions != otherThrownExceptions) { // TypeConstants.NoExceptions int currentThrownExceptionsLength = currentThrownExceptions == null ? 0 : currentThrownExceptions.length;
public static MethodInfo createMethod(byte classFileBytes[], int offsets[], int offset) { MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset); int attributesCount = methodInfo.u2At(6); int readOffset = 8; AnnotationInfo[] annotations = null; for (int i = 0; i < attributesCount; i++) { int utf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset)] - methodInfo.structOffset; char[] attributeName = methodInfo.utf8At(utf8Offset + 3, methodInfo.u2At(utf8Offset + 1)); if (attributeName.length > 0) { switch(attributeName[0]) { case 'S' : if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) methodInfo.signatureUtf8Offset = methodInfo.constantPoolOffsets[methodInfo.u2At(readOffset + 6)] - methodInfo.structOffset; break; case 'R' : AnnotationInfo[][] paramAnnotations = null; if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleAnnotationsName)) { methodAnnotations = decodeMethodAnnotations(readOffset, false, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeVisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, true, methodInfo); } else if (CharOperation.equals(attributeName, AttributeNamesConstants.RuntimeInvisibleParameterAnnotationsName)) { paramAnnotations = decodeParamAnnotations(readOffset, false, methodInfo); readOffset += (6 + methodInfo.u4At(readOffset + 2));
for (int i = 0, max = methods.length; i < max; i++) { MethodInfo method = methods[i]; if (checkAnnotations(typeReferencePattern, method.getAnnotations(), method.getTagBits())) { binaryTypeBinding = locator.cacheBinaryType(classFileBinaryType, binaryType); IMethod methodHandle = classFileBinaryType.getMethod( new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()), CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(method.getMethodDescriptor())))); TypeReferenceMatch match = new TypeReferenceMatch(methodHandle, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
public int compareTo(Object o) { MethodInfo otherMethod = (MethodInfo) o; int result = new String(getSelector()).compareTo(new String(otherMethod.getSelector())); if (result != 0) return result; return new String(getMethodDescriptor()).compareTo(new String(otherMethod.getMethodDescriptor())); } public boolean equals(Object o) {