Do not annotate private members and their parameters (to save space)

This commit is contained in:
Andrey Breslav
2013-11-11 14:02:32 +04:00
parent 0959f7e37c
commit 1f574a9feb
9 changed files with 70 additions and 4 deletions
@@ -99,10 +99,24 @@ public abstract class AnnotationCodegen {
private void generateAdditionalAnnotations(@NotNull Annotated annotated, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
if (annotated instanceof CallableDescriptor) {
generateNullabilityAnnotation(((CallableDescriptor) annotated).getReturnType(), annotationDescriptorsAlreadyPresent);
CallableDescriptor descriptor = (CallableDescriptor) annotated;
// No need to annotate privates, synthetic accessors and their parameters
if (isInvisibleFromTheOutside(descriptor)) return;
if (descriptor instanceof ValueParameterDescriptor && isInvisibleFromTheOutside(descriptor.getContainingDeclaration())) return;
generateNullabilityAnnotation(descriptor.getReturnType(), annotationDescriptorsAlreadyPresent);
}
}
private static boolean isInvisibleFromTheOutside(@Nullable DeclarationDescriptor descriptor) {
if (descriptor instanceof CallableMemberDescriptor && JetTypeMapper.isAccessor((CallableMemberDescriptor) descriptor)) return false;
if (descriptor instanceof MemberDescriptor) {
return AsmUtil.getVisibilityAccessFlag((MemberDescriptor) descriptor) == Opcodes.ACC_PRIVATE;
}
return false;
}
private void generateNullabilityAnnotation(@Nullable JetType type, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
if (type == null) return;
@@ -0,0 +1,12 @@
public final class PrivateInClass implements jet.JetObject {
private final java.lang.String nn = "";
private final java.lang.String n = "";
private final java.lang.String getNn() { /* compiled code */ }
private final java.lang.String getN() { /* compiled code */ }
private final java.lang.String bar(@jet.runtime.typeinfo.JetValueParameter(name = "a") java.lang.String p, @jet.runtime.typeinfo.JetValueParameter(name = "b", type = "?") java.lang.String p1) { /* compiled code */ }
private PrivateInClass(@jet.runtime.typeinfo.JetValueParameter(name = "s", type = "?") java.lang.String p) { /* compiled code */ }
}
@@ -0,0 +1,5 @@
class PrivateInClass private (s: String?) {
private val nn: String = ""
private val n: String? = ""
private fun bar(a: String, b: String?): String? = null
}
@@ -0,0 +1,10 @@
public interface PrivateInTrait extends jet.JetObject {
@org.jetbrains.annotations.NotNull
java.lang.String getNn();
@org.jetbrains.annotations.Nullable
java.lang.String getN();
@org.jetbrains.annotations.Nullable
java.lang.String bar(@org.jetbrains.annotations.NotNull @jet.runtime.typeinfo.JetValueParameter(name = "a") java.lang.String p, @org.jetbrains.annotations.Nullable @jet.runtime.typeinfo.JetValueParameter(name = "b", type = "?") java.lang.String p1);
}
@@ -0,0 +1,5 @@
trait PrivateInTrait {
private val nn: String
private val n: String?
private fun bar(a: String, b: String?): String?
}
@@ -1,5 +1,4 @@
public final class Synthetic implements jet.JetObject {
@org.jetbrains.annotations.NotNull
private final void foo() { /* compiled code */ }
@org.jetbrains.annotations.NotNull
@@ -59,4 +59,13 @@ public final class _DefaultPackage {
@org.jetbrains.annotations.NotNull
public static final void setNullableVarWithGetSet(@org.jetbrains.annotations.Nullable @jet.runtime.typeinfo.JetValueParameter(name = "v", type = "?") java.lang.String p) { /* compiled code */ }
@org.jetbrains.annotations.NotNull
public static final java.lang.String getPrivateNn() { /* compiled code */ }
@org.jetbrains.annotations.Nullable
public static final java.lang.String getPrivateN() { /* compiled code */ }
@org.jetbrains.annotations.Nullable
public static final java.lang.String privateFun(@org.jetbrains.annotations.NotNull @jet.runtime.typeinfo.JetValueParameter(name = "a") java.lang.String p, @org.jetbrains.annotations.Nullable @jet.runtime.typeinfo.JetValueParameter(name = "b", type = "?") java.lang.String p1) { /* compiled code */ }
}
@@ -27,4 +27,8 @@ val nullableValWithGet: String?
var nullableVarWithGetSet: String?
[NotNull] get() = ""
[NotNull] set(v) {}
[NotNull] set(v) {}
private val privateNn: String = ""
private val privateN: String? = ""
private fun privateFun(a: String, b: String?): String? = null
@@ -69,10 +69,18 @@ public class NullabilityAnnotationsTest extends KotlinAsJavaTestBase {
doTest(getTestName(false));
}
public void testPrivateInClass() throws Exception {
doTest(getTestName(false));
}
public void testPrivateInTrait() throws Exception {
doTest(getTestName(false));
}
private void doTest(@NotNull String fqName) {
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
if (!(psiClass instanceof KotlinLightClass)) {
throw new IllegalStateException("Not a light class: " + psiClass);
throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
}
PsiClass delegate = ((KotlinLightClass) psiClass).getDelegate();