Skip navigation links
org.netbeans.modules.classfile/1 1.58

Package org.netbeans.modules.classfile

The org.netbeans.modules.classfile package supports direct access to a Java Virtual Machine classfile contents.

See: Description

Package org.netbeans.modules.classfile Description

The org.netbeans.modules.classfile package supports direct access to a Java Virtual Machine classfile contents. All elements and attributes of a classfile are accessible from this package's API. This package only supports read-only access of classfiles at this time.

The classfile library is not actually a NetBeans module, but is only packaged as one to use NetBeans' Auto Update facility. By being packaged as a module, other (real) NetBeans modules may list it as a dependency and require a minimum version to be present on the system. The classfile library does not use any NetBeans API, only Java core API.

The classfile library has only four constructors, as the only objects that can be created by a client are ClassFile objects (one constructor takes an InputStream of classfile bytes, another takes a filename, and variants of these two constructors allow creation of Code objects to be suppressed). The ClassFile object is then queried for its elements. A ClassFile and its elements should be considered immutable, even though it may be possible to change one of its objects (if so, it's a bug).

Examples

Here is a simple example which dumps out a classfile:


    static void printClass(String classname) {
        try {
            System.out.println(new ClassFile(classname));
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }

Here is an example which prints out any synthetic methods:


    static void printSyntheticMethods(InputStream in) throws IOException {
        ClassFile cf = new ClassFile(in);
        Iterator iter = cf.getMethods();
        while (iter.hasNext()) {
            Method m = (Method)iter.next();
            if (m.isSynthetic())
                 System.out.println(m.toString());
        }
    }

Related Documentation

Skip navigation links
org.netbeans.modules.classfile/1 1.58