Converted to Java regexp code; renamed to avoid enum keyword collision.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1470 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -25,7 +25,7 @@ import java.awt.print.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
import com.samskivert.viztool.enum.*;
|
||||
import com.samskivert.viztool.clenum.*;
|
||||
|
||||
import com.samskivert.viztool.hierarchy.HierarchyVisualizer;
|
||||
import com.samskivert.viztool.summary.SummaryVisualizer;
|
||||
@@ -59,10 +59,10 @@ public class Driver
|
||||
// run ourselves on the classpath
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
// System.err.println("Scanning " + classpath + ".");
|
||||
ClassEnumerator enum = new ClassEnumerator(classpath);
|
||||
ClassEnumerator clenum = new ClassEnumerator(classpath);
|
||||
|
||||
// print out the warnings
|
||||
ClassEnumerator.Warning[] warnings = enum.getWarnings();
|
||||
ClassEnumerator.Warning[] warnings = clenum.getWarnings();
|
||||
for (int i = 0; i < warnings.length; i++) {
|
||||
System.err.println("Warning: " + warnings[i].reason);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class Driver
|
||||
// and finally generate the visualization
|
||||
FilterEnumerator fenum = null;
|
||||
try {
|
||||
fenum = new RegexpEnumerator(regexp, enum);
|
||||
fenum = new RegexpEnumerator(regexp, null, clenum);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Invalid package regular expression " +
|
||||
"[regexp=" + regexp + ", error=" + e + "].");
|
||||
|
||||
@@ -44,9 +44,9 @@ import org.apache.tools.ant.types.Path;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
import com.samskivert.viztool.enum.ClassEnumerator;
|
||||
import com.samskivert.viztool.enum.FilterEnumerator;
|
||||
import com.samskivert.viztool.enum.RegexpEnumerator;
|
||||
import com.samskivert.viztool.clenum.ClassEnumerator;
|
||||
import com.samskivert.viztool.clenum.FilterEnumerator;
|
||||
import com.samskivert.viztool.clenum.RegexpEnumerator;
|
||||
import com.samskivert.viztool.util.FontPicker;
|
||||
|
||||
/**
|
||||
@@ -118,10 +118,10 @@ public class DriverTask extends Task
|
||||
|
||||
// scan the classpath and determine which classes will be
|
||||
// visualized
|
||||
ClassEnumerator enum = new ClassEnumerator(classpath.toString());
|
||||
ClassEnumerator clenum = new ClassEnumerator(classpath.toString());
|
||||
FilterEnumerator fenum = null;
|
||||
try {
|
||||
fenum = new RegexpEnumerator(_classes, _exclude, enum);
|
||||
fenum = new RegexpEnumerator(_classes, _exclude, clenum);
|
||||
} catch (Exception e) {
|
||||
throw new BuildException("Invalid package regular expression " +
|
||||
"[classes=" + _classes +
|
||||
|
||||
+15
-15
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -53,19 +53,19 @@ public class ClassEnumerator implements Iterator
|
||||
while (tok.hasMoreTokens()) {
|
||||
String component = tok.nextToken();
|
||||
// locate an enumerator for this token
|
||||
ComponentEnumerator enum = matchEnumerator(component);
|
||||
if (enum == null) {
|
||||
ComponentEnumerator cenum = matchEnumerator(component);
|
||||
if (cenum == null) {
|
||||
String wmsg = "Unable to match enumerator for " +
|
||||
"component '" + component + "'.";
|
||||
warnings.add(new Warning(wmsg));
|
||||
|
||||
} else {
|
||||
try {
|
||||
// System.out.println("Adding [enum=" + enum +
|
||||
// System.out.println("Adding [enum=" + cenum +
|
||||
// ", component=" + component + "].");
|
||||
// construct an enumerator to enumerate this component
|
||||
// and put it on our list
|
||||
enums.add(enum.enumerate(component));
|
||||
enums.add(cenum.enumerate(component));
|
||||
|
||||
} catch (EnumerationException ee) {
|
||||
// if there was a problem creating an enumerator for
|
||||
@@ -95,10 +95,10 @@ public class ClassEnumerator implements Iterator
|
||||
protected ComponentEnumerator matchEnumerator (String component)
|
||||
{
|
||||
for (int i = 0; i < _enumerators.size(); i++) {
|
||||
ComponentEnumerator enum =
|
||||
ComponentEnumerator cenum =
|
||||
(ComponentEnumerator)_enumerators.get(i);
|
||||
if (enum.matchesComponent(component)) {
|
||||
return enum;
|
||||
if (cenum.matchesComponent(component)) {
|
||||
return cenum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +143,12 @@ public class ClassEnumerator implements Iterator
|
||||
{
|
||||
if (_enumidx < _enums.length) {
|
||||
// grab the current enumerator
|
||||
ComponentEnumerator enum = _enums[_enumidx];
|
||||
ComponentEnumerator cenum = _enums[_enumidx];
|
||||
|
||||
// if it has more classes
|
||||
if (enum.hasMoreClasses()) {
|
||||
if (cenum.hasMoreClasses()) {
|
||||
// get the next one
|
||||
_nextClass = enum.nextClass();
|
||||
_nextClass = cenum.nextClass();
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -182,17 +182,17 @@ public class ClassEnumerator implements Iterator
|
||||
{
|
||||
// run ourselves on the classpath
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
ClassEnumerator enum = new ClassEnumerator(classpath);
|
||||
ClassEnumerator cenum = new ClassEnumerator(classpath);
|
||||
|
||||
// print out the warnings
|
||||
Warning[] warnings = enum.getWarnings();
|
||||
Warning[] warnings = cenum.getWarnings();
|
||||
for (int i = 0; i < warnings.length; i++) {
|
||||
System.out.println("Warning: " + warnings[i].reason);
|
||||
}
|
||||
|
||||
// enumerate over whatever classes we can
|
||||
while (enum.hasNext()) {
|
||||
System.out.println("Class: " + enum.next());
|
||||
while (cenum.hasNext()) {
|
||||
System.out.println("Class: " + cenum.next());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
/**
|
||||
* An enumeration exception is thrown when some problem occurs while
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
/**
|
||||
* The jar file enumerator enumerates all of the classes in a .jar class
|
||||
+5
-5
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -49,12 +49,12 @@ public class PackageEnumerator extends FilterEnumerator
|
||||
{
|
||||
// run ourselves on the classpath
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
ClassEnumerator enum = new ClassEnumerator(classpath);
|
||||
String pkg = "com.samskivert.viztool.enum";
|
||||
PackageEnumerator penum = new PackageEnumerator(pkg, enum, true);
|
||||
ClassEnumerator clenum = new ClassEnumerator(classpath);
|
||||
String pkg = "com.samskivert.viztool.clenum";
|
||||
PackageEnumerator penum = new PackageEnumerator(pkg, clenum, true);
|
||||
|
||||
// print out the warnings
|
||||
ClassEnumerator.Warning[] warnings = enum.getWarnings();
|
||||
ClassEnumerator.Warning[] warnings = clenum.getWarnings();
|
||||
for (int i = 0; i < warnings.length; i++) {
|
||||
System.out.println("Warning: " + warnings[i].reason);
|
||||
}
|
||||
+10
-11
@@ -18,12 +18,11 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.regexp.RE;
|
||||
import org.apache.regexp.RESyntaxException;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* The regex enumerator filters classes based on a regular expression.
|
||||
@@ -31,21 +30,21 @@ import org.apache.regexp.RESyntaxException;
|
||||
public class RegexpEnumerator extends FilterEnumerator
|
||||
{
|
||||
public RegexpEnumerator (String regexp, String exregex, Iterator source)
|
||||
throws RESyntaxException
|
||||
throws PatternSyntaxException
|
||||
{
|
||||
super(source);
|
||||
_regexp = new RE(regexp);
|
||||
_regexp = Pattern.compile(regexp);
|
||||
if (exregex != null) {
|
||||
_exreg = new RE(exregex);
|
||||
_exreg = Pattern.compile(exregex);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean filterClass (String clazz)
|
||||
{
|
||||
return !(_regexp.match(clazz) &&
|
||||
(_exreg == null || !_exreg.match(clazz)));
|
||||
return !(_regexp.matcher(clazz).matches() &&
|
||||
(_exreg == null || !_exreg.matcher(clazz).matches()));
|
||||
}
|
||||
|
||||
protected RE _regexp;
|
||||
protected RE _exreg;
|
||||
protected Pattern _regexp;
|
||||
protected Pattern _exreg;
|
||||
}
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.samskivert.viztool.enum;
|
||||
package com.samskivert.viztool.clenum;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
@@ -30,7 +30,7 @@ import com.samskivert.util.CollectionUtil;
|
||||
|
||||
import com.samskivert.viztool.Log;
|
||||
import com.samskivert.viztool.Visualizer;
|
||||
import com.samskivert.viztool.enum.PackageEnumerator;
|
||||
import com.samskivert.viztool.clenum.PackageEnumerator;
|
||||
|
||||
/**
|
||||
* The hierarchy visualizer displays inheritance hierarchies in a compact
|
||||
|
||||
Reference in New Issue
Block a user