1 /* 2 * Copyright 2021 Google LLC 3 * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.google.devtools.ksp 19 20 import org.jetbrains.kotlin.incremental.LookupTrackerImpl 21 import org.jetbrains.kotlin.incremental.components.LookupTracker 22 import org.jetbrains.kotlin.incremental.components.Position 23 import org.jetbrains.kotlin.incremental.components.ScopeKind 24 25 class DualLookupTracker : LookupTracker { 26 val symbolTracker = LookupTrackerImpl(LookupTracker.DO_NOTHING) 27 val classTracker = LookupTrackerImpl(LookupTracker.DO_NOTHING) 28 29 override val requiresPosition: Boolean 30 get() = symbolTracker.requiresPosition || classTracker.requiresPosition 31 recordnull32 override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) { 33 symbolTracker.record(filePath, position, scopeFqName, scopeKind, name) 34 if (scopeKind == ScopeKind.CLASSIFIER) { 35 val className = scopeFqName.substringAfterLast('.') 36 val outerScope = scopeFqName.substringBeforeLast('.', "<anonymous>") 37 // DO NOT USE: ScopeKind is meaningless 38 classTracker.record(filePath, position, outerScope, scopeKind, className) 39 } 40 } 41 clearnull42 override fun clear() { 43 // Do not clear symbolTracker and classTracker. 44 // LookupTracker.clear() is called in repeatAnalysisIfNeeded, but we need records across all rounds. 45 } 46 } 47