blob: 678f9774fdeb20194034a893560a40e800d08f8f [file] [log] [blame]
Chalard Jean48c6c7d2020-06-25 23:39:15 +09001/*
2 * Copyright (C) 2019 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
17package com.android.testutils
18
19// This function is private because the 2 is hardcoded here, and is not correct if not called
20// directly from __LINE__ or __FILE__.
21private fun callerStackTrace(): StackTraceElement = try {
22 throw RuntimeException()
23} catch (e: RuntimeException) {
24 e.stackTrace[2] // 0 is here, 1 is get() in __FILE__ or __LINE__
25}
26val __FILE__: String get() = callerStackTrace().fileName
27val __LINE__: Int get() = callerStackTrace().lineNumber