Extract SpecialNames.isClassObjectName

This commit is contained in:
Alexander Udalov
2013-10-29 22:03:04 +04:00
parent 69ed375ce1
commit 8b5aa94484
3 changed files with 35 additions and 19 deletions
@@ -29,21 +29,18 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.isClassObjectName;
public class DeserializedResolverUtils {
private DeserializedResolverUtils() {
}
@NotNull
public static FqName kotlinFqNameToJavaFqName(@NotNull FqNameUnsafe kotlinFqName) {
List<String> correctedSegments = new ArrayList<String>();
for (Name segment : kotlinFqName.pathSegments()) {
if (segment.asString().startsWith("<class-object-for")) {
correctedSegments.add(JvmAbi.CLASS_OBJECT_CLASS_NAME);
}
else {
assert !segment.isSpecial();
correctedSegments.add(segment.asString());
}
List<Name> segments = kotlinFqName.pathSegments();
List<String> correctedSegments = new ArrayList<String>(segments.size());
for (Name segment : segments) {
correctedSegments.add(isClassObjectName(segment) ? JvmAbi.CLASS_OBJECT_CLASS_NAME : segment.getIdentifier());
}
return FqName.fromSegments(correctedSegments);
}
@@ -22,10 +22,16 @@ public class SpecialNames {
public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
public static final Name ROOT_NAMESPACE = Name.special("<root namespace>");
private static final String CLASS_OBJECT_FOR = "<class-object-for-";
private SpecialNames() {}
@NotNull
public static Name getClassObjectName(@NotNull Name className) {
return Name.special("<class-object-for-" + className.asString() + ">");
return Name.special(CLASS_OBJECT_FOR + className.asString() + ">");
}
public static boolean isClassObjectName(@NotNull Name name) {
return name.isSpecial() && name.asString().startsWith(CLASS_OBJECT_FOR);
}
}
@@ -1,3 +1,19 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.types.lang;
import org.jetbrains.annotations.NotNull;
@@ -11,6 +27,8 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.isClassObjectName;
public class BuiltInsSerializationUtil {
private static final String CLASS_METADATA_FILE_EXTENSION = "kotlin_class";
private static final String PACKAGE_FILE_NAME = ".kotlin_package";
@@ -23,15 +41,10 @@ public class BuiltInsSerializationUtil {
@NotNull
public static String relativeClassNameToFilePath(@NotNull FqNameUnsafe className) {
List<String> correctedSegments = new ArrayList<String>();
for (Name segment : className.pathSegments()) {
if (segment.asString().startsWith("<class-object-for")) {
correctedSegments.add(CLASS_OBJECT_NAME);
}
else {
assert !segment.isSpecial();
correctedSegments.add(segment.asString());
}
List<Name> segments = className.pathSegments();
List<String> correctedSegments = new ArrayList<String>(segments.size());
for (Name segment : segments) {
correctedSegments.add(isClassObjectName(segment) ? CLASS_OBJECT_NAME : segment.getIdentifier());
}
return FqName.fromSegments(correctedSegments).asString();
}