001 /*
002 * Copyright 2010-2015 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.kotlin.resolve.scopes;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
021 import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
022 import org.jetbrains.kotlin.resolve.DescriptorUtils;
023
024 public interface RedeclarationHandler {
025 RedeclarationHandler DO_NOTHING = new RedeclarationHandler() {
026 @Override
027 public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
028 }
029
030 @Override
031 public void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second) {
032 }
033 };
034 RedeclarationHandler THROW_EXCEPTION = new RedeclarationHandler() {
035 @Override
036 public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
037 throw new IllegalStateException(
038 String.format("Redeclaration: %s (%s) and %s (%s) (no line info available)", DescriptorUtils.getFqName(first), first,
039 DescriptorUtils.getFqName(second), second)
040 );
041 }
042
043 @Override
044 public void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second) {
045 throw new IllegalStateException(
046 String.format("Conflicting overloads: %s (%s) and %s (%s) (no line info available)",
047 DescriptorUtils.getFqName(first), first,
048 DescriptorUtils.getFqName(second), second)
049 );
050 }
051 };
052
053 void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second);
054 void handleConflictingOverloads(@NotNull CallableMemberDescriptor first, @NotNull CallableMemberDescriptor second);
055 }