LCOV - code coverage report
Current view: top level - extensions/api/changes - FileApi.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 18 26 69.2 %
Date: 2022-11-19 15:00:39 Functions: 12 20 60.0 %

          Line data    Source code
       1             : // Copyright (C) 2014 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.api.changes;
      16             : 
      17             : import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
      18             : import com.google.gerrit.extensions.common.BlameInfo;
      19             : import com.google.gerrit.extensions.common.DiffInfo;
      20             : import com.google.gerrit.extensions.restapi.BinaryResult;
      21             : import com.google.gerrit.extensions.restapi.NotImplementedException;
      22             : import com.google.gerrit.extensions.restapi.RestApiException;
      23             : import java.util.List;
      24             : import java.util.OptionalInt;
      25             : 
      26             : public interface FileApi {
      27             :   BinaryResult content() throws RestApiException;
      28             : 
      29             :   /** Diff against the revision's parent version of the file. */
      30             :   DiffInfo diff() throws RestApiException;
      31             : 
      32             :   /**
      33             :    * Diff against the specified base
      34             :    *
      35             :    * @param base revision id of the revision to be used as the diff base
      36             :    */
      37             :   DiffInfo diff(String base) throws RestApiException;
      38             : 
      39             :   /**
      40             :    * Diff against the specified parent
      41             :    *
      42             :    * @param parent 1-based parent number to diff against
      43             :    */
      44             :   DiffInfo diff(int parent) throws RestApiException;
      45             : 
      46             :   /**
      47             :    * Creates a request to retrieve the diff. On the returned request formatting options for the diff
      48             :    * can be set.
      49             :    */
      50             :   DiffRequest diffRequest() throws RestApiException;
      51             : 
      52             :   /** Set the file reviewed or not reviewed */
      53             :   void setReviewed(boolean reviewed) throws RestApiException;
      54             : 
      55             :   /**
      56             :    * Creates a request to retrieve the blame information. On the returned request formatting options
      57             :    * for the blame request can be set.
      58             :    */
      59             :   BlameRequest blameRequest() throws RestApiException;
      60             : 
      61           3 :   abstract class DiffRequest {
      62             :     private String base;
      63             :     private Boolean intraline;
      64             :     private Whitespace whitespace;
      65           3 :     private OptionalInt parent = OptionalInt.empty();
      66             : 
      67             :     public abstract DiffInfo get() throws RestApiException;
      68             : 
      69             :     public DiffRequest withBase(String base) {
      70           3 :       this.base = base;
      71           3 :       return this;
      72             :     }
      73             : 
      74             :     public DiffRequest withIntraline(boolean intraline) {
      75           2 :       this.intraline = intraline;
      76           2 :       return this;
      77             :     }
      78             : 
      79             :     public DiffRequest withWhitespace(Whitespace whitespace) {
      80           2 :       this.whitespace = whitespace;
      81           2 :       return this;
      82             :     }
      83             : 
      84             :     public DiffRequest withParent(int parent) {
      85           2 :       this.parent = OptionalInt.of(parent);
      86           2 :       return this;
      87             :     }
      88             : 
      89             :     public String getBase() {
      90           3 :       return base;
      91             :     }
      92             : 
      93             :     public Boolean getIntraline() {
      94           3 :       return intraline;
      95             :     }
      96             : 
      97             :     public Whitespace getWhitespace() {
      98           3 :       return whitespace;
      99             :     }
     100             : 
     101             :     public OptionalInt getParent() {
     102           3 :       return parent;
     103             :     }
     104             :   }
     105             : 
     106           2 :   abstract class BlameRequest {
     107             :     private boolean forBase;
     108             : 
     109             :     public abstract List<BlameInfo> get() throws RestApiException;
     110             : 
     111             :     public BlameRequest forBase(boolean forBase) {
     112           1 :       this.forBase = forBase;
     113           1 :       return this;
     114             :     }
     115             : 
     116             :     public boolean isForBase() {
     117           2 :       return forBase;
     118             :     }
     119             :   }
     120             : 
     121             :   /**
     122             :    * A default implementation which allows source compatibility when adding new methods to the
     123             :    * interface.
     124             :    */
     125           0 :   class NotImplemented implements FileApi {
     126             :     @Override
     127             :     public BinaryResult content() throws RestApiException {
     128           0 :       throw new NotImplementedException();
     129             :     }
     130             : 
     131             :     @Override
     132             :     public DiffInfo diff() throws RestApiException {
     133           0 :       throw new NotImplementedException();
     134             :     }
     135             : 
     136             :     @Override
     137             :     public DiffInfo diff(String base) throws RestApiException {
     138           0 :       throw new NotImplementedException();
     139             :     }
     140             : 
     141             :     @Override
     142             :     public DiffInfo diff(int parent) throws RestApiException {
     143           0 :       throw new NotImplementedException();
     144             :     }
     145             : 
     146             :     @Override
     147             :     public DiffRequest diffRequest() throws RestApiException {
     148           0 :       throw new NotImplementedException();
     149             :     }
     150             : 
     151             :     @Override
     152             :     public void setReviewed(boolean reviewed) throws RestApiException {
     153           0 :       throw new NotImplementedException();
     154             :     }
     155             : 
     156             :     @Override
     157             :     public BlameRequest blameRequest() throws RestApiException {
     158           0 :       throw new NotImplementedException();
     159             :     }
     160             :   }
     161             : }

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