Protected / final are deprecated in interfaces: scopes and call translator

This commit is contained in:
Mikhail Glukhikh
2015-10-05 14:44:36 +03:00
committed by Mikhail Glukhikh
parent 49a420e3f9
commit 67755d7dca
6 changed files with 32 additions and 27 deletions
@@ -34,7 +34,8 @@ public interface WritableScopeStorage {
var functionsByName: MutableMap<Name, IntList>? // = null
var variablesAndClassifiersByName: MutableMap<Name, IntList>? // = null
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
// Effectively protected: not to be used outside subclasses
fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
val name = descriptor.getName()
val originalDescriptor = variableOrClassDescriptorByName(name)
@@ -52,7 +53,8 @@ public interface WritableScopeStorage {
}
protected fun addFunctionDescriptor(functionDescriptor: FunctionDescriptor) {
// Effectively protected: not to be used outside subclasses
fun addFunctionDescriptor(functionDescriptor: FunctionDescriptor) {
val descriptorIndex = addDescriptor(functionDescriptor)
if (functionsByName == null) {
@@ -63,7 +65,8 @@ public interface WritableScopeStorage {
functionsByName!![name] = functionsByName!![name] + descriptorIndex
}
protected fun variableOrClassDescriptorByName(name: Name, descriptorLimit: Int = addedDescriptors.size()): DeclarationDescriptor? {
// Effectively protected: not to be used outside subclasses
fun variableOrClassDescriptorByName(name: Name, descriptorLimit: Int = addedDescriptors.size()): DeclarationDescriptor? {
if (descriptorLimit == 0) return null
var list = variablesAndClassifiersByName?.get(name)
@@ -77,7 +80,8 @@ public interface WritableScopeStorage {
return null
}
protected fun functionsByName(name: Name, descriptorLimit: Int = addedDescriptors.size()): List<FunctionDescriptor>? {
// Effectively protected: not to be used outside subclasses
fun functionsByName(name: Name, descriptorLimit: Int = addedDescriptors.size()): List<FunctionDescriptor>? {
if (descriptorLimit == 0) return null
var list = functionsByName?.get(name)
@@ -95,7 +99,8 @@ public interface WritableScopeStorage {
return addedDescriptors.size() - 1
}
protected class IntList(val last: Int, val prev: IntList?)
// Effectively protected: not to be used outside subclasses
class IntList(val last: Int, val prev: IntList?)
private fun Int.descriptorByIndex() = addedDescriptors[this]
@@ -49,14 +49,14 @@ public interface JetScope {
// Temporary overloads which will be dropped when all usages will be processed
@Deprecated("Provide `location` explicitly", replaceWith = ReplaceWith("getClassifier(name, NoLookupLocation.UNSORTED)"))
public final fun getClassifier(name: Name): ClassifierDescriptor? = getClassifier(name, NoLookupLocation.UNSORTED)
public fun getClassifier(name: Name): ClassifierDescriptor? = getClassifier(name, NoLookupLocation.UNSORTED)
/**
* All visible descriptors from current scope.
*
* @return All visible descriptors from current scope.
*/
public final fun getAllDescriptors(): Collection<DeclarationDescriptor> = getDescriptors()
public fun getAllDescriptors(): Collection<DeclarationDescriptor> = getDescriptors()
/**
* All visible descriptors from current scope possibly filtered by the given name and kind filters
@@ -66,8 +66,8 @@ public class HierarchySearchRequest<T: PsiElement> (
}
interface HierarchyTraverser<T> {
protected fun nextElements(current: T): Iterable<T>
protected fun shouldDescend(element: T): Boolean
fun nextElements(current: T): Iterable<T>
fun shouldDescend(element: T): Boolean
fun forEach(initialElement: T, body: (T) -> Unit) {
val stack = Stack<T>()
@@ -153,17 +153,17 @@ fun computeExplicitReceiversForInvoke(
}
}
interface CallCase<I : CallInfo> {
abstract class CallCase<I : CallInfo> {
protected fun I.unsupported(message: String = "") : Nothing = throw IllegalStateException("this case unsupported. $this")
protected open fun I.unsupported(message: String = "") : Nothing = throw IllegalStateException("this case unsupported. $this")
protected fun I.noReceivers(): JsExpression = unsupported()
protected open fun I.noReceivers(): JsExpression = unsupported()
protected fun I.dispatchReceiver(): JsExpression = unsupported()
protected open fun I.dispatchReceiver(): JsExpression = unsupported()
protected fun I.extensionReceiver(): JsExpression = unsupported()
protected open fun I.extensionReceiver(): JsExpression = unsupported()
protected fun I.bothReceivers(): JsExpression = unsupported()
protected open fun I.bothReceivers(): JsExpression = unsupported()
final fun translate(callInfo: I): JsExpression {
val result = if (callInfo.dispatchReceiver == null) {
@@ -182,9 +182,9 @@ interface CallCase<I : CallInfo> {
}
}
interface FunctionCallCase : CallCase<FunctionCallInfo>
abstract class FunctionCallCase : CallCase<FunctionCallInfo>()
interface VariableAccessCase : CallCase<VariableAccessInfo>
abstract class VariableAccessCase : CallCase<VariableAccessInfo>()
interface DelegateIntrinsic<I : CallInfo> {
fun I.canBeApply(): Boolean = true
@@ -44,7 +44,7 @@ public fun CallArgumentTranslator.ArgumentsInfo.argsWithReceiver(receiver: JsExp
}
// call may be native and|or with spreadOperator
object DefaultFunctionCallCase : FunctionCallCase {
object DefaultFunctionCallCase : FunctionCallCase() {
// TODO: refactor after fix ArgumentsInfo - duplicate code
private fun nativeSpreadFunWithDispatchOrExtensionReceiver(argumentsInfo: CallArgumentTranslator.ArgumentsInfo, functionName: JsName): JsExpression {
val cachedReceiver = argumentsInfo.cachedReceiver!!
@@ -134,7 +134,7 @@ object DelegateFunctionIntrinsic : DelegateIntrinsic<FunctionCallInfo> {
}
}
abstract class AnnotatedAsNativeXCallCase(val annotation: PredefinedAnnotation) : FunctionCallCase {
abstract class AnnotatedAsNativeXCallCase(val annotation: PredefinedAnnotation) : FunctionCallCase() {
abstract fun translateCall(receiver: JsExpression, argumentsInfo: CallArgumentTranslator.ArgumentsInfo): JsExpression
fun canApply(callInfo: FunctionCallInfo): Boolean = AnnotationsUtils.hasAnnotation(callInfo.callableDescriptor, annotation)
@@ -160,7 +160,7 @@ object NativeSetterCallCase : AnnotatedAsNativeXCallCase(PredefinedAnnotation.NA
}
}
object InvokeIntrinsic : FunctionCallCase {
object InvokeIntrinsic : FunctionCallCase() {
fun canApply(callInfo: FunctionCallInfo): Boolean {
val callableDescriptor = callInfo.callableDescriptor
if (callableDescriptor.getName() != OperatorConventions.INVOKE)
@@ -198,7 +198,7 @@ object InvokeIntrinsic : FunctionCallCase {
}
}
object ConstructorCallCase : FunctionCallCase {
object ConstructorCallCase : FunctionCallCase() {
fun canApply(callInfo: FunctionCallInfo): Boolean {
return callInfo.callableDescriptor is ConstructorDescriptor
}
@@ -218,7 +218,7 @@ object ConstructorCallCase : FunctionCallCase {
}
}
object SuperCallCase : FunctionCallCase {
object SuperCallCase : FunctionCallCase() {
fun canApply(callInfo: FunctionCallInfo): Boolean {
return callInfo.isSuperInvocation()
}
@@ -231,7 +231,7 @@ object SuperCallCase : FunctionCallCase {
}
}
object DynamicInvokeAndBracketAccessCallCase : FunctionCallCase {
object DynamicInvokeAndBracketAccessCallCase : FunctionCallCase() {
fun canApply(callInfo: FunctionCallInfo): Boolean =
callInfo.resolvedCall.getCall().getCallType() != Call.CallType.DEFAULT && callInfo.callableDescriptor.isDynamic()
@@ -252,7 +252,7 @@ object DynamicInvokeAndBracketAccessCallCase : FunctionCallCase {
}
}
object DynamicOperatorCallCase : FunctionCallCase {
object DynamicOperatorCallCase : FunctionCallCase() {
fun canApply(callInfo: FunctionCallInfo): Boolean =
callInfo.callableDescriptor.isDynamic() &&
callInfo.resolvedCall.getCall().getCallElement() let {
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils.isVarCapturedInClosure
import org.jetbrains.kotlin.js.translate.context.Namer.getCapturedVarAccessor
object NativeVariableAccessCase : VariableAccessCase {
object NativeVariableAccessCase : VariableAccessCase() {
override fun VariableAccessInfo.extensionReceiver(): JsExpression {
return constructAccessExpression(JsNameRef(variableName, extensionReceiver!!))
}
@@ -41,7 +41,7 @@ object NativeVariableAccessCase : VariableAccessCase {
}
}
object DefaultVariableAccessCase : VariableAccessCase {
object DefaultVariableAccessCase : VariableAccessCase() {
override fun VariableAccessInfo.noReceivers(): JsExpression {
val functionRef = context.aliasOrValue(callableDescriptor) {
context.getQualifiedReference(variableDescriptor)
@@ -107,7 +107,7 @@ object DelegatePropertyAccessIntrinsic : DelegateIntrinsic<VariableAccessInfo> {
}
}
object SuperPropertyAccessCase : VariableAccessCase {
object SuperPropertyAccessCase : VariableAccessCase() {
override fun VariableAccessInfo.dispatchReceiver(): JsExpression {
val variableName = context.program().getStringLiteral(this.variableName.getIdent())
return if (isGetAccess())