Skip to content

pragmatic-objects/oo-structsubtype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OO-Structsubtype

Travis AppVeyor Codecov

Annoation processor that enables declaring Java interfaces with imitation of structural subtyping support

Quick start

  1. Add maven dependency:
<dependency>
    <groupId>com.pragmaticobjects.oo.structsubtype</groupId>
    <artifactId>structsubtype-codegen</artifactId>
    <version>x.y.z</version>
</dependency>
  1. Declare some interfaces:
interface UserName {
    String userName();
}

interface UserAddress {
    String zip();
    String address();
}
  1. Place @StructSubtype declaration to the package-info.java of the package where you want the subtype to be generated
@StructSubtype(name = "User", inherits = { UserName.class, UserAddress.class }
package com.example;

import com.pragmaticobjects.oo.structsubtype.api.StructSubtype;
  1. Build the project. A source for new type will be generated at the annotated package. The type will be substitutable at each of it's testators.
interface User extends UserName, UserAddress {}

Note that generated interfaces within one package may be subtypes of each other, if one inherits all features of the other:

@StructSubtype(name = "Recipient", inherits = { UserName.class, UserAddress.class }
@StructSubtype(name = "PassportIdentity", inherits = { UserName.class, PassportId.class }
@StructSubtype(name = "User", inherits = { UserName.class, PassportId.class, UserAddress.class  }
package com.example;
// Since `User` inherits every feature of `Recipient` and `PassportIdentity`, it is considered as a subtype of them.
interface User extends UserName, PassportId, UserAddress, Recipient, PassportIdentity {}

About

Structural subtyping support for Java interfaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published