# Class CompilationRule

java.lang.Object
com.google.testing.compile.CompilationRule

All Implemented Interfaces:
  `org.junit.rules.TestRule`

public final class CompilationRule extends Object implements org.junit.rules.TestRule
A `JUnit4` `Rule` that executes tests such that a instances of `Elements` and `Types` are available during execution.

To use this rule in a test, just add the following field:

    @Rule public CompilationRule compilationRule = new CompilationRule();

Author:
  Gregory Kick

## Constructor Summary

Constructors
Constructor
Description
`CompilationRule()`

## Method Summary

Modifier and Type
Method
Description
`org.junit.runners.model.Statement`
`apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)`
`Elements`
`getElements()`
Returns the `Elements` instance associated with the current execution of the rule.
`Types`
`getTypes()`
Returns the `Types` instance associated with the current execution of the rule.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CompilationRule

public CompilationRule()

## Method Details

### apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)

Specified by:
  `apply` in interface `org.junit.rules.TestRule`

### getElements

public Elements getElements()
Returns the `Elements` instance associated with the current execution of the rule.

Throws:
  `IllegalStateException` - if this method is invoked outside the execution of the rule.

### getTypes

public Types getTypes()
Returns the `Types` instance associated with the current execution of the rule.

Throws:
  `IllegalStateException` - if this method is invoked outside the execution of the rule.