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.builtins;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.kotlin.name.FqName;
021 import org.jetbrains.kotlin.name.Name;
022
023 import java.util.Collections;
024 import java.util.EnumSet;
025 import java.util.Set;
026
027 public enum PrimitiveType {
028 BOOLEAN("Boolean"),
029 CHAR("Char"),
030 BYTE("Byte"),
031 SHORT("Short"),
032 INT("Int"),
033 FLOAT("Float"),
034 LONG("Long"),
035 DOUBLE("Double"),
036 ;
037
038 public static final Set<PrimitiveType> NUMBER_TYPES =
039 Collections.unmodifiableSet(EnumSet.of(CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE));
040
041 private final Name typeName;
042 private final Name arrayTypeName;
043 private FqName typeFqName = null;
044 private FqName arrayTypeFqName = null;
045
046 private PrimitiveType(String typeName) {
047 this.typeName = Name.identifier(typeName);
048 this.arrayTypeName = Name.identifier(typeName + "Array");
049 }
050
051 @NotNull
052 public Name getTypeName() {
053 return typeName;
054 }
055
056 @NotNull
057 public FqName getTypeFqName() {
058 if (typeFqName != null)
059 return typeFqName;
060
061 typeFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(typeName);
062 return typeFqName;
063 }
064
065 @NotNull
066 public Name getArrayTypeName() {
067 return arrayTypeName;
068 }
069
070 @NotNull
071 public FqName getArrayTypeFqName() {
072 if (arrayTypeFqName != null)
073 return arrayTypeFqName;
074
075 arrayTypeFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(arrayTypeName);
076 return arrayTypeFqName;
077 }
078 }