blob: af8be11606b50f73498f18f786d397379224c22c [file] [log] [blame]
Mårten Kongstad90087242024-04-16 09:55:56 +02001/*
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@file:JvmName("Main")
17
18package com.android.checkflaggedapis
19
Mårten Kongstadacfeb112024-04-16 10:30:26 +020020import com.github.ajalt.clikt.core.CliktCommand
21import com.github.ajalt.clikt.core.ProgramResult
22
Mårten Kongstade0179972024-04-16 11:16:44 +020023/**
24 * Class representing the fully qualified name of a class, method or field.
25 *
26 * This tool reads a multitude of input formats all of which represents the fully qualified path to
27 * a Java symbol slightly differently. To keep things consistent, all parsed APIs are converted to
28 * Symbols.
29 *
30 * All parts of the fully qualified name of the Symbol are separated by a dot, e.g.:
31 * <pre>
32 * package.class.inner-class.field
33 * </pre>
34 */
35@JvmInline
36internal value class Symbol(val name: String) {
37 companion object {
38 private val FORBIDDEN_CHARS = listOf('/', '#', '$')
39
40 /** Create a new Symbol from a String that may include delimiters other than dot. */
41 fun create(name: String): Symbol {
42 var sanitizedName = name
43 for (ch in FORBIDDEN_CHARS) {
44 sanitizedName = sanitizedName.replace(ch, '.')
45 }
46 return Symbol(sanitizedName)
47 }
48 }
49
50 init {
51 require(!name.isEmpty()) { "empty string" }
52 for (ch in FORBIDDEN_CHARS) {
53 require(!name.contains(ch)) { "$name: contains $ch" }
54 }
55 }
56
57 override fun toString(): String = name.toString()
58}
59
Mårten Kongstaddc3fc2e2024-04-16 11:23:22 +020060/**
61 * Class representing the fully qualified name of an aconfig flag.
62 *
63 * This includes both the flag's package and name, separated by a dot, e.g.:
64 * <pre>
65 * com.android.aconfig.test.disabled_ro
66 * <pre>
67 */
68@JvmInline
69internal value class Flag(val name: String) {
70 override fun toString(): String = name.toString()
71}
72
Mårten Kongstadacfeb112024-04-16 10:30:26 +020073class CheckCommand : CliktCommand() {
74 override fun run() {
75 println("hello world")
76 throw ProgramResult(0)
77 }
78}
79
80fun main(args: Array<String>) = CheckCommand().main(args)