Replace RedeclarationHandler by LocalRedeclarationChecker

This commit is contained in:
Stanislav Erokhin
2016-02-24 21:15:52 +03:00
parent 7d32fad063
commit f85abed6e6
19 changed files with 178 additions and 207 deletions
@@ -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");
* 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.psiUtil.PsiUtilsKt;
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.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor;
@@ -574,7 +572,7 @@ public class BodyResolver {
final ConstructorDescriptor unsubstitutedPrimaryConstructor
) {
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>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -810,7 +808,7 @@ public class BodyResolver {
final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null,
LexicalScopeKind.PROPERTY_ACCESSOR_BODY,
RedeclarationHandler.DO_NOTHING, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
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");
* 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.dataClassUtils.DataClassUtilsKt;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
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.*;
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
import org.jetbrains.kotlin.storage.StorageManager;
@@ -723,7 +720,7 @@ public class DescriptorResolver {
}
else {
LexicalWritableScope writableScope = new LexicalWritableScope(
scope, containingDeclaration, false, null, new TraceBasedRedeclarationHandler(trace),
scope, containingDeclaration, false, null, new TraceBasedLocalRedeclarationChecker(trace),
LexicalScopeKind.PROPERTY_HEADER);
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
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");
* 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.LexicalScopeKind
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.storage.StorageManager
import org.jetbrains.kotlin.types.DeferredType
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
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.isFunctionExpression
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
import java.util.*
class FunctionDescriptorResolver(
@@ -140,7 +139,7 @@ class FunctionDescriptorResolver(
expectedFunctionType: KotlinType
) {
val innerScope = LexicalWritableScope(scope, functionDescriptor, true, null,
TraceBasedRedeclarationHandler(trace), LexicalScopeKind.FUNCTION_HEADER)
TraceBasedLocalRedeclarationChecker(trace), LexicalScopeKind.FUNCTION_HEADER)
val typeParameterDescriptors = descriptorResolver.
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.typeParameters, trace)
@@ -281,7 +280,7 @@ class FunctionDescriptorResolver(
scope,
constructorDescriptor,
false, null,
TraceBasedRedeclarationHandler(trace),
TraceBasedLocalRedeclarationChecker(trace),
LexicalScopeKind.CONSTRUCTOR_HEADER
)
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");
* you may not use this file except in compliance with the License.
@@ -62,18 +62,17 @@ public class FunctionDescriptorUtil {
@NotNull
public static LexicalScope getFunctionInnerScope(@NotNull LexicalScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
return getFunctionInnerScope(outerScope, descriptor, redeclarationHandler);
return getFunctionInnerScope(outerScope, descriptor, new TraceBasedLocalRedeclarationChecker(trace));
}
@NotNull
public static LexicalScope getFunctionInnerScope(
@NotNull LexicalScope outerScope,
@NotNull final FunctionDescriptor descriptor,
@NotNull RedeclarationHandler redeclarationHandler
@NotNull LocalRedeclarationChecker redeclarationChecker
) {
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>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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");
* 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.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
import org.jetbrains.kotlin.utils.Printer
class LexicalScopeImpl @JvmOverloads constructor(
@@ -28,10 +27,9 @@ class LexicalScopeImpl @JvmOverloads constructor(
override val isOwnerDescriptorAccessibleByLabel: Boolean,
override val implicitReceiver: ReceiverParameterDescriptor?,
override val kind: LexicalScopeKind,
redeclarationHandler: RedeclarationHandler = RedeclarationHandler.DO_NOTHING,
redeclarationChecker: LocalRedeclarationChecker = LocalRedeclarationChecker.DO_NOTHING,
initialize: LexicalScopeImpl.InitializeHandler.() -> Unit = {}
): LexicalScope, WritableScopeStorage(redeclarationHandler) {
override val parent = parent.takeSnapshot()
): LexicalScope, LexicalScopeStorage(parent, redeclarationChecker) {
init {
InitializeHandler().initialize()
@@ -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");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,19 @@
package org.jetbrains.kotlin.resolve.scopes
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.resolve.OverloadUtil
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
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()
@@ -31,12 +38,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
val name = descriptor.name
val originalDescriptor = variableOrClassDescriptorByName(name)
if (originalDescriptor != null) {
redeclarationHandler.handleRedeclaration(originalDescriptor, descriptor)
}
val descriptorIndex = addDescriptor(descriptor)
if (variablesAndClassifiersByName == null) {
@@ -48,8 +49,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
}
protected fun addFunctionDescriptorInternal(functionDescriptor: FunctionDescriptor) {
checkOverloadConflicts(functionDescriptor)
val name = functionDescriptor.name
val descriptorIndex = addDescriptor(functionDescriptor)
if (functionsByName == null) {
@@ -59,23 +58,6 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
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? {
if (descriptorLimit == 0) return null
@@ -104,6 +86,7 @@ abstract class WritableScopeStorage(val redeclarationHandler: RedeclarationHandl
}
private fun addDescriptor(descriptor: DeclarationDescriptor): Int {
redeclarationChecker.checkBeforeAddingToScope(this, descriptor)
addedDescriptors.add(descriptor)
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");
* 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.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
import org.jetbrains.kotlin.utils.Printer
class LexicalWritableScope(
@@ -27,17 +26,15 @@ class LexicalWritableScope(
override val ownerDescriptor: DeclarationDescriptor,
override val isOwnerDescriptorAccessibleByLabel: Boolean,
override val implicitReceiver: ReceiverParameterDescriptor?,
redeclarationHandler: RedeclarationHandler,
redeclarationChecker: LocalRedeclarationChecker,
override val kind: LexicalScopeKind
) : LexicalScope, WritableScopeStorage(redeclarationHandler) {
) : LexicalScopeStorage(parent, redeclarationChecker) {
enum class LockLevel {
WRITING,
BOTH,
READING
}
override val parent = parent.takeSnapshot()
private var lockLevel: LockLevel = LockLevel.WRITING
private var lastSnapshot: Snapshot? = null
@@ -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");
* 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.Nullable;
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;
public final class ScopeUtils {
@@ -44,7 +47,7 @@ public final class ScopeUtils {
) {
return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER,
// redeclaration on type parameters should be reported early, see: DescriptorResolver.resolvePropertyDescriptor()
RedeclarationHandler.DO_NOTHING,
LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
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");
* 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.LexicalScopeKind;
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.KotlinType;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
@@ -163,7 +164,7 @@ public class ExpressionTypingServices {
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
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);
KotlinTypeInfo r;
@@ -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");
* 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.DescriptorToSourceUtils;
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.LexicalScopeKind;
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.utils.ScopeUtilsKt;
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.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;
public class ExpressionTypingUtils {
@@ -82,7 +82,7 @@ public class ExpressionTypingUtils {
@NotNull
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) {
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);
return scope;
}
@@ -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");
* 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.resolve.DescriptorUtils
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.test.*
import org.jetbrains.kotlin.test.KotlinTestUtils.TestFileFactoryNoModules
@@ -217,12 +220,13 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
private class ScopeWithClassifiers(classifiers: List<ClassifierDescriptor>) : MemberScopeImpl() {
private val classifierMap = HashMap<Name, ClassifierDescriptor>()
val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION
init {
for (classifier in classifiers) {
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");
* 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);
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
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>() {
@Override
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");
* 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);
assert contextClass instanceof ClassDescriptor;
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
RedeclarationHandler.THROW_EXCEPTION,
ThrowingLocalRedeclarationChecker.INSTANCE,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
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");
* 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.tests.di.InjectionKt;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -210,7 +209,7 @@ public class TypeUnifierTest extends KotlinLiteFixture {
private TypeProjection makeType(String typeStr) {
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>() {
@Override
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");
* you may not use this file except in compliance with the License.
@@ -164,7 +164,7 @@ fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: Declarati
is FunctionDescriptor ->
FunctionDescriptorUtil.getFunctionInnerScope(getOuterScope(descriptor, resolutionFacade),
descriptor, RedeclarationHandler.DO_NOTHING)
descriptor, LocalRedeclarationChecker.DO_NOTHING)
is PropertyDescriptor ->
ScopeUtils.makeScopeForPropertyHeader(getOuterScope(descriptor, resolutionFacade), 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");
* 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.isExtension
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.scopes.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
@@ -267,7 +266,7 @@ object ReplaceWithAnnotationAnalyzer {
is FunctionDescriptor -> {
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 -> {