1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.metalava.model.snapshot
18 
19 import com.android.tools.metalava.model.Codebase
20 import com.android.tools.metalava.model.CodebaseFragment
21 import com.android.tools.metalava.model.testing.transformer.CodebaseTransformer
22 
23 /** A [CodebaseTransformer] that will return a snapshot of the supplied [Codebase]. */
24 // @AutoService(CodebaseTransformer.class)
25 class SnapshotCodebaseTransformer : CodebaseTransformer {
transformnull26     override fun transform(codebase: Codebase): Codebase {
27         val fragment =
28             CodebaseFragment.create(
29                     codebase,
30                     // Copy every Item from the input.
31                     ::NonFilteringDelegatingVisitor,
32                 )
33                 .snapshotIncludingRevertedItems(
34                     // Allow references to any Item in the original.
35                     ::NonFilteringDelegatingVisitor,
36                 )
37         return fragment.codebase
38     }
39 }
40