ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.filespace
Class PkgTree

java.lang.Object
  extended byjavafe.filespace.Tree
      extended byjavafe.filespace.HashTree
          extended byjavafe.filespace.PreloadedTree
              extended byjavafe.filespace.PkgTree

public class PkgTree
extends PreloadedTree

A PkgTree is a filtered representation of a filespace Tree (cf PathComponent) where some files and directories that are clearly not part of the Java namespace have been filtered out; the remaining nodes can be divided into two categories: (a) (usually interior) nodes that correspond to potential Java packages, and (b) exterior nodes that correspond to files that reside in one of the potential Java packages and that have an extension (e.g., .java).

A function, isPackage(Tree), is provided to distinguish the two categories. A convenience function, packages(Tree), is provided to enumerate all the potential Java packages in a PkgTree.

isPackage(Tree) depends only on a node's label; this ensures that a UnionTree of several PkgTree's never combines package and non-package nodes into a single node. (This is why (b) excludes files without extensions.) Accordingly, PkgTree's accessors and enumerators can also be used on UnionTrees of PkgTrees.

This module is meant to do a reasonable job of identifying potential packages. It is not 100% accurate, however, erring on the side of admitting too many packages. For example, it does not attempt to disallow package names containing Java keywords.


Field Summary
protected  java.util.Hashtable edges
          The mapping between our outgoing edge's labels and the subTrees they point to.
protected static int IGNORE
          ignore the node and its children
protected static int INCLUDE_NODE
          include the node but not its children
protected static int INCLUDE_TREE
          include the node and its children
static java.lang.String rootPackageName
          The name to use for root packages
protected  Tree underlyingTree
          The non-null filespace Tree we are filtering
 
Fields inherited from class javafe.filespace.Tree
data
 
Constructor Summary
  PkgTree(Tree underlyingTree)
          Filter a non-null filespace Tree, leaving potential Java packages and files.
protected PkgTree(Tree parent, java.lang.String label, Tree underlyingTree)
          Create a non-root node.
 
Method Summary
 java.util.Enumeration children()
          * Fetching and counting children: * *
static java.util.Enumeration components(Tree P, java.lang.String E)
          Enumerate all the components of package P with extension E in sorted order (of labels).
 void ensureEdgesLoaded()
          Ensure that the edges map is ready for use
 Tree getChild(java.lang.String label)
          Fetch our direct child along the edge labelled label.
static java.lang.String getPackageName(Tree node)
          Return the human-readable name of a package.
protected static int getStatus(Tree node)
          Decide what to do with a node of the underlying filespace, returning one of the following codes: IGNORE, INCLUDE_NODE, or INCLUDE_TREE.
static boolean isPackage(Tree node)
          Is a node of a PkgTree (or a union of PkgTree's) a potential Java package?
protected  void loadEdges()
          Load the edges map for use.
static void main(java.lang.String[] args)
          A simple test driver
static java.util.Enumeration packages(Tree node)
          Enumerate all the potential packages of a PkgTree (or a union of PkgTree's) in depth-first pre-order using lexical ordering on siblings (cf.
 void printDetails(java.lang.String prefix)
          Extend printDetails to include our isPackage status
 
Methods inherited from class javafe.filespace.Tree
getChildrenCount, getLabel, getParent, getQualifiedChild, getQualifiedName, getRootNode, getSimpleName, isLeaf, print
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

underlyingTree

protected Tree underlyingTree
The non-null filespace Tree we are filtering


IGNORE

protected static final int IGNORE
ignore the node and its children

See Also:
Constant Field Values

INCLUDE_NODE

protected static final int INCLUDE_NODE
include the node but not its children

See Also:
Constant Field Values

INCLUDE_TREE

protected static final int INCLUDE_TREE
include the node and its children

See Also:
Constant Field Values

rootPackageName

public static java.lang.String rootPackageName
The name to use for root packages


edges

protected java.util.Hashtable edges
The mapping between our outgoing edge's labels and the subTrees they point to. No entry for a label means no edge with that label exists.

Invariant: all elements of edges are Trees and all keys are Strings.

Constructor Detail

PkgTree

public PkgTree(Tree underlyingTree)
Filter a non-null filespace Tree, leaving potential Java packages and files.


PkgTree

protected PkgTree(Tree parent,
                  java.lang.String label,
                  Tree underlyingTree)
Create a non-root node. underlyingTree must be a non-null filespace Tree.

Method Detail

getStatus

protected static int getStatus(Tree node)
Decide what to do with a node of the underlying filespace, returning one of the following codes: IGNORE, INCLUDE_NODE, or INCLUDE_TREE.


loadEdges

protected void loadEdges()
Load the edges map for use.

Specified by:
loadEdges in class PreloadedTree

isPackage

public static boolean isPackage(Tree node)
Is a node of a PkgTree (or a union of PkgTree's) a potential Java package?


getPackageName

public static java.lang.String getPackageName(Tree node)
Return the human-readable name of a package. Uses rootPackageName as the name of root packages.

Note: the resulting name will only make sense if node is a package.


packages

public static java.util.Enumeration packages(Tree node)
Enumerate all the potential packages of a PkgTree (or a union of PkgTree's) in depth-first pre-order using lexical ordering on siblings (cf. TreeWalker).


components

public static java.util.Enumeration components(Tree P,
                                               java.lang.String E)
Enumerate all the components of package P with extension E in sorted order (of labels).

For a PkgTree (or a union of PkgTrees), if E is "", then all direct potential subpackages will be selected. Otherwise, only non-subpackages will be selected.


printDetails

public void printDetails(java.lang.String prefix)
Extend printDetails to include our isPackage status

Overrides:
printDetails in class Tree

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
A simple test driver

Throws:
java.io.IOException

ensureEdgesLoaded

public final void ensureEdgesLoaded()
Ensure that the edges map is ready for use


children

public final java.util.Enumeration children()
* Fetching and counting children: * *

Overrides:
children in class HashTree

getChild

public final Tree getChild(java.lang.String label)
Description copied from class: HashTree
Fetch our direct child along the edge labelled label. Iff there is no such child, return null.

Overrides:
getChild in class HashTree

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage