Package org.apache.tapestry5.internal.plastic.asm

Examples of org.apache.tapestry5.internal.plastic.asm.ClassWriter


    final class ClassRule extends Rule {

        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

    private void createImplementationClass(String className, String status) throws Exception
    {
        String internalName = PlasticInternalUtils.toInternalName(className);

        ClassWriter cw = createClassWriter(internalName, "java/lang/Object", ACC_PUBLIC);

        // Add default constructor

        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();


        mv = cw.visitMethod(ACC_PUBLIC, "getStatus", "()Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitLdcInsn(status);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        cw.visitEnd();

        writeBytecode(cw, internalName);
    }
View Full Code Here

        writeBytecode(cw, internalName);
    }

    private ClassWriter createClassWriter(String internalName, String baseClassInternalName, int classModifiers)
    {
        ClassWriter cw = new ClassWriter(0);

        cw.visit(V1_5, classModifiers, internalName, null,
                baseClassInternalName, new String[]{
                PlasticInternalUtils.toInternalName(ReloadableService.class.getName())
        });

        return cw;
View Full Code Here

    private void createInvalidImplentationClass() throws Exception
    {
        String internalName = PlasticInternalUtils.toInternalName(CLASS);

        ClassWriter cw = createClassWriter(internalName, "java/lang/Object", ACC_PUBLIC);

        // Add default constructor

        MethodVisitor mv = cw.visitMethod(ACC_PROTECTED, "<init>", "()V", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        // Notice the  class is abstract, so no implementation.

        cw.visitEnd();

        writeBytecode(cw, internalName);
    }
View Full Code Here

        }
    }

    private byte[] toBytecode(ClassNode classNode)
    {
        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

        classNode.accept(writer);

        return writer.toByteArray();
    }
View Full Code Here

        String internalName = PlasticInternalUtils.toInternalName(CLASS);

        createImplementationClass(BASE_CLASS, "initial from base");


        ClassWriter cw = createClassWriter(internalName, baseClassInternalName, ACC_PUBLIC);

        // Add default constructor

        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, baseClassInternalName, "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        cw.visitEnd();

        writeBytecode(cw, internalName);

        Registry registry = createRegistry();
View Full Code Here

    }


    private void createSynthComponentClass(String name) throws Exception
    {
        ClassWriter cw = helper.createWriter(SYNTH_COMPONENT_CLASSNAME, BASIC_COMPONENT_CLASSNAME, Named.class.getName());

        helper.implementPublicConstructor(cw, BASIC_COMPONENT_CLASSNAME);

        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitLdcInsn(name);
        mv.visitInsn(ARETURN);
        mv.visitEnd();

        cw.visitEnd();

        helper.writeFile(cw, SYNTH_COMPONENT_CLASSNAME);
    }
View Full Code Here

    }

    private Class createSyntheticMethodModuleClass() throws NoSuchMethodException
    {

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);

        cw.visit(V1_5, ACC_PUBLIC, "EnhancedSyntheticMethodModule", null,
                PlasticInternalUtils.toInternalName(SyntheticMethodModule.class.getName()), null);

        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC, "synth", "()V", null, null);
        mv.visitCode();
        mv.visitInsn(RETURN);
        mv.visitEnd();

        cw.visitEnd();

        byte[] bytecode = cw.toByteArray();

        ClassLoader loader = Thread.currentThread().getContextClassLoader();

        PlasticClassLoader plasticLoader = new PlasticClassLoader(loader, new NoopClassLoaderDelegate());
View Full Code Here

    {
        this.parent = parent;
        this.transformer = transformer;
        this.logger = logger;
        this.internalRequestGlobals = internalRequestGlobals;
        this.changeTracker = new URLChangeTracker(classpathURLConverter);

        initializeService();
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.internal.plastic.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.