Move jet.Kotlin* annotations to package "kotlin.jvm.internal"

Also rename poorly named KotlinPackageFragment -> KotlinPackagePart
This commit is contained in:
Alexander Udalov
2014-02-14 17:58:19 +04:00
parent 0da92e22a2
commit aef0fabd53
14 changed files with 53 additions and 61 deletions
@@ -77,7 +77,7 @@ public class PackagePartCodegen extends MemberCodegen {
);
v.visitSource(jetFile.getName(), null);
writeKotlinPackageFragmentAnnotation();
writeKotlinPackagePartAnnotation();
for (JetDeclaration declaration : jetFile.getDeclarations()) {
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
@@ -90,8 +90,8 @@ public class PackagePartCodegen extends MemberCodegen {
v.done();
}
private void writeKotlinPackageFragmentAnnotation() {
AnnotationVisitor av = v.newAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT), true);
private void writeKotlinPackagePartAnnotation() {
AnnotationVisitor av = v.newAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_PART), true);
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
av.visitEnd();
}
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import java.lang.annotation.Annotation;
public class KotlinPackageFragmentAnnotationTest extends CodegenTestCase {
public class KotlinPackagePartAnnotationTest extends CodegenTestCase {
public static final FqName PACKAGE_NAME = new FqName("test");
@Override
@@ -36,7 +36,7 @@ public class KotlinPackageFragmentAnnotationTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
public void testKotlinPackageFragmentIsWritten() throws Exception {
public void testKotlinPackagePartAnnotationIsWritten() throws Exception {
loadText("package " + PACKAGE_NAME + "\n\nfun foo() = 42\n");
String facadeFileName = JvmClassName.byFqNameWithoutInnerClasses(PackageClassUtils.getPackageClassFqName(PACKAGE_NAME)).getInternalName() + ".class";
@@ -45,26 +45,26 @@ public class KotlinPackageFragmentAnnotationTest extends CodegenTestCase {
String filePath = outputFile.getRelativePath();
if (!filePath.equals(facadeFileName)) {
// The file which is not a facade is a package fragment
// The file which is not a facade is a package part
String fqName = filePath.substring(0, filePath.length() - ".class".length()).replace('/', '.');
Class aClass = generateClass(fqName);
Class<?> aClass = generateClass(fqName);
Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT.asString());
Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(JvmAnnotationNames.KOTLIN_PACKAGE_PART.asString());
assertTrue("No KotlinPackageFragment annotation on a package fragment",
assertTrue("No KotlinPackagePart annotation on a package part",
aClass.isAnnotationPresent(annotationClass));
Annotation kotlinPackageFragment = aClass.getAnnotation(annotationClass);
Annotation kotlinPackagePart = aClass.getAnnotation(annotationClass);
Integer version = (Integer) CodegenTestUtil.getAnnotationAttribute(kotlinPackageFragment, "abiVersion");
Integer version = (Integer) CodegenTestUtil.getAnnotationAttribute(kotlinPackagePart, "abiVersion");
assertNotNull(version);
assertTrue("KotlinPackageFragment annotation is written with an unsupported format",
assertTrue("KotlinPackagePart annotation is written with an unsupported format",
AbiVersionUtil.isAbiVersionCompatible(version));
return;
}
}
fail("No package fragment was found: " + outputFiles.asList());
fail("No package part was found: " + outputFiles.asList());
}
}
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -32,9 +31,12 @@ public final class AnnotationLoadingUtil {
public static final FqName JETBRAINS_READONLY_ANNOTATION = new FqName("org.jetbrains.annotations.ReadOnly");
public static final FqName JL_CLASS_FQ_NAME = new FqName("java.lang.Class");
@SuppressWarnings("deprecation")
public static boolean isSpecialAnnotation(@NotNull FqName fqName) {
return fqName.asString().startsWith("jet.runtime.typeinfo.")
|| fqName.equals(JETBRAINS_NOT_NULL_ANNOTATION)
|| fqName.equals(JvmAnnotationNames.OLD_KOTLIN_CLASS)
|| fqName.equals(JvmAnnotationNames.OLD_KOTLIN_PACKAGE)
|| fqName.equals(JvmAnnotationNames.KOTLIN_CLASS)
|| fqName.equals(JvmAnnotationNames.KOTLIN_PACKAGE);
}
@@ -16,32 +16,29 @@
package org.jetbrains.jet.lang.resolve.java;
import jet.KotlinClass;
import jet.KotlinPackage;
import jet.KotlinPackageFragment;
import jet.KotlinTraitImpl;
import org.jetbrains.jet.lang.resolve.name.FqName;
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
public final class JvmAnnotationNames {
public static final FqName KOTLIN_CLASS = fqNameByClass(KotlinClass.class);
public static final FqName KOTLIN_PACKAGE = fqNameByClass(KotlinPackage.class);
public static final FqName KOTLIN_PACKAGE_FRAGMENT = fqNameByClass(KotlinPackageFragment.class);
public static final FqName KOTLIN_TRAIT_IMPL = fqNameByClass(KotlinTraitImpl.class);
public static final FqName KOTLIN_CLASS = new FqName("kotlin.jvm.internal.KotlinClass");
public static final FqName KOTLIN_PACKAGE = new FqName("kotlin.jvm.internal.KotlinPackage");
public static final FqName KOTLIN_PACKAGE_PART = new FqName("kotlin.jvm.internal.KotlinPackagePart");
public static final FqName KOTLIN_TRAIT_IMPL = new FqName("kotlin.jvm.internal.KotlinTraitImpl");
public static final String ABI_VERSION_FIELD_NAME = "abiVersion";
public static final String DATA_FIELD_NAME = "data";
@Deprecated
public static final FqName OLD_JET_CLASS_ANNOTATION = new FqName("jet.runtime.typeinfo.JetClass");
@Deprecated
public static final FqName OLD_JET_PACKAGE_CLASS_ANNOTATION = new FqName("jet.runtime.typeinfo.JetPackageClass");
@Deprecated
public static final FqName OLD_KOTLIN_CLASS = new FqName("jet.KotlinClass");
@Deprecated
public static final FqName OLD_KOTLIN_PACKAGE = new FqName("jet.KotlinPackage");
@Deprecated
public static final FqName OLD_KOTLIN_PACKAGE_FRAGMENT = new FqName("jet.KotlinPackageFragment");
@Deprecated
public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl");
private JvmAnnotationNames() {
}
@@ -20,11 +20,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPackageFragmentDescriptor;
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
import org.jetbrains.jet.lang.resolve.java.structure.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -38,8 +35,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqNameSafe;
public final class DescriptorResolverUtils {
public static final FqName OBJECT_FQ_NAME = new FqName("java.lang.Object");
@@ -49,7 +44,7 @@ public final class DescriptorResolverUtils {
public static boolean isCompiledKotlinPackageClass(@NotNull JavaClass javaClass) {
if (javaClass.getOriginKind() == JavaClass.OriginKind.COMPILED) {
return javaClass.findAnnotation(JvmAnnotationNames.KOTLIN_PACKAGE) != null
|| javaClass.findAnnotation(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT) != null;
|| javaClass.findAnnotation(JvmAnnotationNames.KOTLIN_PACKAGE_PART) != null;
}
return false;
}
@@ -24,7 +24,7 @@ public class KotlinClassHeader {
public enum Kind {
CLASS,
PACKAGE_FACADE,
PACKAGE_FRAGMENT,
PACKAGE_PART,
TRAIT_IMPL,
INCOMPATIBLE_ABI_VERSION
}
@@ -22,12 +22,10 @@ import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCompatible;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.*;
@@ -41,12 +39,15 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
static {
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_CLASS), CLASS);
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_PACKAGE), PACKAGE_FACADE);
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_PACKAGE_FRAGMENT), PACKAGE_FRAGMENT);
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_PACKAGE_PART), PACKAGE_PART);
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_TRAIT_IMPL), TRAIT_IMPL);
//noinspection deprecation
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(OLD_JET_CLASS_ANNOTATION), INCOMPATIBLE_ABI_VERSION);
//noinspection deprecation
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(OLD_JET_PACKAGE_CLASS_ANNOTATION), INCOMPATIBLE_ABI_VERSION);
@SuppressWarnings("deprecation")
List<FqName> incompatible = Arrays.asList(OLD_JET_CLASS_ANNOTATION, OLD_JET_PACKAGE_CLASS_ANNOTATION, OLD_KOTLIN_CLASS,
OLD_KOTLIN_PACKAGE, OLD_KOTLIN_PACKAGE_FRAGMENT, OLD_KOTLIN_TRAIT_IMPL);
for (FqName fqName : incompatible) {
HEADER_KINDS.put(JvmClassName.byFqNameWithoutInnerClasses(fqName), INCOMPATIBLE_ABI_VERSION);
}
}
private int version = AbiVersionUtil.INVALID_VERSION;
@@ -99,7 +100,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
if (newKind == CLASS || newKind == PACKAGE_FACADE) {
return kotlinClassOrPackageVisitor(annotationClassName);
}
else if (newKind == PACKAGE_FRAGMENT || newKind == TRAIT_IMPL) {
else if (newKind == PACKAGE_PART || newKind == TRAIT_IMPL) {
return annotationWithAbiVersionVisitor(annotationClassName);
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package jet;
package kotlin.jvm.internal;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package jet;
package kotlin.jvm.internal;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -14,12 +14,12 @@
* limitations under the License.
*/
package jet;
package kotlin.jvm.internal;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface KotlinPackageFragment {
public @interface KotlinPackagePart {
int abiVersion();
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package jet;
package kotlin.jvm.internal;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,8 +22,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import jet.KotlinClass;
import jet.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.descriptors.serialization.*;
@@ -54,7 +52,7 @@ public class JetFromJavaDescriptorHelper {
/* Will iterate through short name caches
Kotlin packages from jar a class files will be collected from java cache
Kotlin package classes from sources will be collected with JetShortNamesCache.getClassesByName */
return getClassesByAnnotation(KotlinPackage.class.getSimpleName(), project, scope);
return getClassesByAnnotation("KotlinPackage", project, scope);
}
/**
@@ -77,14 +75,11 @@ public class JetFromJavaDescriptorHelper {
static Collection<PsiClass> getCompiledClassesForTopLevelObjects(Project project, GlobalSearchScope scope) {
Set<PsiClass> jetObjectClasses = Sets.newHashSet();
Collection<PsiClass> classesByAnnotation = getClassesByAnnotation(KotlinClass.class.getSimpleName(), project, scope);
Collection<PsiClass> classesByAnnotation = getClassesByAnnotation("KotlinClass", project, scope);
for (PsiClass psiClass : classesByAnnotation) {
ClassKind kind = getCompiledClassKind(psiClass);
if (kind == null) {
continue;
}
if (psiClass.getContainingClass() == null && kind == ClassKind.OBJECT) {
if (kind == ClassKind.OBJECT && psiClass.getContainingClass() == null) {
jetObjectClasses.add(psiClass);
}
}
@@ -174,7 +169,7 @@ public class JetFromJavaDescriptorHelper {
boolean shouldBeExtension
) {
Collection<FqName> result = Sets.newHashSet();
Collection<PsiClass> packageClasses = getClassesByAnnotation(KotlinPackage.class.getSimpleName(), project, scope);
Collection<PsiClass> packageClasses = getClassesByAnnotation("KotlinPackage", project, scope);
for (PsiClass psiClass : packageClasses) {
String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null) {
@@ -46,7 +46,7 @@ public class EmptyPackageFragmentClsStubBuilderFactory extends ClsStubBuilderFac
if (file.getName().contains(PackageClassUtils.PACKAGE_CLASS_NAME_SUFFIX + "-") &&
StdFileTypes.CLASS.getDefaultExtension().equals(file.getExtension())) {
KotlinClassHeader header = new VirtualFileKotlinClass(LockBasedStorageManager.NO_LOCKS, file).getClassHeader();
return header != null && header.getKind() == KotlinClassHeader.Kind.PACKAGE_FRAGMENT;
return header != null && header.getKind() == KotlinClassHeader.Kind.PACKAGE_PART;
}
return false;
}
@@ -63,6 +63,8 @@ public class KotlinAbiVersionIndex extends ScalarIndexExtension<Integer> {
private final Set<String> kotlinAnnotationsDesc = new ImmutableSet.Builder<String>()
.add(asmDescByFqNameWithoutInnerClasses(OLD_JET_CLASS_ANNOTATION))
.add(asmDescByFqNameWithoutInnerClasses(OLD_JET_PACKAGE_CLASS_ANNOTATION))
.add(asmDescByFqNameWithoutInnerClasses(OLD_KOTLIN_CLASS))
.add(asmDescByFqNameWithoutInnerClasses(OLD_KOTLIN_PACKAGE))
.add(asmDescByFqNameWithoutInnerClasses(KOTLIN_CLASS))
.add(asmDescByFqNameWithoutInnerClasses(KOTLIN_PACKAGE))
.build();