default -> companion: replace all mentions of default and default object
This commit is contained in:
+8
-8
@@ -16,22 +16,22 @@
|
||||
|
||||
package kotlin.js.internal
|
||||
|
||||
private object DoubleDefaultObject : FloatingPointConstants<Double> {
|
||||
private object DoubleCompanionObject : FloatingPointConstants<Double> {
|
||||
override val POSITIVE_INFINITY: Double = js("Number.POSITIVE_INFINITY")
|
||||
override val NEGATIVE_INFINITY: Double = js("Number.NEGATIVE_INFINITY")
|
||||
override val NaN: Double = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object FloatDefaultObject : FloatingPointConstants<Float> {
|
||||
private object FloatCompanionObject : FloatingPointConstants<Float> {
|
||||
override val POSITIVE_INFINITY : Float = js("Number.POSITIVE_INFINITY")
|
||||
override val NEGATIVE_INFINITY : Float = js("Number.NEGATIVE_INFINITY")
|
||||
override val NaN : Float = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object IntDefaultObject {}
|
||||
private object LongDefaultObject {}
|
||||
private object ShortDefaultObject {}
|
||||
private object ByteDefaultObject {}
|
||||
private object IntCompanionObject {}
|
||||
private object LongCompanionObject {}
|
||||
private object ShortCompanionObject {}
|
||||
private object ByteCompanionObject {}
|
||||
|
||||
private object StringDefaultObject {}
|
||||
private object EnumDefaultObject {}
|
||||
private object StringCompanionObject {}
|
||||
private object EnumCompanionObject {}
|
||||
+1
-1
@@ -18,4 +18,4 @@ package org.jetbrains.kotlin.js.test.semantics
|
||||
|
||||
import org.jetbrains.kotlin.js.test.SingleFileTranslationTest
|
||||
|
||||
public abstract class AbstractDefaultObjectTest : SingleFileTranslationTest("objectIntrinsics/")
|
||||
public abstract class AbstractCompanionObjectTest : SingleFileTranslationTest("objectIntrinsics/")
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
|
||||
@TestMetadata("compiler/testData/codegen/box/objectIntrinsics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class DefaultObjectTestGenerated extends AbstractDefaultObjectTest {
|
||||
public class CompanionObjectTestGenerated extends AbstractCompanionObjectTest {
|
||||
public void testAllFilesPresentInObjectIntrinsics() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/objectIntrinsics"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public final class Namer {
|
||||
private static final String RECEIVER_PARAMETER_NAME = "$receiver";
|
||||
|
||||
private static final String THROW_NPE_FUN_NAME = "throwNPE";
|
||||
private static final String DEFAULT_OBJECT_GETTER = "object";
|
||||
private static final String DEFAULT_OBJECT_INITIALIZER = "object_initializer$";
|
||||
private static final String COMPANION_OBJECT_GETTER = "object";
|
||||
private static final String COMPANION_OBJECT_INITIALIZER = "object_initializer$";
|
||||
private static final String PROTOTYPE_NAME = "prototype";
|
||||
public static final String CAPTURED_VAR_FIELD = "v";
|
||||
|
||||
@@ -173,13 +173,13 @@ public final class Namer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression getDefaultObjectAccessor(@NotNull JsExpression referenceToClass) {
|
||||
return new JsNameRef(DEFAULT_OBJECT_GETTER, referenceToClass);
|
||||
public static JsExpression getCompanionObjectAccessor(@NotNull JsExpression referenceToClass) {
|
||||
return new JsNameRef(COMPANION_OBJECT_GETTER, referenceToClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getNameForDefaultObjectInitializer() {
|
||||
return DEFAULT_OBJECT_INITIALIZER;
|
||||
public static String getNameForCompanionObjectInitializer() {
|
||||
return COMPANION_OBJECT_INITIALIZER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -264,10 +264,10 @@ public final class StaticContext {
|
||||
return scope.declareFreshName(getSuggestedName(descriptor));
|
||||
}
|
||||
};
|
||||
Rule<JsName> constructorOrDefaultObjectHasTheSameNameAsTheClass = new Rule<JsName>() {
|
||||
Rule<JsName> constructorOrCompanionObjectHasTheSameNameAsTheClass = new Rule<JsName>() {
|
||||
@Override
|
||||
public JsName apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof ConstructorDescriptor || (DescriptorUtils.isDefaultObject(descriptor))) {
|
||||
if (descriptor instanceof ConstructorDescriptor || (DescriptorUtils.isCompanionObject(descriptor))) {
|
||||
//noinspection ConstantConditions
|
||||
return getNameForDescriptor(descriptor.getContainingDeclaration());
|
||||
}
|
||||
@@ -352,7 +352,7 @@ public final class StaticContext {
|
||||
|
||||
addRule(namesForDynamic);
|
||||
addRule(namesForStandardClasses);
|
||||
addRule(constructorOrDefaultObjectHasTheSameNameAsTheClass);
|
||||
addRule(constructorOrCompanionObjectHasTheSameNameAsTheClass);
|
||||
addRule(propertyOrPropertyAccessor);
|
||||
addRule(predefinedObjectsHasUnobfuscatableNames);
|
||||
addRule(overridingDescriptorsReferToOriginalName);
|
||||
@@ -484,10 +484,10 @@ public final class StaticContext {
|
||||
result, namer.getModuleReference(program.getStringLiteral(moduleName)));
|
||||
}
|
||||
};
|
||||
Rule<JsExpression> constructorOrDefaultObjectHasTheSameQualifierAsTheClass = new Rule<JsExpression>() {
|
||||
Rule<JsExpression> constructorOrCompanionObjectHasTheSameQualifierAsTheClass = new Rule<JsExpression>() {
|
||||
@Override
|
||||
public JsExpression apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof ConstructorDescriptor || DescriptorUtils.isDefaultObject(descriptor)) {
|
||||
if (descriptor instanceof ConstructorDescriptor || DescriptorUtils.isCompanionObject(descriptor)) {
|
||||
//noinspection ConstantConditions
|
||||
return getQualifierForDescriptor(descriptor.getContainingDeclaration());
|
||||
}
|
||||
@@ -531,7 +531,7 @@ public final class StaticContext {
|
||||
};
|
||||
|
||||
addRule(libraryObjectsHaveKotlinQualifier);
|
||||
addRule(constructorOrDefaultObjectHasTheSameQualifierAsTheClass);
|
||||
addRule(constructorOrCompanionObjectHasTheSameQualifierAsTheClass);
|
||||
addRule(standardObjectsHaveKotlinQualifier);
|
||||
addRule(packageLevelDeclarationsHaveEnclosingPackagesNamesAsQualifier);
|
||||
addRule(nativeObjectsHaveNativePartOfFullQualifier);
|
||||
|
||||
@@ -98,7 +98,7 @@ private fun ReceiverParameterDescriptor.getNameForCapturedReceiver(): String {
|
||||
"receiverDescriptor = $this, " +"containingDeclaration = $containingDeclaration"
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isDefaultObject(containingDeclaration)) {
|
||||
if (DescriptorUtils.isCompanionObject(containingDeclaration)) {
|
||||
return containingDeclaration.getContainingDeclaration()!!.getNameForCapturedDescriptor(namePostfix = "$")
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -124,7 +124,7 @@ public final class ClassTranslator extends AbstractTranslator {
|
||||
declarationContext = declarationContext.newDeclaration(descriptor, definitionPlace);
|
||||
}
|
||||
|
||||
declarationContext = fixContextForDefaultObjectAccessing(declarationContext);
|
||||
declarationContext = fixContextForCompanionObjectAccessing(declarationContext);
|
||||
|
||||
invocationArguments.add(getSuperclassReferences(declarationContext));
|
||||
DelegationTranslator delegationTranslator = new DelegationTranslator(classDeclaration, context());
|
||||
@@ -171,20 +171,20 @@ public final class ClassTranslator extends AbstractTranslator {
|
||||
return invocationArguments;
|
||||
}
|
||||
|
||||
private TranslationContext fixContextForDefaultObjectAccessing(TranslationContext declarationContext) {
|
||||
// In Kotlin we can access to default object members without qualifier just by name, but we should translate it to access with FQ name.
|
||||
// So create alias for default object receiver parameter.
|
||||
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
JsExpression referenceToClass = translateAsFQReference(defaultObjectDescriptor.getContainingDeclaration(), declarationContext);
|
||||
JsExpression defaultObjectAccessor = Namer.getDefaultObjectAccessor(referenceToClass);
|
||||
ReceiverParameterDescriptor defaultObjectReceiver = getReceiverParameterForDeclaration(defaultObjectDescriptor);
|
||||
declarationContext.aliasingContext().registerAlias(defaultObjectReceiver, defaultObjectAccessor);
|
||||
private TranslationContext fixContextForCompanionObjectAccessing(TranslationContext declarationContext) {
|
||||
// In Kotlin we can access to companion object members without qualifier just by name, but we should translate it to access with FQ name.
|
||||
// So create alias for companion object receiver parameter.
|
||||
ClassDescriptor companionObjectDescriptor = descriptor.getCompanionObjectDescriptor();
|
||||
if (companionObjectDescriptor != null) {
|
||||
JsExpression referenceToClass = translateAsFQReference(companionObjectDescriptor.getContainingDeclaration(), declarationContext);
|
||||
JsExpression companionObjectAccessor = Namer.getCompanionObjectAccessor(referenceToClass);
|
||||
ReceiverParameterDescriptor companionObjectReceiver = getReceiverParameterForDeclaration(companionObjectDescriptor);
|
||||
declarationContext.aliasingContext().registerAlias(companionObjectReceiver, companionObjectAccessor);
|
||||
}
|
||||
|
||||
// Overlap alias of default object receiver for accessing from containing class(see previous if block),
|
||||
// because inside default object we should use simple name for access.
|
||||
if (isDefaultObject(descriptor)) {
|
||||
// Overlap alias of companion object receiver for accessing from containing class(see previous if block),
|
||||
// because inside companion object we should use simple name for access.
|
||||
if (isCompanionObject(descriptor)) {
|
||||
declarationContext = declarationContext.innerContextWithAliased(descriptor.getThisAsReceiverParameter(), JsLiteral.THIS);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.types.JetType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.initializer.InitializerUtils.createDefaultObjectInitializer;
|
||||
import static org.jetbrains.kotlin.js.translate.initializer.InitializerUtils.createCompanionObjectInitializer;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getClassDescriptor;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getFunctionDescriptor;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getSupertypesWithoutFakes;
|
||||
@@ -85,7 +85,7 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
|
||||
@Override
|
||||
public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, TranslationContext context) {
|
||||
if (!declaration.isDefault()) {
|
||||
if (!declaration.isCompanion()) {
|
||||
// parsed it in initializer visitor => no additional actions are needed
|
||||
return null;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
|
||||
ClassDescriptor descriptor = getClassDescriptor(context.bindingContext(), declaration);
|
||||
JsFunction fun = TranslationUtils.simpleReturnFunction(context.getScopeForDescriptor(descriptor), value);
|
||||
staticResult.add(createDefaultObjectInitializer(fun, context));
|
||||
staticResult.add(createCompanionObjectInitializer(fun, context));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -70,8 +70,8 @@ public final class InitializerUtils {
|
||||
initializers.add(expression.makeStmt());
|
||||
}
|
||||
|
||||
public static JsPropertyInitializer createDefaultObjectInitializer(JsExpression value, TranslationContext context) {
|
||||
JsStringLiteral defaultObjectInitStr = context.program().getStringLiteral(Namer.getNameForDefaultObjectInitializer());
|
||||
return new JsPropertyInitializer(defaultObjectInitStr, value);
|
||||
public static JsPropertyInitializer createCompanionObjectInitializer(JsExpression value, TranslationContext context) {
|
||||
JsStringLiteral companionObjectInitStr = context.program().getStringLiteral(Namer.getNameForCompanionObjectInitializer());
|
||||
return new JsPropertyInitializer(companionObjectInitStr, value);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
|
||||
|
||||
@Override
|
||||
public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, @NotNull TranslationContext context) {
|
||||
if (!declaration.isDefault()) {
|
||||
if (!declaration.isCompanion()) {
|
||||
InitializerUtils.generateObjectInitializer(declaration, result, context);
|
||||
}
|
||||
return null;
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.js.translate.intrinsic.objects
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsArrayAccess
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||
import org.jetbrains.kotlin.backend.common.builtins.DefaultObjectMapping
|
||||
import org.jetbrains.kotlin.backend.common.builtins.CompanionObjectMapping
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
@@ -35,12 +35,12 @@ class DefaultClassObjectIntrinsic(val fqName: FqName, val moduleName: String): O
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectIntrinsics : DefaultObjectMapping() {
|
||||
public class ObjectIntrinsics : CompanionObjectMapping() {
|
||||
public fun getIntrinsic(classDescriptor: ClassDescriptor): ObjectIntrinsic {
|
||||
if (!hasMappingToObject(classDescriptor)) return NO_OBJECT_INTRINSIC
|
||||
|
||||
val containingDeclaration = classDescriptor.getContainingDeclaration()
|
||||
val name = Name.identifier(containingDeclaration.getName().asString() + "DefaultObject")
|
||||
val name = Name.identifier(containingDeclaration.getName().asString() + "CompanionObject")
|
||||
|
||||
return DefaultClassObjectIntrinsic(FqName("kotlin.js.internal").child(name), LibrarySourcesConfig.STDLIB_JS_MODULE_NAME)
|
||||
}
|
||||
|
||||
+13
-13
@@ -35,20 +35,20 @@ import java.util.List;
|
||||
import static org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator.translateAsFQReference;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getDescriptorForReferenceExpression;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonDefaultObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||
|
||||
public class DefaultObjectAccessTranslator extends AbstractTranslator implements CachedAccessTranslator {
|
||||
public class CompanionObjectAccessTranslator extends AbstractTranslator implements CachedAccessTranslator {
|
||||
@NotNull
|
||||
/*package*/ static DefaultObjectAccessTranslator newInstance(
|
||||
/*package*/ static CompanionObjectAccessTranslator newInstance(
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
DeclarationDescriptor referenceDescriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
assert referenceDescriptor != null : "JetSimpleName expression must reference a descriptor " + expression.getText();
|
||||
return new DefaultObjectAccessTranslator(referenceDescriptor, context);
|
||||
return new CompanionObjectAccessTranslator(referenceDescriptor, context);
|
||||
}
|
||||
|
||||
/*package*/ static boolean isDefaultObjectReference(
|
||||
/*package*/ static boolean isCompanionObjectReference(
|
||||
@NotNull JetReferenceExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
@@ -57,15 +57,15 @@ public class DefaultObjectAccessTranslator extends AbstractTranslator implements
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JsExpression referenceToDefaultObject;
|
||||
private final JsExpression referenceToCompanionObject;
|
||||
|
||||
private DefaultObjectAccessTranslator(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
|
||||
private CompanionObjectAccessTranslator(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.referenceToDefaultObject = generateReferenceToDefaultObject(descriptor, context);
|
||||
this.referenceToCompanionObject = generateReferenceToCompanionObject(descriptor, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsExpression generateReferenceToDefaultObject(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
|
||||
private static JsExpression generateReferenceToCompanionObject(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
ObjectIntrinsic objectIntrinsic = context.intrinsics().getObjectIntrinsic((ClassDescriptor) descriptor);
|
||||
if (objectIntrinsic.exists()) {
|
||||
@@ -74,23 +74,23 @@ public class DefaultObjectAccessTranslator extends AbstractTranslator implements
|
||||
}
|
||||
|
||||
JsExpression fqReference = translateAsFQReference(descriptor, context);
|
||||
if (isNonDefaultObject(descriptor) || isEnumEntry(descriptor)) {
|
||||
if (isNonCompanionObject(descriptor) || isEnumEntry(descriptor)) {
|
||||
return fqReference;
|
||||
}
|
||||
|
||||
return Namer.getDefaultObjectAccessor(fqReference);
|
||||
return Namer.getCompanionObjectAccessor(fqReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsExpression translateAsGet() {
|
||||
return referenceToDefaultObject;
|
||||
return referenceToCompanionObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsExpression translateAsSet(@NotNull JsExpression toSetTo) {
|
||||
throw new IllegalStateException("default object can't be set");
|
||||
throw new IllegalStateException("companion object can't be set");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
+5
-5
@@ -53,17 +53,17 @@ public final class ReferenceTranslator {
|
||||
) {
|
||||
JsExpression simpleName = translateSimpleName(expression, context);
|
||||
|
||||
// Ignore qualifier if expression is EnumEntry or default object reference and always use FQ name.
|
||||
// Ignore qualifier if expression is EnumEntry or companion object reference and always use FQ name.
|
||||
DeclarationDescriptor descriptor = BindingUtils.getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
//TODO: should go away when objects inside classes are supported
|
||||
if (DescriptorUtils.isDefaultObject(descriptor) && !AnnotationsUtils.isNativeObject(descriptor)) {
|
||||
if (DescriptorUtils.isCompanionObject(descriptor) && !AnnotationsUtils.isNativeObject(descriptor)) {
|
||||
return simpleName;
|
||||
}
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor entryClass = (ClassDescriptor) descriptor;
|
||||
if (entryClass.getKind() == ClassKind.ENUM_ENTRY && !AnnotationsUtils.isNativeObject(entryClass)) {
|
||||
DeclarationDescriptor enumClass = entryClass.getContainingDeclaration();
|
||||
qualifier = Namer.getDefaultObjectAccessor(translateAsFQReference(enumClass, context));
|
||||
qualifier = Namer.getCompanionObjectAccessor(translateAsFQReference(enumClass, context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ public final class ReferenceTranslator {
|
||||
if (canBePropertyAccess(referenceExpression, context)) {
|
||||
return VariableAccessTranslator.newInstance(context, referenceExpression, receiver);
|
||||
}
|
||||
if (DefaultObjectAccessTranslator.isDefaultObjectReference(referenceExpression, context)) {
|
||||
return DefaultObjectAccessTranslator.newInstance(referenceExpression, context);
|
||||
if (CompanionObjectAccessTranslator.isCompanionObjectReference(referenceExpression, context)) {
|
||||
return CompanionObjectAccessTranslator.newInstance(referenceExpression, context);
|
||||
}
|
||||
return ReferenceAccessTranslator.newInstance(referenceExpression, context);
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ package foo
|
||||
import kotlin.reflect.KMemberProperty
|
||||
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
val ref: KMemberProperty<A, String> = A::foo
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
package foo
|
||||
|
||||
class Foo() {
|
||||
default object {
|
||||
companion object {
|
||||
val bar = "Foo.bar ";
|
||||
var boo = "FAIL";
|
||||
fun baz() = "Foo.baz() "
|
||||
|
||||
@@ -4,7 +4,7 @@ class A {
|
||||
private val p: Int
|
||||
get() = 4
|
||||
|
||||
default object B {
|
||||
companion object B {
|
||||
val p: Int
|
||||
get() = 6
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
trait A {
|
||||
default object {
|
||||
companion object {
|
||||
val OK: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package foo
|
||||
|
||||
trait Named {
|
||||
default object Bar {
|
||||
companion object Bar {
|
||||
val g = "a";
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
default object {
|
||||
companion object {
|
||||
val g = "b";
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ fun box(): String {
|
||||
assertEquals("a", Named.Bar.g, "Named.Bar.g")
|
||||
assertEquals("a", Named.g, "Named.g")
|
||||
|
||||
assertEquals("b", Foo.Default.g, "Foo.Default.g")
|
||||
assertEquals("b", Foo.Companion.g, "Foo.Companion.g")
|
||||
assertEquals("b", Foo.g, "Foo.g")
|
||||
|
||||
assertEquals("b", foo(Foo), "foo(Foo)")
|
||||
assertEquals("b", foo(Foo.Default), "foo(Foo.Default)")
|
||||
assertEquals("b", foo(Foo.Companion), "foo(Foo.Companion)")
|
||||
|
||||
assertEquals("c", Named.ext(), "Named.ext()")
|
||||
assertEquals("c", Named.Bar.ext(), "Named.Bar.ext()")
|
||||
@@ -28,6 +28,6 @@ fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo(f: Foo.Default) = f.g
|
||||
fun foo(f: Foo.Companion) = f.g
|
||||
|
||||
fun Named.Bar.ext() = "c"
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A {
|
||||
var a = 3
|
||||
default object {
|
||||
companion object {
|
||||
var a = -2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A {
|
||||
val a = 3
|
||||
default object {
|
||||
companion object {
|
||||
val a = 2
|
||||
val b = 5
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ open class A {
|
||||
fun foo(): Int {
|
||||
return 5
|
||||
}
|
||||
default object: A() {
|
||||
companion object: A() {
|
||||
val c = a
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
default object: A() {
|
||||
companion object: A() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ object A {
|
||||
}
|
||||
|
||||
class B {
|
||||
default object {
|
||||
companion object {
|
||||
val a = 21
|
||||
fun foo() = 3
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
class A {
|
||||
fun foo() = "O"
|
||||
default object {
|
||||
companion object {
|
||||
fun bar() = "K"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C() {
|
||||
default object {
|
||||
companion object {
|
||||
fun create() = C()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class C() {
|
||||
fun getInstance(): Runnable = C
|
||||
|
||||
default object: Runnable {
|
||||
companion object: Runnable {
|
||||
override fun run(): Unit {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ abstract open class Default {
|
||||
}
|
||||
|
||||
class MyInt() {
|
||||
default object : Default {
|
||||
companion object : Default {
|
||||
override fun defaultValue(): Int = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun toDefault<T : Any>(t: T) where default object T : Default = T.defaultValue()
|
||||
fun toDefault<T : Any>(t: T) where class object T : Default = T.defaultValue()
|
||||
|
||||
fun box(): String = if (toDefault<MyInt>(MyInt()) == 610) "OK" else "fail"
|
||||
|
||||
@@ -15,7 +15,7 @@ class InlineAll {
|
||||
return s()
|
||||
}
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
inline fun inline(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ trait InlineTrait {
|
||||
return s()
|
||||
}
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
inline final fun finalInline(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ fun f(x: Int): Int = x * 2
|
||||
fun Int.f(): Int = this * 3
|
||||
|
||||
class A(var value: Int) {
|
||||
default object {
|
||||
companion object {
|
||||
fun f(): Int = 5
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
native
|
||||
class A(val c: Int) {
|
||||
native
|
||||
default object {
|
||||
companion object {
|
||||
val g: Int = noImpl
|
||||
val c: String = noImpl
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ object Object {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
@@ -109,7 +109,7 @@ object Object {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
@@ -121,7 +121,7 @@ object Object {
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
@@ -145,7 +145,7 @@ class Class {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
@@ -162,14 +162,14 @@ class Class {
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
native("aaa")
|
||||
val a: Trait = noImpl
|
||||
var b: String = noImpl
|
||||
@@ -190,7 +190,7 @@ trait Trait {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
@@ -203,14 +203,14 @@ trait Trait {
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val a: Trait = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
@@ -24,7 +24,7 @@ fun Bar.test2(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl
|
||||
native
|
||||
class Bar(val size: Int, order: Int = 0) {
|
||||
fun test(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl
|
||||
default object {
|
||||
companion object {
|
||||
fun startNewTest(): Boolean = noImpl
|
||||
var hasOrderProblem: Boolean = false
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ object B {
|
||||
}
|
||||
|
||||
class C {
|
||||
default object {
|
||||
companion object {
|
||||
fun ov() = "d"
|
||||
}
|
||||
object query {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun enum() { enum() }
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun eval() { eval() }
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun `for`() { `for`() }
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun `if`() { `if`() }
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun foo(export: String) {
|
||||
assertEquals("123", export)
|
||||
testRenamed("export", { export })
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun foo(extends: String) {
|
||||
assertEquals("123", extends)
|
||||
testRenamed("extends", { extends })
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun foo(`in`: String) {
|
||||
assertEquals("123", `in`)
|
||||
testRenamed("in", { `in` })
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
fun foo(`null`: String) {
|
||||
assertEquals("123", `null`)
|
||||
testRenamed("null", { `null` })
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val t: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val t: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val t: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val t: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val const: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val `continue`: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val debugger: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
val `do`: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
var default: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
var delete: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
var `else`: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class TestClass {
|
||||
default object {
|
||||
companion object {
|
||||
var `false`: Int = 0
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class delete { default object {} }
|
||||
class delete { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("delete", { delete })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class enum { default object {} }
|
||||
class enum { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("enum", { enum })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class `package` { default object {} }
|
||||
class `package` { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("package", { `package` })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
class `return` { default object {} }
|
||||
class `return` { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("return", { `return` })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
trait eval { default object {} }
|
||||
trait eval { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("eval", { eval })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
trait export { default object {} }
|
||||
trait export { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("export", { export })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
trait `super` { default object {} }
|
||||
trait `super` { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("super", { `super` })
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the generateTestDataForReservedWords.kt. DO NOT EDIT!
|
||||
|
||||
trait `this` { default object {} }
|
||||
trait `this` { companion object {} }
|
||||
|
||||
fun box(): String {
|
||||
testNotRenamed("this", { `this` })
|
||||
|
||||
Reference in New Issue
Block a user