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 FUNCTION1_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/Function1");
036        public static final Type INT_RANGE_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/IntRange");
037        public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadata");
038        public static final Type PROPERTY_METADATA_IMPL_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadataImpl");
039    
040        public static final Type K_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMemberProperty");
041        public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMutableMemberProperty");
042    
043        public static final Type K_CLASS_IMPL_TYPE = reflectInternal("KClassImpl");
044        public static final Type K_PACKAGE_IMPL_TYPE = reflectInternal("KPackageImpl");
045        public static final Type K_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KTopLevelVariableImpl");
046        public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KMutableTopLevelVariableImpl");
047        public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelExtensionPropertyImpl");
048        public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelExtensionPropertyImpl");
049    
050        public static final String REFLECTION_INTERNAL_PACKAGE = reflectInternal("InternalPackage").getInternalName();
051    
052        public static final Type OBJECT_REF_TYPE = Type.getObjectType("kotlin/jvm/internal/Ref$ObjectRef");
053    
054        @NotNull
055        private static Type reflectInternal(@NotNull String className) {
056            return Type.getObjectType("kotlin/reflect/jvm/internal/" + className);
057        }
058    
059        @NotNull
060        public static Type getType(@NotNull Class<?> javaClass) {
061            Type type = TYPES_MAP.get(javaClass);
062            if (type == null) {
063                type = Type.getType(javaClass);
064                TYPES_MAP.put(javaClass, type);
065            }
066            return type;
067        }
068    
069        private AsmTypeConstants() {
070        }
071    }