Beispiel #1
0
 /**
  * Find a matching method in a type.
  *
  * @param type JDT method
  * @param jMethod TypeOracle method object to find
  * @return method declaration or null if not found
  */
 private static AbstractMethodDeclaration findMethod(
     TypeDeclaration type, JAbstractMethod jMethod) {
   List<AbstractMethodDeclaration> candidates = findNamedMethods(type, jMethod.getName());
   if (candidates.size() == 0) {
     return null;
   }
   if (candidates.size() == 1) {
     return candidates.get(0);
   }
   nextCandidate:
   for (AbstractMethodDeclaration candidate : candidates) {
     int n = candidate.arguments == null ? 0 : candidate.arguments.length;
     JParameter[] params = jMethod.getParameters();
     if (n != params.length) {
       continue;
     }
     for (int i = 0; i < n; ++i) {
       if (!typeMatches(candidate.arguments[i].type, params[i].getType())) {
         continue nextCandidate;
       }
     }
     return candidate;
   }
   return null;
 }
Beispiel #2
0
 /**
  * Return the real argument names for a given method from the source.
  *
  * @param method method to lookup parameter names for
  * @return array of argument names or null if no source is available
  */
 public synchronized String[] getArguments(JAbstractMethod method) {
   JClassType type = method.getEnclosingType();
   JClassType topType = getTopmostType(type);
   CompilationUnitDeclaration cud = getCudForTopLevelType(topType);
   if (cud == null) {
     return null;
   }
   TypeDeclaration jdtType = findType(cud, type.getQualifiedBinaryName());
   if (jdtType == null) {
     // TODO(jat): any thing else to do here?
     return null;
   }
   AbstractMethodDeclaration jdtMethod = findMethod(jdtType, method);
   if (jdtMethod == null) {
     // TODO(jat): any thing else to do here?
     return null;
   }
   int n = jdtMethod.arguments.length;
   String[] argNames = new String[n];
   for (int i = 0; i < n; ++i) {
     argNames[i] = String.valueOf(jdtMethod.arguments[i].name);
   }
   return argNames;
 }