- data CompilationUnit = CompilationUnit (Maybe PackageDecl) [ImportDecl] [TypeDecl]
- data PackageDecl = PackageDecl Name
- data ImportDecl = ImportDecl Bool Name Bool
- data TypeDecl
- data ClassDecl
- data ClassBody = ClassBody [Decl]
- data EnumBody = EnumBody [EnumConstant] [Decl]
- data EnumConstant = EnumConstant Ident [Argument] (Maybe ClassBody)
- data InterfaceDecl = InterfaceDecl [Modifier] Ident [TypeParam] [RefType] InterfaceBody
- data InterfaceBody = InterfaceBody [MemberDecl]
- data Decl
- data MemberDecl
- data VarDecl = VarDecl VarDeclId (Maybe VarInit)
- data VarDeclId
- data VarInit
- data FormalParam = FormalParam [Modifier] Type Bool VarDeclId
- data MethodBody = MethodBody (Maybe Block)
- data ConstructorBody = ConstructorBody (Maybe ExplConstrInv) [BlockStmt]
- data ExplConstrInv
- data Modifier
- data Annotation
- desugarAnnotation :: Annotation -> (Name, [(Ident, ElementValue)])
- desugarAnnotation' :: Annotation -> Annotation
- data ElementValue
- data Block = Block [BlockStmt]
- data BlockStmt
- data Stmt
- = StmtBlock Block
- | IfThen Exp Stmt
- | IfThenElse Exp Stmt Stmt
- | While Exp Stmt
- | BasicFor (Maybe ForInit) (Maybe Exp) (Maybe [Exp]) Stmt
- | EnhancedFor [Modifier] Type Ident Exp Stmt
- | Empty
- | ExpStmt Exp
- | Assert Exp (Maybe Exp)
- | Switch Exp [SwitchBlock]
- | Do Stmt Exp
- | Break (Maybe Ident)
- | Continue (Maybe Ident)
- | Return (Maybe Exp)
- | Synchronized Exp Block
- | Throw Exp
- | Try Block [Catch] (Maybe Block)
- | Labeled Ident Stmt
- data Catch = Catch FormalParam Block
- data SwitchBlock = SwitchBlock SwitchLabel [BlockStmt]
- data SwitchLabel
- data ForInit
- type ExceptionType = RefType
- type Argument = Exp
- data Exp
- = Lit Literal
- | ClassLit (Maybe Type)
- | This
- | ThisClass Name
- | InstanceCreation [TypeArgument] ClassType [Argument] (Maybe ClassBody)
- | QualInstanceCreation Exp [TypeArgument] Ident [Argument] (Maybe ClassBody)
- | ArrayCreate Type [Exp] Int
- | ArrayCreateInit Type Int ArrayInit
- | FieldAccess FieldAccess
- | MethodInv MethodInvocation
- | ArrayAccess ArrayIndex
- | ExpName Name
- | PostIncrement Exp
- | PostDecrement Exp
- | PreIncrement Exp
- | PreDecrement Exp
- | PrePlus Exp
- | PreMinus Exp
- | PreBitCompl Exp
- | PreNot Exp
- | Cast Type Exp
- | BinOp Exp Op Exp
- | InstanceOf Exp RefType
- | Cond Exp Exp Exp
- | Assign Lhs AssignOp Exp
- data Literal
- data Op
- data AssignOp
- data Lhs
- data ArrayIndex = ArrayIndex Exp Exp
- data FieldAccess
- data MethodInvocation
- data ArrayInit = ArrayInit [VarInit]
- data Type
- data RefType
- data ClassType = ClassType [(Ident, [TypeArgument])]
- data TypeArgument
- data WildcardBound
- data PrimType
- data TypeParam = TypeParam Ident [RefType]
- data Ident = Ident String
- data Name = Name [Ident]
A compilation unit is the top level syntactic goal symbol of a Java program.
A package declaration appears within a compilation unit to indicate the package to which the compilation unit belongs.
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.
A type declaration declares a class type or an interface type.
A class declaration specifies a new named reference type.
|ClassDecl [Modifier] Ident [TypeParam] (Maybe RefType) [RefType] ClassBody|
|EnumDecl [Modifier] Ident [RefType] EnumBody|
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.
The body of an enum type may contain enum constants.
An enum constant defines an instance of the enum type.
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.
The body of an interface may declare members of the interface.
A declaration is either a member declaration, or a declaration of an initializer, which may be static.
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.
A member class is a class whose declaration is directly enclosed in another class or interface declaration.
A member interface is an interface whose declaration is directly enclosed in another class or interface declaration.
A declaration of a variable, which may be explicitly initialized.
The name of a variable in a declaration, which may be an array.
Multi-dimensional arrays are represented by nested applications of
Explicit initializer for a variable declaration.
A formal parameter in method declaration. The last parameter for a given declaration may be marked as variable arity, indicated by the boolean argument.
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
The first statement of a constructor body may be an explicit invocation of another constructor of the same class or of the direct superclass.
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.
|ThisInvoke [RefType] [Argument]|
|SuperInvoke [RefType] [Argument]|
|PrimarySuperInvoke Exp [RefType] [Argument]|
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.
Annotations have three different forms: no-parameter, single-parameter or key-value pairs
Annotations may contain annotations or (loosely) expressions
A block is a sequence of statements, local class declarations and local variable declaration statements within braces.
A block statement is either a normal statement, a local class declaration or a local variable declaration.
A Java statement.
A statement can be a nested block.
|IfThen Exp Stmt|
|IfThenElse Exp Stmt Stmt|
|While Exp Stmt|
|BasicFor (Maybe ForInit) (Maybe Exp) (Maybe [Exp]) Stmt|
|EnhancedFor [Modifier] Type Ident Exp Stmt|
An empty statement does nothing.
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|
|Break (Maybe Ident)|
|Continue (Maybe Ident)|
|Return (Maybe Exp)|
|Synchronized Exp Block|
|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.
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.
A block of code labelled with a
default within a
A label within a
Initialization code for a basic
A Java expression.
A literal denotes a fixed, unchanging value.
|ClassLit (Maybe Type)|
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.
A field access expression.
A method invocation expression.
An array access expression refers to a variable that is a component of an array.
An expression name, e.g. a variable.
Post-incrementation expression, i.e. an expression followed by
Post-decrementation expression, i.e. an expression followed by
Pre-incrementation expression, i.e. an expression preceded by
Pre-decrementation expression, i.e. an expression preceded by
Unary plus, the promotion of the value of the expression to a primitive numeric type.
Unary minus, the promotion of the negation of the value of the expression to a primitive numeric type.
Unary bitwise complementation: note that, in all cases,
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
|Assign Lhs AssignOp Exp|
Assignment of the result of an expression to a variable.
A literal denotes a fixed, unchanging value.
A binary infix operator.
An assignment operator.
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.
Assign to a variable
Assign through a field access
Assign to an array
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.
Accessing a field of the superclass.
|ClassFieldAccess Name Ident|
Accessing a (static) field of a named class.
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.
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
There are two kinds of types in the Java programming language: primitive types and reference types.
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.
A class or interface type consists of a type declaration specifier, optionally followed by type arguments (in which case it is a parameterized type).
Type arguments may be either reference types or wildcards.
Wildcards may be given explicit bounds, either upper (
extends) or lower (
A primitive type is predefined by the Java programming language and named by its reserved keyword.
A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class.
A single identifier.