Drop some of explicit ClassKind.CLASS_OBJECT and OBJECT usages

This commit is contained in:
Pavel V. Talanov
2015-03-04 14:51:37 +03:00
parent fa590a5b83
commit 350864b22f
16 changed files with 43 additions and 38 deletions
@@ -36,17 +36,17 @@ public fun DeclarationDescriptor.hasIntrinsicAnnotation(): Boolean {
}
public fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
isPlatformStaticIn(ClassKind.OBJECT, ClassKind.CLASS)
isPlatformStaticIn { DescriptorUtils.isNonDefaultObject(it) || DescriptorUtils.isClass(it) }
public fun CallableDescriptor.isPlatformStaticInDefaultObject(): Boolean =
isPlatformStaticIn(ClassKind.CLASS_OBJECT)
isPlatformStaticIn { DescriptorUtils.isDefaultObject(it) }
private fun CallableDescriptor.isPlatformStaticIn(vararg kinds: ClassKind): Boolean =
private fun CallableDescriptor.isPlatformStaticIn(predicate: (DeclarationDescriptor) -> Boolean): Boolean =
when (this) {
is PropertyAccessorDescriptor -> {
val propertyDescriptor = getCorrespondingProperty()
kinds.any { DescriptorUtils.isKindOf(propertyDescriptor.getContainingDeclaration(), it) } &&
predicate(propertyDescriptor.getContainingDeclaration()!!) &&
(hasPlatformStaticAnnotation() || propertyDescriptor.hasPlatformStaticAnnotation())
}
else -> kinds.any { DescriptorUtils.isKindOf(getContainingDeclaration(), it) } && hasPlatformStaticAnnotation()
else -> predicate(getContainingDeclaration()) && hasPlatformStaticAnnotation()
}
@@ -60,7 +60,7 @@ public class DeclarationResolver {
public fun checkRedeclarationsInInnerClassNames(c: TopDownAnalysisContext) {
for (classDescriptor in c.getDeclaredClasses().values()) {
if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
if (DescriptorUtils.isDefaultObject(classDescriptor)) {
// Default objects should be considered during analysing redeclarations in classes
continue
}
@@ -39,6 +39,8 @@ import java.util.*;
import static org.jetbrains.kotlin.diagnostics.Errors.*;
import static org.jetbrains.kotlin.lexer.JetTokens.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
public class ModifiersChecker {
private static final Collection<JetModifierKeywordToken> MODALITY_MODIFIERS =
@@ -363,11 +365,10 @@ public class ModifiersChecker {
@NotNull
public static Visibility getDefaultClassVisibility(@NotNull ClassDescriptor descriptor) {
ClassKind kind = descriptor.getKind();
if (kind == ClassKind.ENUM_ENTRY) {
if (isEnumEntry(descriptor)) {
return Visibilities.PUBLIC;
}
if (kind == ClassKind.CLASS_OBJECT) {
if (isDefaultObject(descriptor)) {
return ((ClassDescriptor) descriptor.getContainingDeclaration()).getVisibility();
}
return Visibilities.INTERNAL;