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.load.java.components;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
022 import org.jetbrains.kotlin.descriptors.ClassDescriptor;
023 import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
024 import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
025 import org.jetbrains.kotlin.load.java.structure.JavaMethod;
026 import org.jetbrains.kotlin.types.KotlinType;
027
028 import java.util.Collections;
029 import java.util.List;
030
031 public interface SignaturePropagator {
032 SignaturePropagator DO_NOTHING = new SignaturePropagator() {
033 @NotNull
034 @Override
035 public PropagatedSignature resolvePropagatedSignature(
036 @NotNull JavaMethod method,
037 @NotNull ClassDescriptor owner,
038 @NotNull KotlinType returnType,
039 @Nullable KotlinType receiverType,
040 @NotNull List<ValueParameterDescriptor> valueParameters,
041 @NotNull List<TypeParameterDescriptor> typeParameters
042 ) {
043 return new PropagatedSignature(
044 returnType, receiverType, valueParameters, typeParameters, Collections.<String>emptyList(), false
045 );
046 }
047
048 @Override
049 public void reportSignatureErrors(@NotNull CallableMemberDescriptor descriptor, @NotNull List<String> signatureErrors) {
050 throw new UnsupportedOperationException("Should not be called");
051 }
052 };
053
054 class PropagatedSignature {
055 private final KotlinType returnType;
056 private final KotlinType receiverType;
057 private final List<ValueParameterDescriptor> valueParameters;
058 private final List<TypeParameterDescriptor> typeParameters;
059 private final List<String> signatureErrors;
060 private final boolean hasStableParameterNames;
061
062 public PropagatedSignature(
063 @NotNull KotlinType returnType,
064 @Nullable KotlinType receiverType,
065 @NotNull List<ValueParameterDescriptor> valueParameters,
066 @NotNull List<TypeParameterDescriptor> typeParameters,
067 @NotNull List<String> signatureErrors,
068 boolean hasStableParameterNames
069 ) {
070 this.returnType = returnType;
071 this.receiverType = receiverType;
072 this.valueParameters = valueParameters;
073 this.typeParameters = typeParameters;
074 this.signatureErrors = signatureErrors;
075 this.hasStableParameterNames = hasStableParameterNames;
076 }
077
078 @NotNull
079 public KotlinType getReturnType() {
080 return returnType;
081 }
082
083 @Nullable
084 public KotlinType getReceiverType() {
085 return receiverType;
086 }
087
088 @NotNull
089 public List<ValueParameterDescriptor> getValueParameters() {
090 return valueParameters;
091 }
092
093 @NotNull
094 public List<TypeParameterDescriptor> getTypeParameters() {
095 return typeParameters;
096 }
097
098 public boolean hasStableParameterNames() {
099 return hasStableParameterNames;
100 }
101
102 @NotNull
103 public List<String> getErrors() {
104 return signatureErrors;
105 }
106 }
107
108 @NotNull
109 PropagatedSignature resolvePropagatedSignature(
110 @NotNull JavaMethod method,
111 @NotNull ClassDescriptor owner,
112 @NotNull KotlinType returnType,
113 @Nullable KotlinType receiverType,
114 @NotNull List<ValueParameterDescriptor> valueParameters,
115 @NotNull List<TypeParameterDescriptor> typeParameters
116 );
117
118 void reportSignatureErrors(@NotNull CallableMemberDescriptor descriptor, @NotNull List<String> signatureErrors);
119 }