...
Use Case 4: Find overloaded methods with multiple parameters that share a single type.
Covariant Arrays
In Java and C#, array subtyping is covariant, meaning that type B\[\] is considered a subtype of A\[\] whenever B is a subtype of A. However, this relation can cause runtime exceptions. Consider the following Java code where Banana and Apple are subtypes of Fruit: Wiki Markup
Code Block |
---|
Banana[] bananas = new Banana[5]; Fruit[] fruit = bananas; fruits[0] = new Apple(); // ArrayStore Exception peelBanana(bananas[0]); // Apple??? |
...
The assignment to the first element of the variable fruit on line 3 will cause an ArrayStore exception. Although statically, the variable fruit has type Fruit\[\], its runtime type is Banana\[\] and thus we cannot use it to store an Apple.
Use Case 5: Find occurences of covariant array uses in assignment, method calls, constructor instantiations and return statements.
...
Use Case 6: Find occurences of nested try/catch blocks that rethrow an exception.
Evaluation
*\[This section is work in progress\]* Wiki Markup
X = not supported
✓ = supported
? = not sure
| Final Array & Anonymous Class | Generic Constructors | Capture Conversion Idiom | Overloaded Methods Sharing Single Type | Covariant Arrays | Rethrown Exception |
---|---|---|---|---|---|---|
JTL | X | X | X | ? | X | X |
BBQ | X | X | X | ? | X | X |
SOUL | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
JQuery | X | X | X | X (*1) | X | X |
.QL (*2) | ✓ | ? | ? | ? | ✓ | ? |
Jackpot | X | ✓ | X | X | X | ✓ |
PMD (Xpath) | X | X | X | X | X | X |
*1: can find overloaded methods but not sharing single type: method(?C, ?M1), method(?C, ?M2), likeThis(?M1, ?M2). Tested with operations available in eclipse plugin. Paper describe different operations that don't seem to be supported.
*2: .QL documentation & tool is kept secretive for competitive advantage protection
JTL
- no working Eclipse plugin found. (authors emailed)
- argument list pattern (sec 2.2) public _ (_, String, *) : any public method that accept a String as its second argument and returns any type
- quantifiers: no, all, exists...
- anonymous class
- pattern naming (integral := byte | short | int | long)
- variable binding
- no structural matching of AST (deemed difficult because uses class files) (so can't look match on a loop for example or find all local variables in method)
- no submethod information (local vars etc)
read\[F\]/write\[F\] predicates to indicate whether a method reads/write to a field. Nice feature: write\[_\] tells whether method writes to a field at all. Q: How do we do this recursively? All methods within the method are not writing to fields...Wiki Markup - no support for generics (according to documentation)
Use case 1 not possible because no support for local variable decl. Use case 2 & 3 not possible because no support for generics/wildcards (due to bytecode source). Use 4 not possible because no support for statements & types of expressions. Use case 6 not possible because no control flow support.
BBQ
- doesn't detect local inner classes (local & anonymous). Only inner classes (doesn't differentiate): class in all classes
- no access to local variable declared in methods
- no support for generics.
- no support for constructors (considered as method init)
- no AST structural matching. (e.g loops ...)
- no variable binding/unification
- set operators (union, intersection)
- support for read/write of fields references
Similar reasons to JTL.
SOUL
...
- http://jquery.cs.ubc.ca/documentation/toc.html
- http://jquery.cs.ubc.ca/documentation/appendix2.html
- variable binding through predicatesunmigrated-wiki-markup
- support for read & efftects of fields (write) \ [writes(?B,?F,?L) means: "Block ?B writes to field ?F at location ?L"\]
- no structural (statement) matching (e.g pattern match on a loop or body of a method)
- no generics support
- no quantifiers
Similar reasons to JTL.
.QL
- New version stores every AST node unit in DB
- has notion of aggregates (count, sum, max, min, avg)
- ".QL: Object-Oriented Queries made Easy"
Very expressive. Though sql statements may not scale for control flow matching. (direct ast pattern matching is clearer for some use cases)
...
- http://www.ing.iac.es/~docs/external/java/pmd/rules/design.html
- http://code.google.com/p/code-cop-code/wiki/PmdRulesCodecop
- structural matching: all AST hiearchy can be queried through Xpath expression
- can't express subtype relations. E.g. assignments where RHS is supertype of left handside and different
- no variable binding
- support generic constructors but not bind it to enclosing class: //ConstructorDeclaration//TypeParameters
- no support for read/write effects
No variable binding support which restricts a lot of the analysis.
Taxonomy
...
*\[This section is work in progress\]*
Query Language Features
- variable binding
- quantifiers (forall, exists, no)
- predicates
- set operators
- aggregate operators
- behavioural template matching
- list pattern matching (parameters, generics)
- querying style
...
- Attributed AST Nodes
- control flow statements
- local variables
- generics / wildcards
- anonymous class
Conclusion/Ideas
*\[This section is work in progress\]*[This section is work in progress] Wiki Markup
Relational based query languages not low level enough.
...
Week | Date | Log | Milestones |
---|---|---|---|
1 | 9 July - 13 July |
|
|
2 | 16 July - 20 July |
|
|
3 | 23 July - 27 July |
| Milestone 1
|
4 | 30 July - 3 August |
|
|
5 | 6 August - 10 August |
|
|
6 | 13 August - 17 August |
| Milestone 2
|
7 | 20 August - 24 August |
| Milestone 3
|
8 | 27 August - 31 August |
| Milestone 4
|
9 | 3 September - 7 September |
| Milestone 5
|
10 | 10 September - 14 September |
|
|
11 | 17 September - 21 September |
|
|
12 | 24 September - 28 September |
|
|
13 | 1 October - 5 October |
| DEMO |
14 | 8 October - 12 October |
| DEMO |
Demo Plan
Aim
Give a live demonstration of the query language for two use cases: Covariant Arrays assignments & Overloaded Methods sharing single type
...
- Web interface for Demo
Relevant Literature
\[1\] Brian Goetz. Language designer's notebook: Quantitative language design. [ http://www.ibm.com/developerworks/java/library/j-ldn1/|http://www.ibm.com/developerworks/java/library/j-ldn1/].unmigrated-wiki-markup Wiki Markup
\[2\] Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2011. Java generics adoption: how new features are introduced, championed, or ignored. In Proceedings of the 8th Working Conference on Mining Software Repositories (MSR '11)unmigrated-wiki-markup
\[3\] Ewan Tempero, Craig Anslow, Jens Dietrich, Ted Han, Jing Li, Markus Lumpe, Hayden Melton, and James Noble. 2010. The Qualitas Corpus: A Curated Collection of Java Code for Empirical Studies. In Proceedings of the 2010 Asia Pacific Software Engineering Conference (APSEC '10)unmigrated-wiki-markup
\[4\] Joseph Gil and Keren Lenz. 2010. The use of overloading in JAVA programs. In Proceedings of the 24th European conference on Object-oriented programming (ECOOP '10)
\[5\] Raoul-Gabriel Urma and Janina Voigt. Using the OpenJDK to Investigate Covariance in Java. Java Magazine May/June 2012. Wiki Markup
Related Projects
...
\[a\] Refactoring NG. [http://kenai.com/projects/refactoringng| http://kenai.com/projects/refactoringng]unmigrated-wiki-markup
\[b\] Tal Tal Cohen, Joseph (Yossi) Gil, and Itay Maman. 2006. JTL: the Java tools language. In Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications (OOPSLA '06)unmigrated-wiki-markup
\[c\] Browse By Query. [http://browsebyquery.sourceforge.net/| http://browsebyquery.sourceforge.net/]