Combine all metadata annotations into one kotlin/Metadata

This commit is contained in:
Alexander Udalov
2015-12-28 21:22:28 +03:00
parent 661af854fa
commit 59dab0a558
27 changed files with 300 additions and 45 deletions
@@ -28,6 +28,8 @@ import java.util.HashSet;
import java.util.Set;
public final class JvmAnnotationNames {
public static final FqName METADATA = new FqName("kotlin.Metadata");
public static final FqName KOTLIN_CLASS = new FqName("kotlin.jvm.internal.KotlinClass");
public static final FqName KOTLIN_FILE_FACADE = new FqName("kotlin.jvm.internal.KotlinFileFacade");
public static final FqName KOTLIN_MULTIFILE_CLASS = new FqName("kotlin.jvm.internal.KotlinMultifileClass");
@@ -38,8 +40,15 @@ public final class JvmAnnotationNames {
public static final FqName KOTLIN_LOCAL_CLASS = new FqName("kotlin.jvm.internal.KotlinLocalClass");
public static final String VERSION_FIELD_NAME = "version";
public static final String METADATA_VERSION_FIELD_NAME = "mv";
public static final String BYTECODE_VERSION_FIELD_NAME = "bv";
public static final String FILE_PART_CLASS_NAMES_FIELD_NAME = "filePartClassNames";
public static final String MULTIFILE_CLASS_NAME_FIELD_NAME = "multifileClassName";
public static final String KIND_FIELD_NAME = "k";
public static final String METADATA_DATA_FIELD_NAME = "d1";
public static final String METADATA_STRINGS_FIELD_NAME = "d2";
public static final String SYNTHETIC_CLASS_KIND_FIELD_NAME = "xi";
public static final String METADATA_MULTIFILE_CLASS_NAME_FIELD_NAME = "xs";
public static final String DATA_FIELD_NAME = "data";
public static final String STRINGS_FIELD_NAME = "strings";
public static final String MODULE_NAME_FIELD_NAME = "moduleName";
@@ -66,7 +75,9 @@ public final class JvmAnnotationNames {
private static final Set<JvmClassName> NULLABILITY_ANNOTATIONS = new HashSet<JvmClassName>();
private static final Set<JvmClassName> SPECIAL_META_ANNOTATIONS = new HashSet<JvmClassName>();
static {
for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS)) {
for (FqName fqName : Arrays.asList(
METADATA, KOTLIN_CLASS, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS
)) {
SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName));
}
@@ -29,12 +29,19 @@ class KotlinClassHeader(
val isInterfaceDefaultImpls: Boolean,
val isLocalClass: Boolean
) {
enum class Kind {
CLASS,
FILE_FACADE,
MULTIFILE_CLASS,
MULTIFILE_CLASS_PART,
SYNTHETIC_CLASS
// See kotlin.Metadata
enum class Kind(val id: Int) {
CLASS(1),
FILE_FACADE(2),
SYNTHETIC_CLASS(3),
MULTIFILE_CLASS(4),
MULTIFILE_CLASS_PART(5);
}
enum class SyntheticClassKind(val id: Int) {
FUNCTION(1),
LOCAL_CLASS(2),
INTERFACE_DEFAULT_IMPLS(3);
}
override fun toString() = "$kind " + (if (isLocalClass) "(local) " else "") + "version=$metadataVersion"
+70
View File
@@ -0,0 +1,70 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin
/**
* This annotation is present on any class file produced by the Kotlin compiler and is read by the compiler and reflection.
* Parameters have very short names on purpose: these names appear in the generated class files, and we'd like to reduce their size.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
internal annotation class Metadata(
/**
* A kind of the metadata this annotation encodes. Kotlin compiler recognizes the following kinds (see KotlinClassHeader.Kind):
*
* 1 Class
* 2 File
* 3 Synthetic class
* 4 Multi-file class facade
* 5 Multi-file class part
*
* The class file with a kind not listed here is treated as a non-Kotlin file.
*/
val k: Int = 1,
/**
* The version of the metadata provided in the arguments of this annotation.
*/
val mv: IntArray = intArrayOf(),
/**
* The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation.
*/
val bv: IntArray = intArrayOf(),
/**
* Metadata in a custom format. The format may be different (or even absent) for different kinds.
*/
val d1: Array<String> = arrayOf(),
/**
* An addition to [d1]: array of strings which occur in metadata, written in plain text so that strings already present
* in the constant pool are reused. These strings may be then indexed in the metadata by an integer index in this array.
*/
val d2: Array<String> = arrayOf(),
/**
* An extra string. For a multi-file part class, internal name of the facade class.
*/
val xs: String = "",
/**
* An extra integer. For a synthetic class, the specific kind of this class which is one of the following:
*
* 1 Anonymous class for a lambda or a function reference
* 2 Local class or anonymous object literal
* 3 Implicit nested DefaultImpls class for an interface
*
* A value other than this (e.g. 0) or a missing value means this is a synthetic class of some other sort.
* This kind has no effect on the compiler because it doesn't read synthetic class metadata. It may be used in IDEs and tools.
*/
val xi: Int = 0
)