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        public static final Type ENUM_TYPE = getType(Enum.class);
033    
034        public static final Type UNIT_TYPE = Type.getObjectType("kotlin/Unit");
035    
036        public static final Type LAMBDA = Type.getObjectType("kotlin/jvm/internal/Lambda");
037        public static final Type FUNCTION_REFERENCE = Type.getObjectType("kotlin/jvm/internal/FunctionReference");
038        public static final Type PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/PropertyReference0");
039        public static final Type PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/PropertyReference1");
040        public static final Type PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/PropertyReference2");
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        public static final Type MUTABLE_PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2");
044    
045    
046        public static final Type[] PROPERTY_REFERENCE_IMPL = {
047                Type.getObjectType("kotlin/jvm/internal/PropertyReference0Impl"),
048                Type.getObjectType("kotlin/jvm/internal/PropertyReference1Impl"),
049                Type.getObjectType("kotlin/jvm/internal/PropertyReference2Impl")
050        };
051        public static final Type[] MUTABLE_PROPERTY_REFERENCE_IMPL = {
052                Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference0Impl"),
053                Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1Impl"),
054                Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2Impl")
055        };
056    
057        public static final Type K_CLASS_TYPE = reflect("KClass");
058        public static final Type K_CLASS_ARRAY_TYPE = Type.getObjectType("[" + K_CLASS_TYPE.getDescriptor());
059        public static final Type K_DECLARATION_CONTAINER_TYPE = reflect("KDeclarationContainer");
060    
061        public static final Type K_FUNCTION = reflect("KFunction");
062    
063        public static final Type K_PROPERTY_TYPE = reflect("KProperty");
064        public static final Type K_PROPERTY0_TYPE = reflect("KProperty0");
065        public static final Type K_PROPERTY1_TYPE = reflect("KProperty1");
066        public static final Type K_PROPERTY2_TYPE = reflect("KProperty2");
067        public static final Type K_MUTABLE_PROPERTY0_TYPE = reflect("KMutableProperty0");
068        public static final Type K_MUTABLE_PROPERTY1_TYPE = reflect("KMutableProperty1");
069        public static final Type K_MUTABLE_PROPERTY2_TYPE = reflect("KMutableProperty2");
070    
071        public static final String REFLECTION = "kotlin/jvm/internal/Reflection";
072    
073        public static final String REF_TYPE_PREFIX = "kotlin/jvm/internal/Ref$";
074        public static final Type OBJECT_REF_TYPE = Type.getObjectType(REF_TYPE_PREFIX + "ObjectRef");
075    
076        public static final Type DEFAULT_CONSTRUCTOR_MARKER = Type.getObjectType("kotlin/jvm/internal/DefaultConstructorMarker");
077    
078        @NotNull
079        private static Type reflect(@NotNull String className) {
080            return Type.getObjectType("kotlin/reflect/" + className);
081        }
082    
083        @NotNull
084        public static Type getType(@NotNull Class<?> javaClass) {
085            Type type = TYPES_MAP.get(javaClass);
086            if (type == null) {
087                type = Type.getType(javaClass);
088                TYPES_MAP.put(javaClass, type);
089            }
090            return type;
091        }
092    
093        private AsmTypes() {
094        }
095    }