xmlkit.XMLKit.Element Java Examples

The following examples show how to use xmlkit.XMLKit.Element. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitMethodHandle(CONSTANT_MethodHandle_info c, Integer p) {
String value = slist.get(p);
    if (value == null) {
        try {
            value = c.reference_kind.name();
            value = value.concat(" "
                    + visit(cfpool.get(c.reference_index), c.reference_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_MethodHandle",
                      new String[]{"id", p.toString()},
                      value));

        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #2
Source File: ClassReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitMethodref(CONSTANT_Methodref_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.class_index), c.class_index);
            value = value.concat(" " +
                                 visit(cfpool.get(c.name_and_type_index),
                                 c.name_and_type_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_Methodref",
                      new String[]{"id", p.toString()},
                      value));

        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #3
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitMethodType(CONSTANT_MethodType_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.descriptor_index), c.descriptor_index);
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_MethodType",
                      new String[]{"id", p.toString()},
                      value));
        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #4
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitInvokeDynamic(CONSTANT_InvokeDynamic_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = bsmlist.get(c.bootstrap_method_attr_index) + " "
                    + visit(cfpool.get(c.name_and_type_index), c.name_and_type_index);
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_InvokeDynamic",
                      new String[]{"id", p.toString()},
                      value));

        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #5
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info c,
                                      Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.class_index), c.class_index);
            value = value.concat(" " +
                                 visit(cfpool.get(c.name_and_type_index),
                                 c.name_and_type_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_InterfaceMethodref",
                      new String[]{"id", p.toString()},
                      value));

        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #6
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitNameAndType(CONSTANT_NameAndType_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.name_index), c.name_index);
            value = value.concat(" " +
                    visit(cfpool.get(c.type_index), c.type_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_NameAndType",
                      new String[]{"id", p.toString()},
                      value));
        } catch (InvalidIndex ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #7
Source File: ClassReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readCP(ClassFile c) throws IOException {
    cpool = new Element("ConstantPool", c.constant_pool.size());
    ConstantPoolVisitor cpv = new ConstantPoolVisitor(cpool, c,
            c.constant_pool.size());
    for (int i = 1 ; i < c.constant_pool.size() ; i++) {
        try {
            cpv.visit(c.constant_pool.get(i), i);
        } catch (InvalidIndex ex) {
            // can happen periodically when accessing doubles etc. ignore it
            // ex.printStackTrace();
        }
    }
    thePool = cpv.getPoolList();
    if (verbose) {
        for (int i = 0; i < thePool.size(); i++) {
            System.out.println("[" + i + "]: " + thePool.get(i));
        }
    }
    if (keepCP) {
        cfile.add(cpool);
    }
}
 
Example #8
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitString(CONSTANT_String_info c, Integer p) {
    try {

        String value = slist.get(p);
        if (value == null) {
            value = c.getString();
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_String",
                      new String[]{"id", p.toString()},
                      value));
        }
        return value;
    } catch (ConstantPoolException ex) {
        throw new RuntimeException("Fatal error", ex);
    }
}
 
Example #9
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitClass(CONSTANT_Class_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.name_index), c.name_index);
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_Class",
                    new String[]{"id", p.toString()},
                    value));
        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #10
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String visitClass(CONSTANT_Class_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.name_index), c.name_index);
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_Class",
                    new String[]{"id", p.toString()},
                    value));
        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
 
Example #11
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #12
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String visitDouble(CONSTANT_Double_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        value = Double.toString(c.value);
        slist.set(p, value);
        xpool.add(new Element("CONSTANT_Double",
                  new String[]{"id", p.toString()},
                  value));
    }
    return value;
}
 
Example #13
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute rita, Element p) {
    Element e = new Element(x.getCpString(rita.attribute_name_index));
    for (TypeAnnotation pa : rita.annotations) {
        parseTypeAnnotations(pa, e);
    }
    e.sort();
    p.add(e);
    return null;
}
 
Example #14
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Element readFrom(File file) throws IOException {
    try (InputStream strm = new FileInputStream(file)) {
        Element e = readFrom(new BufferedInputStream(strm));
        if (keepPath) {
            e.setAttr("path", file.toString());
        }
        return e;
    }
}
 
Example #15
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void parseTypeAnnotations(TypeAnnotation pa, Element p) {
    Element pta = new Element("RuntimeVisibleTypeAnnotation");
    p.add(pta);
    Position pos = pa.position;
    parsePosition(pos, pta);
    parseAnnotation(pa.annotation, pta);
}
 
Example #16
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #17
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example #18
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitInnerClasses(InnerClasses_attribute ic, Element p) {
    for (Info info : ic.classes) {
        Element e = new Element(x.getCpString(ic.attribute_name_index));
        e.setAttr("class", x.getCpString(info.inner_class_info_index));
        e.setAttr("outer", x.getCpString(info.outer_class_info_index));
        e.setAttr("name", x.getCpString(info.inner_name_index));
        e.setAttr("flags", x.flagString(info.inner_class_access_flags,
                "InnerClass"));
        e.trimToSize();
        p.add(e);
    }
    return null;
}
 
Example #19
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #20
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #21
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Element readFrom(File file) throws IOException {
    try (InputStream strm = new FileInputStream(file)) {
        Element e = readFrom(new BufferedInputStream(strm));
        if (keepPath) {
            e.setAttr("path", file.toString());
        }
        return e;
    }
}
 
Example #22
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitArrayType(Instruction i, TypeKind tk, Void p) {
    Element ie = new Element(i.getMnemonic());
    ie.setAttr("num", "" + tk.value);
    ie.setAttr("val", tk.name);
    return ie;
}
 
Example #23
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitSourceID(SourceID_attribute sid, Element p) {
    Element e = new Element(x.getCpString(sid.attribute_name_index));
    e.add(x.getCpString(sid.sourceID_index));
    e.trimToSize();
    p.add(e);
    return null;
}
 
Example #24
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ConstantPoolVisitor(Element xpool, ClassFile cf, int size) {
    slist = new ArrayList<>(size);
    for (int i = 0 ; i < size; i++) {
        slist.add(null);
    }
    this.xpool = xpool;
    this.cf = cf;
    this.cfpool = cf.constant_pool;
    bsmlist = readBSM();
}
 
Example #25
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitSourceDebugExtension(SourceDebugExtension_attribute sde,
                                            Element p) {
    String aname = x.getCpString(sde.attribute_name_index);
    Element se = new Element(aname);
    se.setAttr("val", sde.getValue());
    se.trimToSize();
    p.add(se);
    return null;
}
 
Example #26
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example #27
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitArrayType(Instruction i, TypeKind tk, Void p) {
    Element ie = new Element(i.getMnemonic());
    ie.setAttr("num", "" + tk.value);
    ie.setAttr("val", tk.name);
    return ie;
}
 
Example #28
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute rva,
                                              Element p) {
    Element e = new Element(x.getCpString(rva.attribute_name_index));
    parseAnnotations(rva.annotations, e);
    e.trimToSize();
    p.add(e);
    return null;
}
 
Example #29
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visit_append_frame(append_frame a, Void p) {
   Element e = new Element("AppendFrame" + (a.frame_type - 251));
   e.setAttr("tag", "" + a.frame_type);
   e.addAll(getVerificationTypeInfo("Local", a.locals));
   e.trimToSize();
   return e;
}
 
Example #30
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitConstantPoolRefAndValue(Instruction i, int i1, int i2, Void p) {
    // workaround for a potential bug in classfile
    Element ie = new Element(i.getMnemonic());
    if (i.getOpcode().equals(Opcode.IINC_W)) {
        ie.setAttr("loc", "" + i1);
        ie.setAttr("num", "" + i2);
    } else {
        ie.setAttr("ref", x.getCpString(i1));
        ie.setAttr("val", "" + i2);
    }
    return ie;
}