Platform API (IDEA-211307): add annotations prohibiting certain types of API usages.

Added annotations @ApiStatus.NonExtendable and @ApiStatus.OverrideOnly.
Added corresponding inspections checking violation of usages of annotated API.
Fix a couple of bugs in ApiUsageUastVisitor. Enforce both "processReference" (for class) and "processConstructorInvocation" (for constructor) events. Suppose code "new SomeClass(42)". We want ApiUsageVisitorBase to invoke both "processReference" for "SomeClass" and "processConstructorInvocation" for "SomeClass()", though they point to the same PSI element.

GitOrigin-RevId: 811b4d5a875dcb246582df1cd2e6be48cc96c990
This commit is contained in:
Sergey Patrikeev
2019-04-25 17:08:57 +03:00
committed by intellij-monorepo-bot
parent 1849ef6a1e
commit 44ad67b999
47 changed files with 795 additions and 92 deletions

View File

@@ -0,0 +1,72 @@
package plugin;
import library.JavaClass;
import library.JavaInterface;
import library.JavaMethodOwner;
import library.KotlinClass;
import library.KotlinInterface;
import library.KotlinMethodOwner;
//Extensions of Java classes
class JavaInheritor extends <warning descr="Class 'library.JavaClass' must not be extended">JavaClass</warning> {
}
class JavaImplementor implements <warning descr="Interface 'library.JavaInterface' must not be implemented">JavaInterface</warning> {
}
interface JavaInterfaceInheritor extends <warning descr="Interface 'library.JavaInterface' must not be extended">JavaInterface</warning> {
}
class JavaMethodOverrider extends JavaMethodOwner {
@Override
public void <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() {
}
}
//Extensions of Kotlin classes
class KotlinInheritor extends <warning descr="Class 'library.KotlinClass' must not be extended">KotlinClass</warning> {
}
class KotlinImplementor implements <warning descr="Interface 'library.KotlinInterface' must not be implemented">KotlinInterface</warning> {
}
interface KotlinInterfaceInheritor extends <warning descr="Interface 'library.JavaInterface' must not be extended">JavaInterface</warning> {
}
class KotlinMethodOverrider extends KotlinMethodOwner {
@Override
public void <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() {
}
}
class AnynymousClasses {
public void anonymous() {
new <warning descr="Class 'library.JavaClass' must not be extended">JavaClass</warning>() {
};
new <warning descr="Interface 'library.JavaInterface' must not be implemented">JavaInterface</warning>() {
};
new <warning descr="Class 'library.KotlinClass' must not be extended">KotlinClass</warning>() {
};
new <warning descr="Interface 'library.KotlinInterface' must not be implemented">KotlinInterface</warning>() {
};
new JavaMethodOwner() {
@Override
public void <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() {
}
};
new KotlinMethodOwner() {
@Override
public void <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() {
}
};
}
}

View File

@@ -0,0 +1,48 @@
package plugin.kotlin
import library.JavaClass
import library.JavaInterface
import library.JavaMethodOwner
import library.KotlinClass
import library.KotlinInterface
import library.KotlinMethodOwner
//Extensions of Java classes
class JavaInheritor : <warning descr="Class 'library.JavaClass' must not be extended">JavaClass</warning>()
class JavaImplementor : <warning descr="Interface 'library.JavaInterface' must not be implemented">JavaInterface</warning>
interface JavaInterfaceInheritor : <warning descr="Interface 'library.JavaInterface' must not be extended">JavaInterface</warning>
class JavaMethodOverrider : JavaMethodOwner() {
override fun <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() = Unit
}
//Extensions of Kotlin classes
class KotlinInheritor : <warning descr="Class 'library.KotlinClass' must not be extended">KotlinClass</warning>()
class KotlinImplementor : <warning descr="Interface 'library.KotlinInterface' must not be implemented">KotlinInterface</warning>
interface KotlinInterfaceInheritor : <warning descr="Interface 'library.KotlinInterface' must not be extended">KotlinInterface</warning>
class KotlinMethodOverrider : KotlinMethodOwner() {
override fun <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() = Unit
}
fun anonymousClasses() {
object : <warning descr="Class 'library.JavaClass' must not be extended">JavaClass</warning>() { }
object : <warning descr="Interface 'library.JavaInterface' must not be implemented">JavaInterface</warning> { }
object : <warning descr="Class 'library.KotlinClass' must not be extended">KotlinClass</warning>() { }
object : <warning descr="Interface 'library.KotlinInterface' must not be implemented">KotlinInterface</warning> { }
object : JavaMethodOwner() {
override fun <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() = Unit
}
object : KotlinMethodOwner() {
override fun <warning descr="Method 'doNotOverride()' must not be overridden">doNotOverride</warning>() = Unit
}
}