private static void compareMethods(String contextPrefix, IBinaryMethod expectedMethod, IBinaryMethod actualMethod) { contextPrefix = contextPrefix + "." + safeString(expectedMethod.getSelector()); //$NON-NLS-1$ compareAnnotations(contextPrefix, expectedMethod.getAnnotations(), actualMethod.getAnnotations()); assertEquals(contextPrefix + ": The argument names didn't match.", expectedMethod.getArgumentNames(), //$NON-NLS-1$ actualMethod.getArgumentNames()); assertEquals(contextPrefix + ": The default values didn't match.", expectedMethod.getDefaultValue(), //$NON-NLS-1$ actualMethod.getDefaultValue()); expectedMethod.getExceptionTypeNames(), actualMethod.getExceptionTypeNames()); expectedMethod.getGenericSignature(), actualMethod.getGenericSignature()); assertEquals(contextPrefix + ": The method descriptors did not match.", expectedMethod.getMethodDescriptor(), //$NON-NLS-1$ actualMethod.getMethodDescriptor()); assertEquals(contextPrefix + ": The modifiers didn't match.", expectedMethod.getModifiers(), //$NON-NLS-1$ actualMethod.getModifiers()); int minAnnotatedParameters = Math.min(expectedMethod.getAnnotatedParametersCount(), actualMethod.getAnnotatedParametersCount()); for (int idx = 0; idx < minAnnotatedParameters; idx++) { compareAnnotations(contextPrefix, expectedMethod.getParameterAnnotations(idx, classFileName), actualMethod.getParameterAnnotations(idx, classFileName)); for (int idx = minAnnotatedParameters; idx < expectedMethod.getAnnotatedParametersCount(); idx++) { compareAnnotations(contextPrefix, new IBinaryAnnotation[0], expectedMethod.getParameterAnnotations(idx, classFileName)); for (int idx = minAnnotatedParameters; idx < actualMethod.getAnnotatedParametersCount(); idx++) {
@Override public ITypeAnnotationWalker enrichWithExternalAnnotationsFor(ITypeAnnotationWalker walker, Object member, LookupEnvironment environment) { if (walker == ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER && this.annotationProvider != null) { if (member == null) { return this.annotationProvider.forTypeHeader(environment); } else if (member instanceof IBinaryField) { IBinaryField field = (IBinaryField) member; char[] fieldSignature = field.getGenericSignature(); if (fieldSignature == null) fieldSignature = field.getTypeName(); return this.annotationProvider.forField(field.getName(), fieldSignature, environment); } else if (member instanceof IBinaryMethod) { IBinaryMethod method = (IBinaryMethod) member; char[] methodSignature = method.getGenericSignature(); if (methodSignature == null) methodSignature = method.getMethodDescriptor(); return this.annotationProvider.forMethod( method.isConstructor() ? TypeConstants.INIT : method.getSelector(), methodSignature, environment); } } return walker; }
public static SignatureWrapper getGenericSignature(IBinaryMethod next) { char[] signature = next.getGenericSignature(); if (signature == null) { signature = next.getMethodDescriptor(); } return new SignatureWrapper(signature); }
private char[] getSelectorAndDescriptor(IBinaryMethod binaryMethod) { return CharArrayUtils.concat(binaryMethod.getSelector(), binaryMethod.getMethodDescriptor()); }
public IAnnotation[] getAnnotations() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); } public ILocalVariable[] getParameters() throws JavaModelException {
char[] signature = methodInfo.getGenericSignature(); if (signature == null) { useGenericSignature = false; signature = methodInfo.getMethodDescriptor(); String selector = new String(methodInfo.getSelector()); final boolean isConstructor = methodInfo.isConstructor(); if (isConstructor) { selector = type.getElementName(); int length = pNames.length; System.arraycopy(pNames, 0, (pNames = new String[length + 1]), 1, length); char[] descriptor = methodInfo.getMethodDescriptor(); final String[] parameterTypes = Signature.getParameterTypes(new String(descriptor)); pNames[0] = parameterTypes[0]; signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); } catch (JavaModelException e) { signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); char[][] argumentNames = methodInfo.getArgumentNames(); if (argumentNames == null || argumentNames.length < max) { argumentNames = new char[max][]; IBinaryAnnotation[] parameterAnnotations = methodInfo.getParameterAnnotations(j); if (parameterAnnotations != null) {
public static void methodToStringContent(StringBuffer buffer, IBinaryMethod method) { int modifiers = method.getModifiers(); char[] desc = method.getGenericSignature(); if (desc == null) desc = method.getMethodDescriptor(); buffer .append('{') + ((modifiers & 0x0040) == 0x0040 ? "bridge " : Util.EMPTY_STRING) //$NON-NLS-1$ + ((modifiers & 0x0080) == 0x0080 ? "varargs " : Util.EMPTY_STRING)) //$NON-NLS-1$ .append(method.getSelector()) .append(desc) .append('}'); Object defaultValue = method.getDefaultValue(); if (defaultValue != null) { buffer.append(" default "); //$NON-NLS-1$ IBinaryAnnotation[] annotations = method.getAnnotations(); for (int i = 0, l = annotations == null ? 0 : annotations.length; i < l; i++) { buffer.append(annotations[i]); int annotatedParameterCount = method.getAnnotatedParametersCount(); for (int i = 0; i < annotatedParameterCount; i++) { buffer.append("param" + (i - 1)); //$NON-NLS-1$ buffer.append('\n'); IBinaryAnnotation[] infos = method.getParameterAnnotations(i, new char[0]); for (int j = 0, k = infos == null ? 0 : infos.length; j < k; j++) { buffer.append(infos[j]);
for (int i = 0, max = methods.length; i < max; i++) { IBinaryMethod 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);
boolean matchConstructor(ConstructorPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!pattern.findDeclarations) return false; // only relevant when finding declarations if (!(binaryInfo instanceof IBinaryMethod)) return false; IBinaryMethod method = (IBinaryMethod) binaryInfo; if (!method.isConstructor()) return false; if (!checkDeclaringType(enclosingBinaryType, pattern.declaringSimpleName, pattern.declaringQualification, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; if (pattern.parameterSimpleNames != null) { char[] methodDescriptor = convertClassFileFormat(method.getMethodDescriptor()); if (!checkParameters(methodDescriptor, pattern.parameterSimpleNames, pattern.parameterQualifications, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } return true; } boolean matchField(FieldPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) { buffer.append(tabString(tab)); if (info == null) { toStringName(buffer); buffer.append(" (not open)"); //$NON-NLS-1$ } else if (info == NO_INFO) { toStringName(buffer); } else { IBinaryMethod methodInfo = (IBinaryMethod) info; int flags = methodInfo.getModifiers(); if (Flags.isStatic(flags)) { buffer.append("static "); //$NON-NLS-1$ } if (!methodInfo.isConstructor()) { buffer.append(Signature.toString(getReturnType(methodInfo))); buffer.append(' '); } toStringName(buffer, flags); } } protected void toStringName(StringBuffer buffer) {
if (this.exceptionTypes == null) { IBinaryMethod info = (IBinaryMethod) getElementInfo(); char[] genericSignature = info.getGenericSignature(); if (genericSignature != null) { char[] dotBasedSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.'); char[][] eTypeNames = info.getExceptionTypeNames(); if (eTypeNames == null || eTypeNames.length == 0) { this.exceptionTypes = CharOperation.NO_STRINGS;
IBinaryAnnotation[] annotations = method.getAnnotations(); boolean explicitNullness = false; if (annotations != null) { int numParamAnnotations = method.getAnnotatedParametersCount(); if (numParamAnnotations > 0) { for (int j = 0; j < numVisibleParams; j++) { if (numParamAnnotations > 0) { int startIndex = numParamAnnotations - numVisibleParams; IBinaryAnnotation[] paramAnnotations = method.getParameterAnnotations(j+startIndex); if (paramAnnotations != null) { for (int i = 0; i < paramAnnotations.length; i++) {
char[][] argumentNames = info.getArgumentNames(); if (argumentNames == null || argumentNames.length < length) { argumentNames = new char[length][]; true); localVariables[i] = localVariable; IAnnotation[] annotations = getAnnotations(localVariable, info.getParameterAnnotations(i - startIndex)); localVariable.annotations = annotations;
char[][] argumentNames = info.getArgumentNames(); if (argumentNames == null || argumentNames.length < length) { argumentNames = new char[length][]; true); localVariables[i] = localVariable; IAnnotation[] annotations = getAnnotations(localVariable, info.getParameterAnnotations(i), info.getTagBits()); localVariable.annotations = annotations;
@Override public String getSignature() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); return new String(info.getMethodDescriptor()); } /**
@Override public IMemberValuePair getDefaultValue() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); Object defaultValue = info.getDefaultValue(); if (defaultValue == null) return null; MemberValuePair memberValuePair = new MemberValuePair(getElementName()); memberValuePair.value = Util.getAnnotationMemberValue(this, memberValuePair, defaultValue); return memberValuePair; } /*
public int getFlags() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); return info.getModifiers(); } /*
@Override public boolean isConstructor() throws JavaModelException { if (!getElementName().equals(this.parent.getElementName())) { // faster than reaching the info return false; } IBinaryMethod info = (IBinaryMethod) getElementInfo(); return info.isConstructor(); } /*
/** * @see IMethod#getTypeParameterSignatures() * @since 3.0 * @deprecated */ public String[] getTypeParameterSignatures() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); char[] genericSignature = info.getGenericSignature(); if (genericSignature == null) return CharOperation.NO_STRINGS; char[] dotBasedSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.'); char[][] typeParams = Signature.getTypeParameters(dotBasedSignature); return CharOperation.toStrings(typeParams); }
final boolean isConstructor = methodInfo.isConstructor(); boolean isEnum = false; try { char[] signature = methodInfo.getGenericSignature(); String[] pNames = null; if (signature == null) { useGenericSignature = false; signature = methodInfo.getMethodDescriptor(); if (isEnum && isConstructor) { pNames = Signature.getParameterTypes(new String(signature)); String selector = new String(methodInfo.getSelector()); if (isConstructor) { selector = type.getElementName(); int length = pNames.length; System.arraycopy(pNames, 0, (pNames = new String[length + 1]), 1, length); char[] descriptor = methodInfo.getMethodDescriptor(); final String[] parameterTypes = Signature.getParameterTypes(new String(descriptor)); pNames[0] = parameterTypes[0]; signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); } catch (JavaModelException e) { signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature));