當前位置: 首頁>>代碼示例>>Java>>正文


Java FieldVisitor類代碼示例

本文整理匯總了Java中org.objectweb.asm.FieldVisitor的典型用法代碼示例。如果您正苦於以下問題:Java FieldVisitor類的具體用法?Java FieldVisitor怎麽用?Java FieldVisitor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FieldVisitor類屬於org.objectweb.asm包,在下文中一共展示了FieldVisitor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: begin

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public void begin(final String name, final Attributes attrs) {
    String desc = attrs.getValue("desc");
    boolean visible = Boolean.valueOf(attrs.getValue("visible"))
            .booleanValue();
    int typeRef = Integer.parseInt(attrs.getValue("typeRef"));
    TypePath typePath = TypePath.fromString(attrs.getValue("typePath"));

    Object v = peek();
    if (v instanceof ClassVisitor) {
        push(((ClassVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof FieldVisitor) {
        push(((FieldVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof MethodVisitor) {
        push(((MethodVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    }
}
 
開發者ID:ItzSomebody,項目名稱:DirectLeaks-AntiReleak-Remover,代碼行數:21,代碼來源:ASMContentHandler.java

示例2: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    StringBuilder sb = new StringBuilder();
    appendAccess(access | ACCESS_FIELD, sb);

    AttributesImpl att = new AttributesImpl();
    att.addAttribute("", "access", "access", "", sb.toString());
    att.addAttribute("", "name", "name", "", name);
    att.addAttribute("", "desc", "desc", "", desc);
    if (signature != null) {
        att.addAttribute("", "signature", "signature", "",
                encode(signature));
    }
    if (value != null) {
        att.addAttribute("", "value", "value", "", encode(value.toString()));
    }

    return new SAXFieldAdapter(sa, att);
}
 
開發者ID:ItzSomebody,項目名稱:DirectLeaks-AntiReleak-Remover,代碼行數:21,代碼來源:SAXClassAdapter.java

示例3: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE
            + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC
            + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE
            + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC
            + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
    CheckMethodAdapter.checkDesc(desc, false);
    if (signature != null) {
        checkFieldSignature(signature);
    }
    if (value != null) {
        CheckMethodAdapter.checkConstant(value);
    }
    FieldVisitor av = super
            .visitField(access, name, desc, signature, value);
    return new CheckFieldAdapter(av);
}
 
開發者ID:ItzSomebody,項目名稱:DirectLeaks-AntiReleak-Remover,代碼行數:22,代碼來源:CheckClassAdapter.java

示例4: assertFiledTypes

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
private void assertFiledTypes(final Class<?> type, String... expected)
        throws IOException {
    final ClassReader reader = new ClassReader(type.getName());
    final Set<String> actual = new HashSet<String>();
    reader.accept(new ClassVisitor(Opcodes.ASM5) {
        @Override
        public FieldVisitor visitField(int access, String name,
                String desc, String signature, Object value) {
            if ((access & Opcodes.ACC_SYNTHETIC) == 0) {
                if (signature == null) {
                    signature = desc;
                }
                cyclicRefsTest.getTypesFromSignature(signature, actual);
            }
            return null;
        }
    }, 0);
    assertEquals(new HashSet<String>(Arrays.asList(expected)), actual);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:CyclicReferencesTestTest.java

示例5: generate

import org.objectweb.asm.FieldVisitor; //導入依賴的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

示例6: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(final int access,
    final String name, final String desc,
    final String signature, final Object value) {
    this.dirs.addIf("attributes")
        .add("attribute")
        .set(name)
        .attr("type", desc.replaceAll(";$", ""))
        .attr(
            "public",
            (access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC
        )
        .attr(
            "static",
            (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC
        )
        .up().up();
    return super.visitField(
        access, name, desc, signature, value
    );
}
 
開發者ID:yegor256,項目名稱:jpeek,代碼行數:22,代碼來源:Skeleton.java

示例7: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        cp.newUTF8("Synthetic");
    }
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        cp.newUTF8("Deprecated");
    }
    cp.newUTF8(name);
    cp.newUTF8(desc);
    if (signature != null) {
        cp.newUTF8("Signature");
        cp.newUTF8(signature);
    }
    if (value != null) {
        cp.newConst(value);
    }
    return new FieldConstantsCollector(cv.visitField(access, name, desc,
            signature, value), cp);
}
 
開發者ID:acmerli,項目名稱:fastAOP,代碼行數:22,代碼來源:ClassConstantsCollector.java

示例8: visitLdcInsn

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public void visitLdcInsn(Object cst) {
    if (!(cst instanceof Type)) {
        super.visitLdcInsn(cst);
        return;
    }

    // transform Foo.class for 1.2 compatibility
    String ldcName = ((Type) cst).getInternalName();
    String fieldName = "class$" + ldcName.replace('/', '$');
    if (!classOptimizer.syntheticClassFields.contains(ldcName)) {
        classOptimizer.syntheticClassFields.add(ldcName);
        FieldVisitor fv = classOptimizer.syntheticFieldVisitor(ACC_STATIC
                | ACC_SYNTHETIC, fieldName, "Ljava/lang/Class;");
        fv.visitEnd();
    }

    String clsName = classOptimizer.clsName;
    mv.visitFieldInsn(GETSTATIC, clsName, fieldName, "Ljava/lang/Class;");
}
 
開發者ID:acmerli,項目名稱:fastAOP,代碼行數:21,代碼來源:MethodOptimizer.java

示例9: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    String s = remapper.mapFieldName(className, name, desc);
    if ("-".equals(s)) {
        return null;
    }
    if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) {
        if ((access & Opcodes.ACC_FINAL) != 0
                && (access & Opcodes.ACC_STATIC) != 0 && desc.length() == 1) {
            return null;
        }
        if ("org/objectweb/asm".equals(pkgName) && s.equals(name)) {
            System.out.println("INFO: " + clsName + "." + s
                    + " could be renamed");
        }
        super.visitField(access, name, desc, null, value);
    } else {
        if (!s.equals(name)) {
            throw new RuntimeException("The public or protected field "
                    + className + '.' + name + " must not be renamed.");
        }
        super.visitField(access, name, desc, null, value);
    }
    return null; // remove debug info
}
 
開發者ID:acmerli,項目名稱:fastAOP,代碼行數:27,代碼來源:ClassOptimizer.java

示例10: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(
       final int access,
       final String name,
       final String desc,
       final String signature,
       final Object value)
   {
   	if ((access & ACC_SYNTHETIC) == 0) {
        JvmFieldBuilder fieldBuilder = new JvmFieldBuilder(
        		result,
        		(access & ACC_STATIC) == 0 ? typeParameters : null,
        		proxies,
   				access,
        		name,
        		desc,
        		signature,
        		value);
        return fieldBuilder;
   	}
   	return null;
   }
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:23,代碼來源:JvmDeclaredTypeBuilder.java

示例11: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(int access, String name, String desc, String sig, Object o) {
  if (this.classOnly) {
    return super.visitField(access, name, desc, sig, o);
  }
  if (name.startsWith("$") || name.startsWith("this$")) {
    return super.visitField(access, name, desc, sig, o);
  }
  if (includePrivate) {
    return new FieldAnalyzeVisitor(this, access, name, desc, sig)
        .setTypeMap(this.getTypeMap())
        .parseSignature();
  }
  // log.debug("Field Name:{}", name);
  if ((Opcodes.ACC_PRIVATE & access) == 0) {
    return new FieldAnalyzeVisitor(this, access, name, desc, sig)
        .setTypeMap(this.getTypeMap())
        .parseSignature();
  }
  return super.visitField(access, name, desc, sig, o);
}
 
開發者ID:mopemope,項目名稱:meghanada-server,代碼行數:22,代碼來源:ClassAnalyzeVisitor.java

示例12: generateFields

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
/**
 * Emits the bytecode for all fields of the class
 */
protected void generateFields() {
       for (SootField f : sc.getFields()) {
           String name = f.getName();
           String desc = toTypeDesc(f.getType());
           String sig = null;
           if (f.hasTag("SignatureTag")) {
               SignatureTag genericSignature = (SignatureTag) f
                       .getTag("SignatureTag");
               sig = genericSignature.getSignature();
           }
           Object value = getDefaultValue(f);
           int access = getModifiers(f.getModifiers(), f);
           FieldVisitor fv = cv.visitField(access, name, desc, sig, value);
           if (fv != null) {
               generateAnnotations(fv, f);
               generateAttributes(fv, f);
               fv.visitEnd();
           }
       }
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:24,代碼來源:AbstractASMBackend.java

示例13: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    if ("$VALUES".equals(name) && classStack.peek().isEnum()) {
        return null;
    }

    String signatureDesc = signature != null ? signature : desc;
    SignatureReader r = new SignatureReader(signatureDesc);
    CustomTraceSignatureVisitor sv = new CustomTraceSignatureVisitor(Opcodes.ACC_PUBLIC);
    r.accept(sv);

    FieldInfo field = FieldInfo.fieldInfo()
        .name(name)
        .modifiers(access)
        .type(sv.getTypeOrSuperclass())
        .value(value)
        .build();
    classStack.peek().addToFields(field);
    return new FieldProcessor(field);
}
 
開發者ID:aalmiray,項目名稱:naum,代碼行數:21,代碼來源:ClassProcessor.java

示例14: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value)
{
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE
            + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC
            + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE
            + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC
            + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED);
    CheckMethodAdapter.checkIdentifier(name, "field name");
    CheckMethodAdapter.checkDesc(desc, false);
    if (signature != null) {
        // TODO
    }
    if (value != null) {
        CheckMethodAdapter.checkConstant(value);
    }
    FieldVisitor av = cv.visitField(access, name, desc, signature, value);
    return new CheckFieldAdapter(av);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:25,代碼來源:CheckClassAdapter.java

示例15: visitField

import org.objectweb.asm.FieldVisitor; //導入依賴的package包/類
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value)
{
    buf.setLength(0);
    buf.append("{\n");
    buf.append("fv = cw.visitField(");
    appendAccess(access | ACCESS_FIELD);
    buf.append(", ");
    appendConstant(name);
    buf.append(", ");
    appendConstant(desc);
    buf.append(", ");
    appendConstant(signature);
    buf.append(", ");
    appendConstant(value);
    buf.append(");\n");
    text.add(buf.toString());
    ASMifierFieldVisitor aav = new ASMifierFieldVisitor();
    text.add(aav.getText());
    text.add("}\n");
    return aav;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:27,代碼來源:ASMifierClassVisitor.java


注:本文中的org.objectweb.asm.FieldVisitor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。