本文整理汇总了Java中org.objectweb.asm.FieldVisitor.visitEnd方法的典型用法代码示例。如果您正苦于以下问题:Java FieldVisitor.visitEnd方法的具体用法?Java FieldVisitor.visitEnd怎么用?Java FieldVisitor.visitEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.FieldVisitor
的用法示例。
在下文中一共展示了FieldVisitor.visitEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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;");
}
示例3: 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();
}
}
}
示例4: visitMethods
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
static void visitMethods(String className, ClassWriter cw, String methodName, @Nullable List<Method> methods) {
if (methods != null) {
final FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, KEYS, format("[%s", dKey), null, null);
fv.visitEnd();
for (int i = 0; i < methods.size(); i++) {
final Method method = methods.get(i);
final TypeToken<?> typeToken = TypeToken.of(method.getGenericReturnType());
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method),
format("()%s", getDescriptor(typeToken)), null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETSTATIC, className, KEYS, format("[%s", dKey));
visitIntInsn(mv, i);
mv.visitInsn(AALOAD);
mv.visitMethodInsn(INVOKEVIRTUAL, className, methodName,
format("(%s)Ljava/util/Optional;", dKey), false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/Optional", "get", "()Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(method.getReturnType()));
mv.visitInsn(ARETURN);
mv.visitMaxs(3, 1);
mv.visitEnd();
}
}
}
示例5: visit
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
@Override public boolean visit (FieldDeclaration f) {
ClassWriter cw = currentClass.cw;
int mods = f.getFlags ();
boolean addedMethod = false;
if (FlagsHelper.isStatic (mods) && f.hasInitializer ()) {
addedMethod = true;
addMethod (getStaticBlock ());
}
// TODO: handle initializer blocks
for (VariableDeclarator vd : f.getVariables ().get ()) {
String id = vd.getId ();
String signature = GenericTypeHelper.getGenericType (f.getType ());
// int access, String name, String desc, String signature, Object value
FieldVisitor fw = cw.visitField (mods, id, getType (f.getType ()), signature, null);
fw.visitEnd ();
TreeNode tn = vd.getInitializer ();
if (tn != null) {
toType (tn, f).visit (this);
storeValue (mods, id, f.getExpressionType ().getDescriptor ());
}
}
if (addedMethod)
removeMethod ();
return false;
}
示例6: visit
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
public void visit(ClassVisitor visitor)
{
FieldVisitor fieldVisitor = visitor.visitField(toAccessModifier(access),
name,
type.getType(),
type.getGenericSignature(),
null);
if (fieldVisitor == null) {
return;
}
for (AnnotationDefinition annotation : annotations) {
annotation.visitFieldAnnotation(fieldVisitor);
}
fieldVisitor.visitEnd();
}
示例7: registerFields
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
public static void registerFields(BytecodeContext bc, List<LitString> keys) throws TransformerException {
//if(keys.size()==0) return;
GeneratorAdapter ga = bc.getAdapter();
FieldVisitor fv = bc.getClassWriter().visitField(Opcodes.ACC_PRIVATE ,
"keys", Types.COLLECTION_KEY_ARRAY.toString(), null, null);
fv.visitEnd();
int index=0;
LitString value;
Iterator<LitString> it = keys.iterator();
ga.visitVarInsn(Opcodes.ALOAD, 0);
ga.push(keys.size());
ga.newArray(Types.COLLECTION_KEY);
while(it.hasNext()) {
value=it.next();
ga.dup();
ga.push(index++);
//value.setExternalize(false);
ExpressionUtil.writeOutSilent(value,bc, Expression.MODE_REF);
ga.invokeStatic(KEY_IMPL, KEY_INTERN);
ga.visitInsn(Opcodes.AASTORE);
}
ga.visitFieldInsn(Opcodes.PUTFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString());
}
示例8: transferTraitFields
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
private void transferTraitFields(ClassWriter writer) {
for (FieldNode f : traitNode.fields) {
if (f.name.equals("_super"))
continue;
FieldVisitor v = writer.visitField(ACC_PUBLIC, f.name, f.desc, null, f.value);
if (f.visibleAnnotations != null) {
for (AnnotationNode a : f.visibleAnnotations) {
AnnotationVisitor av = v.visitAnnotation(a.desc, true);
Iterator<Object> it = a.values.iterator();
while (it.hasNext())
av.visit((String) it.next(), it.next());
}
}
v.visitEnd();
}
}
示例9: registerFields
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
public static void registerFields(BytecodeContext bc, List<LitString> keys) throws BytecodeException {
//if(keys.size()==0) return;
GeneratorAdapter ga = bc.getAdapter();
FieldVisitor fv = bc.getClassWriter().visitField(Opcodes.ACC_PRIVATE ,
"keys", Types.COLLECTION_KEY_ARRAY.toString(), null, null);
fv.visitEnd();
int index=0;
LitString value;
Iterator<LitString> it = keys.iterator();
ga.visitVarInsn(Opcodes.ALOAD, 0);
ga.push(keys.size());
ga.newArray(Types.COLLECTION_KEY);
while(it.hasNext()) {
value=it.next();
ga.dup();
ga.push(index++);
//value.setExternalize(false);
ExpressionUtil.writeOutSilent(value,bc, Expression.MODE_REF);
ga.invokeStatic(KEY_IMPL, KEY_INTERN);
ga.visitInsn(Opcodes.AASTORE);
}
ga.visitFieldInsn(Opcodes.PUTFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString());
}
示例10: visitEnd
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
@Override
public void visitEnd() {
super.visitEnd();
apiMemberAdapter.visit(
classMember.getVersion(), classMember.getAccess(), classMember.getName(), classMember.getSignature(),
classMember.getSuperName(), classMember.getInterfaces());
visitAnnotationMembers(classMember.getAnnotations());
for (MethodMember method : methods) {
MethodVisitor mv = apiMemberAdapter.visitMethod(
method.getAccess(), method.getName(), method.getTypeDesc(), method.getSignature(),
method.getExceptions().toArray(new String[0]));
visitAnnotationMembers(mv, method.getAnnotations());
visitAnnotationMembers(mv, method.getParameterAnnotations());
mv.visitEnd();
}
for (FieldMember field : fields) {
FieldVisitor fieldVisitor = apiMemberAdapter.visitField(
field.getAccess(), field.getName(), field.getTypeDesc(), field.getSignature(), null);
visitAnnotationMembers(fieldVisitor, field.getAnnotations());
fieldVisitor.visitEnd();
}
for (InnerClassMember innerClass : innerClasses) {
apiMemberAdapter.visitInnerClass(
innerClass.getName(), innerClass.getOuterName(), innerClass.getInnerName(), innerClass.getAccess());
}
apiMemberAdapter.visitEnd();
}
示例11: addSVUID
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
protected void addSVUID(long svuid) {
FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
+ Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
if (fv != null) {
fv.visitEnd();
}
}
示例12: testClassLoading
import org.objectweb.asm.FieldVisitor; //导入方法依赖的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!");
}
示例13: generateFields
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
private static void generateFields(Method method, ClassWriter cw, Parameter[] parameters) {
FieldVisitor fv;
cw.visitSource(method.getName() + "[email protected]@aspecio", null);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, "parameters", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/reflect/Parameter;>;",
null);
fv.visitEnd();
for (Parameter p : parameters) {
fv = cw.visitField(ACC_PUBLIC, p.getName(), Type.getDescriptor(p.getType()), null, null);
fv.visitEnd();
}
}
示例14: generateFields
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
private static void generateFields(Method method, ClassWriter cw, Parameter[] parameters) {
FieldVisitor fv;
cw.visitSource(method.getName() + "[email protected]", null);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, "parameters", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/reflect/Parameter;>;",
null);
fv.visitEnd();
for (Parameter p : parameters) {
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, p.getName(), Type.getDescriptor(p.getType()), null, null);
fv.visitEnd();
}
}
示例15: visit
import org.objectweb.asm.FieldVisitor; //导入方法依赖的package包/类
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
abstractClass = (access & ACC_ABSTRACT) != 0;
filterClass = name;
superClass = superName;
FieldVisitor fv = cv.visitField(ACC_PUBLIC, "$$injected_servletContext", "Ljavax/servlet/ServletContext;", null,
null);
fv.visitEnd();
fv = cv.visitField(ACC_PUBLIC, "$$injected_superDoFilter", "Ljava/lang/invoke/MethodHandle;", null, null);
fv.visitEnd();
fv = cv.visitField(ACC_PUBLIC, "$$injected_superInit", "Ljava/lang/invoke/MethodHandle;", null, null);
fv.visitEnd();
}