001    /*
002     * Copyright 2010-2013 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.jet.lang.resolve.java;
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    import static org.jetbrains.jet.lang.types.lang.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
026    
027    public class AsmTypeConstants {
028        private static final Map<Class<?>, Type> TYPES_MAP = new HashMap<Class<?>, Type>();
029    
030        public static final Type OBJECT_TYPE = getType(Object.class);
031        public static final Type JAVA_STRING_TYPE = getType(String.class);
032        public static final Type JAVA_THROWABLE_TYPE = getType(Throwable.class);
033    
034        public static final Type UNIT_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/Unit");
035        public static final Type FUNCTION0_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/Function0");
036        public static final Type FUNCTION1_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/Function1");
037        public static final Type INT_RANGE_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/IntRange");
038        public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadata");
039        public static final Type PROPERTY_METADATA_IMPL_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadataImpl");
040    
041        public static final Type OBJECT_REF_TYPE = Type.getObjectType("kotlin/jvm/internal/Ref$ObjectRef");
042    
043        public static Type getType(@NotNull Class<?> javaClass) {
044            Type type = TYPES_MAP.get(javaClass);
045            if (type == null) {
046                type = Type.getType(javaClass);
047                TYPES_MAP.put(javaClass, type);
048            }
049            return type;
050        }
051    
052        private AsmTypeConstants() {
053        }
054    }