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.source.utils 18 19 import com.android.tools.lint.checks.infrastructure.ClassName 20 import java.io.File 21 22 const val PACKAGE_HTML = "package.html" 23 const val OVERVIEW_HTML = "overview.html" 24 const val DOT_JAVA = ".java" 25 const val DOT_KT = ".kt" 26 27 /** Finds the package of the given Java/Kotlin source file, if possible */ findPackagenull28fun findPackage(file: File): String? { 29 val source = file.readText(Charsets.UTF_8) 30 return findPackage(source) 31 } 32 33 /** Finds the package of the given Java/Kotlin source code, if possible */ findPackagenull34private fun findPackage(source: String): String? { 35 return ClassName(source).packageName 36 } 37