Package javassist.bytecode

Examples of javassist.bytecode.ClassFile


    private final byte[] bytes;
    private final ClassFile classFile;

    public CustomClassDescriptor(byte[] bytes) throws IOException {
      this.bytes = bytes;
      this.classFile = new ClassFile( new DataInputStream( new ByteArrayInputStream( bytes ) ) );
    }
View Full Code Here


     * Returns the source file containing the expression.
     *
     * @return null if this information is not available.
     */
    public String getFileName() {
        ClassFile cf = thisClass.getClassFile2();
        if (cf == null)
            return null;
        else
            return cf.getSourceFile();
    }
View Full Code Here

        getCount = 0;
    }

    CtClassType(InputStream ins, ClassPool cp) throws IOException {
        this((String)null, cp);
        classfile = new ClassFile(new DataInputStream(ins));
        qualifiedName = classfile.getName();
    }
View Full Code Here

        return accessors;
    }

    public ClassFile getClassFile2() {
        ClassFile cfile = classfile;
        if (cfile != null)
            return cfile;

        classPool.compress();
        if (rawClassfile != null) {
            try {
                classfile = new ClassFile(new DataInputStream(
                                            new ByteArrayInputStream(rawClassfile)));
                rawClassfile = null;
                getCount = GET_THRESHOLD;
                return classfile;
            }
            catch (IOException e) {
                throw new RuntimeException(e.toString(), e);
            }
        }

        InputStream fin = null;
        try {
            fin = classPool.openClassfile(getName());
            if (fin == null)
                throw new NotFoundException(getName());

            fin = new BufferedInputStream(fin);
            ClassFile cf = new ClassFile(new DataInputStream(fin));
            if (!cf.getName().equals(qualifiedName))
                throw new RuntimeException("cannot find " + qualifiedName + ": "
                        + cf.getName() + " found in "
                        + qualifiedName.replace('.', '/') + ".class");

            classfile = cf;
            return cf;
        }
View Full Code Here

        int i;
        String cname = clazz.getName();
        if (this == clazz || getName().equals(cname))
            return true;

        ClassFile file = getClassFile2();
        String supername = file.getSuperclass();
        if (supername != null && supername.equals(cname))
            return true;

        String[] ifs = file.getInterfaces();
        int num = ifs.length;
        for (i = 0; i < num; ++i)
            if (ifs[i].equals(cname))
                return true;
View Full Code Here

        if (name.equals(oldname))
            return;

        // check this in advance although classNameChanged() below does.
        classPool.checkNotFrozen(name);
        ClassFile cf = getClassFile2();
        super.setName(name);
        cf.setName(name);
        nameReplaced();
        classPool.classNameChanged(oldname, this);
    }
View Full Code Here

            // check this in advance although classNameChanged() below does.
            classPool.checkNotFrozen(newClassName);
        }

        super.replaceClassName(classnames);
        ClassFile cf = getClassFile2();
        cf.renameClass(classnames);
        nameReplaced();

        if (newClassName != null) {
            super.setName(newClassName);
            classPool.classNameChanged(oldClassName, this);
View Full Code Here

    public boolean isEnum() {
       return Modifier.isEnum(getModifiers());
    }

    public int getModifiers() {
        ClassFile cf = getClassFile2();
        int acc = cf.getAccessFlags();
        acc = AccessFlag.clear(acc, AccessFlag.SUPER);
        int inner = cf.getInnerAccessFlags();
        if (inner != -1 && (inner & AccessFlag.STATIC) != 0)
            acc |= AccessFlag.STATIC;

        return AccessFlag.toModifier(acc);
    }
View Full Code Here

        return AccessFlag.toModifier(acc);
    }

    public CtClass[] getNestedClasses() throws NotFoundException {
        ClassFile cf = getClassFile2();
        InnerClassesAttribute ica
            = (InnerClassesAttribute)cf.getAttribute(InnerClassesAttribute.tag);
        if (ica == null)
            return new CtClass[0];

        String thisName = cf.getName() + "$";
        int n = ica.tableLength();
        ArrayList list = new ArrayList(n);
        for (int i = 0; i < n; i++) {
            String name = ica.innerClass(i);
            if (name != null)
View Full Code Here

        return (CtClass[])list.toArray(new CtClass[list.size()]);
    }

    public void setModifiers(int mod) {
        ClassFile cf = getClassFile2();
        if (Modifier.isStatic(mod)) {
            int flags = cf.getInnerAccessFlags();
            if (flags != -1 && (flags & AccessFlag.STATIC) != 0)
                mod = mod & ~Modifier.STATIC;
            else
                throw new RuntimeException("cannot change " + getName() + " into a static class");
        }

        checkModify();
        cf.setAccessFlags(AccessFlag.of(mod));
    }
View Full Code Here

TOP

Related Classes of javassist.bytecode.ClassFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.