FileDocCategorySizeDatePackage
ASMMethod.javaAPI DocGlassfish v2 API10699Fri May 04 22:33:24 BST 2007com.sun.enterprise.tools.verifier.apiscan.classfile

ASMMethod

public class ASMMethod extends com.sun.corba.ee.org.objectweb.asm.commons.EmptyVisitor implements Method
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private static String
resourceBundleName
private static Logger
logger
private SoftReference
owningClass
private String
descriptor
private int
access
private String
signature
private String[]
exceptions
private String
name
private Set
referencedMethods
private Set
referencedClasses
private MethodRef
methodRef
Constructors Summary
public ASMMethod(ClassFile owningClass, String name, String descriptor, int access, String signature, String[] exceptions)


     
                   
                
        this.owningClass = new SoftReference<ClassFile>(owningClass);
        this.name = name;
        this.descriptor = descriptor;
        this.access = access;
        this.signature = signature;
        if(exceptions==null) {
            this.exceptions = new String[0];
        } else {
            this.exceptions = exceptions;
        }
    
Methods Summary
private voidaddClass(java.lang.String nameOrTypeDescriptor)

        //sometimes we get names like Ljava.lang.Integer; or [I. So we need
        // to decode the names.
        if (nameOrTypeDescriptor.indexOf(';") != -1 ||
                nameOrTypeDescriptor.indexOf('[") != -1) {
            referencedClasses.addAll(
                    typeDescriptorToClassNames(nameOrTypeDescriptor));
        } else {
            referencedClasses.add(nameOrTypeDescriptor);
        }
    
private voidaddMethod(java.lang.String owner, java.lang.String name, java.lang.String desc)

        addClass(owner);
        // We don't need the following code as this is not required.
        // because if everything is null, then no class gets loaded.
//        for(String embeddedClassName : typeDescriptorToClassNames(desc)) {
//            referencedClasses.add(embeddedClassName);
//        }
        referencedMethods.add(new MethodRef(owner, name, desc));
    
public static java.lang.StringdecodeAccessFlag(int access)

        StringBuilder result = new StringBuilder("");
        if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
            result.append("private "); // NOI18N
        } else if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
            result.append("protected "); // NOI18N
        } else if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
            result.append("public "); // NOI18N
        }
        if ((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) {
            result.append("abstract "); // NOI18N
        } else if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
            result.append("final "); // NOI18N
        } else if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) {
            result.append("static "); // NOI18N
        }
        if ((access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE) {
            result.append("native "); // NOI18N
        }
        return result.toString();
    
public intgetAccess()

        return access;
    
public java.lang.StringgetDescriptor()

        return descriptor;
    
public java.lang.String[]getExceptions()
{@inheritDoc}

        return exceptions;
    
public java.lang.StringgetName()

        return name;
    
public ClassFilegetOwningClass()

        return owningClass.get();
    
public java.util.CollectiongetReferencedClasses()

        return Collections.unmodifiableCollection(referencedClasses);
    
public java.util.CollectiongetReferencedMethods()

        return Collections.unmodifiableCollection(referencedMethods);
    
public MethodRefgetSelfReference()

        if(methodRef==null){
            methodRef = new MethodRef(owningClass.get().getInternalName(), name, descriptor);
        }
        return methodRef;
    
public java.lang.StringgetSignature()

        return signature;
    
public booleanisNative()

        return (access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE;
    
public java.lang.StringtoString()

        StringBuilder sb = new StringBuilder(
                decodeAccessFlag(access) +
                name +
                " " + // NOI18N
                descriptor+
                "{\n"); // NOI18N
        for(MethodRef mr : referencedMethods){
            sb.append(mr).append("\n"); // NOI18N
        }
        sb.append("}"); // NOI18N
        return sb.toString();
    
private static java.util.ListtypeDescriptorToClassNames(java.lang.String signature)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "typeDescriptorToClassNames", // NOI18N
                new Object[]{signature});
        List<String> result = new ArrayList<String>();
        int i = 0;
        while ((i = signature.indexOf('L", i)) != -1) {
            int j = signature.indexOf(';", i);
            if (j > i) {
                // get name, minus leading 'L' and trailing ';'
                String className = signature.substring(i + 1, j);
                if (!Util.isPrimitive(className)) result.add(className);
                i = j + 1;
            } else
                break;
        }
        if (logger.isLoggable(Level.FINE)) {
            StringBuffer sb = new StringBuffer("Class Names are {"); // NOI18N
            int size = result.size();
            for (int k = 0; k < size; k++) {
                sb.append((String) result.get(k));
                if (k != size - 1) sb.append(", "); // NOI18N
            }
            sb.append("}"); // NOI18N
            logger.finer(sb.toString());
        }
        return result;
    
public voidvisitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitFieldInsn", // NOI18N
                new Object[]{AbstractVisitor.OPCODES[opcode], owner, name, desc});
        addClass(owner);
    
public voidvisitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitMethodInsn", new Object[]{ // NOI18N
                    AbstractVisitor.OPCODES[opcode], owner, name, desc});
        addMethod(owner, name, desc);
    
public voidvisitMultiANewArrayInsn(java.lang.String desc, int dims)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitMultiANewArrayInsn", // NOI18N
                new Object[]{desc});
        addClass(desc);
    
public voidvisitTryCatchBlock(com.sun.corba.ee.org.objectweb.asm.Label start, com.sun.corba.ee.org.objectweb.asm.Label end, com.sun.corba.ee.org.objectweb.asm.Label handler, java.lang.String type)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitTryCatchBlock", // NOI18N
                new Object[]{type});
        if(type!=null) { // try-finally comes as null
            addClass(type);
        }
    
public voidvisitTypeInsn(int opcode, java.lang.String desc)

        logger.entering(
                "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitTypeInsn", new Object[]{ // NOI18N
                    AbstractVisitor.OPCODES[opcode], desc});
        switch (opcode) {
            case Opcodes.INSTANCEOF:
            case Opcodes.CHECKCAST:
            case Opcodes.ANEWARRAY:
                addClass(desc);
                break;
            case Opcodes.NEW:
                // skip as class gets added during constructor call.
                break;
            case Opcodes.NEWARRAY:
                // primitive type array, so skip
                break;
            default:
                logger.logp(Level.WARNING, "com.sun.enterprise.tools.verifier.apiscan.classfile.ASMMethod", "visitTypeInsn", // NOI18N
                        getClass().getName() + ".warning1", AbstractVisitor.OPCODES[opcode]); // NOI18N
                break;
        }