예제 #1
0
 /** Generates the bytecode to autobox the current value on the stack */
 public static boolean box(MethodVisitor mv, Class type) {
   if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) {
     String returnString = "(" + BytecodeHelper.getTypeDescription(type) + ")Ljava/lang/Object;";
     mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, "box", returnString);
     return true;
   }
   return false;
 }
예제 #2
0
  public Closure(Object owner, Object thisObject) {
    this.owner = owner;
    this.delegate = owner;
    this.thisObject = thisObject;

    final CachedClosureClass cachedClass =
        (CachedClosureClass) ReflectionCache.getCachedClass(getClass());
    parameterTypes = cachedClass.getParameterTypes();
    maximumNumberOfParameters = cachedClass.getMaximumNumberOfParameters();
  }
예제 #3
0
 @Override
 public boolean isAssignableFrom(Class argument) {
   return argument == null
       || Closure.class.isAssignableFrom(argument)
       || ReflectionCache.isAssignableFrom(getTheClass(), argument);
 }
  private void registerMethods(
      final Class theClass,
      final boolean useMethodWrapper,
      final boolean useInstanceMethods,
      Map<CachedClass, List<MetaMethod>> map) {
    if (useMethodWrapper) {
      // Here we instantiate objects representing MetaMethods for DGM methods.
      // Calls for such meta methods done without reflection, so more effectively.

      try {
        List<GeneratedMetaMethod.DgmMethodRecord> records =
            GeneratedMetaMethod.DgmMethodRecord.loadDgmInfo();

        for (GeneratedMetaMethod.DgmMethodRecord record : records) {
          Class[] newParams = new Class[record.parameters.length - 1];
          System.arraycopy(record.parameters, 1, newParams, 0, record.parameters.length - 1);

          MetaMethod method =
              new GeneratedMetaMethod.Proxy(
                  record.className,
                  record.methodName,
                  ReflectionCache.getCachedClass(record.parameters[0]),
                  record.returnType,
                  newParams);
          final CachedClass declClass = method.getDeclaringClass();
          List<MetaMethod> arr = map.get(declClass);
          if (arr == null) {
            arr = new ArrayList<MetaMethod>(4);
            map.put(declClass, arr);
          }
          arr.add(method);
          instanceMethods.add(method);
        }
      } catch (Throwable e) {
        e.printStackTrace();
        // we print the error, but we don't stop with an exception here
        // since it is more comfortable this way for development
      }
    } else {
      CachedMethod[] methods = ReflectionCache.getCachedClass(theClass).getMethods();

      for (CachedMethod method : methods) {
        final int mod = method.getModifiers();
        if (Modifier.isStatic(mod)
            && Modifier.isPublic(mod)
            && method.getCachedMethod().getAnnotation(Deprecated.class) == null) {
          CachedClass[] paramTypes = method.getParameterTypes();
          if (paramTypes.length > 0) {
            List<MetaMethod> arr = map.get(paramTypes[0]);
            if (arr == null) {
              arr = new ArrayList<MetaMethod>(4);
              map.put(paramTypes[0], arr);
            }
            if (useInstanceMethods) {
              final NewInstanceMetaMethod metaMethod = new NewInstanceMetaMethod(method);
              arr.add(metaMethod);
              instanceMethods.add(metaMethod);
            } else {
              final NewStaticMetaMethod metaMethod = new NewStaticMetaMethod(method);
              arr.add(metaMethod);
              staticMethods.add(metaMethod);
            }
          }
        }
      }
    }
  }