當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。