Interface CodeContext

All Superinterfaces:
AutoCloseable, CodeLoader, CodeNode, CodeProvider, CodeWithContext

public interface CodeContext extends CodeProvider
A CodeContext is the main entry point of this API. It allows to retrieve and create instances of CodePackage, CodeFile, and CodeType.
Since:
1.0.0
Author:
hohwille
  • Method Details

    • getLanguage

      CodeLanguage getLanguage()
      Returns:
      the CodeLanguage for the current programming language.
    • getParent

      CodeContext getParent()
      Specified by:
      getParent in interface CodeNode
      Returns:
      the parent of this CodeNode. May only be null for instances of CodeContext.
    • getRootType

      CodeType getRootType()
      Returns:
      the root type (for Java it represents Object for TypeScript any).
    • getUnboundedWildcard

      CodeTypeWildcard getUnboundedWildcard()
      Returns:
      the unbounded instance of CodeTypeWildcard (that has no bound). This is typically represented by the type "?" (e.g. in List<?>).
    • getRootEnumerationType

      CodeType getRootEnumerationType()
      Returns:
      the root enumeration type (for Java it represents Enum for TypeScript any).
    • getVoidType

      CodeType getVoidType()
      Returns:
      the void CodeType for a default return.
    • getBooleanType

      CodeType getBooleanType(boolean primitive)
      Parameters:
      primitive - true for primitive boolean and false for Boolean object type.
      Returns:
      the requested boolean type.
    • getRootExceptionType

      CodeType getRootExceptionType()
      Returns:
      the top-level exception CodeType. All sub-types are considered as exceptions. For Java this is Throwable.
    • getQualifiedName

      default String getQualifiedName(String simpleName, CodeType owningType, boolean omitStandardPackages)
      Parameters:
      simpleName - the simple name of the CodeType to resolve.
      owningType - the owning CodeType where the simpleName origins from. It is used as context for the resolution.
      omitStandardPackages - true to omit standard package(s) (for standard types), false otherwise (to enforce qualified name also for standard types).
      Returns:
      the resolved qualified name corresponding to the given simpleName.
    • getQualifiedName

      default String getQualifiedName(String simpleName, CodeFile file, boolean omitStandardPackages)
      Parameters:
      simpleName - the simple name of the CodeType to resolve.
      file - the owning CodeFile where the simpleName origins from. It is used as context for the resolution.
      omitStandardPackages - true to omit standard package(s) (for standard types), false otherwise (to enforce qualified name also for standard types).
      Returns:
      the resolved qualified name corresponding to the given simpleName.
    • getQualifiedNameForStandardType

      String getQualifiedNameForStandardType(String simpleName, boolean omitStandardPackages)
      Parameters:
      simpleName - the simple name of the CodeType.
      omitStandardPackages - true to omit standard package(s) (for standard types), false otherwise (to enforce qualified name also for standard types).
      Returns:
      the corresponding qualified name or null if no standard type (import is required).
    • getFactory

      CodeFactory getFactory()
      Returns:
      the CodeFactory to create specific CodeItems.
    • getOrCreateType

      default CodeType getOrCreateType(String qualifiedName, boolean add)
      Parameters:
      qualifiedName - the qualified name of the requested CodeType.
      add - - true to also add newly created code elements (requires mutable access), false otherwise.
      Returns:
      the requested existing or newly created CodeType.
      See Also:
    • createChildContext

      CodeContext createChildContext()
      Returns:
      a new mutable child context. It will inherit from this context but have its own virtual source that is mutable so you can add your own code.
      See Also: