Download Latest Version jsearch_latest.tar.gz (2.0 MB)
Email in envelope

Get an email when there's a new version of Java source code search

Home / jsearch_0.1b
Name Modified Size InfoDownloads / Week
Parent folder
README 2011-03-20 4.8 kB
jsearch_0.1b.zip 2011-03-20 2.0 MB
jsearch_0.1b.tar.gz 2011-03-20 2.0 MB
Totals: 3 Items   4.0 MB 0
Why do you need this kind of tool? What is wrong with grep?

- Grep is nice tool for search all kind of text but if you really
 need to do complex search in Java file content then you need
 something more powerful.

- This tool will help you to find the variables by name, type, method
  call, assignment, references. etc. For example if you have instances
  for the objects that need finalize methods call at then end you can
  use this tool to search whether the finalize method call has been
  done or not. For example Sql Statement, Connection, ResultSet,
  FileReader, FileWriter, FileInputStream, FileOutputStream objects
  need to close method call at the end otherwise the file handlers
  stay open and waste resources.

- The tool has a Java parser integrated in it so white spaces and
 comments are ignored when searching in the Java code.

- The syntax for the tool is the following:

jsearch.ksh [-ver] | [-regexp] -input <search input> <file names>

-regexp

is the optional parameter and says that we want to use regular
expression search patters. It is jdk 1.6 regular expression syntax.

-input <search input>

-input and "..." it the mandatory parameter for the search patterns
 There are several kind of patterns that you can use:

variable.type=<variable object declaratation/instance creation>
variable.method_call=< object's method call>
variable.object_name=<variable object's name>
variable.statement=<Java statement>

when you give several patterns at the same time you need to separate
them with && characters.

You can also use ! for invert match to search tokens that don't match
for the specific rule.

Here are some examples that you can search with the tool.

1)
We want to search all the variable objects which have Statement
instances and which don't have called the close method calls.

./jsearch.sh -input "variable.type=Statement &&
variable.method_call!=close" Testi.java
Output:
parsing
Testi.java name: s:7 type: name: Statement
methodCalls: [name: executeUpdate:8] assignments: [name:
newStatement():7] references: []

the output shows that there is s variable object which has been
declared in the line number 7 (name: s:7) and it is a Statement object
(name:Statement) and it has only one method call executeUpdate ([name:
executeUpdate:8]) which can found in line 8 and then there is one
assignment ([name: newStatement():7]) for the object which can be
found in line 7 and there are no references for the objects
(references: []). So it doesn't have close method call at all so that
is why it was found. You can find the test class in the below

public class Testi {
   public void foo() {
       Statement s = new Statement();
       s.close();
   }
   public void foo2() {
       Statement s = new Statement();
       s.executeUpdate();
   }


2)
We want to search all the variable objects which have (Statement and
Statement...)  instances and which have all kind of close
method calls and also the variable name is s and s...:

./jsearch.sh  -regexp -input "variable.type=Statement.? &&
variable.method_call=close.* && variable.object_name=s.*" Testi4.java
Output:
parsing Testi8.java
name: s2:4 type: name: Statement:-1 methodCalls: [name: closeAll:6]
assignments:
[name: newStatement():4] references: []
name: sss:3 type: name: Statement:-1 methodCalls: [name: close:5]
assignments: [name: newStatement():3] references: []
name: s2:11 type: name: Statement2:-1 methodCalls: [name: close:13]
assignments: [name: newStatement():11] references: []

As you can see in the below that there are three close method calls
(two closes and one closeAll method call) and there are four
Statements but one (Statement s) doesn't have close method call so it
is not printed and all of those variable names start with s.

public class Testi {
   public void foo() {
       Statement sss = new Statement();
       Statement s2 = new Statement();
       sss.close();
       s2.closeAll();

   }
   public void foo2() {
       Statement s;
       Statement2 s2 = new Statement();
       s.executeUpdate();
       s2.close();
   }
}

The tool notice/works only with the local variables and it doesn't
notice if you give the objects for the reference for some other method
calls which do the closing operations, for example:

   public void foo() {
       Statement s = new Statement();
       finalizeStatements(s);
   }

private void finalizeStatements(Statement s) {
 s.close();
}

If you now try to search Statement object which haven't called the
close method the tool says that you haven't call close method because
the close method call is done in other method (finalizeStatements) not
in the same method (foo) where the Statement declaration is
done. However it will shows you that there is a reference for that
object.
Source: README, updated 2011-03-20