Package br.com.caelum.vraptor.asm

Examples of br.com.caelum.vraptor.asm.ClassWriter


    final String newTypeName = method.getDeclaringClass().getSimpleName().replace('.', '/') + "$"
        + method.getName() + "$" + Math.abs(method.hashCode()) + "$" + (++classLoadCounter);
    logger.debug("Trying to make class for " + newTypeName);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, newTypeName, null, "java/lang/Object", new String[] {"java/io/Serializable"});

    {
      MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    StringBuilder valueLists = new StringBuilder();
    java.lang.reflect.Type[] types = method.getGenericParameterTypes();
    String[] names = provider.parameterNamesFor(method);
    for (int i = 0; i < names.length; i++) {
      names[i] = Info.capitalize(names[i]);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Parameter names found for creating type are: " + Arrays.toString(names));
    }
    for (int i = 0; i < types.length; i++) {
      java.lang.reflect.Type type = types[i];
      if (type instanceof ParameterizedType) {
        parse(cw, (ParameterizedType) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof Class<?>) {
        parse(cw, (Class<?>) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof TypeVariable<?>) {
        ParameterizedType superclass = (ParameterizedType) resourceMethod.getResource().getType().getGenericSuperclass();
        parse(cw, (Class<?>) superclass.getActualTypeArguments()[0], valueLists, newTypeName, names[i]);
      } else {
        throw new IllegalArgumentException("Unable to identify field " + type + " of type "
            + type.getClass().getName());
      }

    }
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {
      @Override
      public Class<?> loadClass(String name) throws ClassNotFoundException {
        if (name.equals(newTypeName)) {
View Full Code Here


    final String newTypeName = method.getDeclaringClass().getSimpleName().replace('.', '/') + "$"
        + method.getName() + "$" + Math.abs(method.hashCode()) + "$" + (++classLoadCounter);
    logger.debug("Trying to make class for " + newTypeName);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, newTypeName, null, "java/lang/Object", new String[] {"java/io/Serializable"});

    {
      MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    StringBuilder valueLists = new StringBuilder();
    java.lang.reflect.Type[] types = method.getGenericParameterTypes();
    String[] names = provider.parameterNamesFor(method);
    for (int i = 0; i < names.length; i++) {
      names[i] = Info.capitalize(names[i]);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Parameter names found for creating type are: " + Arrays.toString(names));
    }
    for (int i = 0; i < types.length; i++) {
      java.lang.reflect.Type type = types[i];
      if (type instanceof ParameterizedType) {
        parse(cw, (ParameterizedType) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof Class<?>) {
        parse(cw, (Class<?>) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof TypeVariable<?>) {
        ParameterizedType superclass = (ParameterizedType) resourceMethod.getResource().getType().getGenericSuperclass();
        parse(cw, (Class<?>) superclass.getActualTypeArguments()[0], valueLists, newTypeName, names[i]);
      } else {
        throw new IllegalArgumentException("Unable to identify field " + type + " of type "
            + type.getClass().getName());
      }

    }
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {
      @Override
      public Class<?> loadClass(String name) throws ClassNotFoundException {
        if (name.equals(newTypeName)) {
View Full Code Here

                optimize(files[i], d, remapper);
            }
        } else if (f.getName().endsWith(".class")) {
            ConstantPool cp = new ConstantPool();
            ClassReader cr = new ClassReader(new FileInputStream(f));
            ClassWriter cw = new ClassWriter(0);
            ClassConstantsCollector ccc = new ClassConstantsCollector(cw, cp);
            ClassOptimizer co = new ClassOptimizer(ccc, remapper);
            cr.accept(co, ClassReader.SKIP_DEBUG);

            Set constants = new TreeSet(new ConstantComparator());
            constants.addAll(cp.values());

            cr = new ClassReader(cw.toByteArray());
            cw = new ClassWriter(0);
            Iterator i = constants.iterator();
            while (i.hasNext()) {
                Constant c = (Constant) i.next();
                c.write(cw);
            }
            cr.accept(cw, ClassReader.SKIP_DEBUG);

            if (MAPPING.getProperty(cr.getClassName() + "/remove") != null) {
                return;
            }
            String n = remapper.mapType(cr.getClassName());
            File g = new File(d, n + ".class");
            if (!g.exists() || g.lastModified() < f.lastModified()) {
                g.getParentFile().mkdirs();
                OutputStream os = new FileOutputStream(g);
                os.write(cw.toByteArray());
                os.close();
            }
        }
    }
View Full Code Here

        @Override
        public final void begin(final String name, final Attributes attrs) {
            int major = Integer.parseInt(attrs.getValue("major"));
            int minor = Integer.parseInt(attrs.getValue("minor"));
            cw = new ClassWriter(computeMax ? ClassWriter.COMPUTE_MAXS : 0);
            Map vals = new HashMap();
            vals.put("version", new Integer(minor << 16 | major));
            vals.put("access", attrs.getValue("access"));
            vals.put("name", attrs.getValue("name"));
            vals.put("parent", attrs.getValue("parent"));
View Full Code Here

                optimize(files[i], d, remapper);
            }
        } else if (f.getName().endsWith(".class")) {
            ConstantPool cp = new ConstantPool();
            ClassReader cr = new ClassReader(new FileInputStream(f));
            ClassWriter cw = new ClassWriter(0);
            ClassConstantsCollector ccc = new ClassConstantsCollector(cw, cp);
            ClassOptimizer co = new ClassOptimizer(ccc, remapper);
            cr.accept(co, ClassReader.SKIP_DEBUG);

            Set constants = new TreeSet(new ConstantComparator());
            constants.addAll(cp.values());

            cr = new ClassReader(cw.toByteArray());
            cw = new ClassWriter(0);
            Iterator i = constants.iterator();
            while (i.hasNext()) {
                Constant c = (Constant) i.next();
                c.write(cw);
            }
            cr.accept(cw, ClassReader.SKIP_DEBUG);

            if (MAPPING.getProperty(cr.getClassName() + "/remove") != null) {
                return;
            }
            String n = remapper.mapType(cr.getClassName());
            File g = new File(d, n + ".class");
            if (!g.exists() || g.lastModified() < f.lastModified()) {
                g.getParentFile().mkdirs();
                OutputStream os = new FileOutputStream(g);
                os.write(cw.toByteArray());
                os.close();
            }
        }
    }
View Full Code Here

    final String newTypeName = method.getDeclaringClass().getSimpleName().replace('.', '/') + "$"
        + method.getName() + "$" + Math.abs(method.hashCode()) + "$" + (++classLoadCounter);
    logger.debug("Trying to make class for " + newTypeName);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, newTypeName, null, "java/lang/Object", new String[] {"java/io/Serializable"});

    {
      MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    StringBuilder valueLists = new StringBuilder();
    java.lang.reflect.Type[] types = method.getGenericParameterTypes();
    String[] names = provider.parameterNamesFor(method);
    for (int i = 0; i < names.length; i++) {
      names[i] = Info.capitalize(names[i]);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Parameter names found for creating type are: " + Arrays.toString(names));
    }
    for (int i = 0; i < types.length; i++) {
      java.lang.reflect.Type type = types[i];
      if (type instanceof ParameterizedType) {
        parse(cw, (ParameterizedType) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof Class) {
        parse(cw, (Class<?>) type, valueLists, newTypeName, names[i]);
      } else if (type instanceof TypeVariable<?>) {
        ParameterizedType superclass = (ParameterizedType) resourceMethod.getResource().getType().getGenericSuperclass();
        parse(cw, (Class<?>) superclass.getActualTypeArguments()[0], valueLists, newTypeName, names[i]);
      } else {
        throw new IllegalArgumentException("Unable to identify field " + type + " of type "
            + type.getClass().getName());
      }

    }
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {
      @Override
      public Class<?> loadClass(String name) throws ClassNotFoundException {
        if (name.equals(newTypeName)) {
View Full Code Here

        @Override
        public final void begin(final String name, final Attributes attrs) {
            int major = Integer.parseInt(attrs.getValue("major"));
            int minor = Integer.parseInt(attrs.getValue("minor"));
            cw = new ClassWriter(computeMax ? ClassWriter.COMPUTE_MAXS : 0);
            Map vals = new HashMap();
            vals.put("version", new Integer(minor << 16 | major));
            vals.put("access", attrs.getValue("access"));
            vals.put("name", attrs.getValue("name"));
            vals.put("parent", attrs.getValue("parent"));
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.asm.ClassWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.