当前位置: 首页 > news >正文

建设部网站官网wordpress创建页面地址设置

建设部网站官网,wordpress创建页面地址设置,网站底部制作,有什么网站可以做商品展示的吗什么是ASM树API#xff1a; ASM树API是ASM的一部分#xff0c;可让您创建/修改内存中的类。 该类被视为信息树。 像整个类一样#xff0c;它是ClassNode的实例#xff0c;其中包含FieldNode对象列表#xff0c;MethodNode对象列表等。本文假设读者已经在这里阅读了第一部分… 什么是ASM树API ASM树API是ASM的一部分可让您创建/修改内存中的类。 该类被视为信息树。 像整个类一样它是ClassNode的实例其中包含FieldNode对象列表MethodNode对象列表等。本文假设读者已经在这里阅读了第一部分。 通过树API的简单类让我们使用树API创建我们的第一类。 同样我将直接进入一个代码示例因为没有什么比代码示例更好。 生成的类具有打印“ Hello World”的主要方法。 TreeAPIDemo.java package com.geekyarticles.asm;import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream;import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode;public class TreeAPIDemo {public static void main(String [] args) throws Exception{ClassNode classNodenew ClassNode(4);//4 is just the API version number//These properties of the classNode must be setclassNode.versionOpcodes.V1_6;//The generated class will only run on JRE 1.6 or aboveclassNode.accessOpcodes.ACC_PUBLIC;classNode.signatureLcom/geekyarticles/asm/Generated;;classNode.namecom/geekyarticles/asm/Generated;classNode.superNamejava/lang/Object;//Create a methodMethodNode mainMethodnew MethodNode(4,Opcodes.ACC_PUBLIC|Opcodes.ACC_STATIC,main, ([Ljava/lang/String;)V,null, null);mainMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, java/lang/System, out, Ljava/io/PrintStream;));mainMethod.instructions.add(new LdcInsnNode(Hello World!));mainMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, java/io/PrintStream, println, (Ljava/lang/String;)V));mainMethod.instructions.add(new InsnNode(Opcodes.RETURN));//Add the method to the classNodeclassNode.methods.add(mainMethod);//Write the classClassWriter cwnew ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);classNode.accept(cw);//Dump the class in a fileFile outDirnew File(out/com/geekyarticles/asm);outDir.mkdirs();DataOutputStream doutnew DataOutputStream(new FileOutputStream(new File(outDir,Generated.class)));dout.write(cw.toByteArray());dout.flush();dout.close();} } 如您所见代码非常简单。 与BCEL相比它的主要优点是与BCEL不同ASM不需要您将每个常量显式添加到常量池中。 相反ASM会照顾常量池本身。 读取类文件 ClassNode是ClassVisitor。 因此读取用于树API的类就像创建ClassReader对象并使用它读取类文件一样简单同时将ClassNode对象作为其accept方法传递给参数。 完成此操作后将通过类中存在的所有信息完全初始化传递的ClassNode。 在下面的示例中我们将打印类中的所有方法。 TreeAPIClassReaderDemo.java package com.geekyarticles.asm;import java.io.FileInputStream; import java.io.InputStream;import org.objectweb.asm.ClassReader; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode;public class TreeAPIClassReaderDemo {public static void main(String[] args) throws Exception{InputStream innew FileInputStream(out/com/geekyarticles/asm/Generated.class);ClassReader crnew ClassReader(in);ClassNode classNodenew ClassNode();//ClassNode is a ClassVisitorcr.accept(classNode, 0);//Lets move through all the methodsfor(MethodNode methodNodeclassNode.methods){System.out.println(methodNode.name methodNode.desc);}}} 修改类文件修改类文件是上述两个过程的组合。 我们首先以通常的方式读取该类对数据进行必要的更改然后将其写回到文件中。 以下程序实现了一些日志代码的自动注入。 当前我们的Logger类仅打印到标准输出。 Loggable注释的每个方法在开始和返回时都将被记录。 在此我们不记录throw-exception。 但是也可以通过检查操作码ATHROW以相同的方式实现。 LoggingInsertion.java package com.geekyarticles.asm;import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Iterator;import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode;public class LoggingInsertion {public static void main(String[] args) throws Exception{InputStream inLoggingInsertion.class.getResourceAsStream(/com/geekyarticles/asm/LoggingTest.class);ClassReader crnew ClassReader(in);ClassNode classNodenew ClassNode();cr.accept(classNode, 0);//Lets move through all the methodsfor(MethodNode methodNodeclassNode.methods){System.out.println(methodNode.name methodNode.desc);boolean hasAnnotationfalse;if(methodNode.visibleAnnotations!null){for(AnnotationNode annotationNodemethodNode.visibleAnnotations){if(annotationNode.desc.equals(Lcom/geekyarticles/asm/Loggable;)){hasAnnotationtrue;break;}}}if(hasAnnotation){//Lets insert the begin loggerInsnList beginListnew InsnList();beginList.add(new LdcInsnNode(methodNode.name));beginList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, com/geekyarticles/asm/Logger, logMethodStart, (Ljava/lang/String;)V));IteratorAbstractInsnNode insnNodesmethodNode.instructions.iterator();while(insnNodes.hasNext()){System.out.println(insnNodes.next().getOpcode());}methodNode.instructions.insert(beginList);System.out.println(methodNode.instructions);//A method can have multiple places for return//All of them must be handled.insnNodesmethodNode.instructions.iterator();while(insnNodes.hasNext()){AbstractInsnNode insninsnNodes.next();System.out.println(insn.getOpcode());if(insn.getOpcode()Opcodes.IRETURN||insn.getOpcode()Opcodes.RETURN||insn.getOpcode()Opcodes.ARETURN||insn.getOpcode()Opcodes.LRETURN||insn.getOpcode()Opcodes.DRETURN){InsnList endListnew InsnList();endList.add(new LdcInsnNode(methodNode.name));endList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, com/geekyarticles/asm/Logger, logMethodReturn, (Ljava/lang/String;)V));methodNode.instructions.insertBefore(insn, endList);}}}}//We are done now. so dump the classClassWriter cwnew ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);classNode.accept(cw);File outDirnew File(out/com/geekyarticles/asm);outDir.mkdirs();DataOutputStream doutnew DataOutputStream(new FileOutputStream(new File(outDir,LoggingTest.class)));dout.write(cw.toByteArray());dout.flush();dout.close();}} LoggingTest.java package com.geekyarticles.asm;public class LoggingTest {public static void run1(){System.out.println(run 1);}Loggablepublic static void run2(){System.out.println(run 2);}Loggablepublic static void main(String [] args){run1();run2();} } 记录器 package com.geekyarticles.asm;public class Logger {public static void logMethodStart(String methodName){System.out.println(Starting method: methodName);}public static void logMethodReturn(String methodName){System.out.println(Ending method: methodName);} } Loggable.java package com.geekyarticles.asm;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Target(ElementType.METHOD) Retention(RetentionPolicy.RUNTIME) public interface Loggable {} 如果运行此程序则生成的文件将依赖于Logger类。 手动将Logger类复制到out目录中的正确软件包。 如果运行生成的类它是LoggingTest类的修改版本则将输出以下内容。 bash-4.1$ java com.geekyarticles.asm.LoggingTest Starting method: main run 1 Starting method: run2 run 2 Ending method: run2 Ending method: main 请注意与普通列表不同在迭代InsnList对象时可以对其进行修改。 任何更改都会立即反映出来。 因此如果在当前位置之后插入了一些指令则也将对其进行迭代。 参考 使用ASM 4处理Java类文件–第二部分 JCG合作伙伴提供的 Tree API   极客文章博客上的Debasish Ray Chawdhuri。 翻译自: https://www.javacodegeeks.com/2012/02/manipulating-java-class-files-with-asm_22.html
http://wiki.neutronadmin.com/news/136880/

相关文章:

  • 新建的网站如何做seo做本地的门户网站
  • 做纺织的都用什么网站石家庄站分布图
  • 番茄wordpress石家庄优化哪家好
  • 网站建设官网免费模板注册规划师报考条件2022
  • 网站访客qq抓取现在那个网站做宣传有效果
  • 国内专业做悬赏的网站怎么做自己的网站弄商城佣金
  • 家装网站模板下载网络技术学习网站
  • 一个在线做笔记的网站网站主机多大
  • 如何用wordpress做网站最新军事战争新闻消息
  • 湖北网站建设制作互联网100个创业项目
  • html5的网站设计网站除了域名还要什么
  • 建站一条龙设计制作wordpress 加载失败
  • asp.net做网站步骤百度优化是什么意思
  • 网站开发维护合同范本没有公司自己做网站
  • 方案库网站温州网站网络公司
  • 济宁500元网站建设杭州市建设信用网网站
  • 建立一个购物网站需要多少钱wordpress站点名字体
  • 国产网站开发工具公司诚信通旺铺网站建设
  • 网站建设方案书 百度文库打开百度搜索网站
  • 响应式网站宽度怎么做网站快捷方式
  • 宁波网站建设设计制作方案与价格网络营销方式举例
  • 医药网站素材网站建设实训的目的
  • 湛江制作网站多少钱个人网站建设策划书怎么写
  • 莱州环球网站建设贵阳观山湖区网站建设
  • 上海正规做网站公司电话杭州旺道企业服务有限公司
  • 怎样跟网站做优化呢网站设置什么意思
  • 想要黑掉一个网站 要怎么做网站404 模板
  • 网站log文件示例自己建设小城市网站得多少钱
  • 文交所网站建设方案重庆网站建设seo公司哪家好
  • 上海高端网站建设服务公电子商务网站建设课程设计报告