Class ServiceContracts

java.lang.Object
io.helidon.service.codegen.ServiceContracts

public class ServiceContracts extends Object
Handling of eligible contracts.

Contract is eligible if it is annotated with Service.Contract, or referenced from service type or its super types via Service.ExternalContracts.

In case the option ServiceOptions.AUTO_ADD_NON_CONTRACT_INTERFACES is set to true, all types are eligible (including classes and not contract annotated types).

  • Method Details

    • create

      public static ServiceContracts create(CodegenOptions options, Function<TypeName,Optional<TypeInfo>> typeInfoFactory, TypeInfo serviceInfo)
      Create new eligible contracts.
      Parameters:
      options - codegen options
      typeInfoFactory - function to obtain a type info (if possible) based on type name
      serviceInfo - service info to analyze
      Returns:
      a new instance to check if an implemented interface or a super type is a contract or not
    • requiredTypeArgument

      public static TypeName requiredTypeArgument(TypeInfo typeInfo, int index)
      Get the desired type parameter of the type info provided.
      Parameters:
      typeInfo - type info to analyze (such as an implemented interface Supplier<String>
      index - index of the type arguments (such as 0)
      Returns:
      the type argument at the requested index, such as java.lang.String
      Throws:
      CodegenException - in case the type argument is not available
    • isEligible

      public boolean isEligible(TypeInfo contractInfo)
      Check if a type info is eligible to be a contract.
      Parameters:
      contractInfo - candidate type info
      Returns:
      whether the candidate is a contract or not
    • isEligible

      public boolean isEligible(TypeName contractType)
      Check if a type is eligible to be a contract.
      Parameters:
      contractType - candidate type
      Returns:
      whether the candidate is a contract or not
    • analyseFactory

      public ServiceContracts.FactoryAnalysis analyseFactory(TypeName factoryInterface)
      Analyse the service info if it is in fact a factory of the expected type.
      Parameters:
      factoryInterface - the provider we check, the provided contract must be the first type argument
      Returns:
      result of the analysis
    • addContracts

      public void addContracts(Set<ResolvedType> contractSet, HashSet<ResolvedType> processed, TypeInfo typeInfo)
      Add contracts from the type (from its implemented interfaces and super types).
      Parameters:
      contractSet - set of contracts to amend with the contracts of the provided type info
      processed - set of processed contracts, to avoid infinite loop
      typeInfo - type info to analyze for contracts