001    /*
002     * Copyright 2010-2013 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.jet.codegen.signature;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.asm4.Type;
022    import org.jetbrains.asm4.commons.Method;
023    
024    import java.util.List;
025    
026    public class JvmMethodSignature {
027        private final Method asmMethod;
028        private final String genericsSignature;
029        private final List<JvmMethodParameterSignature> valueParameters;
030    
031        JvmMethodSignature(
032                @NotNull Method asmMethod,
033                @Nullable String genericsSignature,
034                @NotNull List<JvmMethodParameterSignature> valueParameters
035        ) {
036            this.asmMethod = asmMethod;
037            this.genericsSignature = genericsSignature;
038            this.valueParameters = valueParameters;
039        }
040    
041        @NotNull
042        public Method getAsmMethod() {
043            return asmMethod;
044        }
045    
046        @Nullable
047        public String getGenericsSignature() {
048            return genericsSignature;
049        }
050    
051        @NotNull
052        public List<JvmMethodParameterSignature> getValueParameters() {
053            return valueParameters;
054        }
055    
056        @NotNull
057        public Type getReturnType() {
058            return asmMethod.getReturnType();
059        }
060    
061        @NotNull
062        public JvmMethodSignature replaceName(@NotNull String newName) {
063            return newName.equals(asmMethod.getName()) ?
064                   this :
065                   new JvmMethodSignature(new Method(newName, asmMethod.getDescriptor()), genericsSignature, valueParameters);
066        }
067    
068        @Override
069        public boolean equals(Object o) {
070            if (this == o) return true;
071            if (!(o instanceof JvmMethodSignature)) return false;
072    
073            JvmMethodSignature that = (JvmMethodSignature) o;
074    
075            return asmMethod.equals(that.asmMethod) &&
076                   (genericsSignature == null ? that.genericsSignature == null : genericsSignature.equals(that.genericsSignature)) &&
077                   valueParameters.equals(that.valueParameters);
078        }
079    
080        @Override
081        public int hashCode() {
082            int result = asmMethod.hashCode();
083            result = 31 * result + (genericsSignature != null ? genericsSignature.hashCode() : 0);
084            result = 31 * result + valueParameters.hashCode();
085            return result;
086        }
087    
088        @Override
089        public String toString() {
090            return asmMethod.toString();
091        }
092    }