当前位置: 首页>>代码示例>>Java>>正文


Java ClassWriter.visitEnd方法代码示例

本文整理汇总了Java中org.objectweb.asm.ClassWriter.visitEnd方法的典型用法代码示例。如果您正苦于以下问题:Java ClassWriter.visitEnd方法的具体用法?Java ClassWriter.visitEnd怎么用?Java ClassWriter.visitEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.ClassWriter的用法示例。


在下文中一共展示了ClassWriter.visitEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateProxyClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private void generateProxyClass(ClassWriter visitor, StructSchema<?> viewSchema, StructBindings<?> bindings, Collection<String> interfacesToImplement,
                                Collection<ModelType<?>> viewTypes, Type generatedType, Type superclassType, Class<? extends GeneratedViewState> backingStateType) {
    Class<?> viewClass = viewSchema.getType().getConcreteClass();
    StructSchema<?> delegateSchema = bindings.getDelegateSchema();
    declareClass(visitor, interfacesToImplement, generatedType, superclassType);
    declareStateField(visitor);
    declareTypeConverterField(visitor);
    declareManagedTypeField(visitor);
    declareCanCallSettersField(visitor);
    writeStaticConstructor(visitor, generatedType, viewClass);
    writeConstructor(visitor, generatedType, superclassType, delegateSchema, Type.getType(backingStateType));
    writeToString(visitor, generatedType, viewClass, delegateSchema);
    writeGeneratedViewMethods(visitor, generatedType);
    if (backingStateType == ModelElementState.class) {
        writeManagedInstanceMethods(visitor, generatedType);
    }
    writeGroovyMethods(visitor, viewClass);
    writeViewMethods(visitor, generatedType, viewTypes, bindings);
    writeHashCodeMethod(visitor, generatedType);
    writeEqualsMethod(visitor, generatedType);
    visitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:ManagedProxyClassGenerator.java

示例2: generate

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
/**
 * Generates an implementation of the given managed type.
 *
 * <p>The generated type will:</p>
 *
 * <ul>
 *     <li>extend the given implementation class</li>
 *     <li>implement the given public interface</li>
 *     <li>override each public constructor of the given implementation class</li>
 * </ul>
 */
public Class<?> generate(Class<?> implClass, Class<?> publicContractType) {
    ClassWriter visitor = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

    String generatedTypeName = publicContractType.getName() + "_Impl";
    Type generatedType = Type.getType("L" + generatedTypeName.replaceAll("\\.", "/") + ";");

    Type superclassType = Type.getType(implClass);
    Type publicType = Type.getType(publicContractType);

    generateClass(visitor, generatedType, superclassType, publicType);
    generateConstructors(visitor, implClass, superclassType);
    visitor.visitEnd();

    return defineClass(visitor, publicContractType.getClassLoader(), generatedTypeName);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:27,代码来源:ManagedCollectionProxyClassGenerator.java

示例3: proceed

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Override
public void proceed() {
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    writer.visit(Opcodes.V1_6,
            Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_SUPER,
            RSymbols.R_STYLEABLES_CLASS_NAME,
            null,
            "java/lang/Object",
            null);
    for (String name : symbols.getStyleables().keySet()) {
        writer.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, name, "[I", null, null);
    }

    writeClinit(writer);
    writer.visitEnd();
    byte[] bytes = writer.toByteArray();
    try {
        if (!dir.isDirectory() && !dir.mkdirs()) {
            throw new RuntimeException("Cannot mkdir " + dir);
        }
        Files.write(dir.toPath().resolve(RSymbols.R_STYLEABLES_CLASS_NAME + ".class"), bytes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:26,代码来源:WriteStyleablesProcessor.java

示例4: generate

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public byte[] generate(){
    String className = "eu.mikroskeem.test.shuriken.common.classtools.gen.GeneratedClass";
    String classNameInternal = className.replaceAll("\\.", "/");

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(
            V1_8,
            ACC_PUBLIC + ACC_SUPER,
            classNameInternal,
            null,
            Type.getInternalName(Object.class),
            null);
    FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "test", Type.getDescriptor(String.class), null, "hey");
    fv.visitEnd();
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:24,代码来源:ValidatorTester.java

示例5: compile

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public byte[] compile(String className, Class<?> clazz) throws IOException, CompilerException {
    ClassWriter cw = new ClassWriter(0);

    Type clazzType = Type.getType(clazz);

    String internalName = className.replace('.', '/');
    String classDesc = "L" + internalName + ";";

    String signature = BytecodeGenerator.OBJECT.getDescriptor() + "L" +
            BytecodeGenerator.OBJECT_TEMPLATE.getInternalName() + "<" + clazzType.getDescriptor() + ">;";

    cw.visit(52, ACC_PUBLIC + ACC_SUPER, internalName, signature,
            BytecodeGenerator.OBJECT.getInternalName(),
            new String[]{BytecodeGenerator.OBJECT_TEMPLATE.getInternalName()});

    cw.visitSource(templateName, null);

    createConstructor(cw, classDesc);
    createObjectRender(cw, internalName, classDesc, clazzType);

    DataManager getter = new ClassDataManager(clazz, clazzType);
    generator = new BytecodeGenerator(this, cw, getter, internalName, classDesc);

    generator.insertMethodStart("render");
    parser.parse();
    generator.insertMethodEnd();

    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:31,代码来源:MustacheCompiler.java

示例6: generateClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static byte[] generateClass() {

            ClassWriter cw = new ClassWriter(0);

            cw.visit(52, ACC_SUPER | ACC_PUBLIC, INNER_CLASS_NAME_INTERNAL, null, "java/lang/Object", null);

            cw.visitSource("UnbalancedMonitorsTest.java", null);

            cw.visitInnerClass(INNER_CLASS_NAME_INTERNAL, CLASS_NAME_INTERNAL, "UnbalancedMonitors", ACC_STATIC);

            visitConstructor(cw);
            visitWrongOrder(cw);
            visitBlockStructured(cw, true, false);
            visitBlockStructured(cw, true, true);
            visitBlockStructured(cw, false, false);
            visitBlockStructured(cw, false, true);
            cw.visitEnd();

            return cw.toByteArray();
        }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:UnbalancedMonitorsTest.java

示例7: dump

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static byte[] dump() throws Exception {

            ClassWriter cw = new ClassWriter(0);
            createClassHeader(cw);
            createConstructor(cw);
            createMainMethod(cw);

            cw.visitEnd();

            return cw.toByteArray();
        }
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:12,代码来源:JavaInstallationProbe.java

示例8: generateSyntheticClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Override
public byte[] generateSyntheticClass(String name) {
    ClassWriter visitor = new ClassWriter(0);
    visitor.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, name.replace('.', '/'), null, OBJECT_TYPE.getInternalName(), null);
    visitor.visitEnd();
    return visitor.toByteArray();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:DefaultLegacyTypesSupport.java

示例9: genClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Test
public void genClass()
{
    ClassWriter classWriter = new ClassWriter(0);
    classWriter.visit(V1_6, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
            "cn/edu/ruc/iir/paraflow/loader/consumer/utils/Comparable",
            null,
            "java/lang/Object",
            null);
    classWriter.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
            "LESS", "I", null, -1)
            .visitEnd();
    classWriter.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
            "EQUAL", "I", null, 0)
            .visitEnd();
    classWriter.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
            "GREATER", "I", null, 1)
            .visitEnd();
    classWriter.visitMethod(ACC_PUBLIC + ACC_ABSTRACT,
            "compareTo", "(Ljava/lang/Object;)I", null, null)
            .visitEnd();
    classWriter.visitEnd();
    byte[] bytes = classWriter.toByteArray();

    MyClassLoader myClassLoader = new MyClassLoader();
    Class clazz = myClassLoader.defineClass("cn.edu.ruc.iir.paraflow.loader.consumer.utils.Comparable", bytes);
    try {
        System.out.println(clazz.getField("LESS").getName());
    }
    catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:34,代码来源:ByteCodeGenTest.java

示例10: generateConfigClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
/**
 * Creates AppPerformanceConfig.class file with a static boolean field AppPerformanceConfig#enabled in it.
 *
 * @param value Initializes the AppPerformanceConfig#enabled with value.
 * @return byte array of the class.
 */
public static byte[] generateConfigClass(boolean value) {

  ClassWriter cw = new ClassWriter(0);
  cw.visit(V1_6, ACC_FINAL + ACC_SUPER,
      "com/rakuten/tech/mobile/perf/runtime/internal/AppPerformanceConfig", null,
      "java/lang/Object", null);
  cw.visitField(ACC_PUBLIC + ACC_STATIC, "enabled", "Z", null, value);
  cw.visitEnd();
  return cw.toByteArray();
}
 
开发者ID:rakutentech,项目名称:android-perftracking,代码行数:17,代码来源:ClassGenerator.java

示例11: testClassLoading

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Test
public void testClassLoading() throws Exception {
    SimpleClassLoader simpleClassLoader = new SimpleClassLoader(ClassLoader.getSystemClassLoader());

    String className = getClass().getPackage().getName()+".GeneratedTestClass";
    String classNameInternal = className.replaceAll("\\.", "/");

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, classNameInternal, null, Type.getInternalName(Object.class), null);
    {
        FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "test", Type.getDescriptor(String.class), null, "hey");
        fv.visitEnd();
    }
    {
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
        cw.visitEnd();
    }
    cw.visitEnd();

    /* Test class loading */
    Class<?> generated = ClassLoaderTools.defineClass(simpleClassLoader, className, cw.toByteArray());
    Assertions.assertNotNull(generated, "Class didn't load!");
    Assertions.assertTrue(Reflect.getClass(className, simpleClassLoader).isPresent(),
            "Class isn't present in classloader!");
    Assertions.assertFalse(Reflect.getClass(className).isPresent()
            , "Class is present in system class loader!");

    /* Test field */
    ClassWrapper<?> c = Reflect.construct(Reflect.wrapClass(generated));
    Optional<FieldWrapper<String>> testFieldOptional = c.getField("test", String.class);
    Assertions.assertTrue(testFieldOptional.isPresent(), "Test field is not present!");
    Assertions.assertEquals("hey", testFieldOptional.get().read(), "Test field content didn't match!");
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:39,代码来源:ClassLoadingTester.java

示例12: generate

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static Pair<String, byte[]> generate(){
    String className = "eu/mikroskeem/test/shuriken/classloader/classes/TestClass1";
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(52, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(Object.class), null);
    ClassTools.generateSimpleSuperConstructor(cw, Object.class);
    cw.visitEnd();
    return new Pair<>(className+".class.br", cw.toByteArray());
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:9,代码来源:GenerateTestClass.java

示例13: generateMethodArgsUpdater

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static byte[] generateMethodArgsUpdater(Class<?> classToProxy, Method method, int methodId) throws Exception {

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

        String classToProxyDescriptor = Type.getDescriptor(classToProxy);
        String classToProxyInternalName = Type.getInternalName(classToProxy);

        String suffix = SUFFIX_START + method.getName() + methodId;
        String selfClassInternalName = classToProxyInternalName + suffix;
        String selfClassDescriptor = BytecodeGenUtils.makeSuffixClassDescriptor(classToProxyDescriptor, suffix);

        String argsClassInternalName = classToProxyInternalName + MethodArgumentsGenerator.SUFFIX_START + method.getName() + methodId;

        String constDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
                Stream.concat(Stream.of(List.class), Stream.of(method.getParameterTypes())).map(Type::getType)
                        .toArray(Type[]::new));

        cw.visit(52, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, selfClassInternalName, null, "java/lang/Object",
                new String[] {  "io/primeval/reflex/arguments/ArgumentsUpdater" });
        Parameter[] parameters = method.getParameters();

        generateFields(method, cw, parameters);
        generateConstructor(method, cw, selfClassInternalName, selfClassDescriptor, constDesc, parameters);
        generateHashCodeMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateEqualsMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateToStringMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);


        generateUpdateMethod(cw, selfClassInternalName, selfClassDescriptor, argsClassInternalName, constDesc, parameters);

        generateParametersGetter(cw, selfClassInternalName, selfClassDescriptor);

        generateArgumentSetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateArgumentGetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
        cw.visitEnd();

        return cw.toByteArray();
    }
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:39,代码来源:MethodArgumentssUpdaterGenerator.java

示例14: generateMethodArgs

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static byte[] generateMethodArgs(Class<?> classToProxy, Method method, int methodId) throws Exception {

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

        String classToProxyDescriptor = Type.getDescriptor(classToProxy);
        String classToProxyInternalName = Type.getInternalName(classToProxy);

        String suffix = SUFFIX_START + method.getName() + methodId;
        String selfClassInternalName = classToProxyInternalName + suffix;
        String selfClassDescriptor = BytecodeGenUtils.makeSuffixClassDescriptor(classToProxyDescriptor, suffix);

        String updaterClassInternalName = classToProxyInternalName + MethodArgumentssUpdaterGenerator.SUFFIX_START + method.getName() + methodId;

        String constDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
                Stream.concat(Stream.of(List.class), Stream.of(method.getParameterTypes())).map(Type::getType)
                        .toArray(Type[]::new));

        cw.visit(52, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, selfClassInternalName, null, "java/lang/Object",
                new String[] { "io/primeval/reflex/arguments/Arguments" });
        Parameter[] parameters = method.getParameters();

        generateFields(method, cw, parameters);
        generateConstructor(method, cw, selfClassInternalName, selfClassDescriptor, constDesc, parameters);
        generateHashCodeMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateEqualsMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateToStringMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);

        generateUpdaterMethod(cw, selfClassInternalName, selfClassDescriptor, updaterClassInternalName, constDesc, parameters);

        generateParametersGetter(cw, selfClassInternalName, selfClassDescriptor);
        generateArgumentGetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
        cw.visitEnd();

        return cw.toByteArray();
    }
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:36,代码来源:MethodArgumentsGenerator.java

示例15: compileSimple

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public byte[] compileSimple(String className, Map<String, MustacheType> types) throws IOException, CompilerException {
    ClassWriter cw = new ClassWriter(0);

    String internalName = className.replace('.', '/');
    String classDesc = "L" + internalName + ";";

    cw.visit(52, ACC_PUBLIC + ACC_SUPER,
            internalName, null,
            BytecodeGenerator.OBJECT.getInternalName(),
            new String[]{BytecodeGenerator.SIMPLE_TEMPLATE.getInternalName()});

    cw.visitSource(templateName, null);

    createConstructor(cw, classDesc);

    DataManager data;

    if(types != null && !types.isEmpty()) {
        data = new TypedDataManager(types);
    } else {
        data = new SimpleDataManager();
    }

    generator = new BytecodeGenerator(this, cw, data, className, classDesc);

    generator.insertMethodStart("render");
    parser.parse();
    generator.insertMethodEnd();

    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:33,代码来源:MustacheCompiler.java


注:本文中的org.objectweb.asm.ClassWriter.visitEnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。