language-java-0.2.6: Manipulating Java source: abstract syntax, lexer, parser, and pretty-printer

Safe HaskellSafe-Inferred




data CompilationUnit Source

A compilation unit is the top level syntactic goal symbol of a Java program.

data PackageDecl Source

A package declaration appears within a compilation unit to indicate the package to which the compilation unit belongs.


PackageDecl Name 

data ImportDecl Source

An import declaration allows a static member or a named type to be referred to by a single unqualified identifier. The first argument signals whether the declaration only imports static members. The last argument signals whether the declaration brings all names in the named type or package, or only brings a single name into scope.


ImportDecl Bool Name Bool 

data TypeDecl Source

A type declaration declares a class type or an interface type.

data ClassDecl Source

A class declaration specifies a new named reference type.

data ClassBody Source

A class body may contain declarations of members of the class, that is, fields, classes, interfaces and methods. A class body may also contain instance initializers, static initializers, and declarations of constructors for the class.


ClassBody [Decl] 

data EnumBody Source

The body of an enum type may contain enum constants.


EnumBody [EnumConstant] [Decl] 

data EnumConstant Source

An enum constant defines an instance of the enum type.

data InterfaceDecl Source

An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.

data InterfaceBody Source

The body of an interface may declare members of the interface.


InterfaceBody [MemberDecl] 

data Decl Source

A declaration is either a member declaration, or a declaration of an initializer, which may be static.

data MemberDecl Source

A class or interface member can be an inner class or interface, a field or constant, or a method or constructor. An interface may only have as members constants (not fields), abstract methods, and no constructors.


FieldDecl [Modifier] Type [VarDecl]

The variables of a class type are introduced by field declarations.

MethodDecl [Modifier] [TypeParam] (Maybe Type) Ident [FormalParam] [ExceptionType] MethodBody

A method declares executable code that can be invoked, passing a fixed number of values as arguments.

ConstructorDecl [Modifier] [TypeParam] Ident [FormalParam] [ExceptionType] ConstructorBody

A constructor is used in the creation of an object that is an instance of a class.

MemberClassDecl ClassDecl

A member class is a class whose declaration is directly enclosed in another class or interface declaration.

MemberInterfaceDecl InterfaceDecl

A member interface is an interface whose declaration is directly enclosed in another class or interface declaration.

data VarDecl Source

A declaration of a variable, which may be explicitly initialized.


VarDecl VarDeclId (Maybe VarInit) 

data VarDeclId Source

The name of a variable in a declaration, which may be an array.


VarId Ident 
VarDeclArray VarDeclId

Multi-dimensional arrays are represented by nested applications of VarDeclArray.

data VarInit Source

Explicit initializer for a variable declaration.

data FormalParam Source

A formal parameter in method declaration. The last parameter for a given declaration may be marked as variable arity, indicated by the boolean argument.

data MethodBody Source

A method body is either a block of code that implements the method or simply a semicolon, indicating the lack of an implementation (modelled by Nothing).


MethodBody (Maybe Block) 

data ConstructorBody Source

The first statement of a constructor body may be an explicit invocation of another constructor of the same class or of the direct superclass.

data ExplConstrInv Source

An explicit constructor invocation invokes another constructor of the same class, or a constructor of the direct superclass, which may be qualified to explicitly specify the newly created object's immediately enclosing instance.

data Modifier Source

A modifier specifying properties of a given declaration. In general only a few of these modifiers are allowed for each declaration type, for instance a member type declaration may only specify one of public, private or protected.

data Annotation Source

Annotations have three different forms: no-parameter, single-parameter or key-value pairs

data ElementValue Source

Annotations may contain annotations or (loosely) expressions


EVVal VarInit 
EVAnn Annotation 

data Block Source

A block is a sequence of statements, local class declarations and local variable declaration statements within braces.


Block [BlockStmt] 

data BlockStmt Source

A block statement is either a normal statement, a local class declaration or a local variable declaration.

data Stmt Source

A Java statement.


StmtBlock Block

A statement can be a nested block.

IfThen Exp Stmt

The if-then statement allows conditional execution of a statement.

IfThenElse Exp Stmt Stmt

The if-then-else statement allows conditional choice of two statements, executing one or the other but not both.

While Exp Stmt

The while statement executes an expression and a statement repeatedly until the value of the expression is false.

BasicFor (Maybe ForInit) (Maybe Exp) (Maybe [Exp]) Stmt

The basic for statement executes some initialization code, then executes an expression, a statement, and some update code repeatedly until the value of the expression is false.

EnhancedFor [Modifier] Type Ident Exp Stmt

The enhanced for statement iterates over an array or a value of a class that implements the iterator interface.


An empty statement does nothing.

ExpStmt Exp

Certain kinds of expressions may be used as statements by following them with semicolons: assignments, pre- or post-inc- or decrementation, method invocation or class instance creation expressions.

Assert Exp (Maybe Exp)

An assertion is a statement containing a boolean expression, where an error is reported if the expression evaluates to false.

Switch Exp [SwitchBlock]

The switch statement transfers control to one of several statements depending on the value of an expression.

Do Stmt Exp

The do statement executes a statement and an expression repeatedly until the value of the expression is false.

Break (Maybe Ident)

A break statement transfers control out of an enclosing statement.

Continue (Maybe Ident)

A continue statement may occur only in a while, do, or for statement. Control passes to the loop-continuation point of that statement.

Return (Maybe Exp) 
Synchronized Exp Block

A synchronized statement acquires a mutual-exclusion lock on behalf of the executing thread, executes a block, then releases the lock. While the executing thread owns the lock, no other thread may acquire the lock.

Throw Exp

A throw statement causes an exception to be thrown.

Try Block [Catch] (Maybe Block)

A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If the try statement has a finally clause, then another block of code is executed, no matter whether the try block completes normally or abruptly, and no matter whether a catch clause is first given control.

Labeled Ident Stmt

Statements may have label prefixes.

data Catch Source

If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause.


Catch FormalParam Block 

data SwitchBlock Source

A block of code labelled with a case or default within a switch statement.

data SwitchLabel Source

A label within a switch statement.


SwitchCase Exp

The expression contained in the case must be a Lit or an enum constant.


data ForInit Source

Initialization code for a basic for statement.

type ExceptionType = RefTypeSource

An exception type has to be a class type or a type variable.

type Argument = ExpSource

Arguments to methods and constructors are expressions.

data Exp Source

A Java expression.


Lit Literal

A literal denotes a fixed, unchanging value.

ClassLit (Maybe Type)

A class literal, which is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void (modelled by Nothing), followed by a . and the token class.


The keyword this denotes a value that is a reference to the object for which the instance method was invoked, or to the object being constructed.

ThisClass Name

Any lexically enclosing instance can be referred to by explicitly qualifying the keyword this.

InstanceCreation [TypeArgument] ClassType [Argument] (Maybe ClassBody)

A class instance creation expression is used to create new objects that are instances of classes. | The first argument is a list of non-wildcard type arguments to a generic constructor. What follows is the type to be instantiated, the list of arguments passed to the constructor, and optionally a class body that makes the constructor result in an object of an anonymous class.

QualInstanceCreation Exp [TypeArgument] Ident [Argument] (Maybe ClassBody)

A qualified class instance creation expression enables the creation of instances of inner member classes and their anonymous subclasses.

ArrayCreate Type [Exp] Int

An array instance creation expression is used to create new arrays. The last argument denotes the number of dimensions that have no explicit length given. These dimensions must be given last.

ArrayCreateInit Type Int ArrayInit

An array instance creation expression may come with an explicit initializer. Such expressions may not be given explicit lengths for any of its dimensions.

FieldAccess FieldAccess

A field access expression.

MethodInv MethodInvocation

A method invocation expression.

ArrayAccess ArrayIndex

An array access expression refers to a variable that is a component of an array.

ExpName Name

An expression name, e.g. a variable.

PostIncrement Exp

Post-incrementation expression, i.e. an expression followed by ++.

PostDecrement Exp

Post-decrementation expression, i.e. an expression followed by --.

PreIncrement Exp

Pre-incrementation expression, i.e. an expression preceded by ++.

PreDecrement Exp

Pre-decrementation expression, i.e. an expression preceded by --.

PrePlus Exp

Unary plus, the promotion of the value of the expression to a primitive numeric type.

PreMinus Exp

Unary minus, the promotion of the negation of the value of the expression to a primitive numeric type.

PreBitCompl Exp

Unary bitwise complementation: note that, in all cases, ~x equals (-x)-1.

PreNot Exp

Logical complementation of boolean values.

Cast Type Exp

A cast expression converts, at run time, a value of one numeric type to a similar value of another numeric type; or confirms, at compile time, that the type of an expression is boolean; or checks, at run time, that a reference value refers to an object whose class is compatible with a specified reference type.

BinOp Exp Op Exp

The application of a binary operator to two operand expressions.

InstanceOf Exp RefType

Testing whether the result of an expression is an instance of some reference type.

Cond Exp Exp Exp

The conditional operator ? : uses the boolean value of one expression to decide which of two other expressions should be evaluated.

Assign Lhs AssignOp Exp

Assignment of the result of an expression to a variable.

data Literal Source

A literal denotes a fixed, unchanging value.

data Op Source

A binary infix operator.


data Lhs Source

The left-hand side of an assignment expression. This operand may be a named variable, such as a local variable or a field of the current object or class, or it may be a computed variable, as can result from a field access or an array access.


NameLhs Name

Assign to a variable

FieldLhs FieldAccess

Assign through a field access

ArrayLhs ArrayIndex

Assign to an array

data ArrayIndex Source

Array access


ArrayIndex Exp Exp

Index into an array

data FieldAccess Source

A field access expression may access a field of an object or array, a reference to which is the value of either an expression or the special keyword super.


PrimaryFieldAccess Exp Ident

Accessing a field of an object or array computed from an expression.

SuperFieldAccess Ident

Accessing a field of the superclass.

ClassFieldAccess Name Ident

Accessing a (static) field of a named class.

data MethodInvocation Source

A method invocation expression is used to invoke a class or instance method.


MethodCall Name [Argument]

Invoking a specific named method.

PrimaryMethodCall Exp [RefType] Ident [Argument]

Invoking a method of a class computed from a primary expression, giving arguments for any generic type parameters.

SuperMethodCall [RefType] Ident [Argument]

Invoking a method of the super class, giving arguments for any generic type parameters.

ClassMethodCall Name [RefType] Ident [Argument]

Invoking a method of the superclass of a named class, giving arguments for any generic type parameters.

TypeMethodCall Name [RefType] Ident [Argument]

Invoking a method of a named type, giving arguments for any generic type parameters.

data ArrayInit Source

An array initializer may be specified in a declaration, or as part of an array creation expression, creating an array and providing some initial values


ArrayInit [VarInit] 

data Type Source

There are two kinds of types in the Java programming language: primitive types and reference types.

data RefType Source

There are three kinds of reference types: class types, interface types, and array types. Reference types may be parameterized with type arguments. Type variables cannot be syntactically distinguished from class type identifiers, and are thus represented uniformly as single ident class types.


ClassRefType ClassType 
ArrayType Type

TypeVariable Ident

data ClassType Source

A class or interface type consists of a type declaration specifier, optionally followed by type arguments (in which case it is a parameterized type).


ClassType [(Ident, [TypeArgument])] 

data TypeArgument Source

Type arguments may be either reference types or wildcards.

data WildcardBound Source

Wildcards may be given explicit bounds, either upper (extends) or lower (super) bounds.

data PrimType Source

A primitive type is predefined by the Java programming language and named by its reserved keyword.

data TypeParam Source

A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class.


TypeParam Ident [RefType] 

data Ident Source

A single identifier.


Ident String 

data Name Source

A name, i.e. a period-separated list of identifiers.


Name [Ident]