Line data Source code
1 : // Copyright (C) 2015 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.server.patch; 16 : 17 : import com.google.auto.value.AutoValue; 18 : import com.google.common.collect.ImmutableList; 19 : import com.google.common.collect.ImmutableSet; 20 : import com.google.gerrit.entities.Project; 21 : import java.util.List; 22 : import java.util.Set; 23 : import org.eclipse.jgit.diff.Edit; 24 : import org.eclipse.jgit.lib.ObjectId; 25 : 26 : @AutoValue 27 5 : public abstract class IntraLineDiffArgs { 28 : public static IntraLineDiffArgs create( 29 : Text aText, 30 : Text bText, 31 : List<Edit> edits, 32 : Set<Edit> editsDueToRebase, 33 : Project.NameKey project, 34 : ObjectId commit, 35 : String path) { 36 5 : return new AutoValue_IntraLineDiffArgs( 37 5 : aText, bText, deepCopyEdits(edits), deepCopyEdits(editsDueToRebase), project, commit, path); 38 : } 39 : 40 : private static ImmutableList<Edit> deepCopyEdits(List<Edit> edits) { 41 5 : return edits.stream().map(IntraLineDiffArgs::copy).collect(ImmutableList.toImmutableList()); 42 : } 43 : 44 : private static ImmutableSet<Edit> deepCopyEdits(Set<Edit> edits) { 45 5 : return edits.stream().map(IntraLineDiffArgs::copy).collect(ImmutableSet.toImmutableSet()); 46 : } 47 : 48 : private static Edit copy(Edit edit) { 49 5 : return new Edit(edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()); 50 : } 51 : 52 : public abstract Text aText(); 53 : 54 : public abstract Text bText(); 55 : 56 : public abstract ImmutableList<Edit> edits(); 57 : 58 : public abstract ImmutableSet<Edit> editsDueToRebase(); 59 : 60 : public abstract Project.NameKey project(); 61 : 62 : public abstract ObjectId commit(); 63 : 64 : public abstract String path(); 65 : }