Skip to content

Annotations

Timm Friebe edited this page Jun 9, 2018 · 6 revisions

XP Compiler supports annotations with HHVM's attributes syntax. Annotations can be placed on types, methods, fields as well as method parameters.

The most simple form of an annotation is simply its name as a literal, e.g. test. Annotations may have a value, which is enclosed in braces, e.g. author('Timm Friebe'). Annotations are surrounded by << and >>, and separated by commas.

use unittest\actions\RuntimeVersion;
use Unittest\TestCase;

<<action(new RuntimeVersion('>=7.0'))>>
class FixtureTest extends TestCase {

  <<test>>
  public function can_create() {
    new Fixture('http://url');
  }

  <<test, expect(IllegalArgumentException::class>>
  public function cannot_create_with_malformed_host() {
    new Fixture('http:--');
  }
}

The value inside an annotation can be any of the following:

  • A primitive value
  • An array
  • A map
  • A class constant, including the ::class special constant
  • A static member variable
  • An instance creation expression, as seen above
  • A function
Clone this wiki locally