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.name;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    
022    public class SpecialNames {
023        public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
024        public static final Name ROOT_PACKAGE = Name.special("<root package>");
025    
026        public static final Name DEFAULT_NAME_FOR_COMPANION_OBJECT = Name.identifier("Companion");
027    
028        // This name is used as a key for the case when something has no name _due to a syntactic error_
029        // Example: fun (x: Int) = 5
030        //          There's no name for this function in the PSI
031        // The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
032        public static final Name SAFE_IDENTIFIER_FOR_NO_NAME = Name.identifier("no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
033    
034        @NotNull
035        public static Name safeIdentifier(@Nullable Name name) {
036            return name != null && !name.isSpecial() ? name : SAFE_IDENTIFIER_FOR_NO_NAME;
037        }
038    
039        @NotNull
040        public static Name safeIdentifier(@Nullable String name) {
041            return safeIdentifier(name == null ? null : Name.identifier(name));
042        }
043    
044        public static boolean isSafeIdentifier(@NotNull Name name) {
045            return !name.asString().isEmpty() && !name.isSpecial();
046        }
047    
048        private SpecialNames() {}
049    }