LCOV - code coverage report
Current view: top level - extensions/validators - CommentForValidation.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 10 10 100.0 %
Date: 2022-11-19 15:00:39 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2019 The Android Open Source Project
       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.gerrit.extensions.validators;
      16             : 
      17             : import com.google.auto.value.AutoValue;
      18             : 
      19             : /**
      20             :  * Holds a comment's text and some metadata in order to pass it to a validation plugin.
      21             :  *
      22             :  * @see CommentValidator
      23             :  */
      24             : @AutoValue
      25          65 : public abstract class CommentForValidation {
      26             : 
      27             :   /** The creator of the comment. */
      28          65 :   public enum CommentSource {
      29             :     /** A regular user comment. */
      30          65 :     HUMAN,
      31             :     /** A robot comment. */
      32          65 :     ROBOT
      33             :   }
      34             : 
      35             :   /** The type of comment. */
      36          66 :   public enum CommentType {
      37             :     /** A regular (inline) comment. */
      38          66 :     INLINE_COMMENT,
      39             :     /** A file comment. */
      40          66 :     FILE_COMMENT,
      41             :     /** A change message. */
      42          66 :     CHANGE_MESSAGE
      43             :   }
      44             : 
      45             :   public static CommentForValidation create(
      46             :       CommentSource source, CommentType type, String text, int size) {
      47          65 :     return new AutoValue_CommentForValidation(source, type, text, size);
      48             :   }
      49             : 
      50             :   public abstract CommentSource getSource();
      51             : 
      52             :   public abstract CommentType getType();
      53             : 
      54             :   /**
      55             :    * Returns the comment text. Note that especially for robot comments the total size may be
      56             :    * significantly larger and should be determined by using {@link #getApproximateSize()}.
      57             :    */
      58             :   public abstract String getText();
      59             : 
      60             :   /**
      61             :    * Returns this instance's approximate size in bytes for the purpose of applying size limits. For
      62             :    * robot comments this may be significantly larger than the size of the comment text.
      63             :    */
      64             :   public abstract int getApproximateSize();
      65             : 
      66             :   public CommentValidationFailure failValidation(String message) {
      67           5 :     return CommentValidationFailure.create(this, message);
      68             :   }
      69             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750