Package wyvern.tools.parsing.parselang.java

Examples of wyvern.tools.parsing.parselang.java.StoringFileManager


    JavaCompiler jc = javax.tools.ToolProvider.getSystemJavaCompiler();

    List<StringFileObject> compilationUnits = Arrays.asList(new StringFileObject(javaClassName, target.toString()));
    StoringClassLoader loader = new StoringClassLoader(this.getClass().getClassLoader());
    StoringFileManager sfm = new StoringFileManager(jc.getStandardFileManager(null, null, null),
        loader);

    StringFileObject sfo = new StringFileObject(javaClassName, target.toString());
    sfm.putFileForInput(StandardLocation.SOURCE_PATH, "", javaClassName, sfo);
    JavaCompiler.CompilationTask ct = jc.getTask(null, sfm, null, null, null, Arrays.asList(sfo));

    if (!ct.call())
      throw new RuntimeException();

    loader.applyTransformer(name->name.equals(javaClassName), cw -> new ClassVisitor(Opcodes.ASM5, new CheckClassAdapter(cw)) {
      @Override
      public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        if (!name.equals("<init>"))
          return super.visitMethod(access, name, desc, signature, exceptions);


        String ndesc = org.objectweb.asm.Type.getMethodDescriptor(org.objectweb.asm.Type.VOID_TYPE,
            org.objectweb.asm.Type.getType(Value.class));
        org.objectweb.asm.Type thisType = org.objectweb.asm.Type.getType("L" + javaClassName + ";");

        MethodVisitor res = new CheckMethodAdapter(super.visitMethod(access, name, ndesc, null, exceptions));
        GeneratorAdapter generator = new GeneratorAdapter(
            res,
            Opcodes.ASM5,
            "<init>",
            ndesc);
        generator.visitCode();
        generator.loadThis();
        generator.invokeConstructor(org.objectweb.asm.Type.getType(SingleDFAEngine.class), Method.getMethod("void <init>()"));
        generator.loadThis();
        generator.loadArg(0);
        generator.putField(thisType, PAIRED_OBJECT_NAME,
            org.objectweb.asm.Type.getType(Value.class));
        generator.returnValue();
        generator.visitMaxs(2, 2);
        generator.visitEnd();

        return new MethodVisitor(Opcodes.ASM5) {};
      }
    });

    Class javaClass = sfm.getClassLoader().loadClass(javaClassName);

    JavaClassDecl jcd = Util.javaToWyvDecl(javaClass);


    JavaClassDecl terminalsDecl = StreamSupport.stream(jcd.getDecls().getDeclIterator().spliterator(), false)
View Full Code Here

TOP

Related Classes of wyvern.tools.parsing.parselang.java.StoringFileManager

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.