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        public static final Type PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/PropertyReference0");
040        public static final Type PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/PropertyReference1");
041        public static final Type MUTABLE_PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference0");
042        public static final Type MUTABLE_PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1");
043    
044        public static final Type K_CLASS_TYPE = reflect("KClass");
045        public static final Type K_CLASS_ARRAY_TYPE = Type.getObjectType("[" + K_CLASS_TYPE.getDescriptor());
046        public static final Type K_PACKAGE_TYPE = reflect("KPackage");
047        public static final Type K_DECLARATION_CONTAINER_TYPE = reflect("KDeclarationContainer");
048    
049        public static final Type K_FUNCTION = reflect("KFunction");
050    
051        public static final Type K_PROPERTY0_TYPE = reflect("KProperty0");
052        public static final Type K_PROPERTY1_TYPE = reflect("KProperty1");
053        public static final Type K_MUTABLE_PROPERTY0_TYPE = reflect("KMutableProperty0");
054        public static final Type K_MUTABLE_PROPERTY1_TYPE = reflect("KMutableProperty1");
055    
056        public static final String REFLECTION = "kotlin/jvm/internal/Reflection";
057    
058        public static final String REF_TYPE_PREFIX = "kotlin/jvm/internal/Ref$";
059        public static final Type OBJECT_REF_TYPE = Type.getObjectType(REF_TYPE_PREFIX + "ObjectRef");
060    
061        public static final Type DEFAULT_CONSTRUCTOR_MARKER = Type.getObjectType("kotlin/jvm/internal/DefaultConstructorMarker");
062    
063        @NotNull
064        private static Type reflect(@NotNull String className) {
065            return Type.getObjectType("kotlin/reflect/" + className);
066        }
067    
068        @NotNull
069        public static Type getType(@NotNull Class<?> javaClass) {
070            Type type = TYPES_MAP.get(javaClass);
071            if (type == null) {
072                type = Type.getType(javaClass);
073                TYPES_MAP.put(javaClass, type);
074            }
075            return type;
076        }
077    
078        private AsmTypes() {
079        }
080    }