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

ClosureCompilerImplBase

public abstract class ClosureCompilerImplBase extends Object implements ClosureCompiler
This is the base class for classes that actually implement ClosureCompiler interface, i.e. {@link BCELClosureCompilerImpl} and {@link ASMClosureCompilerImpl}. It contains common implementation for above classes.
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
protected ClassFileLoader
loader
protected HashSet
excludedClasses
protected HashSet
excludedPackages
protected HashSet
excludedPatterns
protected HashSet
visitedClasses
private static String
resourceBundleName
protected static Logger
logger
private static final String
myClassName
Constructors Summary
protected ClosureCompilerImplBase(ClassFileLoader loader)

param
loader the ClassFileLoader that is used to load the referenced classes.

 // NOI18N

                                   
       
        this.loader = loader;
    
Methods Summary
public voidaddExcludedClass(java.lang.String className)

param
className the class name to be excluded from closure computation. It is in the external class name format (i.e. java.util.Map$Entry instead of java.util.Map.Entry). When the closure compiler sees a class matches this name, it does not try to compute its closure any more. It merely adds this name to the closure. So the final closure will contain this class name, but not its dependencies.

        excludedClasses.add(className);
    
public voidaddExcludedPackage(java.lang.String pkgName)

param
pkgName the package name of classes to be excluded from closure computation. It is in the external format (i.e. java.lang (See no trailing '.'). When the closure compiler sees a class whose package name matches this name, it does not try to compute the closure of that class any more. It merely adds that class name to the closure. So the final closure will contain that class name, but not its dependencies.

        excludedPackages.add(pkgName);
    
public voidaddExcludedPattern(java.lang.String pattern)

param
pattern the pattern for the names of classes to be excluded from closure computation. It is in the external format (i.e. org.apache.). When the closure compiler sees a class whose name begins with this pattern, it does not try to compute the closure of that class any more. It merely adds that class name to the closure. So the final closure will contain that class name, but not its dependencies. Among all the excluded list, it is given the lowest priority in search order.

        excludedPatterns.add(pattern);
    
public booleanbuildClosure(java.util.jar.JarFile jar)

param
jar whose classes it will try to build closure of. This is a convenience method which iterates over all the entries in a jar file and computes their closure.

        boolean result = true;
        for (java.util.Enumeration entries = jar.entries();
             entries.hasMoreElements();) {
            String clsName = ((java.util.jar.JarEntry) entries.nextElement()).getName();
            if (clsName.endsWith(".class")) { // NOI18N
                String externalClsName = clsName.substring(0,
                        clsName.lastIndexOf(".class")) // NOI18N
                        .replace('/", '.");
                boolean newresult = this.buildClosure(externalClsName);
                result = newresult && result;
            }
        }//for all jar entries
        return result;
    
public java.util.CollectiongetNativeMethods()

        throw new UnsupportedOperationException();
    
protected static java.lang.StringgetPackageName(java.lang.String className)

param
className name of class in external format.
return
package name in dotted format, e.g. java.lang for java.lang.void

        int idx = className.lastIndexOf('.");
        if (idx != -1) {
            return className.substring(0, idx);
        } else
            return "";
    
protected booleanneedToBuildClosure(java.lang.String className)

param
className name of class in external format.
return

        boolean result = true;
        if (visitedClasses.contains(className))
            result = false;
        else if (excludedClasses.contains(className)) {
            result = false;
        } else if (excludedPackages.contains(getPackageName(className))) {
            result = false;
        } else {
            for (Iterator i = excludedPatterns.iterator(); i.hasNext();) {
                String pattern = (String) i.next();
                if (className.startsWith(pattern)) {
                    result = false;
                    break;
                }
            }
        }
        logger.logp(Level.FINEST, myClassName, "needToBuildClosure", // NOI18N
                className + " " + result); // NOI18N
        return result;