Class ContextualLookupHelper

java.lang.Object
com.hedera.pbj.compiler.impl.ContextualLookupHelper

public class ContextualLookupHelper extends Object
Wrapper around LookupHelper adding the context of which protobuf source file the lookup is happening within. This makes it easy to carry the source files context for lookup so that the package and imports are correctly understood.
  • Constructor Details

    • ContextualLookupHelper

      public ContextualLookupHelper(LookupHelper lookupHelper, File srcProtoFileContext)
      Create a new ContextualLookupHelper delegating to lookupHelper with the context of srcProtoFileContext.
      Parameters:
      lookupHelper - Lookup helper that we are delegating to
      srcProtoFileContext - The proto source file for context
  • Method Details

    • getLookupHelper

      public LookupHelper getLookupHelper()
      Get the LookupHelper instance backing this ContextualLookupHelper.
    • getUnqualifiedClassForMessage

      public String getUnqualifiedClassForMessage(FileType fileType, Protobuf3Parser.MessageDefContext context)
      Get the unqualified Java class name for given message or enum.
      Parameters:
      fileType - The type of file we want the package for
      context - Parser Context, a message or enum
      Returns:
      java package to put model class in
    • getFullyQualifiedMessageClassname

      public String getFullyQualifiedMessageClassname(FileType fileType, Protobuf3Parser.MessageDefContext message)
      Get the fully qualified class name for a msgDef with given fileType that would be generated by PBJ.
      Parameters:
      fileType - The type of file we want the fully qualified class name for
      message - The msgDef to get fully qualified class name for
      Returns:
      fully qualified class name
    • getComparableFields

      public List<String> getComparableFields(Protobuf3Parser.MessageDefContext message)
      Get the set of fields that are comparable for a given message.
      Parameters:
      message - The message to get comparable fields for
      Returns:
      set of field names that are comparable
    • getPackage

      public String getPackage(FileType fileType, org.antlr.v4.runtime.ParserRuleContext message)
      Get the Java package a class should be generated into for a given ParserRuleContext and file type. Examples of supported ParserRuleContext: MessageDefContext, EnumDefContext, ServiceDefContext. This method throws an exception if the package cannot be determined.
      Parameters:
      fileType - The type of file we want the package for
      message - The msgDef to get package for
      Returns:
      java package to put model class in
    • getPackageFieldMessageType

      public String getPackageFieldMessageType(FileType fileType, Protobuf3Parser.FieldContext fieldContext)
      Get the Java package a class should be generated into for a given fieldContext and file type.
      Parameters:
      fileType - The type of file we want the package for
      fieldContext - The field to get package for message type for
      Returns:
      java package to put model class in
    • getPackageFieldType

      public String getPackageFieldType(FileType fileType, Protobuf3Parser.Type_Context typeContext)
      Get the Java package a class should be generated into for a given message or enum typeContext and file type.
      Parameters:
      fileType - The type of file we want the package for
      typeContext - The field to get package for message type for
      Returns:
      java package to put model class in
    • getCompleteClass

      public String getCompleteClass(org.antlr.v4.runtime.ParserRuleContext typeContext)
      Get the complete Java class name for a given message and file type, including outer classes names, but w/o the package name.
      Parameters:
      typeContext - The field to get package for message type for
      Returns:
      java package to put model class in
    • getPackageOneofFieldMessageType

      public String getPackageOneofFieldMessageType(FileType fileType, Protobuf3Parser.OneofFieldContext fieldContext)
      Get the PBJ Java package a class should be generated into for a given fieldContext and file type.
      Parameters:
      fileType - The type of file we want the package for
      fieldContext - The field to get package for message type for
      Returns:
      java package to put model class in
    • isEnum

      public boolean isEnum(Protobuf3Parser.MessageTypeContext messageType)
      Check if the given messageType is a known enum
      Parameters:
      messageType - to check if enum
      Returns:
      true if known as an enum, recorded by addEnum()
    • isComparable

      public boolean isComparable(Protobuf3Parser.MessageTypeContext messageType)
      Check if the given messageType is comparable.
      Parameters:
      messageType - to check if enum
      Returns:
      true if comparable