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 public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType("kotlin/PropertyMetadata");
035 public static final Type PROPERTY_METADATA_IMPL_TYPE = Type.getObjectType("kotlin/PropertyMetadataImpl");
036
037 public static final Type LAMBDA = Type.getObjectType("kotlin/jvm/internal/Lambda");
038 public static final Type FUNCTION_REFERENCE = Type.getObjectType("kotlin/jvm/internal/FunctionReference");
039
040 public static final Type K_CLASS_TYPE = reflect("KClass");
041 public static final Type K_CLASS_ARRAY_TYPE = Type.getObjectType("[" + K_CLASS_TYPE.getDescriptor());
042 public static final Type K_PACKAGE_TYPE = reflect("KPackage");
043
044 public static final Type K_FUNCTION = reflect("KFunction");
045 public static final Type K_TOP_LEVEL_FUNCTION = reflect("KTopLevelFunction");
046 public static final Type K_MEMBER_FUNCTION = reflect("KMemberFunction");
047 public static final Type K_TOP_LEVEL_EXTENSION_FUNCTION = reflect("KTopLevelExtensionFunction");
048 public static final Type K_LOCAL_FUNCTION = reflect("KLocalFunction");
049
050 public static final Type K_MEMBER_PROPERTY_TYPE = reflect("KMemberProperty");
051 public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = reflect("KMutableMemberProperty");
052 public static final Type K_TOP_LEVEL_VARIABLE_TYPE = reflect("KTopLevelVariable");
053 public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_TYPE = reflect("KMutableTopLevelVariable");
054 public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KTopLevelExtensionProperty");
055 public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KMutableTopLevelExtensionProperty");
056
057 public static final String REFLECTION = "kotlin/jvm/internal/Reflection";
058
059 public static final String REF_TYPE_PREFIX = "kotlin/jvm/internal/Ref$";
060 public static final Type OBJECT_REF_TYPE = Type.getObjectType(REF_TYPE_PREFIX + "ObjectRef");
061
062 public static final Type DEFAULT_CONSTRUCTOR_MARKER = Type.getObjectType("kotlin/jvm/internal/DefaultConstructorMarker");
063
064 @NotNull
065 private static Type reflect(@NotNull String className) {
066 return Type.getObjectType("kotlin/reflect/" + className);
067 }
068
069 @NotNull
070 public static Type getType(@NotNull Class<?> javaClass) {
071 Type type = TYPES_MAP.get(javaClass);
072 if (type == null) {
073 type = Type.getType(javaClass);
074 TYPES_MAP.put(javaClass, type);
075 }
076 return type;
077 }
078
079 private AsmTypes() {
080 }
081 }