Introduced getFqNameSafe method.

This commit is contained in:
Evgeny Gerashchenko
2013-12-04 18:51:06 +04:00
parent 3352d8a954
commit a49551dd35
22 changed files with 50 additions and 37 deletions
@@ -110,19 +110,37 @@ public class DescriptorUtils {
@NotNull
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
FqName safe = getFqNameSafeIfPossible(descriptor);
return safe != null ? safe.toUnsafe() : getFqNameUnsafe(descriptor);
}
@NotNull
public static FqName getFqNameSafe(@NotNull DeclarationDescriptor descriptor) {
FqName safe = getFqNameSafeIfPossible(descriptor);
return safe != null ? safe : getFqNameUnsafe(descriptor).toSafe();
}
@Nullable
private static FqName getFqNameSafeIfPossible(@NotNull DeclarationDescriptor descriptor) {
if (descriptor instanceof ModuleDescriptor || ErrorUtils.isError(descriptor)) {
return FqName.ROOT.toUnsafe();
return FqName.ROOT;
}
if (descriptor instanceof PackageViewDescriptor) {
return ((PackageViewDescriptor) descriptor).getFqName().toUnsafe();
return ((PackageViewDescriptor) descriptor).getFqName();
}
else if (descriptor instanceof PackageFragmentDescriptor) {
return ((PackageFragmentDescriptor) descriptor).getFqName().toUnsafe();
return ((PackageFragmentDescriptor) descriptor).getFqName();
}
return null;
}
@NotNull
private static FqNameUnsafe getFqNameUnsafe(@NotNull DeclarationDescriptor descriptor) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.CLASS_OBJECT) {
DeclarationDescriptor classOfClassObject = containingDeclaration.getContainingDeclaration();
assert classOfClassObject != null;
@@ -310,7 +310,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
ClassDescriptor annotationClass = (ClassDescriptor) annotation.getType().getConstructor().getDeclarationDescriptor();
assert annotationClass != null;
if (!excludedAnnotationClasses.contains(DescriptorUtils.getFqName(annotationClass).toSafe())) {
if (!excludedAnnotationClasses.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
builder.append(renderType(annotation.getType()));
if (verbose) {
builder.append("(").append(StringUtil.join(DescriptorUtils.getSortedValueArguments(annotation, this), ", ")).append(")");