Replace RedeclarationHandler by LocalRedeclarationChecker
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,14 +32,12 @@ import org.jetbrains.kotlin.lexer.KtTokens;
|
|||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
|
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
|
||||||
import org.jetbrains.kotlin.types.*;
|
import org.jetbrains.kotlin.types.*;
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor;
|
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor;
|
||||||
@@ -574,7 +572,7 @@ public class BodyResolver {
|
|||||||
final ConstructorDescriptor unsubstitutedPrimaryConstructor
|
final ConstructorDescriptor unsubstitutedPrimaryConstructor
|
||||||
) {
|
) {
|
||||||
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
|
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
|
||||||
LexicalScopeKind.DEFAULT_VALUE, RedeclarationHandler.DO_NOTHING,
|
LexicalScopeKind.DEFAULT_VALUE, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
@@ -810,7 +808,7 @@ public class BodyResolver {
|
|||||||
final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
|
final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
|
||||||
innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null,
|
innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null,
|
||||||
LexicalScopeKind.PROPERTY_ACCESSOR_BODY,
|
LexicalScopeKind.PROPERTY_ACCESSOR_BODY,
|
||||||
RedeclarationHandler.DO_NOTHING, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
handler.addVariableDescriptor(fieldDescriptor);
|
handler.addVariableDescriptor(fieldDescriptor);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -45,10 +45,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||||
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt;
|
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ScopeUtils;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||||
import org.jetbrains.kotlin.storage.StorageManager;
|
import org.jetbrains.kotlin.storage.StorageManager;
|
||||||
@@ -723,7 +720,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LexicalWritableScope writableScope = new LexicalWritableScope(
|
LexicalWritableScope writableScope = new LexicalWritableScope(
|
||||||
scope, containingDeclaration, false, null, new TraceBasedRedeclarationHandler(trace),
|
scope, containingDeclaration, false, null, new TraceBasedLocalRedeclarationChecker(trace),
|
||||||
LexicalScopeKind.PROPERTY_HEADER);
|
LexicalScopeKind.PROPERTY_HEADER);
|
||||||
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
|
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
|
||||||
propertyDescriptor, writableScope, scope, typeParameters, trace);
|
propertyDescriptor, writableScope, scope, typeParameters, trace);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -38,9 +38,9 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker
|
||||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.DeferredType
|
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
|||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
|
||||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class FunctionDescriptorResolver(
|
class FunctionDescriptorResolver(
|
||||||
@@ -140,7 +139,7 @@ class FunctionDescriptorResolver(
|
|||||||
expectedFunctionType: KotlinType
|
expectedFunctionType: KotlinType
|
||||||
) {
|
) {
|
||||||
val innerScope = LexicalWritableScope(scope, functionDescriptor, true, null,
|
val innerScope = LexicalWritableScope(scope, functionDescriptor, true, null,
|
||||||
TraceBasedRedeclarationHandler(trace), LexicalScopeKind.FUNCTION_HEADER)
|
TraceBasedLocalRedeclarationChecker(trace), LexicalScopeKind.FUNCTION_HEADER)
|
||||||
|
|
||||||
val typeParameterDescriptors = descriptorResolver.
|
val typeParameterDescriptors = descriptorResolver.
|
||||||
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.typeParameters, trace)
|
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.typeParameters, trace)
|
||||||
@@ -281,7 +280,7 @@ class FunctionDescriptorResolver(
|
|||||||
scope,
|
scope,
|
||||||
constructorDescriptor,
|
constructorDescriptor,
|
||||||
false, null,
|
false, null,
|
||||||
TraceBasedRedeclarationHandler(trace),
|
TraceBasedLocalRedeclarationChecker(trace),
|
||||||
LexicalScopeKind.CONSTRUCTOR_HEADER
|
LexicalScopeKind.CONSTRUCTOR_HEADER
|
||||||
)
|
)
|
||||||
parameterScope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH)
|
parameterScope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -62,18 +62,17 @@ public class FunctionDescriptorUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static LexicalScope getFunctionInnerScope(@NotNull LexicalScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
public static LexicalScope getFunctionInnerScope(@NotNull LexicalScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
||||||
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
return getFunctionInnerScope(outerScope, descriptor, new TraceBasedLocalRedeclarationChecker(trace));
|
||||||
return getFunctionInnerScope(outerScope, descriptor, redeclarationHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static LexicalScope getFunctionInnerScope(
|
public static LexicalScope getFunctionInnerScope(
|
||||||
@NotNull LexicalScope outerScope,
|
@NotNull LexicalScope outerScope,
|
||||||
@NotNull final FunctionDescriptor descriptor,
|
@NotNull final FunctionDescriptor descriptor,
|
||||||
@NotNull RedeclarationHandler redeclarationHandler
|
@NotNull LocalRedeclarationChecker redeclarationChecker
|
||||||
) {
|
) {
|
||||||
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
||||||
return new LexicalScopeImpl(outerScope, descriptor, true, receiver, LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationHandler,
|
return new LexicalScopeImpl(outerScope, descriptor, true, receiver, LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationChecker,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
|
|||||||
-66
@@ -1,66 +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;
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler;
|
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.CONFLICTING_OVERLOADS;
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.REDECLARATION;
|
|
||||||
|
|
||||||
public class TraceBasedRedeclarationHandler implements RedeclarationHandler {
|
|
||||||
private final BindingTrace trace;
|
|
||||||
|
|
||||||
public TraceBasedRedeclarationHandler(@NotNull BindingTrace trace) {
|
|
||||||
this.trace = trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
|
||||||
reportRedeclaration(first);
|
|
||||||
reportRedeclaration(second);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second) {
|
|
||||||
reportConflictingOverloads(first, second.getContainingDeclaration());
|
|
||||||
reportConflictingOverloads(second, first.getContainingDeclaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reportConflictingOverloads(CallableMemberDescriptor conflicting, DeclarationDescriptor withContainedIn) {
|
|
||||||
PsiElement reportElement = DescriptorToSourceUtils.descriptorToDeclaration(conflicting);
|
|
||||||
if (reportElement != null) {
|
|
||||||
trace.report(CONFLICTING_OVERLOADS.on(reportElement, conflicting, withContainedIn));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("No declaration found for " + conflicting);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reportRedeclaration(DeclarationDescriptor descriptor) {
|
|
||||||
PsiElement firstElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
|
|
||||||
if (firstElement != null) {
|
|
||||||
trace.report(REDECLARATION.on(firstElement, descriptor.getName().asString()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("No declaration found for " + descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.scopes
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
|
|
||||||
class LexicalScopeImpl @JvmOverloads constructor(
|
class LexicalScopeImpl @JvmOverloads constructor(
|
||||||
@@ -28,10 +27,9 @@ class LexicalScopeImpl @JvmOverloads constructor(
|
|||||||
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
||||||
override val implicitReceiver: ReceiverParameterDescriptor?,
|
override val implicitReceiver: ReceiverParameterDescriptor?,
|
||||||
override val kind: LexicalScopeKind,
|
override val kind: LexicalScopeKind,
|
||||||
redeclarationHandler: RedeclarationHandler = RedeclarationHandler.DO_NOTHING,
|
redeclarationChecker: LocalRedeclarationChecker = LocalRedeclarationChecker.DO_NOTHING,
|
||||||
initialize: LexicalScopeImpl.InitializeHandler.() -> Unit = {}
|
initialize: LexicalScopeImpl.InitializeHandler.() -> Unit = {}
|
||||||
): LexicalScope, WritableScopeStorage(redeclarationHandler) {
|
): LexicalScope, LexicalScopeStorage(parent, redeclarationChecker) {
|
||||||
override val parent = parent.takeSnapshot()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
InitializeHandler().initialize()
|
InitializeHandler().initialize()
|
||||||
|
|||||||
+12
-29
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,12 +17,19 @@
|
|||||||
package org.jetbrains.kotlin.resolve.scopes
|
package org.jetbrains.kotlin.resolve.scopes
|
||||||
|
|
||||||
import com.intellij.util.SmartList
|
import com.intellij.util.SmartList
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.OverloadUtil
|
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandler) {
|
abstract class LexicalScopeStorage(
|
||||||
|
parent: HierarchicalScope,
|
||||||
|
val redeclarationChecker: LocalRedeclarationChecker
|
||||||
|
): LexicalScope {
|
||||||
|
override val parent = parent.takeSnapshot()
|
||||||
|
|
||||||
protected val addedDescriptors: MutableList<DeclarationDescriptor> = SmartList()
|
protected val addedDescriptors: MutableList<DeclarationDescriptor> = SmartList()
|
||||||
|
|
||||||
@@ -31,12 +38,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
|
|||||||
|
|
||||||
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
|
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
|
||||||
val name = descriptor.name
|
val name = descriptor.name
|
||||||
|
|
||||||
val originalDescriptor = variableOrClassDescriptorByName(name)
|
|
||||||
if (originalDescriptor != null) {
|
|
||||||
redeclarationHandler.handleRedeclaration(originalDescriptor, descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
val descriptorIndex = addDescriptor(descriptor)
|
val descriptorIndex = addDescriptor(descriptor)
|
||||||
|
|
||||||
if (variablesAndClassifiersByName == null) {
|
if (variablesAndClassifiersByName == null) {
|
||||||
@@ -48,8 +49,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun addFunctionDescriptorInternal(functionDescriptor: FunctionDescriptor) {
|
protected fun addFunctionDescriptorInternal(functionDescriptor: FunctionDescriptor) {
|
||||||
checkOverloadConflicts(functionDescriptor)
|
|
||||||
|
|
||||||
val name = functionDescriptor.name
|
val name = functionDescriptor.name
|
||||||
val descriptorIndex = addDescriptor(functionDescriptor)
|
val descriptorIndex = addDescriptor(functionDescriptor)
|
||||||
if (functionsByName == null) {
|
if (functionsByName == null) {
|
||||||
@@ -59,23 +58,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
|
|||||||
functionsByName!![name] = functionsByName!![name] + descriptorIndex
|
functionsByName!![name] = functionsByName!![name] + descriptorIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOverloadConflicts(functionDescriptor: FunctionDescriptor) {
|
|
||||||
val name = functionDescriptor.name
|
|
||||||
val originalFunctions = functionsByName(name).orEmpty()
|
|
||||||
val originalVariableOrClass = variableOrClassDescriptorByName(name)
|
|
||||||
val potentiallyConflictingOverloads =
|
|
||||||
if (originalVariableOrClass is ClassDescriptor)
|
|
||||||
originalFunctions + originalVariableOrClass.constructors
|
|
||||||
else
|
|
||||||
originalFunctions
|
|
||||||
for (overloadedDescriptor in potentiallyConflictingOverloads) {
|
|
||||||
if (!OverloadUtil.isOverloadable(overloadedDescriptor, functionDescriptor)) {
|
|
||||||
redeclarationHandler.handleConflictingOverloads(functionDescriptor, overloadedDescriptor)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun variableOrClassDescriptorByName(name: Name, descriptorLimit: Int = addedDescriptors.size): DeclarationDescriptor? {
|
protected fun variableOrClassDescriptorByName(name: Name, descriptorLimit: Int = addedDescriptors.size): DeclarationDescriptor? {
|
||||||
if (descriptorLimit == 0) return null
|
if (descriptorLimit == 0) return null
|
||||||
|
|
||||||
@@ -104,6 +86,7 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addDescriptor(descriptor: DeclarationDescriptor): Int {
|
private fun addDescriptor(descriptor: DeclarationDescriptor): Int {
|
||||||
|
redeclarationChecker.checkBeforeAddingToScope(this, descriptor)
|
||||||
addedDescriptors.add(descriptor)
|
addedDescriptors.add(descriptor)
|
||||||
return addedDescriptors.size - 1
|
return addedDescriptors.size - 1
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.scopes
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
|
|
||||||
class LexicalWritableScope(
|
class LexicalWritableScope(
|
||||||
@@ -27,17 +26,15 @@ class LexicalWritableScope(
|
|||||||
override val ownerDescriptor: DeclarationDescriptor,
|
override val ownerDescriptor: DeclarationDescriptor,
|
||||||
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
||||||
override val implicitReceiver: ReceiverParameterDescriptor?,
|
override val implicitReceiver: ReceiverParameterDescriptor?,
|
||||||
redeclarationHandler: RedeclarationHandler,
|
redeclarationChecker: LocalRedeclarationChecker,
|
||||||
override val kind: LexicalScopeKind
|
override val kind: LexicalScopeKind
|
||||||
) : LexicalScope, WritableScopeStorage(redeclarationHandler) {
|
) : LexicalScopeStorage(parent, redeclarationChecker) {
|
||||||
enum class LockLevel {
|
enum class LockLevel {
|
||||||
WRITING,
|
WRITING,
|
||||||
BOTH,
|
BOTH,
|
||||||
READING
|
READING
|
||||||
}
|
}
|
||||||
|
|
||||||
override val parent = parent.takeSnapshot()
|
|
||||||
|
|
||||||
private var lockLevel: LockLevel = LockLevel.WRITING
|
private var lockLevel: LockLevel = LockLevel.WRITING
|
||||||
private var lastSnapshot: Snapshot? = null
|
private var lastSnapshot: Snapshot? = null
|
||||||
|
|
||||||
|
|||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.*
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.OverloadUtil
|
||||||
|
|
||||||
|
interface LocalRedeclarationChecker {
|
||||||
|
fun checkBeforeAddingToScope(scope: LexicalScope, newDescriptor: DeclarationDescriptor)
|
||||||
|
|
||||||
|
object DO_NOTHING : LocalRedeclarationChecker {
|
||||||
|
override fun checkBeforeAddingToScope(scope: LexicalScope, newDescriptor: DeclarationDescriptor) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class AbstractLocalRedeclarationChecker : LocalRedeclarationChecker {
|
||||||
|
override fun checkBeforeAddingToScope(scope: LexicalScope, newDescriptor: DeclarationDescriptor) {
|
||||||
|
val name = newDescriptor.name
|
||||||
|
val location = NoLookupLocation.WHEN_CHECK_REDECLARATIONS
|
||||||
|
when (newDescriptor) {
|
||||||
|
is ClassifierDescriptor, is VariableDescriptor -> {
|
||||||
|
val otherDescriptor = scope.getContributedClassifier(name, location)
|
||||||
|
?: scope.getContributedVariables(name, location).firstOrNull()
|
||||||
|
if (otherDescriptor != null) {
|
||||||
|
handleRedeclaration(otherDescriptor, newDescriptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is FunctionDescriptor -> {
|
||||||
|
val otherFunctions = scope.getContributedFunctions(name, location)
|
||||||
|
val otherClass = scope.getContributedClassifier(name, location)
|
||||||
|
val potentiallyConflictingOverloads =
|
||||||
|
if (otherClass is ClassDescriptor)
|
||||||
|
otherFunctions + otherClass.constructors
|
||||||
|
else
|
||||||
|
otherFunctions
|
||||||
|
|
||||||
|
for (overloadedDescriptor in potentiallyConflictingOverloads) {
|
||||||
|
if (!OverloadUtil.isOverloadable(overloadedDescriptor, newDescriptor)) {
|
||||||
|
handleConflictingOverloads(newDescriptor, overloadedDescriptor)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> throw IllegalStateException("Unexpected type of descriptor: ${newDescriptor.javaClass.name}, descriptor: $newDescriptor")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor)
|
||||||
|
protected abstract fun handleConflictingOverloads(first: CallableMemberDescriptor, second: CallableMemberDescriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
object ThrowingLocalRedeclarationChecker : AbstractLocalRedeclarationChecker() {
|
||||||
|
override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) {
|
||||||
|
throw IllegalStateException(String.format("Redeclaration: %s (%s) and %s (%s) (no line info available)",
|
||||||
|
DescriptorUtils.getFqName(first), first,
|
||||||
|
DescriptorUtils.getFqName(second), second))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleConflictingOverloads(first: CallableMemberDescriptor, second: CallableMemberDescriptor) {
|
||||||
|
throw IllegalStateException(String.format("Conflicting overloads: %s (%s) and %s (%s) (no line info available)",
|
||||||
|
DescriptorUtils.getFqName(first), first,
|
||||||
|
DescriptorUtils.getFqName(second), second))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TraceBasedLocalRedeclarationChecker(val trace: BindingTrace): AbstractLocalRedeclarationChecker() {
|
||||||
|
override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) {
|
||||||
|
reportRedeclaration(first)
|
||||||
|
reportRedeclaration(second)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleConflictingOverloads(first: CallableMemberDescriptor, second: CallableMemberDescriptor) {
|
||||||
|
reportConflictingOverloads(first, second.containingDeclaration)
|
||||||
|
reportConflictingOverloads(second, first.containingDeclaration)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reportConflictingOverloads(conflicting: CallableMemberDescriptor, withContainedIn: DeclarationDescriptor) {
|
||||||
|
val reportElement = DescriptorToSourceUtils.descriptorToDeclaration(conflicting)
|
||||||
|
if (reportElement != null) {
|
||||||
|
trace.report(Errors.CONFLICTING_OVERLOADS.on(reportElement, conflicting, withContainedIn))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw IllegalStateException("No declaration found for " + conflicting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reportRedeclaration(descriptor: DeclarationDescriptor) {
|
||||||
|
val firstElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
|
||||||
|
if (firstElement != null) {
|
||||||
|
trace.report(Errors.REDECLARATION.on(firstElement, descriptor.name.asString()))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw IllegalStateException("No declaration found for " + descriptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +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.annotations.NotNull;
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|
||||||
|
|
||||||
public interface RedeclarationHandler {
|
|
||||||
RedeclarationHandler DO_NOTHING = new RedeclarationHandler() {
|
|
||||||
@Override
|
|
||||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
RedeclarationHandler THROW_EXCEPTION = new RedeclarationHandler() {
|
|
||||||
@Override
|
|
||||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
String.format("Redeclaration: %s (%s) and %s (%s) (no line info available)", DescriptorUtils.getFqName(first), first,
|
|
||||||
DescriptorUtils.getFqName(second), second)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
String.format("Conflicting overloads: %s (%s) and %s (%s) (no line info available)",
|
|
||||||
DescriptorUtils.getFqName(first), first,
|
|
||||||
DescriptorUtils.getFqName(second), second)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second);
|
|
||||||
void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second);
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,10 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.utils.Printer;
|
import org.jetbrains.kotlin.utils.Printer;
|
||||||
|
|
||||||
public final class ScopeUtils {
|
public final class ScopeUtils {
|
||||||
@@ -44,7 +47,7 @@ public final class ScopeUtils {
|
|||||||
) {
|
) {
|
||||||
return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER,
|
return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER,
|
||||||
// redeclaration on type parameters should be reported early, see: DescriptorResolver.resolvePropertyDescriptor()
|
// redeclaration on type parameters should be reported early, see: DescriptorResolver.resolvePropertyDescriptor()
|
||||||
RedeclarationHandler.DO_NOTHING,
|
LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker;
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||||
@@ -163,7 +164,7 @@ public class ExpressionTypingServices {
|
|||||||
|
|
||||||
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
|
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
|
||||||
LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null,
|
LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null,
|
||||||
new TraceBasedRedeclarationHandler(context.trace), LexicalScopeKind.CODE_BLOCK);
|
new TraceBasedLocalRedeclarationChecker(context.trace), LexicalScopeKind.CODE_BLOCK);
|
||||||
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
KotlinTypeInfo r;
|
KotlinTypeInfo r;
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,10 +34,10 @@ import org.jetbrains.kotlin.psi.*;
|
|||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||||
import org.jetbrains.kotlin.resolve.ObservableBindingTrace;
|
import org.jetbrains.kotlin.resolve.ObservableBindingTrace;
|
||||||
import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
import static org.jetbrains.kotlin.diagnostics.Errors.TYPE_INFERENCE_ERRORS;
|
||||||
import static org.jetbrains.kotlin.resolve.BindingContext.PROCESSED;
|
import static org.jetbrains.kotlin.resolve.BindingContext.PROCESSED;
|
||||||
|
|
||||||
public class ExpressionTypingUtils {
|
public class ExpressionTypingUtils {
|
||||||
@@ -82,7 +82,7 @@ public class ExpressionTypingUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) {
|
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) {
|
||||||
LexicalWritableScope scope = new LexicalWritableScope(context.scope, context.scope.getOwnerDescriptor(), false, null,
|
LexicalWritableScope scope = new LexicalWritableScope(context.scope, context.scope.getOwnerDescriptor(), false, null,
|
||||||
new TraceBasedRedeclarationHandler(context.trace), scopeKind);
|
new TraceBasedLocalRedeclarationChecker(context.trace), scopeKind);
|
||||||
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -38,7 +38,10 @@ import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
|||||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||||
import org.jetbrains.kotlin.test.*
|
import org.jetbrains.kotlin.test.*
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils.TestFileFactoryNoModules
|
import org.jetbrains.kotlin.test.KotlinTestUtils.TestFileFactoryNoModules
|
||||||
@@ -217,12 +220,13 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
|||||||
|
|
||||||
private class ScopeWithClassifiers(classifiers: List<ClassifierDescriptor>) : MemberScopeImpl() {
|
private class ScopeWithClassifiers(classifiers: List<ClassifierDescriptor>) : MemberScopeImpl() {
|
||||||
private val classifierMap = HashMap<Name, ClassifierDescriptor>()
|
private val classifierMap = HashMap<Name, ClassifierDescriptor>()
|
||||||
val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (classifier in classifiers) {
|
for (classifier in classifiers) {
|
||||||
classifierMap.put(classifier.name, classifier)?.let {
|
classifierMap.put(classifier.name, classifier)?.let {
|
||||||
redeclarationHandler.handleRedeclaration(it, classifier)
|
throw IllegalStateException(String.format("Redeclaration: %s (%s) and %s (%s) (no line info available)",
|
||||||
|
DescriptorUtils.getFqName(it), it,
|
||||||
|
DescriptorUtils.getFqName(classifier), classifier))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -93,7 +93,7 @@ public class DefaultModalityModifiersTest extends KotlinLiteFixture {
|
|||||||
AnalysisResult bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(file);
|
AnalysisResult bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(file);
|
||||||
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||||
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||||
LexicalScopeKind.SYNTHETIC, RedeclarationHandler.DO_NOTHING,
|
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -94,7 +94,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
|
final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
|
||||||
assert contextClass instanceof ClassDescriptor;
|
assert contextClass instanceof ClassDescriptor;
|
||||||
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||||
RedeclarationHandler.THROW_EXCEPTION,
|
ThrowingLocalRedeclarationChecker.INSTANCE,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.test.KotlinLiteFixture;
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -210,7 +209,7 @@ public class TypeUnifierTest extends KotlinLiteFixture {
|
|||||||
|
|
||||||
private TypeProjection makeType(String typeStr) {
|
private TypeProjection makeType(String typeStr) {
|
||||||
LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, builtIns.getBuiltInsModule(),
|
LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, builtIns.getBuiltInsModule(),
|
||||||
false, null, LexicalScopeKind.SYNTHETIC, RedeclarationHandler.DO_NOTHING,
|
false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -164,7 +164,7 @@ fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: Declarati
|
|||||||
|
|
||||||
is FunctionDescriptor ->
|
is FunctionDescriptor ->
|
||||||
FunctionDescriptorUtil.getFunctionInnerScope(getOuterScope(descriptor, resolutionFacade),
|
FunctionDescriptorUtil.getFunctionInnerScope(getOuterScope(descriptor, resolutionFacade),
|
||||||
descriptor, RedeclarationHandler.DO_NOTHING)
|
descriptor, LocalRedeclarationChecker.DO_NOTHING)
|
||||||
|
|
||||||
is PropertyDescriptor ->
|
is PropertyDescriptor ->
|
||||||
ScopeUtils.makeScopeForPropertyHeader(getOuterScope(descriptor, resolutionFacade), descriptor)
|
ScopeUtils.makeScopeForPropertyHeader(getOuterScope(descriptor, resolutionFacade), descriptor)
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||||
@@ -267,7 +266,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
|
|
||||||
is FunctionDescriptor -> {
|
is FunctionDescriptor -> {
|
||||||
val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null
|
val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null
|
||||||
FunctionDescriptorUtil.getFunctionInnerScope(outerScope, descriptor, RedeclarationHandler.DO_NOTHING)
|
FunctionDescriptorUtil.getFunctionInnerScope(outerScope, descriptor, LocalRedeclarationChecker.DO_NOTHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
is PropertyDescriptor -> {
|
is PropertyDescriptor -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user