Annotation Interface Conduit


@Retention(RUNTIME) @Target(TYPE) public @interface Conduit
Declares an interface as a view over a class in the scanned jar.

Conduit never loads or runs the classes it scans, so a value it reconstructs (a constructor call, a factory call, a builder chain) is not an instance of anything. A conduit gives that value a typed face. Each method on the interface reads one piece of it, worked out from the bytecode that built it.

@Conduit("com.example.Color")
public interface Color {
    int red();
    int green();
    int blue();
}

A conduit can be returned from another conduit, or taken as a parameter by an Intercept handler, and is wrapped as needed.

Resolving a method

Each call on a conduit is resolved against the reconstructed value, in this order:

  1. Conduit.Implementation returns the class the value resolves to.
  2. Conduit.Bind entries, tried in the order they are declared.
  3. Method.Calls and Method.Chain, narrowed by Argument.Index.
  4. Method.Index, then Argument.Index on its own.
  5. Otherwise the method name (or Argument.Named) is looked up on the target class as a field assigned in its constructor, or as a method whose return value can be evaluated. A get or is prefix is dropped when looking for a field.
  6. Failing all of that, the method's position in the interface is used as an argument index into the constructor or factory call.

A method that cannot be resolved returns null, or an empty List, Set or Map for collection types. Boxed types such as Integer over int are preferred since a primitive cannot hold the missing case.

Conduits are usually generated from the real class rather than written by hand. See org.geysermc.conduit.generate.ConduitGenerator.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Describes one place a conduit method's value can come from.
    static @interface 
    Container for repeated Conduit.Bind entries.
    static @interface 
    Marks a method that returns the binary name of the class implementing this conduit's target, or null if it cannot be told.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The binary name of the class this conduit mirrors, such as "com.example.Color" or "com.example.Outer$Inner".
  • Element Details

    • value

      String value
      The binary name of the class this conduit mirrors, such as "com.example.Color" or "com.example.Outer$Inner".
      Returns:
      the target class name