예제 #1
0
 /**
  * Tries to find the given {@link IApiMethod} in the given {@link IType}. If a matching method is
  * not found <code>null</code> is returned
  *
  * @param type the type top look in for the given {@link IApiMethod}
  * @param method the {@link IApiMethod} to look for
  * @return the {@link IMethod} from the given {@link IType} that matches the given {@link
  *     IApiMethod} or <code>null</code> if no matching method is found
  * @throws JavaModelException
  * @throws CoreException
  */
 protected IMethod findMethodInType(IType type, IApiMethod method)
     throws JavaModelException, CoreException {
   String[] parameterTypes = Signature.getParameterTypes(method.getSignature());
   for (int i = 0; i < parameterTypes.length; i++) {
     parameterTypes[i] = parameterTypes[i].replace('/', '.');
   }
   String methodname = method.getName();
   if (method.isConstructor()) {
     IApiType enclosingType = method.getEnclosingType();
     if (enclosingType.isMemberType() && !Flags.isStatic(enclosingType.getModifiers())) {
       // remove the synthetic argument that corresponds to the enclosing type
       int length = parameterTypes.length - 1;
       System.arraycopy(parameterTypes, 1, (parameterTypes = new String[length]), 0, length);
     }
     methodname = enclosingType.getSimpleName();
   }
   IMethod Qmethod = type.getMethod(methodname, parameterTypes);
   IMethod[] methods = type.getMethods();
   IMethod match = null;
   for (int i = 0; i < methods.length; i++) {
     IMethod m = methods[i];
     if (m.isSimilar(Qmethod)) {
       match = m;
       break;
     }
   }
   return match;
 }
 /**
  * Adds all visible methods to the given set in the specified type.
  *
  * @param type type to analyze
  * @param members set to add methods to
  * @param modifiers visibilities to consider
  */
 private void gatherVisibleMethods(IApiType type, Set<MethodKey> members, int modifiers) {
   IApiMethod[] methods = type.getMethods();
   for (int i = 0; i < methods.length; i++) {
     IApiMethod method = methods[i];
     if ((method.getModifiers() & modifiers) > 0
         && !method.isConstructor()
         && !method.isSynthetic()) {
       members.add(new MethodKey(type.getName(), method.getName(), method.getSignature(), false));
     }
   }
 }
예제 #3
0
 /**
  * Returns a method descriptor with a resolved signature for the given method descriptor with an
  * unresolved signature.
  *
  * @param descriptor method to resolve
  * @return resolved method descriptor or the same method descriptor if unable to resolve
  * @exception CoreException if unable to resolve the method and a class file container was
  *     provided for this purpose
  */
 private IMethodDescriptor resolveMethod(IMethodDescriptor descriptor) throws CoreException {
   if (fContainer != null) {
     IReferenceTypeDescriptor type = descriptor.getEnclosingType();
     IApiTypeRoot classFile = fContainer.findTypeRoot(type.getQualifiedName());
     if (classFile != null) {
       IApiType structure = classFile.getStructure();
       if (structure != null) {
         IApiMethod[] methods = structure.getMethods();
         for (int i = 0; i < methods.length; i++) {
           IApiMethod method = methods[i];
           if (descriptor.getName().equals(method.getName())) {
             String signature = method.getSignature();
             String descriptorSignature = descriptor.getSignature().replace('/', '.');
             if (Signatures.matchesSignatures(
                 descriptorSignature, signature.replace('/', '.'))) {
               return descriptor.getEnclosingType().getMethod(method.getName(), signature);
             }
             String genericSignature = method.getGenericSignature();
             if (genericSignature != null) {
               if (Signatures.matchesSignatures(
                   descriptorSignature, genericSignature.replace('/', '.'))) {
                 return descriptor.getEnclosingType().getMethod(method.getName(), signature);
               }
             }
           }
         }
       }
     }
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             ApiPlugin.PLUGIN_ID,
             MessageFormat.format(
                 "Unable to resolve method signature: {0}",
                 new String[] {descriptor.toString()}),
             null)); //$NON-NLS-1$
   }
   return descriptor;
 }