AllOpen: Do not make private members open (KT-16627)
This commit is contained in:
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.allopen
|
package org.jetbrains.kotlin.allopen
|
||||||
|
|
||||||
import org.jetbrains.annotations.TestOnly
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.extensions.AnnotationBasedExtension
|
import org.jetbrains.kotlin.extensions.AnnotationBasedExtension
|
||||||
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
|
||||||
@@ -48,6 +48,10 @@ abstract class AbstractAllOpenDeclarationAttributeAltererExtension : Declaration
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modifierListOwner.hasModifier(KtTokens.PRIVATE_KEYWORD) && modifierListOwner is KtCallableDeclaration) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
val descriptor = declaration as? ClassDescriptor ?: containingDeclaration ?: return null
|
val descriptor = declaration as? ClassDescriptor ?: containingDeclaration ?: return null
|
||||||
if (descriptor.hasSpecialAnnotation(modifierListOwner)) {
|
if (descriptor.hasSpecialAnnotation(modifierListOwner)) {
|
||||||
return if (modifierListOwner.hasModifier(KtTokens.FINAL_KEYWORD))
|
return if (modifierListOwner.hasModifier(KtTokens.FINAL_KEYWORD))
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
annotation class AllOpen
|
||||||
|
|
||||||
|
@AllOpen
|
||||||
|
private class Test {
|
||||||
|
fun publicMethod() {}
|
||||||
|
val publicProp: String = ""
|
||||||
|
|
||||||
|
protected fun protectedMethod() {}
|
||||||
|
protected val protectedProp: String = ""
|
||||||
|
|
||||||
|
private fun privateMethod() {}
|
||||||
|
private val privateProp: String = ""
|
||||||
|
|
||||||
|
internal fun internalMethod() {}
|
||||||
|
internal val internalProp: String = ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
@java.lang.annotation.Retention
|
||||||
|
@kotlin.Metadata
|
||||||
|
public annotation class AllOpen
|
||||||
|
|
||||||
|
@AllOpen
|
||||||
|
@kotlin.Metadata
|
||||||
|
class Test {
|
||||||
|
private final @org.jetbrains.annotations.NotNull field internalProp: java.lang.String
|
||||||
|
private final field privateProp: java.lang.String
|
||||||
|
private final @org.jetbrains.annotations.NotNull field protectedProp: java.lang.String
|
||||||
|
private final @org.jetbrains.annotations.NotNull field publicProp: java.lang.String
|
||||||
|
public method <init>(): void
|
||||||
|
public @org.jetbrains.annotations.NotNull method getInternalProp$test_module(): java.lang.String
|
||||||
|
protected @org.jetbrains.annotations.NotNull method getProtectedProp(): java.lang.String
|
||||||
|
public @org.jetbrains.annotations.NotNull method getPublicProp(): java.lang.String
|
||||||
|
public method internalMethod$test_module(): void
|
||||||
|
private final method privateMethod(): void
|
||||||
|
protected method protectedMethod(): void
|
||||||
|
public method publicMethod(): void
|
||||||
|
}
|
||||||
+6
@@ -78,6 +78,12 @@ public class BytecodeListingTestForAllOpenGenerated extends AbstractBytecodeList
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateMembers.kt")
|
||||||
|
public void testPrivateMembers() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/allopen/allopen-cli/testData/bytecodeListing/privateMembers.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("sealed.kt")
|
@TestMetadata("sealed.kt")
|
||||||
public void testSealed() throws Exception {
|
public void testSealed() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/allopen/allopen-cli/testData/bytecodeListing/sealed.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/allopen/allopen-cli/testData/bytecodeListing/sealed.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user