Beispiel #1
0
  /**
   * Determine the name of parameter with index i in the given method. Use the locals attributes
   * about local variables from the classfile. Note: This is still work in progress.
   *
   * @param method
   * @param locals
   * @param i
   * @return the name of the parameter if available or a number if not.
   */
  static String parameterNameFor(CtBehavior method, LocalVariableAttribute locals, int i) {

    if (locals == null) {
      return Integer.toString(i + 1);
    }

    int modifiers = method.getModifiers();

    int j = i;

    if (Modifier.isSynchronized(modifiers)) {
      // skip object to synchronize upon.
      j++;
      // System.err.println("Synchronized");
    }
    if (Modifier.isStatic(modifiers) == false) {
      // skip "this"
      j++;
      // System.err.println("Instance");
    }
    String variableName = locals.variableName(j);
    // if (variableName.equals("this")) {
    // System.err.println("'this' returned as a parameter name for "
    // + method.getName() + " index " + j
    // +
    // ", names are probably shifted. Please submit source for class in slf4j bugreport");
    // }
    return variableName;
  }
Beispiel #2
0
    AccessType(Method method) {
      int modifier = method.getModifiers();
      if (Modifier.isPrivate(modifier)) {
        throw new UnsupportedOperationException("method = private");
      }
      if (Modifier.isFinal(modifier)) {
        throw new UnsupportedOperationException("method = final");
      }

      this.method = method;

      accesssType = "";
      staticType = "";
      syncType = "";
      methodName = "";

      methodName = method.getName();

      if (Modifier.isProtected(modifier)) {
        accesssType = "protected";
      }
      if (Modifier.isPackage(modifier)) {
        accesssType = "";
      }
      if (Modifier.isPublic(modifier)) {
        accesssType = "public";
      }
      if (Modifier.isStatic(modifier)) {
        staticType = "static";
      }
      if (Modifier.isSynchronized(modifier)) {
        syncType = "synchronized";
      }

      returnType = createParameterName(method.getReturnType());

      Set<String> throwSet = new HashSet<String>();
      for (Class<?> ex : method.getExceptionTypes()) {
        throwSet.add(ex.getSimpleName());
      }
      this.throwSet = throwSet;

      List<Parameter> paramList = new ArrayList<Parameter>();
      for (Class<?> p : method.getParameterTypes()) {
        paramList.add(createParameterName(p));
      }
      this.paramList = paramList;
    }