Changeset 2706


Ignore:
Timestamp:
Apr 17, 2007, 11:34:16 PM (14 years ago)
Author:
yura
Message:
Location:
to-imperative/trunk/java/org/refal/plus
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/org/refal/plus/comp/FormatReader.java

    r2689 r2706  
    11/* $Id$ */
    2 /* vim: set ts=2 sw=2 : */
     2/* vim: set et ts=2 sw=2 : */
    33
    44package org.refal.plus.comp;
     
    88public class FormatReader implements ClassVisitor
    99{
    10         class MethodFormatAnnotationReader implements AnnotationVisitor
    11         {
    12                 public MethodFormatAnnotationReader () {}
     10  class MethodFormatAnnotationReader implements AnnotationVisitor
     11  {
     12    public MethodFormatAnnotationReader () {}
    1313
    14                 public void visit(String name, Object value) {
    15             System.out.println(name+" - "+value);
    16                         if (value instanceof String)
    17                                 formats = formats.concat((String) value);
    18                 }
    19                 public AnnotationVisitor visitAnnotation (String name, String desc) { System.out.println("A: "+name+" - "+desc);return null; }
    20                 public AnnotationVisitor visitArray (String name) { System.out.println("Arr: "+name); return null; }
    21                 public void visitEnd () {}
    22                 public void visitEnum (String name, String desc, String value) {}
    23         }
     14    public void visit (String name, Object value) {
     15      if (name.equals("value") && value instanceof String)
     16      {
     17        if (! formats.equals(""))
     18          formats += "";
     19        formats += ((String) value);
     20      }
     21    }
     22    public AnnotationVisitor visitAnnotation (String name, String desc) { return null; }
     23    public AnnotationVisitor visitArray (String name) { return null; }
     24    public void visitEnd () {}
     25    public void visitEnum (String name, String desc, String value) {}
     26  }
    2427
    25         class MethodFormatReader implements MethodVisitor
    26         {
    27                 public MethodFormatReader () {}
     28  class MethodFormatReader implements MethodVisitor
     29  {
     30    public MethodFormatReader () {}
    2831
    29                 public AnnotationVisitor visitAnnotation (String desc, boolean visible) { System.out.println("VA: "+desc+" "+visible); return new MethodFormatAnnotationReader(); }
    30                 public AnnotationVisitor visitAnnotationDefault () { return new MethodFormatAnnotationReader(); }
    31                 public void visitAttribute (Attribute attr) {}
    32                 public void visitCode () {}
    33                 public void visitEnd () {}
    34                 public void visitFieldInsn (int opcode, String owner, String name, String desc) {}
    35                 public void visitFrame (int type, int nLocal, Object[] local, int nStack, Object[] stack) {}
    36                 public void visitIincInsn (int var, int increment) {}
    37                 public void visitInsn (int opcode) {}
    38                 public void visitIntInsn (int opcode, int operand) {}
    39                 public void visitJumpInsn (int opcode, Label label) {}
    40                 public void visitLabel (Label label) {}
    41                 public void visitLdcInsn (Object cst) {}
    42                 public void visitLineNumber (int line, Label start) {}
    43                 public void visitLocalVariable (String name, String desc, String signature, Label start, Label end, int index) {}
    44                 public void visitLookupSwitchInsn (Label dflt, int[] keys, Label[] labels) {}
    45                 public void visitMaxs (int maxStack, int maxLocals) {}
    46                 public void visitMethodInsn (int opcode, String owner, String name, String desc) {}
    47                 public void visitMultiANewArrayInsn (String desc, int dims) {}
    48                 public AnnotationVisitor visitParameterAnnotation (int parameter, String desc, boolean visible) { return null; }
    49                 public void visitTableSwitchInsn (int min, int max, Label dflt, Label[] labels) {}
    50                 public void visitTryCatchBlock (Label start, Label end, Label handler, String type) {}
    51                 public void visitTypeInsn (int opcode, String desc) {}
    52                 public void visitVarInsn (int opcode, int var) {}
    53         }
     32    public AnnotationVisitor visitAnnotation (String desc, boolean visible) {
     33      if (desc.equals("Lorg/refal/plus/RefalFormat;"))
     34        return new MethodFormatAnnotationReader();
     35      else
     36        return null;
     37    }
     38    public AnnotationVisitor visitAnnotationDefault () { return null; }
     39    public void visitAttribute (Attribute attr) {}
     40    public void visitCode () {}
     41    public void visitEnd () {}
     42    public void visitFieldInsn (int opcode, String owner, String name, String desc) {}
     43    public void visitFrame (int type, int nLocal, Object[] local, int nStack, Object[] stack) {}
     44    public void visitIincInsn (int var, int increment) {}
     45    public void visitInsn (int opcode) {}
     46    public void visitIntInsn (int opcode, int operand) {}
     47    public void visitJumpInsn (int opcode, Label label) {}
     48    public void visitLabel (Label label) {}
     49    public void visitLdcInsn (Object cst) {}
     50    public void visitLineNumber (int line, Label start) {}
     51    public void visitLocalVariable (String name, String desc, String signature, Label start, Label end, int index) {}
     52    public void visitLookupSwitchInsn (Label dflt, int[] keys, Label[] labels) {}
     53    public void visitMaxs (int maxStack, int maxLocals) {}
     54    public void visitMethodInsn (int opcode, String owner, String name, String desc) {}
     55    public void visitMultiANewArrayInsn (String desc, int dims) {}
     56    public AnnotationVisitor visitParameterAnnotation (int parameter, String desc, boolean visible) { return null; }
     57    public void visitTableSwitchInsn (int min, int max, Label dflt, Label[] labels) {}
     58    public void visitTryCatchBlock (Label start, Label end, Label handler, String type) {}
     59    public void visitTypeInsn (int opcode, String desc) {}
     60    public void visitVarInsn (int opcode, int var) {}
     61  }
    5462
    55         String formats;
     63  String formats;
    5664
    57         public FormatReader () {
    58                 formats = "";
    59         }
     65  public FormatReader () {
     66    formats = "";
     67  }
    6068
    61         public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {}
    62         public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return null;   }
    63         public void visitAttribute(Attribute attr) {}
    64         public void visitEnd() {}
    65         public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { return null;     }
    66         public void visitInnerClass(String name, String outerName, String innerName, int access) {}
    67         public MethodVisitor visitMethod (int access, String name, String desc, String signature, String[] exceptions) { return new MethodFormatReader(); }
    68         public void visitOuterClass(String owner, String name, String desc) {}
    69         public void visitSource(String source, String debug) {}
     69  public void visit (int version, int access, String name, String signature, String superName, String[] interfaces) {}
     70  public AnnotationVisitor visitAnnotation (String desc, boolean visible) { return null; }
     71  public void visitAttribute (Attribute attr) {}
     72  public void visitEnd () {}
     73  public FieldVisitor visitField (int access, String name, String desc, String signature, Object value) { return null;  }
     74  public void visitInnerClass (String name, String outerName, String innerName, int access) {}
     75  public MethodVisitor visitMethod (int access, String name, String desc, String signature, String[] exceptions) { return new MethodFormatReader(); }
     76  public void visitOuterClass (String owner, String name, String desc) {}
     77  public void visitSource (String source, String debug) {}
    7078
    71         public static String ReadFormats (String classname) {
    72                 try {
    73                         ClassReader cr = new ClassReader(classname);
    74                         FormatReader cv = new FormatReader();
    75                         cr.accept(cv, 0);
    76                         return cv.formats;
    77                 } catch (java.io.IOException ioe) {
    78                         return null;
    79                 }
    80         }
     79  public static String ReadFormats (String classname) {
     80    try {
     81      ClassReader cr = new ClassReader(classname);
     82      FormatReader cv = new FormatReader();
     83      cr.accept(cv, 0);
     84      return cv.formats;
     85    } catch (java.io.IOException ioe) {
     86      return null;
     87    }
     88  }
    8189
    82         public static void main (String[] args) throws Exception {
    83                 for (int i = 0; i < args.length; i++) {
    84                         System.out.println(args[i]);
    85                         System.out.println(ReadFormats(args[i]));
    86                 }
    87         }
     90  public static void main (String[] args) throws Exception {
     91    for (int i = 0; i < args.length; i++) {
     92      System.out.println(args[i]);
     93      System.out.println(ReadFormats(args[i]));
     94    }
     95  }
    8896}
Note: See TracChangeset for help on using the changeset viewer.