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.*;
022    import org.jetbrains.kotlin.load.java.structure.JavaField;
023    import org.jetbrains.kotlin.load.java.structure.JavaMember;
024    import org.jetbrains.kotlin.load.java.structure.JavaMethod;
025    import org.jetbrains.kotlin.types.JetType;
026    
027    import java.util.Collections;
028    import java.util.List;
029    
030    public interface ExternalSignatureResolver {
031        abstract class MemberSignature {
032            private final List<String> signatureErrors;
033    
034            protected MemberSignature(@NotNull List<String> signatureErrors) {
035                this.signatureErrors = signatureErrors;
036            }
037    
038            @NotNull
039            public List<String> getErrors() {
040                return signatureErrors;
041            }
042        }
043    
044        class AlternativeMethodSignature extends MemberSignature {
045            private final JetType returnType;
046            private final JetType receiverType;
047            private final List<ValueParameterDescriptor> valueParameters;
048            private final List<TypeParameterDescriptor> typeParameters;
049            private final boolean hasStableParameterNames;
050    
051            public AlternativeMethodSignature(
052                    @Nullable JetType returnType,
053                    @Nullable JetType receiverType,
054                    @NotNull List<ValueParameterDescriptor> valueParameters,
055                    @NotNull List<TypeParameterDescriptor> typeParameters,
056                    @NotNull List<String> signatureErrors,
057                    boolean hasStableParameterNames
058            ) {
059                super(signatureErrors);
060                this.returnType = returnType;
061                this.receiverType = receiverType;
062                this.valueParameters = valueParameters;
063                this.typeParameters = typeParameters;
064                this.hasStableParameterNames = hasStableParameterNames;
065            }
066    
067            @Nullable
068            public JetType getReturnType() {
069                return returnType;
070            }
071    
072            @Nullable
073            public JetType getReceiverType() {
074                return receiverType;
075            }
076    
077            @NotNull
078            public List<ValueParameterDescriptor> getValueParameters() {
079                return valueParameters;
080            }
081    
082            @NotNull
083            public List<TypeParameterDescriptor> getTypeParameters() {
084                return typeParameters;
085            }
086    
087            public boolean hasStableParameterNames() {
088                return hasStableParameterNames;
089            }
090        }
091    
092        class AlternativeFieldSignature extends MemberSignature {
093            private final JetType returnType;
094    
095            public AlternativeFieldSignature(@NotNull JetType returnType, @Nullable String signatureError) {
096                super(signatureError == null ? Collections.<String>emptyList() : Collections.singletonList(signatureError));
097                this.returnType = returnType;
098            }
099    
100            @NotNull
101            public JetType getReturnType() {
102                return returnType;
103            }
104        }
105    
106        class PropagatedMethodSignature extends AlternativeMethodSignature {
107            private final List<FunctionDescriptor> superMethods;
108    
109            public PropagatedMethodSignature(
110                    @Nullable JetType returnType,
111                    @Nullable JetType receiverType,
112                    @NotNull List<ValueParameterDescriptor> valueParameters,
113                    @NotNull List<TypeParameterDescriptor> typeParameters,
114                    @NotNull List<String> signatureErrors,
115                    boolean hasStableParameterNames,
116                    @NotNull List<FunctionDescriptor> superMethods
117            ) {
118                super(returnType, receiverType, valueParameters, typeParameters, signatureErrors, hasStableParameterNames);
119                this.superMethods = superMethods;
120            }
121    
122            @NotNull
123            public List<FunctionDescriptor> getSuperMethods() {
124                return superMethods;
125            }
126        }
127    
128        @NotNull
129        PropagatedMethodSignature resolvePropagatedSignature(
130                @NotNull JavaMethod method,
131                @NotNull ClassDescriptor owner,
132                @NotNull JetType returnType,
133                @Nullable JetType receiverType,
134                @NotNull List<ValueParameterDescriptor> valueParameters,
135                @NotNull List<TypeParameterDescriptor> typeParameters
136        );
137    
138        @NotNull
139        AlternativeMethodSignature resolveAlternativeMethodSignature(
140                @NotNull JavaMember methodOrConstructor,
141                boolean hasSuperMethods,
142                @Nullable JetType returnType,
143                @Nullable JetType receiverType,
144                @NotNull List<ValueParameterDescriptor> valueParameters,
145                @NotNull List<TypeParameterDescriptor> typeParameters,
146                boolean hasStableParameterNames
147        );
148    
149        @NotNull
150        AlternativeFieldSignature resolveAlternativeFieldSignature(
151                @NotNull JavaField field,
152                @NotNull JetType returnType,
153                boolean isVar
154        );
155    
156        void reportSignatureErrors(@NotNull CallableMemberDescriptor descriptor, @NotNull List<String> signatureErrors);
157    }