1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.google.api.generator.engine.ast; 16 17 import com.google.auto.value.AutoValue; 18 import com.google.common.collect.ImmutableList; 19 import java.util.Arrays; 20 import java.util.Collections; 21 import java.util.List; 22 23 @AutoValue 24 public abstract class PackageInfoDefinition implements AstNode { pakkage()25 public abstract String pakkage(); 26 fileHeader()27 public abstract ImmutableList<CommentStatement> fileHeader(); 28 headerCommentStatements()29 public abstract ImmutableList<CommentStatement> headerCommentStatements(); 30 annotations()31 public abstract ImmutableList<AnnotationNode> annotations(); 32 toBuilder()33 public abstract Builder toBuilder(); 34 35 @Override accept(AstNodeVisitor visitor)36 public void accept(AstNodeVisitor visitor) { 37 visitor.visit(this); 38 } 39 builder()40 public static Builder builder() { 41 return new AutoValue_PackageInfoDefinition.Builder() 42 .setFileHeader(Collections.emptyList()) 43 .setHeaderCommentStatements(Collections.emptyList()) 44 .setAnnotations(Collections.emptyList()); 45 } 46 47 @AutoValue.Builder 48 public abstract static class Builder { setPakkage(String pakkage)49 public abstract Builder setPakkage(String pakkage); 50 setFileHeader(CommentStatement... headerComments)51 public Builder setFileHeader(CommentStatement... headerComments) { 52 return setFileHeader(Arrays.asList(headerComments)); 53 } 54 setFileHeader(List<CommentStatement> fileHeader)55 public abstract Builder setFileHeader(List<CommentStatement> fileHeader); 56 setHeaderCommentStatements(CommentStatement... comments)57 public Builder setHeaderCommentStatements(CommentStatement... comments) { 58 return setHeaderCommentStatements(Arrays.asList(comments)); 59 } 60 setHeaderCommentStatements( List<CommentStatement> headerCommentStatements)61 public abstract Builder setHeaderCommentStatements( 62 List<CommentStatement> headerCommentStatements); 63 setAnnotations(AnnotationNode... annotations)64 public Builder setAnnotations(AnnotationNode... annotations) { 65 return setAnnotations(Arrays.asList(annotations)); 66 } 67 setAnnotations(List<AnnotationNode> annotations)68 public abstract Builder setAnnotations(List<AnnotationNode> annotations); 69 autoBuild()70 abstract PackageInfoDefinition autoBuild(); 71 build()72 public PackageInfoDefinition build() { 73 PackageInfoDefinition packageInfo = autoBuild(); 74 String contextInfo = String.format("package info for %s", packageInfo.pakkage()); 75 NodeValidator.checkNoNullElements(packageInfo.fileHeader(), "file header", contextInfo); 76 NodeValidator.checkNoNullElements( 77 packageInfo.headerCommentStatements(), "header comments", contextInfo); 78 NodeValidator.checkNoNullElements(packageInfo.annotations(), "annotations", contextInfo); 79 return packageInfo; 80 } 81 } 82 } 83