Implemented HiddenDeclaration annotation (doc-comment to be added!)

This commit is contained in:
Valentin Kipyatkov
2015-08-28 20:18:32 +03:00
parent ba4fb3e37c
commit e8dc9ede31
12 changed files with 205 additions and 6 deletions
@@ -610,6 +610,8 @@ public class CallResolver {
) {
final List<CallCandidateResolutionContext<D>> candidateResolutionContexts = ContainerUtil.newArrayList();
for (final ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
if (DescriptorUtilPackage.isAnnotatedAsHidden(resolutionCandidate.getDescriptor())) continue;
candidatePerfCounter.time(new Function0<Unit>() {
@Override
public Unit invoke() {
+4
View File
@@ -575,6 +575,10 @@ public interface FloatingPointConstants</*0*/ T> {
public interface Function</*0*/ out R> {
}
kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR}) kotlin.annotation.annotation(mustBeDocumented = true, retention = AnnotationRetention.BINARY) public final class HiddenDeclaration : kotlin.Annotation {
/*primary*/ public constructor HiddenDeclaration()
}
public final enum class InlineOption : kotlin.Enum<kotlin.InlineOption> {
enum entry LOCAL_CONTINUE_AND_BREAK
@@ -0,0 +1,74 @@
package test
// imports should be resolved
import test.topLevelFun
import test.topLevelProperty
@HiddenDeclaration
fun topLevelFun(){}
@HiddenDeclaration
var topLevelProperty = 1
@HiddenDeclaration
fun String.topLevelExtensionFun(){}
@HiddenDeclaration
val String.topLevelExtensionProperty: Int get() = 1
open class A {
constructor(<!UNUSED_PARAMETER!>p<!>: Int) : this(<!TYPE_MISMATCH!>""<!>) {}
@HiddenDeclaration
constructor(<!UNUSED_PARAMETER!>s<!>: String){}
@HiddenDeclaration
open fun memberFun(){}
@HiddenDeclaration
val memberProperty = 1
@HiddenDeclaration
fun String.memberExtensionFun(){}
@HiddenDeclaration
val String.memberExtensionProperty: Int get() = 1
fun foo() {
<!UNRESOLVED_REFERENCE!>topLevelFun<!>()
<!UNRESOLVED_REFERENCE, VARIABLE_EXPECTED!>topLevelProperty<!><!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>++<!>
"".<!UNRESOLVED_REFERENCE!>topLevelExtensionFun<!>()
"".<!UNRESOLVED_REFERENCE!>topLevelExtensionProperty<!>
<!UNRESOLVED_REFERENCE!>memberFun<!>()
<!UNRESOLVED_REFERENCE!>memberProperty<!>
"".<!UNRESOLVED_REFERENCE!>memberExtensionFun<!>()
"".<!UNRESOLVED_REFERENCE!>memberExtensionProperty<!>
A(<!TYPE_MISMATCH!>""<!>)
}
}
interface I {
@HiddenDeclaration
fun foo1()
@HiddenDeclaration
fun foo2()
}
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class X<!> : I {
override fun foo1() {
}
}
class B : A(<!TYPE_MISMATCH!>""<!>) {
// still can override it
override fun memberFun() {
super.<!UNRESOLVED_REFERENCE!>memberFun<!>() // but cannot call super :)
}
}
class C : A {
constructor() : super(<!TYPE_MISMATCH!>""<!>)
}
@@ -0,0 +1,62 @@
package
package test {
kotlin.HiddenDeclaration() internal var topLevelProperty: kotlin.Int
kotlin.HiddenDeclaration() internal val kotlin.String.topLevelExtensionProperty: kotlin.Int
kotlin.HiddenDeclaration() internal fun topLevelFun(): kotlin.Unit
kotlin.HiddenDeclaration() internal fun kotlin.String.topLevelExtensionFun(): kotlin.Unit
internal open class A {
public constructor A(/*0*/ p: kotlin.Int)
kotlin.HiddenDeclaration() public constructor A(/*0*/ s: kotlin.String)
kotlin.HiddenDeclaration() internal final val memberProperty: kotlin.Int = 1
kotlin.HiddenDeclaration() internal final val kotlin.String.memberExtensionProperty: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
kotlin.HiddenDeclaration() internal open fun memberFun(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
kotlin.HiddenDeclaration() internal final fun kotlin.String.memberExtensionFun(): kotlin.Unit
}
internal final class B : test.A {
public constructor B()
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ val memberProperty: kotlin.Int
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ val kotlin.String.memberExtensionProperty: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open override /*1*/ fun memberFun(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ fun kotlin.String.memberExtensionFun(): kotlin.Unit
}
internal final class C : test.A {
public constructor C()
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ val memberProperty: kotlin.Int
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ val kotlin.String.memberExtensionProperty: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
kotlin.HiddenDeclaration() internal open override /*1*/ /*fake_override*/ fun memberFun(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
kotlin.HiddenDeclaration() internal final override /*1*/ /*fake_override*/ fun kotlin.String.memberExtensionFun(): kotlin.Unit
}
internal interface I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.HiddenDeclaration() internal abstract fun foo1(): kotlin.Unit
kotlin.HiddenDeclaration() internal abstract fun foo2(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class X : test.I {
public constructor X()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo1(): kotlin.Unit
kotlin.HiddenDeclaration() internal abstract override /*1*/ /*fake_override*/ fun foo2(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -11676,6 +11676,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("HiddenDeclarations.kt")
public void testHiddenDeclarations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt");
doTest(fileName);
}
@TestMetadata("incompleteConstructorInvocation.kt")
public void testIncompleteConstructorInvocation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.kt");
+7
View File
@@ -77,3 +77,10 @@ public annotation(retention = SOURCE) class suppress(vararg val names: String)
*/
target(FUNCTION)
public annotation(retention = SOURCE) class tailRecursive
/**
* TODO
*/
target(FUNCTION, PROPERTY, CONSTRUCTOR)
annotation(retention = BINARY, mustBeDocumented = true)
public class HiddenDeclaration
@@ -198,3 +198,8 @@ public val DeclarationDescriptor.parentsWithSelf: Sequence<DeclarationDescriptor
public val DeclarationDescriptor.parents: Sequence<DeclarationDescriptor>
get() = parentsWithSelf.drop(1)
private val HIDDEN_ANNOTATION_FQ_NAME = FqName("kotlin.HiddenDeclaration") /*TODO*/
public fun DeclarationDescriptor.isAnnotatedAsHidden(): Boolean = annotations.findAnnotation(HIDDEN_ANNOTATION_FQ_NAME) != null
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotatedAsHidden
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
@@ -75,7 +76,7 @@ public class ReferenceVariantsHelper(
): Collection<DeclarationDescriptor> {
var variants: Collection<DeclarationDescriptor>
= getReferenceVariantsNoVisibilityFilter(expression, kindFilter, nameFilter, explicitReceiverData, useRuntimeReceiverType)
.filter(visibilityFilter)
.filter { !it.isAnnotatedAsHidden() && visibilityFilter(it) }
variants = ShadowedDeclarationsFilter(context, resolutionFacade, expression, explicitReceiverData).filter(variants)
@@ -0,0 +1,14 @@
package test
@HiddenDeclaration
fun hiddenFun(){}
fun notHiddenFun(){}
@HiddenDeclaration
var hiddenProperty: Int = 1
var notHiddenProperty: Int = 1
@HiddenDeclaration
val String.hiddenExtension: Int get() = 1
@@ -0,0 +1,16 @@
package test
@HiddenDeclaration
fun hiddenFunFromSameFile(){}
fun String.foo() {
hid<caret>
}
// INVOCATION_COUNT: 2
// ABSENT: hiddenFun
// ABSENT: hiddenProperty
// ABSENT: hiddenFunFromSameFile
// ABSENT: hiddenExtension
// EXIST: notHiddenFun
// EXIST: notHiddenProperty
@@ -125,6 +125,12 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
doTest(fileName);
}
@TestMetadata("HiddenDeclarations")
public void testHiddenDeclarations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/HiddenDeclarations/");
doTest(fileName);
}
@TestMetadata("InImportedFunctionLiteralParameter")
public void testInImportedFunctionLiteralParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/InImportedFunctionLiteralParameter/");
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotatedAsHidden
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
@@ -57,11 +58,12 @@ public class KotlinIndicesHelper(
private val moduleDescriptor = resolutionFacade.moduleDescriptor
private val project = resolutionFacade.project
private val descriptorFilter =
if (applyExcludeSettings)
{ d -> visibilityFilter(d) && !isExcludedFromAutoImport(d) }
else
visibilityFilter
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@ {
if (it.isAnnotatedAsHidden()) return@filter false
if (!visibilityFilter(it)) return@filter false
if (applyExcludeSettings && isExcludedFromAutoImport(it)) return@filter false
true
}
public fun getTopLevelCallablesByName(name: String): Collection<CallableDescriptor> {
val declarations = HashSet<JetNamedDeclaration>()