Package org.codehaus.janino.tools
Class JGrep
- java.lang.Object
-
- org.codehaus.janino.tools.JGrep
-
public class JGrep extends java.lang.Object
Reads a set of compilation units from the file system and searches it for specific Java™ constructs, e.g. invocations of a particular method. Usage:java org.codehaus.janino.JGrep \ [ -dirs directory-name-patterns ] \ [ -files file-name-patterns ] \ { directory-path } \ -method-invocation class.method(arg-types) java org.codehaus.janino.JGrep -help
If "-dirs" is not given, then all directory-pathes are scanned for files. The directory-name-patterns work as described inStringPattern.parseCombinedPattern(String)
.If "-files" is not given, then all files ending in ".java" are read. The file-name-patterns work as described in
StringPattern.parseCombinedPattern(String)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JGrep.Action
private class
JGrep.JGrepIClassLoader
A specializedIClassLoader
that loadsIClass
es from the following sources: An already-parsed compilation unit A class file in the output directory (if existant and younger than source file) A source file in any of the source path directories The parent class loader Notice that theJGrep.JGrepIClassLoader
is an inner class ofJGrep
and heavily usesJGrep
's members.(package private) static interface
JGrep.MethodInvocationAction
An entity that does something with a method invocation, e.g.(package private) static interface
JGrep.MethodInvocationPredicate
A predicate that examines a method invocation.private static class
JGrep.MethodInvocationTarget
-
Field Summary
Fields Modifier and Type Field Description private Benchmark
benchmark
private static boolean
DEBUG
private IClassLoader
iClassLoader
private java.lang.String
optionalCharacterEncoding
private java.util.List<UnitCompiler>
parsedCompilationUnits
private static java.lang.String[]
USAGE
-
Constructor Summary
Constructors Constructor Description JGrep(java.io.File[] classPath, java.io.File[] optionalExtDirs, java.io.File[] optionalBootClassPath, java.lang.String optionalCharacterEncoding, boolean verbose)
JGrep(IClassLoader iClassLoader, java.lang.String optionalCharacterEncoding, boolean verbose)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.io.File
getClassFile(java.lang.String className, java.io.File sourceFile, java.io.File optionalDestinationDirectory)
Construct the name of a file that could store the byte code of the class with the given name.private void
jGrep(java.io.File[] rootDirectories, StringPattern[] directoryNamePatterns, StringPattern[] fileNamePatterns, java.util.List<JGrep.MethodInvocationTarget> methodInvocationTargets)
private void
jGrep(java.util.Iterator<java.io.File> sourceFilesIterator, java.util.List<JGrep.MethodInvocationTarget> methodInvocationTargets)
static void
main(java.lang.String[] args)
Command line interface.private Java.CompilationUnit
parseCompilationUnit(java.io.File sourceFile, java.lang.String optionalCharacterEncoding)
Read one compilation unit from a file and parse it.private static JGrep.MethodInvocationTarget
parseMethodInvocationPattern(java.lang.String mip)
private static java.lang.String
readIdentifierPattern(Parser p)
(package private) static boolean
typeMatches(java.lang.String pattern, java.lang.String typeName)
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
parsedCompilationUnits
private final java.util.List<UnitCompiler> parsedCompilationUnits
-
USAGE
private static final java.lang.String[] USAGE
-
iClassLoader
private final IClassLoader iClassLoader
-
optionalCharacterEncoding
private final java.lang.String optionalCharacterEncoding
-
benchmark
private final Benchmark benchmark
-
-
Constructor Detail
-
JGrep
public JGrep(java.io.File[] classPath, java.io.File[] optionalExtDirs, java.io.File[] optionalBootClassPath, java.lang.String optionalCharacterEncoding, boolean verbose)
-
JGrep
public JGrep(IClassLoader iClassLoader, java.lang.String optionalCharacterEncoding, boolean verbose)
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Command line interface.
-
parseMethodInvocationPattern
private static JGrep.MethodInvocationTarget parseMethodInvocationPattern(java.lang.String mip) throws CompileException, java.io.IOException
- Throws:
CompileException
java.io.IOException
-
readIdentifierPattern
private static java.lang.String readIdentifierPattern(Parser p) throws CompileException, java.io.IOException
- Throws:
CompileException
java.io.IOException
-
typeMatches
static boolean typeMatches(java.lang.String pattern, java.lang.String typeName)
- Returns:
- Whether the fully qualified
typeName
matches thepattern
, or, iff the pattern does not contain a period, the simple type name oftypeName
matches thepattern
-
jGrep
private void jGrep(java.io.File[] rootDirectories, StringPattern[] directoryNamePatterns, StringPattern[] fileNamePatterns, java.util.List<JGrep.MethodInvocationTarget> methodInvocationTargets) throws CompileException, java.io.IOException
- Throws:
CompileException
java.io.IOException
-
jGrep
private void jGrep(java.util.Iterator<java.io.File> sourceFilesIterator, java.util.List<JGrep.MethodInvocationTarget> methodInvocationTargets) throws CompileException, java.io.IOException
- Throws:
CompileException
java.io.IOException
-
parseCompilationUnit
private Java.CompilationUnit parseCompilationUnit(java.io.File sourceFile, java.lang.String optionalCharacterEncoding) throws CompileException, java.io.IOException
Read one compilation unit from a file and parse it.The
inputStream
is closed before the method returns.- Returns:
- the parsed compilation unit
- Throws:
CompileException
java.io.IOException
-
getClassFile
public static java.io.File getClassFile(java.lang.String className, java.io.File sourceFile, java.io.File optionalDestinationDirectory)
Construct the name of a file that could store the byte code of the class with the given name.If
optionalDestinationDirectory
is non-null, the returned path is theoptionalDestinationDirectory
plus the package of the class (with dots replaced with file separators) plus the class name plus ".class". Example: "destdir/pkg1/pkg2/Outer$Inner.class"If
optionalDestinationDirectory
is null, the returned path is the directory of thesourceFile
plus the class name plus ".class". Example: "srcdir/Outer$Inner.class"- Parameters:
className
- E.g. "pkg1.pkg2.Outer$Inner"sourceFile
- E.g. "srcdir/Outer.java"optionalDestinationDirectory
- E.g. "destdir"
-
-