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.jet.lang.resolve.name.FqName;
021    import org.jetbrains.jet.lang.types.lang.PrimitiveType;
022    
023    import java.util.HashSet;
024    import java.util.Set;
025    
026    public enum JvmPrimitiveType {
027        BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean"),
028        CHAR(PrimitiveType.CHAR, "char", "java.lang.Character"),
029        BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte"),
030        SHORT(PrimitiveType.SHORT, "short", "java.lang.Short"),
031        INT(PrimitiveType.INT, "int", "java.lang.Integer"),
032        FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float"),
033        LONG(PrimitiveType.LONG, "long", "java.lang.Long"),
034        DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double"),
035        ;
036    
037        private static final Set<FqName> WRAPPERS_CLASS_NAMES;
038    
039        static {
040            WRAPPERS_CLASS_NAMES = new HashSet<FqName>();
041    
042            for (JvmPrimitiveType primitiveType : values()) {
043                WRAPPERS_CLASS_NAMES.add(primitiveType.getWrapperFqName());
044            }
045        }
046    
047        public static boolean isWrapperClassName(@NotNull FqName className) {
048            return WRAPPERS_CLASS_NAMES.contains(className);
049        }
050    
051        private final PrimitiveType primitiveType;
052        private final String name;
053        private final FqName wrapperFqName;
054    
055        private JvmPrimitiveType(@NotNull PrimitiveType primitiveType, @NotNull String name, @NotNull String wrapperClassName) {
056            this.primitiveType = primitiveType;
057            this.name = name;
058            this.wrapperFqName = new FqName(wrapperClassName);
059        }
060    
061        @NotNull
062        public PrimitiveType getPrimitiveType() {
063            return primitiveType;
064        }
065    
066        @NotNull
067        public String getName() {
068            return name;
069        }
070    
071        @NotNull
072        public FqName getWrapperFqName() {
073            return wrapperFqName;
074        }
075    }