Protected / final are deprecated in interfaces: scopes and call translator
This commit is contained in:
committed by
Mikhail Glukhikh
parent
49a420e3f9
commit
67755d7dca
@@ -34,7 +34,8 @@ public interface WritableScopeStorage {
|
|||||||
var functionsByName: MutableMap<Name, IntList>? // = null
|
var functionsByName: MutableMap<Name, IntList>? // = null
|
||||||
var variablesAndClassifiersByName: 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 name = descriptor.getName()
|
||||||
|
|
||||||
val originalDescriptor = variableOrClassDescriptorByName(name)
|
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)
|
val descriptorIndex = addDescriptor(functionDescriptor)
|
||||||
|
|
||||||
if (functionsByName == null) {
|
if (functionsByName == null) {
|
||||||
@@ -63,7 +65,8 @@ public interface WritableScopeStorage {
|
|||||||
functionsByName!![name] = functionsByName!![name] + descriptorIndex
|
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
|
if (descriptorLimit == 0) return null
|
||||||
|
|
||||||
var list = variablesAndClassifiersByName?.get(name)
|
var list = variablesAndClassifiersByName?.get(name)
|
||||||
@@ -77,7 +80,8 @@ public interface WritableScopeStorage {
|
|||||||
return null
|
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
|
if (descriptorLimit == 0) return null
|
||||||
|
|
||||||
var list = functionsByName?.get(name)
|
var list = functionsByName?.get(name)
|
||||||
@@ -95,7 +99,8 @@ public interface WritableScopeStorage {
|
|||||||
return addedDescriptors.size() - 1
|
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]
|
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
|
// Temporary overloads which will be dropped when all usages will be processed
|
||||||
@Deprecated("Provide `location` explicitly", replaceWith = ReplaceWith("getClassifier(name, NoLookupLocation.UNSORTED)"))
|
@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.
|
* All visible descriptors from current scope.
|
||||||
*
|
*
|
||||||
* @return 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
|
* All visible descriptors from current scope possibly filtered by the given name and kind filters
|
||||||
|
|||||||
+2
-2
@@ -66,8 +66,8 @@ public class HierarchySearchRequest<T: PsiElement> (
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface HierarchyTraverser<T> {
|
interface HierarchyTraverser<T> {
|
||||||
protected fun nextElements(current: T): Iterable<T>
|
fun nextElements(current: T): Iterable<T>
|
||||||
protected fun shouldDescend(element: T): Boolean
|
fun shouldDescend(element: T): Boolean
|
||||||
|
|
||||||
fun forEach(initialElement: T, body: (T) -> Unit) {
|
fun forEach(initialElement: T, body: (T) -> Unit) {
|
||||||
val stack = Stack<T>()
|
val stack = Stack<T>()
|
||||||
|
|||||||
+8
-8
@@ -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 {
|
final fun translate(callInfo: I): JsExpression {
|
||||||
val result = if (callInfo.dispatchReceiver == null) {
|
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> {
|
interface DelegateIntrinsic<I : CallInfo> {
|
||||||
fun I.canBeApply(): Boolean = true
|
fun I.canBeApply(): Boolean = true
|
||||||
|
|||||||
+7
-7
@@ -44,7 +44,7 @@ public fun CallArgumentTranslator.ArgumentsInfo.argsWithReceiver(receiver: JsExp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call may be native and|or with spreadOperator
|
// call may be native and|or with spreadOperator
|
||||||
object DefaultFunctionCallCase : FunctionCallCase {
|
object DefaultFunctionCallCase : FunctionCallCase() {
|
||||||
// TODO: refactor after fix ArgumentsInfo - duplicate code
|
// TODO: refactor after fix ArgumentsInfo - duplicate code
|
||||||
private fun nativeSpreadFunWithDispatchOrExtensionReceiver(argumentsInfo: CallArgumentTranslator.ArgumentsInfo, functionName: JsName): JsExpression {
|
private fun nativeSpreadFunWithDispatchOrExtensionReceiver(argumentsInfo: CallArgumentTranslator.ArgumentsInfo, functionName: JsName): JsExpression {
|
||||||
val cachedReceiver = argumentsInfo.cachedReceiver!!
|
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
|
abstract fun translateCall(receiver: JsExpression, argumentsInfo: CallArgumentTranslator.ArgumentsInfo): JsExpression
|
||||||
|
|
||||||
fun canApply(callInfo: FunctionCallInfo): Boolean = AnnotationsUtils.hasAnnotation(callInfo.callableDescriptor, annotation)
|
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 {
|
fun canApply(callInfo: FunctionCallInfo): Boolean {
|
||||||
val callableDescriptor = callInfo.callableDescriptor
|
val callableDescriptor = callInfo.callableDescriptor
|
||||||
if (callableDescriptor.getName() != OperatorConventions.INVOKE)
|
if (callableDescriptor.getName() != OperatorConventions.INVOKE)
|
||||||
@@ -198,7 +198,7 @@ object InvokeIntrinsic : FunctionCallCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ConstructorCallCase : FunctionCallCase {
|
object ConstructorCallCase : FunctionCallCase() {
|
||||||
fun canApply(callInfo: FunctionCallInfo): Boolean {
|
fun canApply(callInfo: FunctionCallInfo): Boolean {
|
||||||
return callInfo.callableDescriptor is ConstructorDescriptor
|
return callInfo.callableDescriptor is ConstructorDescriptor
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ object ConstructorCallCase : FunctionCallCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object SuperCallCase : FunctionCallCase {
|
object SuperCallCase : FunctionCallCase() {
|
||||||
fun canApply(callInfo: FunctionCallInfo): Boolean {
|
fun canApply(callInfo: FunctionCallInfo): Boolean {
|
||||||
return callInfo.isSuperInvocation()
|
return callInfo.isSuperInvocation()
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ object SuperCallCase : FunctionCallCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object DynamicInvokeAndBracketAccessCallCase : FunctionCallCase {
|
object DynamicInvokeAndBracketAccessCallCase : FunctionCallCase() {
|
||||||
fun canApply(callInfo: FunctionCallInfo): Boolean =
|
fun canApply(callInfo: FunctionCallInfo): Boolean =
|
||||||
callInfo.resolvedCall.getCall().getCallType() != Call.CallType.DEFAULT && callInfo.callableDescriptor.isDynamic()
|
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 =
|
fun canApply(callInfo: FunctionCallInfo): Boolean =
|
||||||
callInfo.callableDescriptor.isDynamic() &&
|
callInfo.callableDescriptor.isDynamic() &&
|
||||||
callInfo.resolvedCall.getCall().getCallElement() let {
|
callInfo.resolvedCall.getCall().getCallElement() let {
|
||||||
|
|||||||
+3
-3
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils.isVarCapturedInClosure
|
|||||||
import org.jetbrains.kotlin.js.translate.context.Namer.getCapturedVarAccessor
|
import org.jetbrains.kotlin.js.translate.context.Namer.getCapturedVarAccessor
|
||||||
|
|
||||||
|
|
||||||
object NativeVariableAccessCase : VariableAccessCase {
|
object NativeVariableAccessCase : VariableAccessCase() {
|
||||||
override fun VariableAccessInfo.extensionReceiver(): JsExpression {
|
override fun VariableAccessInfo.extensionReceiver(): JsExpression {
|
||||||
return constructAccessExpression(JsNameRef(variableName, extensionReceiver!!))
|
return constructAccessExpression(JsNameRef(variableName, extensionReceiver!!))
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ object NativeVariableAccessCase : VariableAccessCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object DefaultVariableAccessCase : VariableAccessCase {
|
object DefaultVariableAccessCase : VariableAccessCase() {
|
||||||
override fun VariableAccessInfo.noReceivers(): JsExpression {
|
override fun VariableAccessInfo.noReceivers(): JsExpression {
|
||||||
val functionRef = context.aliasOrValue(callableDescriptor) {
|
val functionRef = context.aliasOrValue(callableDescriptor) {
|
||||||
context.getQualifiedReference(variableDescriptor)
|
context.getQualifiedReference(variableDescriptor)
|
||||||
@@ -107,7 +107,7 @@ object DelegatePropertyAccessIntrinsic : DelegateIntrinsic<VariableAccessInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object SuperPropertyAccessCase : VariableAccessCase {
|
object SuperPropertyAccessCase : VariableAccessCase() {
|
||||||
override fun VariableAccessInfo.dispatchReceiver(): JsExpression {
|
override fun VariableAccessInfo.dispatchReceiver(): JsExpression {
|
||||||
val variableName = context.program().getStringLiteral(this.variableName.getIdent())
|
val variableName = context.program().getStringLiteral(this.variableName.getIdent())
|
||||||
return if (isGetAccess())
|
return if (isGetAccess())
|
||||||
|
|||||||
Reference in New Issue
Block a user