Java srcML Language Documentation

Statements XML Element Subelements

if statement

<if>

<condition>, <then>, <else>, <elseif>

while statement

<while>

<condition>, <block>

for statement

<for>

<control>, <block>

do statement

<do>

<condition>, <block>

break statement

<break>

<name>

continue statement

<continue>

<name>

label statement

<label>

<name>

return statement

<return>

switch statement

<switch>

<condition>, <case>

case statement

<case>

<expr>

default statement

<default>

assert statement

<assert>

<expr>

block

<block>

empty statement

<empty_stmt>

Specifiers XML Element Subelements

abstract

<specifier>

default method implementation

<specifier>

final

<specifier>

synchronized

<specifier>

transient

<specifier>

native

<specifier>

private

<specifier>

protected

<specifier>

public

<specifier>

static

<specifier>

<block>

volatile

<specifier>

strictfp

<specifier>

Declarations, Definitions and Initializations XML Element Subelements

variable declaration and initialization

<decl_stmt>

<decl>, <init>

method definition

<function>

<type>, <name>, <parameter_list>

lambda functions

<lambda>

<parameter_list>, <expr>, <block>

anonymous class

<class>

<super>, <block>

Classes, Interfaces, Annotations and Enums XML Element Subelements

class definition

<class>

<name>

interface

<interface>

<name>, <block>

annotation definition

<annotation_defn>

<name>, <block>

annotation use

<annotation>

<name>, <argument_list>

enum definition

<enum>

<block>, <name>

extends

<extends>

<name>

implements

<implements>

<name>

constructor

<Constructor>

<name>, <parameter_list>

receiver parameter

<name>

static initialization block

<static>

<block>

default annotation property value

<default>

Expressions XML Element Subelements

function call

<call>

<name>, <argument_list>

ternary operator

<ternary>

<condition>, <then>, <else>

this

<name>

super

<name>

method reference

<name>

Other XML Element Subelements

cast

<operator>

import

<import>

<name>

package

<package>

<name>

synchronized statement

<synchronized>

<init>, <block>

Exceptions XML Element Subelements

throw

<throw>

<expr>

throws

<throws>

<name>

try

<try>

<init>, <block>, <catch>, <finally>

catch

<catch>

<parameter_list>, <block>

finally

<finally>

<block>

Generic XML Element Subelements

generic class definition

<class>

<name>, <argument_list>, <block>

generic variable declaration

<decl_stmt>

<decl>

generic method definition

<function>

<name>, <argument_list>, <parameter_list>, <block>

bound generic parameter

<extends>

<name>

generic wildcard

<extends>

<name>

if statement


Element

Subelements

XPath Queries

  • if statements

    //src:if
  • if statement conditions

    //src:if/src:condition
  • then statements

    //src:if/src:then
  • else statements

    //src:if/src:else
  • if statements without an else statement (this only refers to else and not else if)

    //src:if[not(src:else)]
  • nested if statements (include else if)

    //src:if//src:if
  • else-if statements

    //src:elseif

Examples

if(x > 5)
    y+=4;
<if>if<condition>(<expr><name>x</name> <operator>&gt;</operator> <literal type="number">5</literal></expr>)</condition><then><block type="pseudo">
    <expr_stmt><expr><name>y</name><operator>+=</operator><literal type="number">4</literal></expr>;</expr_stmt></block></then></if>
if ( i > 0 ) {
    y = x / i;
}
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> <block>{
    <expr_stmt><expr><name>y</name> <operator>=</operator> <name>x</name> <operator>/</operator> <name>i</name></expr>;</expr_stmt>
}</block></then></if>
if ( i > 0 )
    y = x / i;
else 
{
    x = i;
    y = f( x );
}
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then><block type="pseudo">
    <expr_stmt><expr><name>y</name> <operator>=</operator> <name>x</name> <operator>/</operator> <name>i</name></expr>;</expr_stmt></block></then>
<else>else 
<block>{
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt>
    <expr_stmt><expr><name>y</name> <operator>=</operator> <call><name>f</name><argument_list>( <argument><expr><name>x</name></expr></argument> )</argument_list></call></expr>;</expr_stmt>
}</block></else></if>

Without braces

if ( i > 0 )
    if ( j > i )
        x = j;
    else
        x = i;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then><block type="pseudo">
    <if>if <condition>( <expr><name>j</name> <operator>&gt;</operator> <name>i</name></expr> )</condition><then><block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></then>
    <else>else<block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt></block></else></if></block></then></if>

With braces

if ( i > 0 ) 
{
    if ( j > i )
        x = j;
}
else
    x = i;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> 
<block>{
    <if>if <condition>( <expr><name>j</name> <operator>&gt;</operator> <name>i</name></expr> )</condition><then><block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></then></if>
}</block></then>
<else>else<block type="pseudo">
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt></block></else></if>
if ( i > 0 ) 
{
 	x = i;   
}
else if( i < 0)
	x = q;
else 
    x = j;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> 
<block>{
 	<expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt>   
}</block></then>
<elseif>else <if>if<condition>( <expr><name>i</name> <operator>&lt;</operator> <literal type="number">0</literal></expr>)</condition><then><block type="pseudo">
	<expr_stmt><expr><name>x</name> <operator>=</operator> <name>q</name></expr>;</expr_stmt></block></then></if></elseif>
<else>else<block type="pseudo"> 
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></else></if>

while statement


Element

Subelements

XPath Queries

  • while loops

    //src:while
  • while-loop conditions

    //src:while/src:condition
  • while loops with a condition containing the variable i

    //src:while[src:condition//src:name = 'i']

Example

while ( i >= 0 ) 
{
    string1[i] = string2[i];
    i--;
}
<while>while <condition>( <expr><name>i</name> <operator>&gt;=</operator> <literal type="number">0</literal></expr> )</condition> 
<block>{
    <expr_stmt><expr><name><name>string1</name><index>[<expr><name>i</name></expr>]</index></name> <operator>=</operator> <name><name>string2</name><index>[<expr><name>i</name></expr>]</index></name></expr>;</expr_stmt>
    <expr_stmt><expr><name>i</name><operator>--</operator></expr>;</expr_stmt>
}</block></while>

for statement


Element

Subelements

XPath Queries

  • for loops

    //src:for
  • for-loop initializations

    //src:for/src:control/src:init
  • for-loop conditions

    //src:for/src:control/src:condition
  • for-loop increments

    //src:for/src:control/src:incr
  • for loops that declare a variable with a single character name (e.g. x, i or y)

    //src:for[string-length(src:control/src:init/src:decl/src:name) = 1]
  • for loops that use post-increment as part of the increment expression

    //src:for[src:control/src:incr/src:expr//node()/following-sibling::src:operator[.= '++']]
  • range-based for loops

    //src:for[src:control/src:init/src:decl/src:range]

Examples

for( ;; ) { }
<for>for<control>( <init>;</init><condition>;</condition> <incr/>)</control> <block>{ }</block></for>
for (i = 0; i < max; i++ ) 
{
  if ( line[i] == ' ' )
  {
      space++;
  }
  if ( line[i] == '\t' )
  {
      tab++;
  }
}
<for>for <control>(<init><expr><name>i</name> <operator>=</operator> <literal type="number">0</literal></expr>;</init> <condition><expr><name>i</name> <operator>&lt;</operator> <name>max</name></expr>;</condition> <incr><expr><name>i</name><operator>++</operator></expr></incr> )</control> 
<block>{
  <if>if <condition>( <expr><name><name>line</name><index>[<expr><name>i</name></expr>]</index></name> <operator>==</operator> <literal type="char">' '</literal></expr> )</condition><then>
  <block>{
      <expr_stmt><expr><name>space</name><operator>++</operator></expr>;</expr_stmt>
  }</block></then></if>
  <if>if <condition>( <expr><name><name>line</name><index>[<expr><name>i</name></expr>]</index></name> <operator>==</operator> <literal type="char">'\t'</literal></expr> )</condition><then>
  <block>{
      <expr_stmt><expr><name>tab</name><operator>++</operator></expr>;</expr_stmt>
  }</block></then></if>
}</block></for>
for(int i =0; i < 10;++i)
	a += x[i];
<for>for<control>(<init><decl><type><name>int</name></type> <name>i</name> <init>=<expr><literal type="number">0</literal></expr></init></decl>;</init> <condition><expr><name>i</name> <operator>&lt;</operator> <literal type="number">10</literal></expr>;</condition><incr><expr><operator>++</operator><name>i</name></expr></incr>)</control><block type="pseudo">
	<expr_stmt><expr><name>a</name> <operator>+=</operator> <name><name>x</name><index>[<expr><name>i</name></expr>]</index></name></expr>;</expr_stmt></block></for>
for (int item : numbers) {
    System.out.println("Count is: " + item);
}
<for>for <control>(<init><decl><type><name>int</name></type> <name>item</name> <range>: <expr><name>numbers</name></expr></range></decl></init>)</control> <block>{
    <expr_stmt><expr><call><name><name>System</name><operator>.</operator><name>out</name><operator>.</operator><name>println</name></name><argument_list>(<argument><expr><literal type="string">"Count is: "</literal> <operator>+</operator> <name>item</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
}</block></for>

break statement


Element

Subelement

XPath Queries

  • break statements

    //src:break
  • break statements in for loops

    //src:break[ancestor::src:for]
  • break statements that break to the exit label

    //src:break[src:name[.='exit']]

Examples

char c;
for(;;) {
    printf_s( "\nPress any key, Q to quit: " );

    // Convert to character value
    scanf_s("%c", &c);
    if (c == 'Q')
        break;
}
<decl_stmt><decl><type><name>char</name></type> <name>c</name></decl>;</decl_stmt>
<for>for<control>(<init>;</init><condition>;</condition><incr/>)</control> <block>{
    <expr_stmt><expr><call><name>printf_s</name><argument_list>( <argument><expr><literal type="string">"\nPress any key, Q to quit: "</literal></expr></argument> )</argument_list></call></expr>;</expr_stmt>

    <comment type="line">// Convert to character value</comment>
    <expr_stmt><expr><call><name>scanf_s</name><argument_list>(<argument><expr><literal type="string">"%c"</literal></expr></argument>, <argument><expr><operator>&amp;</operator><name>c</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
    <if>if <condition>(<expr><name>c</name> <operator>==</operator> <literal type="char">'Q'</literal></expr>)</condition><then><block type="pseudo">
        <break>break;</break></block></then></if>
}</block></for>
break label;
<break>break <name>label</name>;</break>

label statement


Element

Subelement

XPath Query

  • labels

    //src:label

Example

stop:
<label><name>stop</name>:</label>

return statement


Element

XPath Queries

  • return statements

    //src:return
  • functions with more then one return

    //src:function[ count(.//src:return) > 1]

Examples

return( s * (long long)s );
<return>return<expr><operator>(</operator> <name>s</name> <operator>*</operator> <operator>(</operator><name>long</name> <name>long</name><operator>)</operator><name>s</name> <operator>)</operator></expr>;</return>
return;
<return>return;</return>

case statement


Element

Subelement

XPath Queries

  • case labels

    //src:case
  • case labels named SATURDAY

    //src:case[.//src:name = 'SATURDAY']
  • switch statements with a case label named SATURDAY

    //src:switch[src:block/src:case[.//src:name = 'SATURDAY']]

Example

case THREE:
<case>case <expr><name>THREE</name></expr>:</case>

default statement


Element

XPath Queries

  • default labels

    //src:default
  • switch statements with a default label

    //src:switch[src:block/src:default]

Example

default case

default:
<default>default:</default>

assert statement


Element

Subelement

XPath Queries

  • assert statements

    //src:assert
  • methods with assert statements

    //src:function[src:block//src:assert]

Example

assert expr1 : expr2 ;
<assert>assert <expr><name>expr1</name> <operator>:</operator> <name>expr2</name></expr> ;</assert>

empty statement


Element

XPath Query

  • empty statements

    //src:empty_stmt

Example

;
<empty_stmt>;</empty_stmt>

abstract


Element

XPath Queries

  • abstract classes

    //src:class[src:specifier[.='abstract']]
  • abstract methods

    //src:function[src:type/src:specifier[.='abstract']]

Examples

abstract class MyClass
{
}
<class><specifier>abstract</specifier> class <name>MyClass</name>
<block>{
}</block></class>
abstract String myMethod();
<function_decl><specifier>abstract</specifier> <type><name>String</name></type> <name>myMethod</name><parameter_list>()</parameter_list>;</function_decl>

default method implementation


Element

XPath Query

  • methods with default implementations

    //src:function[src:type/src:specifier[.='default']]

Example

default ZonedDateTime getZonedDateTime(String zoneString) { return null; } 
<function><specifier>default</specifier> <type><name>ZonedDateTime</name></type> <name>getZonedDateTime</name><parameter_list>(<parameter><decl><type><name>String</name></type> <name>zoneString</name></decl></parameter>)</parameter_list> <block>{ <return>return <expr><literal type="null">null</literal></expr>;</return> }</block></function> 

final


Element

XPath Queries

  • final classes

    //src:class[src:specifier[.='final']]
  • final methods

    //src:function[src:type/src:specifier[.='final']]
  • final variable declarations

    //src:decl[src:type/src:specifier[.='final']]

Examples

 public final class MyFinalClass
 {
 }
 <class><specifier>public</specifier> <specifier>final</specifier> class <name>MyFinalClass</name>
 <block>{
 }</block></class>
public final String myFinalMethod()
{
}
<function><specifier>public</specifier> <specifier>final</specifier> <type><name>String</name></type> <name>myFinalMethod</name><parameter_list>()</parameter_list>
<block>{
}</block></function>
final int speedlimit=90;
<decl_stmt><decl><type><specifier>final</specifier> <name>int</name></type> <name>speedlimit</name><init>=<expr><literal type="number">90</literal></expr></init></decl>;</decl_stmt>

synchronized


Element

XPath Query

  • synchronized methods

    //src:function[src:type/src:specifier[.='synchronized']]

Example

public synchronized String mySyncMethod()
{
}
<function><specifier>public</specifier> <specifier>synchronized</specifier> <type><name>String</name></type> <name>mySyncMethod</name><parameter_list>()</parameter_list>
<block>{
}</block></function>

transient


Element

XPath Query

  • transient variable declarations

    //src:decl[src:type/src:specifier[.='transient']]

Example

transient String password;
<decl_stmt><decl><specifier>transient</specifier> <type><name>String</name></type> <name>password</name></decl>;</decl_stmt>

native


Element

XPath Query

  • native function declarations

    //src:function_decl[src:type/src:specifier[.='native']]

Example

 native String getProcessorType();
 <function_decl><specifier>native</specifier> <type><name>String</name></type> <name>getProcessorType</name><parameter_list>()</parameter_list>;</function_decl>

private


Element

XPath Queries

  • private classes

    //src:class[src:specifier[.='private'][ancestor::src:class]]
  • private member variables

    //src:decl_stmt[src:decl/src:type/src:specifier[.='private']][ancestor::src:class]
  • private methods

    //src:function[src:type/src:specifier[.='private']]

Examples

public class MyPublicClass {
    private class Helper
    {
    }
}
<class><specifier>public</specifier> class <name>MyPublicClass</name> <block>{
    <class><specifier>private</specifier> class <name>Helper</name>
    <block>{
    }</block></class>
}</block></class>
private int i;
<decl_stmt><decl><specifier>private</specifier> <type><name>int</name></type> <name>i</name></decl>;</decl_stmt>
private String myMethod()
{ }
<function><specifier>private</specifier> <type><name>String</name></type> <name>myMethod</name><parameter_list>()</parameter_list>
<block>{ }</block></function>

protected


Element

XPath Queries

  • protected classes

    //src:class[src:specifier[.='protected'][ancestor::src:class]]
  • protected member variables

    //src:decl_stmt[src:decl/src:type/src:specifier[.='protected']][ancestor::src:class]
  • protected methods

    //src:function[src:type/src:specifier[.='protected']]

Examples

public class Temp {
    protected class MyProtectedClass
    {
    }
}
<class><specifier>public</specifier> class <name>Temp</name> <block>{
    <class><specifier>protected</specifier> class <name>MyProtectedClass</name>
    <block>{
    }</block></class>
}</block></class>
protected int i;
<decl_stmt><decl><specifier>protected</specifier> <type><name>int</name></type> <name>i</name></decl>;</decl_stmt>
protected String myMethod()
{ }
<function><specifier>protected</specifier> <type><name>String</name></type> <name>myMethod</name><parameter_list>()</parameter_list>
<block>{ }</block></function>

public


Element

XPath Queries

  • public classes

    //src:class[src:specifier[.='public']]
  • public member variables

    //src:decl_stmt[src:decl/src:type/src:specifier[.='public'][ancestor::src:class]]
  • public methods

    //src:function[src:type/src:specifier[.='public']]

Examples

public class MyPrivateClass
{
}
<class><specifier>public</specifier> class <name>MyPrivateClass</name>
<block>{
}</block></class>
public int i = 50;
<decl_stmt><decl><specifier>public</specifier> <type><name>int</name></type> <name>i</name> <init>= <expr><literal type="number">50</literal></expr></init></decl>;</decl_stmt>
public String getName() { }
<function><specifier>public</specifier> <type><name>String</name></type> <name>getName</name><parameter_list>()</parameter_list> <block>{ }</block></function>

static


Element

Subelement

XPath Queries

  • static methods

    //src:function[src:type/src:specifier [.='static']]
  • static classes

    //src:class[src:specifier [.='static']]
  • static variables

    //src:decl[src:type/src:specifier [.='static']]

Examples

public final static int MAX_OBJECTS = 100;
static int _numObjects = 0;
<decl_stmt><decl><specifier>public</specifier> <type><specifier>final</specifier> <specifier>static</specifier> <name>int</name></type> <name>MAX_OBJECTS</name> <init>= <expr><literal type="number">100</literal></expr></init></decl>;</decl_stmt>
<decl_stmt><decl><specifier>static</specifier> <type><name>int</name></type> <name>_numObjects</name> <init>= <expr><literal type="number">0</literal></expr></init></decl>;</decl_stmt>
static class MyStaticClass
{ }
<class><specifier>static</specifier> class <name>MyStaticClass</name>
<block>{ }</block></class>
static int getNumObjects()
{ }
<function><specifier>static</specifier> <type><name>int</name></type> <name>getNumObjects</name><parameter_list>()</parameter_list>
<block>{ }</block></function>

volatile


Element

XPath Query

  • volatile variable declarations

    //src:decl[src:type/src:specifier[.='volatile']]

Example

volatile int sharedVal;
<decl_stmt><decl><type><specifier>volatile</specifier> <name>int</name></type> <name>sharedVal</name></decl>;</decl_stmt>

strictfp


Element

XPath Query

  • strictfp classes

    //src:class[src:specifier [.='strictfp']]

Example

strictfp class FooNum { }
<class><specifier>strictfp</specifier> class <name>FooNum</name> <block>{ }</block></class>

variable declaration and initialization


Element

Subelements

XPath Queries

  • variable declaration statements

    //src:decl_stmt
  • variable declarations

    //src:decl
  • variable declarations with an initialization

    //src:decl[src:init]
  • array declarations

    //src:decl[src:name/src:index]

Examples

boolean result = true;
char capitalC = 'C';
<decl_stmt><decl><type><name>boolean</name></type> <name>result</name> <init>= <expr><literal type="boolean">true</literal></expr></init></decl>;</decl_stmt>
<decl_stmt><decl><type><name>char</name></type> <name>capitalC</name> <init>= <expr><literal type="char">'C'</literal></expr></init></decl>;</decl_stmt>
char data[] = {'a', 'b', 'c'};
<decl_stmt><decl><type><name>char</name></type> <name><name>data</name><index>[]</index></name> <init>= <expr><block>{<expr><literal type="char">'a'</literal></expr>, <expr><literal type="char">'b'</literal></expr>, <expr><literal type="char">'c'</literal></expr>}</block></expr></init></decl>;</decl_stmt>
String str = new String(data);
<decl_stmt><decl><type><name>String</name></type> <name>str</name> <init>= <expr><operator>new</operator> <call><name>String</name><argument_list>(<argument><expr><name>data</name></expr></argument>)</argument_list></call></expr></init></decl>;</decl_stmt>
String cde = "cde";
<decl_stmt><decl><type><name>String</name></type> <name>cde</name> <init>= <expr><literal type="string">"cde"</literal></expr></init></decl>;</decl_stmt>
int[][] multi = new int[5][10];
<decl_stmt><decl><type><name><name>int</name><index>[]</index><index>[]</index></name></type> <name>multi</name> <init>= <expr><operator>new</operator> <name><name>int</name><index>[<expr><literal type="number">5</literal></expr>]</index><index>[<expr><literal type="number">10</literal></expr>]</index></name></expr></init></decl>;</decl_stmt>

method definition


Element

Subelements

XPath Queries

  • method definitions

    //src:function
  • method-definition return types

    //src:function/src:type
  • method-definition parameters

    //src:function/src:parameter_list/src:parameter
  • method definitions with two parameters

    //src:function[src:parameter_list[count(src:parameter) = 2]]
  • method-definition names

    //src:function/src:name

Examples

int getArea() {
    return width * height;
}
<function><type><name>int</name></type> <name>getArea</name><parameter_list>()</parameter_list> <block>{
    <return>return <expr><name>width</name> <operator>*</operator> <name>height</name></expr>;</return>
}</block></function>
Polygon polygonFrom(Point... corners) { }
<function><type><name>Polygon</name></type> <name>polygonFrom</name><parameter_list>(<parameter><decl><type><name>Point</name><modifier>...</modifier></type> <name>corners</name></decl></parameter>)</parameter_list> <block>{ }</block></function>

lambda functions


Element

Subelements

XPath Query

  • lambda functions

    //src:lambda

Examples

(a, b) -> a - b;
<expr_stmt><expr><lambda><parameter_list>(<parameter><decl><name>a</name></decl></parameter>, <parameter><decl><name>b</name></decl></parameter>)</parameter_list> -&gt;<block type="pseudo"> <expr><name>a</name> <operator>-</operator> <name>b</name></expr></block></lambda></expr>;</expr_stmt>
(Person p) -> p.getGender() == Person.Sex.MALE
        && p.getAge() >= 18
        && p.getAge() <= 25
<expr><lambda><parameter_list>(<parameter><decl><type><name>Person</name></type> <name>p</name></decl></parameter>)</parameter_list> -&gt;<block type="pseudo"> <expr><call><name><name>p</name><operator>.</operator><name>getGender</name></name><argument_list>()</argument_list></call> <operator>==</operator> <name><name>Person</name><operator>.</operator><name>Sex</name><operator>.</operator><name>MALE</name></name>
        <operator>&amp;&amp;</operator> <call><name><name>p</name><operator>.</operator><name>getAge</name></name><argument_list>()</argument_list></call> <operator>&gt;=</operator> <literal type="number">18</literal>
        <operator>&amp;&amp;</operator> <call><name><name>p</name><operator>.</operator><name>getAge</name></name><argument_list>()</argument_list></call> <operator>&lt;=</operator> <literal type="number">25</literal></expr></block></lambda></expr>
(int a, int b) -> {  return a + b; }
<expr_stmt><expr><lambda><parameter_list>(<parameter><decl><type><name>int</name></type> <name>a</name></decl></parameter>, <parameter><decl><type><name>int</name></type> <name>b</name></decl></parameter>)</parameter_list> -&gt; <block>{  <return>return <expr><name>a</name> <operator>+</operator> <name>b</name></expr>;</return> }</block></lambda></expr></expr_stmt>
() -> System.out.println("Hello World");
<expr_stmt><expr><lambda><parameter_list>()</parameter_list> -&gt;<block type="pseudo"> <expr><call><name><name>System</name><operator>.</operator><name>out</name><operator>.</operator><name>println</name></name><argument_list>(<argument><expr><literal type="string">"Hello World"</literal></expr></argument>)</argument_list></call></expr></block></lambda></expr>;</expr_stmt>
() -> 42
<expr><lambda><parameter_list>()</parameter_list> -&gt;<block type="pseudo"> <expr><literal type="number">42</literal></expr></block></lambda></expr>

anonymous class


Element

Subelements

XPath Query

  • anonymous classes

    //src:class[not(src:name)]

Example

HelloWorld spanishGreeting = new HelloWorld() {
	String name = "mundo";
	public void greet() {
	    greetSomeone("mundo");
	}
	public void greetSomeone(String someone) {
    	name = someone;
    	System.out.println("Hola, " + name);
	}
};
<decl_stmt><decl><type><name>HelloWorld</name></type> <name>spanishGreeting</name> <init>= <expr><operator>new</operator> <class><super><name>HelloWorld</name></super><argument_list>()</argument_list> <block>{
	<decl_stmt><decl><type><name>String</name></type> <name>name</name> <init>= <expr><literal type="string">"mundo"</literal></expr></init></decl>;</decl_stmt>
	<function><specifier>public</specifier> <type><name>void</name></type> <name>greet</name><parameter_list>()</parameter_list> <block>{
	    <expr_stmt><expr><call><name>greetSomeone</name><argument_list>(<argument><expr><literal type="string">"mundo"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
	}</block></function>
	<function><specifier>public</specifier> <type><name>void</name></type> <name>greetSomeone</name><parameter_list>(<parameter><decl><type><name>String</name></type> <name>someone</name></decl></parameter>)</parameter_list> <block>{
    	<expr_stmt><expr><name>name</name> <operator>=</operator> <name>someone</name></expr>;</expr_stmt>
    	<expr_stmt><expr><call><name><name>System</name><operator>.</operator><name>out</name><operator>.</operator><name>println</name></name><argument_list>(<argument><expr><literal type="string">"Hola, "</literal> <operator>+</operator> <name>name</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
	}</block></function>
}</block></class></expr></init></decl>;</decl_stmt>

class definition


Element

Subelement

XPath Query

  • classes

    //src:class

Example

class Pair {
}
<class>class <name>Pair</name> <block>{
}</block></class>

annotation definition


Element

Subelements

XPath Query

  • annotation definitions

    //src:annotation_defn

Example

@interface ClassPreambleAnnotation {
}
<annotation_defn>@interface <name>ClassPreambleAnnotation</name> <block>{
}</block></annotation_defn>

annotation use


Element

Subelements

XPath Queries

  • annotations

    //src:annotation
  • -Deprecated annotations

    //src:annotation[src:name='Deprecated']

Examples

@Entity
@Author( name = "Benjamin Franklin", date = "3/27/2003")
@Inventor("Benjamin Franklin")
class Cls {
}
<class><annotation>@<name>Entity</name></annotation>
<annotation>@<name>Author</name><argument_list>( <argument><expr><name>name</name> <operator>=</operator> <literal type="string">"Benjamin Franklin"</literal></expr></argument>, <argument><expr><name>date</name> <operator>=</operator> <literal type="string">"3/27/2003"</literal></expr></argument>)</argument_list></annotation>
<annotation>@<name>Inventor</name><argument_list>(<argument><expr><literal type="string">"Benjamin Franklin"</literal></expr></argument>)</argument_list></annotation>
class <name>Cls</name> <block>{
}</block></class>
@Entity
@Author( name = "Benjamin Franklin", date = "3/27/2003")
@Inventor("Benjamin Franklin")
<annotation>@<name>Entity</name></annotation>
<annotation>@<name>Author</name><argument_list>( <argument><expr><name>name</name> <operator>=</operator> <literal type="string">"Benjamin Franklin"</literal></expr></argument>, <argument><expr><name>date</name> <operator>=</operator> <literal type="string">"3/27/2003"</literal></expr></argument>)</argument_list></annotation>
<annotation>@<name>Inventor</name><argument_list>(<argument><expr><literal type="string">"Benjamin Franklin"</literal></expr></argument>)</argument_list></annotation>

enum definition


Element

Subelements

XPath Queries

  • enums

    //src:enum
  • enum names

    //src:enum/src:name

Example

enum Planet {
    MERCURY,
    VENUS,
    EARTH,
    MARS,
    JUPITER,
    SATURN,
    URANUS,
    NEPTUNE;
}
<enum>enum <name>Planet</name> <block>{
    <decl><name>MERCURY</name></decl>,
    <decl><name>VENUS</name></decl>,
    <decl><name>EARTH</name></decl>,
    <decl><name>MARS</name></decl>,
    <decl><name>JUPITER</name></decl>,
    <decl><name>SATURN</name></decl>,
    <decl><name>URANUS</name></decl>,
    <decl><name>NEPTUNE</name></decl>;
}</block></enum>

extends


Element

Subelement

XPath Queries

  • extends

    //src:extends
  • classes that inherit from BaseClass

    //src:class[src:super/src:extends/src:name[.='BaseClass']]

Example

class DerivedClass
	extends BaseClass
{ }
<class>class <name>DerivedClass</name>
	<super><extends>extends <name>BaseClass</name></extends></super>
<block>{ }</block></class>

implements


Element

Subelement

XPath Queries

  • implements

    //src:implements
  • classes which implement IVehicle

    //src:class[src:super/src:implements/src:name[.='IVehicle']]

Example

public class Truck implements IVehicle
{
}
<class><specifier>public</specifier> class <name>Truck</name> <super><implements>implements <name>IVehicle</name></implements></super>
<block>{
}</block></class>

constructor


Element

Subelements

XPath Query

  • constructors

    //src:constructor

Example

class MyType {
    MyType() { }
}
<class>class <name>MyType</name> <block>{
    <constructor><name>MyType</name><parameter_list>()</parameter_list> <block>{ }</block></constructor>
}</block></class>

receiver parameter


Element

XPath Query

  • constructors with a receiver parameter

    //src:constructor[src:parameter_list/src:parameter/src:decl/src:name/src:name[.='this']]

Example

public void foo(MyType MyType.this) { }
<function><specifier>public</specifier> <type><name>void</name></type> <name>foo</name><parameter_list>(<parameter><decl><type><name>MyType</name></type> <name><name>MyType</name><operator>.</operator><name>this</name></name></decl></parameter>)</parameter_list> <block>{ }</block></function>

static initialization block


Element

Subelement

XPath Query

  • static initialization blocks

    //src:static

Example

class Cls {
	static {

	}  
}
<class>class <name>Cls</name> <block>{
	<static>static <block>{

	}</block></static>  
}</block></class>

default annotation property value


Element

XPath Query

  • annotation properties with a default value

    //src:function_decl[src:default]

Example

   int currentRevision() default 1;
   String lastModified() default "N/A";
   <function_decl><type><name>int</name></type> <name>currentRevision</name><parameter_list>()</parameter_list> <default>default <init><expr><literal type="number">1</literal></expr></init></default>;</function_decl>
   <function_decl><type><name>String</name></type> <name>lastModified</name><parameter_list>()</parameter_list> <default>default <init><expr><literal type="string">"N/A"</literal></expr></init></default>;</function_decl>

super


Element

XPath Query

  • calls to a super constructor

    //src:call[src:name[.='super']]

Example

super(args)
<expr><call><name>super</name><argument_list>(<argument><expr><name>args</name></expr></argument>)</argument_list></call></expr>

import


Element

Subelement

XPath Query

  • import statements

    //src:import

Example

import java.io.File;
import java.net.*;
<import>import <name><name>java</name><operator>.</operator><name>io</name><operator>.</operator><name>File</name></name>;</import>
<import>import <name><name>java</name><operator>.</operator><name>net</name><operator>.</operator><name>*</name></name>;</import>

package


Element

Subelement

XPath Query

  • package declarations

    //src:package

Example

package com.mycompany;
<package>package <name><name>com</name><operator>.</operator><name>mycompany</name></name>;</package>

synchronized statement


Element

Subelements

XPath Query

  • synchronization statements

    //src:synchronized

Example

synchronized (syncObj) {
}
<synchronized>synchronized <init>(<expr><name>syncObj</name></expr>)</init> <block>{
}</block></synchronized>

throw


Element

Subelement

XPath Query

  • uses of throw

    //src:throw

Example

throw new IOException("error reading file");
<throw>throw <expr><operator>new</operator> <call><name>IOException</name><argument_list>(<argument><expr><literal type="string">"error reading file"</literal></expr></argument>)</argument_list></call></expr>;</throw>

throws


Element

Subelement

XPath Queries

  • uses of throws

    //src:throws
  • functions with a throws specification

    //src:function[src:throws]

Examples

public void readFile(String filename) throws IOException {
}
<function><specifier>public</specifier> <type><name>void</name></type> <name>readFile</name><parameter_list>(<parameter><decl><type><name>String</name></type> <name>filename</name></decl></parameter>)</parameter_list> <throws>throws <argument><expr><name>IOException</name></expr></argument></throws> <block>{
}</block></function>
public MyOtherType foo() throws MyExceptionType throws MyExceptionType2 { }
<function><specifier>public</specifier> <type><name>MyOtherType</name></type> <name>foo</name><parameter_list>()</parameter_list> <throws>throws <argument><expr><name>MyExceptionType</name> <throws>throws <argument><expr><name>MyExceptionType2</name> <block>{ }</block></expr></argument></throws></expr></argument></throws></function>
public MyOtherType foo() throws MyExceptionType, MyExceptionType2 { }
<function><specifier>public</specifier> <type><name>MyOtherType</name></type> <name>foo</name><parameter_list>()</parameter_list> <throws>throws <argument><expr><name>MyExceptionType</name></expr></argument>, <argument><expr><name>MyExceptionType2</name></expr></argument></throws> <block>{ }</block></function>
throws MyExceptionType, MyExceptionType2
<throws>throws <argument><expr><name>MyExceptionType</name></expr></argument>, <argument><expr><name>MyExceptionType2</name></expr></argument></throws>

try


Element

Subelements

XPath Queries

  • try blocks

    //src:try
  • try blocks with a resource list

    //src:try[src:init]
  • try blocks with only a finally block

    //src:try[src:finally][not(src:catch)]
  • try blocks with a catch and a finally block

    //src:try[src:finally][src:catch]

Examples

try {

} finally {
	
} 
<try>try <block>{

}</block> <finally>finally <block>{
	
}</block></finally></try> 
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
	return br.readLine();
}
<try>try <init>(<decl><type><name>BufferedReader</name></type> <name>br</name> <init>= <expr><operator>new</operator> <call><name>BufferedReader</name><argument_list>(<argument><expr><operator>new</operator> <call><name>FileReader</name><argument_list>(<argument><expr><name>path</name></expr></argument>)</argument_list></call></expr></argument>)</argument_list></call></expr></init></decl>)</init> <block>{
	<return>return <expr><call><name><name>br</name><operator>.</operator><name>readLine</name></name><argument_list>()</argument_list></call></expr>;</return>
}</block></try>
try {

} catch(Exception varName) {
	
}
<try>try <block>{

}</block> <catch>catch<parameter_list>(<parameter><decl><type><name>Exception</name></type> <name>varName</name></decl></parameter>)</parameter_list> <block>{
	
}</block></catch></try>

finally


Element

Subelement

XPath Query

  • finally blocks

    //src:finally

Example

try {

} catch (Exception e) {

} finally {
	
} 
<try>try <block>{

}</block> <catch>catch <parameter_list>(<parameter><decl><type><name>Exception</name></type> <name>e</name></decl></parameter>)</parameter_list> <block>{

}</block></catch> <finally>finally <block>{
	
}</block></finally></try> 

generic class definition


Element

Subelements

XPath Query

  • generic classes

    //src:class[src:name/src:parameter_list]

Example

class Box<T> {
}
<class>class <name><name>Box</name><parameter_list>&lt;<parameter><name>T</name></parameter>&gt;</parameter_list></name> <block>{
}</block></class>

bound generic parameter


Element

Subelement

XPath Queries

  • bound generic parameters

    //src:argument[src:extends]
  • classes with a bound generic parameter

    //src:class[src:name/src:parameter_list/src:parameter/src:extends]
  • methods with a bound generic parameter

    //src:function[src:type/src:argument_list/src:argument/src:extends]

Examples

public <U extends Number> void inspect(U u){
}
<function><specifier>public</specifier> <parameter_list type="generic">&lt;<parameter><name>U</name> <extends>extends <name>Number</name></extends></parameter>&gt;</parameter_list> <type><name>void</name></type> <name>inspect</name><parameter_list>(<parameter><decl><type><name>U</name></type> <name>u</name></decl></parameter>)</parameter_list><block>{
}</block></function>
<T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) { }
<function><parameter_list type="generic">&lt;<parameter><name>T</name> <extends>extends <name><name>Comparable</name><argument_list type="generic">&lt;<argument><name>T</name></argument>&gt;</argument_list></name></extends></parameter>&gt;</parameter_list> <type><name>int</name></type> <name>countGreaterThan</name><parameter_list>(<parameter><decl><type><name><name>T</name><index>[]</index></name></type> <name>anArray</name></decl></parameter>, <parameter><decl><type><name>T</name></type> <name>elem</name></decl></parameter>)</parameter_list> <block>{ }</block></function>
<T extends Foo & Bar> void doSomething(T input) {
}
<function><parameter_list type="generic">&lt;<parameter><name>T</name> <extends>extends <name>Foo</name></extends> <operator>&amp;</operator> <name>Bar</name></parameter>&gt;</parameter_list> <type><name>void</name></type> <name>doSomething</name><parameter_list>(<parameter><decl><type><name>T</name></type> <name>input</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

generic wildcard


Element

Subelement

XPath Queries

  • functions with a generic wildcard parameter that has an upper bound

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:name/src:argument_list/src:argument[src:name[.='?']][src:extends]]
  • functions with a generic wildcard parameter that is unbound

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:name/src:argument_list/src:argument[src:name[.='?']][not(src:extends)][not(src:super)]]
  • functions with a generic wildcard parameter that has a lower bound

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:name/src:argument_list/src:argument[src:name[.='?']][src:super]]

Examples

upper bound wildcard

public static void process(List<? extends Foo> list) { }
<function><specifier>public</specifier> <specifier>static</specifier> <type><name>void</name></type> <name>process</name><parameter_list>(<parameter><decl><type><name><name>List</name><argument_list type="generic">&lt;<argument><name>?</name> <extends>extends <name>Foo</name></extends></argument>&gt;</argument_list></name></type> <name>list</name></decl></parameter>)</parameter_list> <block>{ }</block></function>

unbound wildcard

void printList(List<?> list) { }
<function><type><name>void</name></type> <name>printList</name><parameter_list>(<parameter><decl><type><name><name>List</name><argument_list type="generic">&lt;<argument><name>?</name></argument>&gt;</argument_list></name></type> <name>list</name></decl></parameter>)</parameter_list> <block>{ }</block></function>

lower bound wildcard

void addNumbers(List<? super Integer> list) { }
<function><type><name>void</name></type> <name>addNumbers</name><parameter_list>(<parameter><decl><type><name><name>List</name><argument_list type="generic">&lt;<argument><name>?</name> <super>super <name>Integer</name></super></argument>&gt;</argument_list></name></type> <name>list</name></decl></parameter>)</parameter_list> <block>{ }</block></function>