ProgramDeclaration.java

  1. package net.morimekta.providence.reflect.model;

  2. import javax.annotation.Nonnull;
  3. import javax.annotation.Nullable;
  4. import java.util.List;
  5. import java.util.Objects;
  6. import java.util.stream.Collectors;

  7. /**
  8.  * <pre>{@code
  9.  * declaration ::= {documentation} ({typedef} | {enum} | {message} | {service} | {const})
  10.  * program     ::= {namespace|include}* {declaration}*
  11.  * }</pre>
  12.  */
  13. public class ProgramDeclaration {
  14.     private final String documentation;
  15.     private final String programName;
  16.     private final List<IncludeDeclaration> includes;
  17.     private final List<NamespaceDeclaration> namespaces;
  18.     private final List<Declaration> declarationList;

  19.     public ProgramDeclaration(@Nullable String documentation,
  20.                               @Nonnull String programName,
  21.                               @Nonnull List<IncludeDeclaration> includes,
  22.                               @Nonnull List<NamespaceDeclaration> namespaces,
  23.                               @Nonnull List<Declaration> declarationList) {
  24.         this.documentation = documentation;
  25.         this.programName = programName;
  26.         this.includes = includes;
  27.         this.namespaces = namespaces;
  28.         this.declarationList = declarationList;
  29.     }

  30.     public String getDocumentation() {
  31.         return documentation;
  32.     }

  33.     public String getProgramName() {
  34.         return programName;
  35.     }

  36.     public List<IncludeDeclaration> getIncludes() {
  37.         return includes;
  38.     }

  39.     public List<NamespaceDeclaration> getNamespaces() {
  40.         return namespaces;
  41.     }

  42.     public List<Declaration> getDeclarationList() {
  43.         return declarationList;
  44.     }

  45.     @Override
  46.     public boolean equals(Object obj) {
  47.         if (obj == this) return true;
  48.         if (!(obj instanceof ProgramDeclaration)) return false;
  49.         ProgramDeclaration other = (ProgramDeclaration) obj;
  50.         return Objects.equals(documentation, other.documentation) &&
  51.                Objects.equals(programName, other.programName) &&
  52.                Objects.equals(includes, other.includes) &&
  53.                Objects.equals(namespaces, other.namespaces) &&
  54.                Objects.equals(declarationList, other.declarationList);
  55.     }

  56.     @Override
  57.     public String toString() {
  58.         return "ThriftProgram{" + programName + ".{" +
  59.                declarationList.stream().map(Declaration::getName).collect(Collectors.joining(",")) + "}}";
  60.     }
  61. }