From 5c6134af81425a75d8ec651c36caf3452aa28c19 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Sat, 31 Oct 2015 08:00:20 +0300 Subject: [PATCH] Minor. Removed WritableScopeImpl. --- .../kotlin/resolve/scopes/WritableScope.kt | 34 --- .../resolve/scopes/WritableScopeImpl.kt | 226 ------------------ 2 files changed, 260 deletions(-) delete mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScope.kt delete mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScopeImpl.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScope.kt deleted file mode 100644 index e84c3ca0da0..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScope.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.scopes - -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.VariableDescriptor - -public interface WritableScope : KtScope { - public fun takeSnapshot(): KtScope - - public fun changeLockLevel(lockLevel: LexicalWritableScope.LockLevel) - - public fun addVariableDescriptor(variableDescriptor: VariableDescriptor) - - public fun addFunctionDescriptor(functionDescriptor: FunctionDescriptor) - - public fun addClassifierDescriptor(classifierDescriptor: ClassifierDescriptor) -} - diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScopeImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScopeImpl.kt deleted file mode 100644 index 782d2803ea5..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/WritableScopeImpl.kt +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.scopes - -import com.intellij.util.SmartList -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.incremental.components.LookupLocation -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.util.collectionUtils.concatInOrder -import org.jetbrains.kotlin.utils.Printer -import java.util.* - -// Reads from: -// 1. Maps -// 2. Worker - -// Writes to: maps - -public class WritableScopeImpl @JvmOverloads constructor( - outerScope: KtScope, - private val ownerDeclarationDescriptor: DeclarationDescriptor, - override val redeclarationHandler: RedeclarationHandler, - private val debugName: String, - implicitReceiver: ReceiverParameterDescriptor? = null, - private val labeledDeclaration: DeclarationDescriptor? = null -) : AbstractScopeAdapter(), WritableScope, WritableScopeStorage { - - override val workerScope: KtScope = if (outerScope is WritableScope) outerScope.takeSnapshot() else outerScope - - override val addedDescriptors = SmartList() - - override var functionsByName: MutableMap? = null - override var variablesAndClassifiersByName: MutableMap? = null - - private val implicitReceiverHierarchy = if (implicitReceiver != null) - listOf(implicitReceiver) + super.getImplicitReceiversHierarchy() - else - super.getImplicitReceiversHierarchy() - - private var lastSnapshot: Snapshot? = null - - override fun getContainingDeclaration() = ownerDeclarationDescriptor - - private var lockLevel: LexicalWritableScope.LockLevel = LexicalWritableScope.LockLevel.WRITING - - override fun changeLockLevel(lockLevel: LexicalWritableScope.LockLevel) { - if (lockLevel.ordinal() < this.lockLevel.ordinal()) { - throw IllegalStateException("cannot lower lock level from " + this.lockLevel + " to " + lockLevel + " at " + toString()) - } - this.lockLevel = lockLevel - } - - private fun checkMayRead() { - if (lockLevel != LexicalWritableScope.LockLevel.READING && lockLevel != LexicalWritableScope.LockLevel.BOTH) { - throw IllegalStateException("cannot read with lock level " + lockLevel + " at " + toString()) - } - } - - private fun checkMayWrite() { - if (lockLevel != LexicalWritableScope.LockLevel.WRITING && lockLevel != LexicalWritableScope.LockLevel.BOTH) { - throw IllegalStateException("cannot write with lock level " + lockLevel + " at " + toString()) - } - } - - override fun takeSnapshot(): KtScope { - checkMayRead() - if (lastSnapshot == null || lastSnapshot!!.descriptorLimit != addedDescriptors.size()) { - lastSnapshot = Snapshot(addedDescriptors.size()) - } - return lastSnapshot!! - } - - override fun getDescriptors(kindFilter: DescriptorKindFilter, - nameFilter: (Name) -> Boolean): Collection { - checkMayRead() - changeLockLevel(LexicalWritableScope.LockLevel.READING) - - val result = ArrayList() - result.addAll(addedDescriptors) - result.addAll(workerScope.getDescriptors(kindFilter, nameFilter)) - return result - } - - override fun getDeclarationsByLabel(labelName: Name): Collection { - checkMayRead() - - val superResult = super.getDeclarationsByLabel(labelName) - return if (labeledDeclaration != null && labeledDeclaration.getName() == labelName) - listOf(labeledDeclaration) + superResult - else - superResult - } - - override fun addVariableDescriptor(variableDescriptor: VariableDescriptor) { - checkMayWrite() - addVariableOrClassDescriptor(variableDescriptor) - } - - override fun getLocalVariable(name: Name): VariableDescriptor? { - checkMayRead() - - val descriptor = variableOrClassDescriptorByName(name) - if (descriptor is VariableDescriptor) { - return descriptor - } - - return workerScope.getLocalVariable(name) - } - - override fun addFunctionDescriptor(functionDescriptor: FunctionDescriptor) { - checkMayWrite() - super.addFunctionDescriptor(functionDescriptor) - } - - override fun getFunctions(name: Name, location: LookupLocation): Collection { - checkMayRead() - - return concatInOrder(functionsByName(name), workerScope.getFunctions(name, location)) - } - - override fun addClassifierDescriptor(classifierDescriptor: ClassifierDescriptor) { - checkMayWrite() - addVariableOrClassDescriptor(classifierDescriptor) - } - - override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { - checkMayRead() - - return variableOrClassDescriptorByName(name) as? ClassifierDescriptor - ?: workerScope.getClassifier(name, location) - } - - override fun getImplicitReceiversHierarchy() = implicitReceiverHierarchy - - override fun getOwnDeclaredDescriptors(): Collection = addedDescriptors - - override fun toString(): String { - return javaClass.getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + " " + debugName + " for " + getContainingDeclaration() - } - - override fun printScopeStructure(p: Printer) { - p.println(javaClass.getSimpleName(), ": ", debugName, " for ", getContainingDeclaration(), " {") - p.pushIndent() - - p.println("lockLevel = ", lockLevel) - - p.print("worker = ") - workerScope.printScopeStructure(p.withholdIndentOnce()) - - p.popIndent() - p.println("}") - } - - private inner class Snapshot(val descriptorLimit: Int) : KtScope by this@WritableScopeImpl { - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { - checkMayRead() - changeLockLevel(LexicalWritableScope.LockLevel.READING) - - val workerResult = workerScope.getDescriptors(kindFilter, nameFilter) - - if (descriptorLimit == 0) return workerResult - - val result = ArrayList(workerResult.size() + descriptorLimit) - for (i in 0..descriptorLimit-1) { - result.add(addedDescriptors[i]) - } - result.addAll(workerResult) - return result - } - - override fun getLocalVariable(name: Name): VariableDescriptor? { - checkMayRead() - - val descriptor = variableOrClassDescriptorByName(name, descriptorLimit) - if (descriptor is VariableDescriptor) { - return descriptor - } - - return workerScope.getLocalVariable(name) - } - - override fun getFunctions(name: Name, location: LookupLocation): Collection { - checkMayRead() - - return concatInOrder(functionsByName(name, descriptorLimit), workerScope.getFunctions(name, location)) - } - - override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { - checkMayRead() - - return variableOrClassDescriptorByName(name, descriptorLimit) as? ClassifierDescriptor - ?: workerScope.getClassifier(name, location) - } - - override fun getOwnDeclaredDescriptors(): Collection = addedDescriptors.truncated(descriptorLimit) - - private fun List.truncated(newSize: Int) = if (newSize == size()) this else subList(0, newSize) - - override fun printScopeStructure(p: Printer) { - p.println(javaClass.getSimpleName(), " {") - p.pushIndent() - - p.println("descriptorLimit = ", descriptorLimit) - - p.print("WritableScope = ") - this@WritableScopeImpl.printScopeStructure(p.withholdIndentOnce()) - - p.popIndent() - p.println("}") - } - } -}