Package net.morimekta.providence.types
Class SimpleTypeRegistry
- java.lang.Object
-
- net.morimekta.providence.types.TypeRegistry
-
- net.morimekta.providence.types.WritableTypeRegistry
-
- net.morimekta.providence.types.SimpleTypeRegistry
-
public class SimpleTypeRegistry extends WritableTypeRegistry
Registry for declared types referenced in a flat space program context. The registry itself does not have a context per se, as these may reference each other recursively. Note that this registry does not handle situations where two programs with the same name exist with a type each with the same name.
-
-
Constructor Summary
Constructors Constructor Description SimpleTypeRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.util.Optional<T>
getConstantValue(TypeReference reference)
This is to check to find a constant given the const name and program context.java.util.Optional<PDeclaredDescriptor<?>>
getDeclaredType(TypeReference reference)
Get the declared type with the given name and program context.java.util.List<PDeclaredDescriptor<?>>
getDeclaredTypes()
java.util.Optional<PService>
getService(TypeReference reference)
Get a service definition from the name and program context.java.util.Optional<TypeReference>
getTypedef(TypeReference reference)
Get a type-definition for the given reference.boolean
isKnownProgram(java.lang.String programName)
void
registerConstant(TypeReference reference, PValueProvider value)
Register a constant value.void
registerService(PService service)
Services are not handled as "declared types", so they need to be registered separately.<T> void
registerType(PDeclaredDescriptor<T> declaredType)
Register a declared type.void
registerTypedef(TypeReference reference, TypeReference target)
Registers a typedef definition.-
Methods inherited from class net.morimekta.providence.types.TypeRegistry
finalTypeReference, getServiceProvider, getTypeProvider, getTypeProvider, requireDeclaredType, requireEnumType, requireMessageType, requireService
-
-
-
-
Method Detail
-
isKnownProgram
public boolean isKnownProgram(@Nonnull java.lang.String programName)
- Specified by:
isKnownProgram
in classTypeRegistry
- Parameters:
programName
- The program name.- Returns:
- True if the program is known in this registry.
-
getTypedef
@Nonnull public java.util.Optional<TypeReference> getTypedef(@Nonnull TypeReference reference)
Description copied from class:TypeRegistry
Get a type-definition for the given reference.- Specified by:
getTypedef
in classTypeRegistry
- Parameters:
reference
- The typedef reference.- Returns:
- Optional typedef definition.
-
getDeclaredTypes
public java.util.List<PDeclaredDescriptor<?>> getDeclaredTypes()
- Specified by:
getDeclaredTypes
in classTypeRegistry
-
getDeclaredType
@Nonnull public java.util.Optional<PDeclaredDescriptor<?>> getDeclaredType(@Nonnull TypeReference reference)
Description copied from class:TypeRegistry
Get the declared type with the given name and program context.- Specified by:
getDeclaredType
in classTypeRegistry
- Parameters:
reference
- The reference to the type.- Returns:
- Optional type descriptor.
-
getService
@Nonnull public java.util.Optional<PService> getService(@Nonnull TypeReference reference)
Description copied from class:TypeRegistry
Get a service definition from the name and program context.- Specified by:
getService
in classTypeRegistry
- Parameters:
reference
- The service reference.- Returns:
- Optional service descriptor.
-
getConstantValue
@Nonnull public <T> java.util.Optional<T> getConstantValue(@Nonnull TypeReference reference)
Description copied from class:TypeRegistry
This is to check to find a constant given the const name and program context. This will return empty if the constant does not exist.- Specified by:
getConstantValue
in classTypeRegistry
- Type Parameters:
T
- The returned value type.- Parameters:
reference
- The constant reference.- Returns:
- The optional const value.
-
registerTypedef
public void registerTypedef(@Nonnull TypeReference reference, @Nonnull TypeReference target)
Description copied from class:WritableTypeRegistry
Registers a typedef definition. This is a pair of two type references. One for the reference itself, and one for the target type definition, including the local program context where it was defined.- Specified by:
registerTypedef
in classWritableTypeRegistry
- Parameters:
reference
- The typedef reference source..target
- The qualified type definition that the name represents with it's own context.
-
registerConstant
public void registerConstant(@Nonnull TypeReference reference, @Nonnull PValueProvider value)
Description copied from class:WritableTypeRegistry
Register a constant value.- Specified by:
registerConstant
in classWritableTypeRegistry
- Parameters:
reference
- The constant reference.value
- The constant value.
-
registerService
public void registerService(@Nonnull PService service)
Description copied from class:WritableTypeRegistry
Services are not handled as "declared types", so they need to be registered separately.- Specified by:
registerService
in classWritableTypeRegistry
- Parameters:
service
- the service to register.
-
registerType
public <T> void registerType(PDeclaredDescriptor<T> declaredType)
Description copied from class:WritableTypeRegistry
Register a declared type.- Specified by:
registerType
in classWritableTypeRegistry
- Type Parameters:
T
- The declared java type.- Parameters:
declaredType
- The descriptor for the type.
-
-