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.kotlin; 018 019 import org.jetbrains.annotations.NotNull; 020 import org.jetbrains.jet.lang.descriptors.ClassDescriptor; 021 import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; 022 import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; 023 import org.jetbrains.jet.lang.resolve.DescriptorUtils; 024 import org.jetbrains.jet.lang.resolve.java.JvmAbi; 025 import org.jetbrains.jet.lang.resolve.name.FqName; 026 import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; 027 import org.jetbrains.jet.lang.resolve.name.Name; 028 029 import java.util.ArrayList; 030 import java.util.List; 031 032 import static org.jetbrains.jet.lang.resolve.name.SpecialNames.isClassObjectName; 033 034 public class DeserializedResolverUtils { 035 private DeserializedResolverUtils() { 036 } 037 038 @NotNull 039 public static FqName kotlinFqNameToJavaFqName(@NotNull FqNameUnsafe kotlinFqName) { 040 List<Name> segments = kotlinFqName.pathSegments(); 041 List<String> correctedSegments = new ArrayList<String>(segments.size()); 042 for (Name segment : segments) { 043 correctedSegments.add(isClassObjectName(segment) ? JvmAbi.CLASS_OBJECT_CLASS_NAME : segment.getIdentifier()); 044 } 045 return FqName.fromSegments(correctedSegments); 046 } 047 048 @NotNull 049 public static FqNameUnsafe naiveKotlinFqName(@NotNull ClassDescriptor descriptor) { 050 DeclarationDescriptor containing = descriptor.getContainingDeclaration(); 051 if (containing instanceof ClassDescriptor) { 052 return naiveKotlinFqName((ClassDescriptor) containing).child(descriptor.getName()); 053 } 054 else if (containing instanceof NamespaceDescriptor) { 055 return DescriptorUtils.getFQName(containing).child(descriptor.getName()); 056 } 057 else { 058 throw new IllegalArgumentException("Class doesn't have a FQ name: " + descriptor); 059 } 060 } 061 }