Remove @data from stdlib and compiler
This commit is contained in:
@@ -479,7 +479,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateFunctionsForDataClasses() {
|
||||
if (!KotlinBuiltIns.isData(descriptor)) return;
|
||||
if (!descriptor.isData()) return;
|
||||
|
||||
new DataClassMethodGeneratorImpl(myClass, bindingContext).generate();
|
||||
}
|
||||
@@ -763,8 +763,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
new DefaultParameterValueLoader() {
|
||||
@Override
|
||||
public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) {
|
||||
assert KotlinBuiltIns.isData((ClassDescriptor) function.getContainingDeclaration())
|
||||
: "Function container should be annotated with [data]: " + function;
|
||||
assert ((ClassDescriptor) function.getContainingDeclaration()).isData()
|
||||
: "Function container must have [data] modifier: " + function;
|
||||
PropertyDescriptor property = bindingContext.get(BindingContext.VALUE_PARAMETER_AS_PROPERTY, valueParameter);
|
||||
assert property != null : "Copy function doesn't correspond to any property: " + function;
|
||||
return codegen.intermediateValueForProperty(property, false, null, StackValue.LOCAL_0);
|
||||
|
||||
@@ -218,7 +218,7 @@ public interface JetTokens {
|
||||
|
||||
// Please synchronize this array with org.jetbrains.kotlin.descriptors.annotations.ANNOTATION_MODIFIERS_FQ_NAMES
|
||||
JetModifierKeywordToken[] ANNOTATION_MODIFIERS_KEYWORDS_ARRAY = new JetModifierKeywordToken[] {
|
||||
DATA_KEYWORD, INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD, ANNOTATION_KEYWORD, CROSSINLINE_KEYWORD
|
||||
INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD, ANNOTATION_KEYWORD, CROSSINLINE_KEYWORD
|
||||
};
|
||||
|
||||
TokenSet MODIFIER_KEYWORDS = TokenSet.create(MODIFIER_KEYWORDS_ARRAY);
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
|
||||
|
||||
public class DataClassAnnotationChecker : DeclarationChecker {
|
||||
@@ -32,7 +34,7 @@ public class DataClassAnnotationChecker : DeclarationChecker {
|
||||
if (descriptor !is ClassDescriptor) return
|
||||
if (declaration !is JetClassOrObject) return
|
||||
|
||||
if (KotlinBuiltIns.isData(descriptor)) {
|
||||
if (descriptor.isData) {
|
||||
if (descriptor.unsubstitutedPrimaryConstructor == null && descriptor.constructors.isNotEmpty()) {
|
||||
declaration.nameIdentifier?.let { diagnosticHolder.report(Errors.PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS.on(it)) }
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -733,7 +731,7 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
private void checkOverrideForComponentFunction(@NotNull final CallableMemberDescriptor componentFunction) {
|
||||
final PsiElement dataAnnotation = findDataAnnotationForDataClass(componentFunction.getContainingDeclaration());
|
||||
final PsiElement dataModifier = findDataModifierForDataClass(componentFunction.getContainingDeclaration());
|
||||
|
||||
checkOverridesForMemberMarkedOverride(componentFunction, false, new CheckOverrideReportStrategy() {
|
||||
private boolean overrideConflict = false;
|
||||
@@ -742,7 +740,7 @@ public class OverrideResolver {
|
||||
public void overridingFinalMember(@NotNull CallableMemberDescriptor overridden) {
|
||||
if (!overrideConflict) {
|
||||
overrideConflict = true;
|
||||
trace.report(DATA_CLASS_OVERRIDE_CONFLICT.on(dataAnnotation, componentFunction, overridden.getContainingDeclaration()));
|
||||
trace.report(DATA_CLASS_OVERRIDE_CONFLICT.on(dataModifier, componentFunction, overridden.getContainingDeclaration()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,7 +748,7 @@ public class OverrideResolver {
|
||||
public void returnTypeMismatchOnOverride(@NotNull CallableMemberDescriptor overridden) {
|
||||
if (!overrideConflict) {
|
||||
overrideConflict = true;
|
||||
trace.report(DATA_CLASS_OVERRIDE_CONFLICT.on(dataAnnotation, componentFunction, overridden.getContainingDeclaration()));
|
||||
trace.report(DATA_CLASS_OVERRIDE_CONFLICT.on(dataModifier, componentFunction, overridden.getContainingDeclaration()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,16 +775,7 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiElement findDataAnnotationForDataClass(@NotNull DeclarationDescriptor dataClass) {
|
||||
AnnotationDescriptor annotation = dataClass.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.data);
|
||||
if (annotation != null) {
|
||||
JetAnnotationEntry entry = DescriptorToSourceUtils.getSourceFromAnnotation(annotation);
|
||||
if (entry != null) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static PsiElement findDataModifierForDataClass(@NotNull DeclarationDescriptor dataClass) {
|
||||
JetClass classDeclaration = (JetClass) DescriptorToSourceUtils.getSourceFromDescriptor(dataClass);
|
||||
if (classDeclaration != null && classDeclaration.getModifierList() != null) {
|
||||
PsiElement modifier = classDeclaration.getModifierList().getModifier(JetTokens.DATA_KEYWORD);
|
||||
@@ -795,7 +784,7 @@ public class OverrideResolver {
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No data annotation is found for data class " + dataClass);
|
||||
throw new IllegalStateException("No data modifier is found for data class " + dataClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve.lazy.descriptors
|
||||
|
||||
import com.google.common.collect.Lists
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
@@ -136,7 +135,7 @@ public open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
private fun generateDataClassMethods(result: MutableCollection<FunctionDescriptor>, name: Name, location: LookupLocation) {
|
||||
if (!KotlinBuiltIns.isData(thisDescriptor)) return
|
||||
if (!thisDescriptor.isData) return
|
||||
|
||||
val constructor = getPrimaryConstructor() ?: return
|
||||
|
||||
@@ -243,7 +242,7 @@ public open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
private fun addDataClassMethods(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
|
||||
if (!KotlinBuiltIns.isData(thisDescriptor)) return
|
||||
if (!thisDescriptor.isData) return
|
||||
|
||||
if (getPrimaryConstructor() == null) return
|
||||
|
||||
|
||||
@@ -20,16 +20,6 @@ import kotlin.annotation.AnnotationRetention.BINARY
|
||||
import kotlin.annotation.AnnotationRetention.SOURCE
|
||||
import kotlin.annotation.AnnotationTarget.*
|
||||
|
||||
/**
|
||||
* Marks the annotated class as a data class. The compiler automatically generates
|
||||
* equals()/hashCode(), toString(), componentN() and copy() functions for data classes.
|
||||
* See [the Kotlin language documentation](http://kotlinlang.org/docs/reference/data-classes.html)
|
||||
* for more information.
|
||||
*/
|
||||
@Target(CLASS)
|
||||
@MustBeDocumented
|
||||
private annotation class data
|
||||
|
||||
/**
|
||||
* Marks the annotated class, function, property, variable or parameter as deprecated.
|
||||
* @property message the message explaining the deprecation and recommending an alternative API to use.
|
||||
|
||||
@@ -138,7 +138,6 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
public final FqName throwable = fqName("Throwable");
|
||||
|
||||
public final FqName data = fqName("data");
|
||||
public final FqName deprecated = fqName("Deprecated");
|
||||
public final FqName tailRecursive = fqName("tailrec");
|
||||
public final FqName inline = fqName("inline");
|
||||
@@ -1029,10 +1028,6 @@ public abstract class KotlinBuiltIns {
|
||||
return FQ_NAMES.cloneable.equals(getFqName(descriptor));
|
||||
}
|
||||
|
||||
public static boolean isData(@NotNull ClassDescriptor classDescriptor) {
|
||||
return containsAnnotation(classDescriptor, FQ_NAMES.data);
|
||||
}
|
||||
|
||||
public static boolean isDeprecated(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
return containsAnnotation(declarationDescriptor, FQ_NAMES.deprecated);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
// Please synchronize this set with JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY
|
||||
public val ANNOTATION_MODIFIERS_FQ_NAMES: Set<FqName> =
|
||||
arrayOf("data", "inline", "noinline", "tailrec", "external", "annotation.annotation", "crossinline").map { FqName("kotlin.$it") }.toSet()
|
||||
arrayOf("inline", "noinline", "tailrec", "external", "annotation.annotation", "crossinline").map { FqName("kotlin.$it") }.toSet()
|
||||
|
||||
public fun KotlinBuiltIns.createDeprecatedAnnotation(message: String, replaceWith: String): AnnotationDescriptor {
|
||||
val deprecatedAnnotation = deprecatedAnnotation
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class ClassTranslator private constructor(
|
||||
bodyVisitor.traverseContainer(classDeclaration, context)
|
||||
delegationTranslator.generateDelegated(properties)
|
||||
|
||||
if (KotlinBuiltIns.isData(descriptor)) {
|
||||
if (descriptor.isData) {
|
||||
JsDataClassGenerator(classDeclaration, context, properties).generate()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user