• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.source
18 
19 import com.android.tools.metalava.model.ClassResolver
20 import com.android.tools.metalava.model.Codebase
21 import com.android.tools.metalava.model.PackageFilter
22 import java.io.File
23 
24 /** Provides support for creating [Codebase] related objects from source files (including jars). */
25 interface SourceParser {
26 
27     /**
28      * Get a [ClassResolver] instance that will resolve classes provided by jars on the [classPath].
29      *
30      * @param classPath a list of jar [File]s.
31      */
getClassResolvernull32     fun getClassResolver(classPath: List<File>): ClassResolver
33 
34     /**
35      * Parse a set of sources into a [Codebase].
36      *
37      * @param sourceSet the list of source files and root directories.
38      * @param description the description to use for [Codebase.description].
39      * @param classPath the possibly empty list of jar files which may provide additional classes
40      *   referenced by the sources.
41      * @param apiPackages an optional [PackageFilter] that if specified will result in only
42      *   including the source classes that match the filter in the
43      *   [Codebase.getTopLevelClassesFromSource] list.
44      * @param projectDescription Lint project model that can describe project structures in detail.
45      *   Only supported by the PSI model.
46      */
47     fun parseSources(
48         sourceSet: SourceSet,
49         description: String,
50         classPath: List<File>,
51         apiPackages: PackageFilter?,
52         projectDescription: File?,
53     ): Codebase
54 
55     /**
56      * Load a [Codebase] from a single jar.
57      *
58      * @param apiJar the jar file from which the [Codebase] will be loaded.
59      * @param classPath the possibly empty list of jar files which may provide additional classes
60      *   referenced by [apiJar].
61      */
62     fun loadFromJar(apiJar: File, classPath: List<File>): Codebase
63 }
64