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.jvm;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.org.objectweb.asm.Type;
021
022 import java.util.HashMap;
023 import java.util.Map;
024
025 public class AsmTypes {
026 private static final Map<Class<?>, Type> TYPES_MAP = new HashMap<Class<?>, Type>();
027
028 public static final Type OBJECT_TYPE = getType(Object.class);
029 public static final Type JAVA_STRING_TYPE = getType(String.class);
030 public static final Type JAVA_THROWABLE_TYPE = getType(Throwable.class);
031 public static final Type JAVA_CLASS_TYPE = getType(Class.class);
032
033 public static final Type UNIT_TYPE = Type.getObjectType("kotlin/Unit");
034
035 public static final Type LAMBDA = Type.getObjectType("kotlin/jvm/internal/Lambda");
036 public static final Type FUNCTION_REFERENCE = Type.getObjectType("kotlin/jvm/internal/FunctionReference");
037 public static final Type PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/PropertyReference0");
038 public static final Type PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/PropertyReference1");
039 public static final Type PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/PropertyReference2");
040 public static final Type MUTABLE_PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference0");
041 public static final Type MUTABLE_PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1");
042 public static final Type MUTABLE_PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2");
043
044 public static final Type[] PROPERTY_REFERENCE_IMPL = {
045 Type.getObjectType("kotlin/jvm/internal/PropertyReference0Impl"),
046 Type.getObjectType("kotlin/jvm/internal/PropertyReference1Impl"),
047 Type.getObjectType("kotlin/jvm/internal/PropertyReference2Impl")
048 };
049 public static final Type[] MUTABLE_PROPERTY_REFERENCE_IMPL = {
050 Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference0Impl"),
051 Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1Impl"),
052 Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2Impl")
053 };
054
055 public static final Type K_CLASS_TYPE = reflect("KClass");
056 public static final Type K_CLASS_ARRAY_TYPE = Type.getObjectType("[" + K_CLASS_TYPE.getDescriptor());
057 public static final Type K_DECLARATION_CONTAINER_TYPE = reflect("KDeclarationContainer");
058
059 public static final Type K_FUNCTION = reflect("KFunction");
060
061 public static final Type K_PROPERTY_TYPE = reflect("KProperty");
062 public static final Type K_PROPERTY0_TYPE = reflect("KProperty0");
063 public static final Type K_PROPERTY1_TYPE = reflect("KProperty1");
064 public static final Type K_PROPERTY2_TYPE = reflect("KProperty2");
065 public static final Type K_MUTABLE_PROPERTY0_TYPE = reflect("KMutableProperty0");
066 public static final Type K_MUTABLE_PROPERTY1_TYPE = reflect("KMutableProperty1");
067 public static final Type K_MUTABLE_PROPERTY2_TYPE = reflect("KMutableProperty2");
068
069 public static final String REFLECTION = "kotlin/jvm/internal/Reflection";
070
071 public static final String REF_TYPE_PREFIX = "kotlin/jvm/internal/Ref$";
072 public static final Type OBJECT_REF_TYPE = Type.getObjectType(REF_TYPE_PREFIX + "ObjectRef");
073
074 public static final Type DEFAULT_CONSTRUCTOR_MARKER = Type.getObjectType("kotlin/jvm/internal/DefaultConstructorMarker");
075
076 @NotNull
077 private static Type reflect(@NotNull String className) {
078 return Type.getObjectType("kotlin/reflect/" + className);
079 }
080
081 @NotNull
082 public static Type getType(@NotNull Class<?> javaClass) {
083 Type type = TYPES_MAP.get(javaClass);
084 if (type == null) {
085 type = Type.getType(javaClass);
086 TYPES_MAP.put(javaClass, type);
087 }
088 return type;
089 }
090
091 private AsmTypes() {
092 }
093 }