Add and use JetClassOrObject#isTopLevel()
This commit is contained in:
@@ -210,4 +210,9 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub> imp
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTopLevel() {
|
||||
return getContainingFile() == getParent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +49,6 @@ public interface JetClassOrObject extends PsiNameIdentifierOwner, JetDeclaration
|
||||
|
||||
@Nullable
|
||||
JetClassBody getBody();
|
||||
|
||||
boolean isTopLevel();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectSt
|
||||
return nameAsDeclaration == null ? null : nameAsDeclaration.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTopLevel() {
|
||||
PsiJetObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
|
||||
+2
-3
@@ -397,7 +397,6 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
|
||||
@NotNull
|
||||
private String[] computeModifiers() {
|
||||
boolean nestedClass = classOrObject.getParent() != classOrObject.getContainingFile();
|
||||
Collection<String> psiModifiers = Sets.newHashSet();
|
||||
|
||||
// PUBLIC, PROTECTED, PRIVATE, ABSTRACT, FINAL
|
||||
@@ -417,7 +416,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
if (classOrObject.hasModifier(PRIVATE_KEYWORD)) {
|
||||
// Top-level private class has PUBLIC visibility in Java
|
||||
// Nested private class has PRIVATE visibility
|
||||
psiModifiers.add(nestedClass ? PsiModifier.PRIVATE : PsiModifier.PUBLIC);
|
||||
psiModifiers.add(classOrObject.isTopLevel() ? PsiModifier.PUBLIC : PsiModifier.PRIVATE);
|
||||
}
|
||||
|
||||
if (!psiModifiers.contains(PsiModifier.PRIVATE) && !psiModifiers.contains(PsiModifier.PROTECTED)) {
|
||||
@@ -433,7 +432,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
psiModifiers.add(PsiModifier.FINAL);
|
||||
}
|
||||
|
||||
if (nestedClass && !classOrObject.hasModifier(INNER_KEYWORD)) {
|
||||
if (!classOrObject.isTopLevel() && !classOrObject.hasModifier(INNER_KEYWORD)) {
|
||||
psiModifiers.add(PsiModifier.STATIC);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class JetPsiHeuristicsUtil {
|
||||
// It is a Kotlin class already, we need to properly check visibility?
|
||||
JetClassOrObject classOrObject = lightClass.getOrigin();
|
||||
|
||||
if (isTopLevelDeclaration(classOrObject) && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
if (classOrObject.isTopLevel() && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
// The class is declared private in the targetPackage
|
||||
// It is visible in this package and all of its subpackages
|
||||
JetFile targetFile = classOrObject.getContainingJetFile();
|
||||
@@ -53,8 +53,4 @@ public class JetPsiHeuristicsUtil {
|
||||
}
|
||||
return member.hasModifierProperty(PsiModifier.PUBLIC) || member.hasModifierProperty(PsiModifier.PROTECTED);
|
||||
}
|
||||
|
||||
public static boolean isTopLevelDeclaration(@NotNull JetClassOrObject classOrObject) {
|
||||
return classOrObject.getContainingFile() == classOrObject.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user