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.codegen.optimization.boxing;
018
019 import com.google.common.collect.ImmutableMap;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.org.objectweb.asm.Type;
022 import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue;
023
024 public class ProgressionIteratorBasicValue extends BasicValue {
025 private final static ImmutableMap<String, Type> VALUES_TYPENAME_TO_TYPE;
026
027 static {
028 VALUES_TYPENAME_TO_TYPE = ImmutableMap.<String, Type>builder().
029 put("Byte", Type.BYTE_TYPE).
030 put("Char", Type.CHAR_TYPE).
031 put("Short", Type.SHORT_TYPE).
032 put("Int", Type.INT_TYPE).
033 put("Long", Type.LONG_TYPE).
034 put("Float", Type.FLOAT_TYPE).
035 put("Double", Type.DOUBLE_TYPE).
036 build();
037 }
038
039 @NotNull
040 private static Type getValuesType(@NotNull String valuesTypeName) {
041 Type type = VALUES_TYPENAME_TO_TYPE.get(valuesTypeName);
042 assert type != null : "Unexpected type " + valuesTypeName;
043 return type;
044 }
045
046 private final Type valuesPrimitiveType;
047 private final String valuesPrimitiveTypeName;
048
049 public ProgressionIteratorBasicValue(@NotNull String valuesPrimitiveTypeName) {
050 super(Type.getObjectType("kotlin/" + valuesPrimitiveTypeName + "Iterator"));
051 this.valuesPrimitiveType = getValuesType(valuesPrimitiveTypeName);
052 this.valuesPrimitiveTypeName = valuesPrimitiveTypeName;
053 }
054
055 public Type getValuesPrimitiveType() {
056 return valuesPrimitiveType;
057 }
058
059 public String getValuesPrimitiveTypeName() {
060 return valuesPrimitiveTypeName;
061 }
062
063 @Override
064 public boolean equals(Object o) {
065 if (this == o) return true;
066 if (o == null || getClass() != o.getClass()) return false;
067 if (!super.equals(o)) return false;
068
069 ProgressionIteratorBasicValue value = (ProgressionIteratorBasicValue) o;
070
071 if (!valuesPrimitiveType.equals(value.valuesPrimitiveType)) return false;
072
073 return true;
074 }
075
076 @NotNull
077 public String getNextMethodName() {
078 return "next" + getValuesPrimitiveTypeName();
079 }
080
081 @NotNull
082 public String getNextMethodDesc() {
083 return "()" + getValuesPrimitiveType().getDescriptor();
084 }
085 }