diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java index 4056960242a..045a3426999 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java @@ -57,9 +57,11 @@ public class SpecialFiles { private static void fillExcludedFiles() { excludedFiles.add("boxAgainstJava"); // Must compile Java files before + excludedFiles.add("boxWithJava"); // Must compile Java files before excludedFiles.add("boxMultiFile"); // MultiFileTest not supported yet excludedFiles.add("boxInline"); // MultiFileTest not supported yet + excludedFiles.add("reflection"); excludedFiles.add("kt3238.kt"); // Reflection excludedFiles.add("kt1482_2279.kt"); // Reflection @@ -68,11 +70,6 @@ public class SpecialFiles { excludedFiles.add("packageQualifiedMethod.kt"); // Cannot change package name excludedFiles.add("classObjectToString.kt"); // Cannot change package name - /* Reflection tests with full-qualified names*/ - excludedFiles.add("insideLambda"); - excludedFiles.add("lambda"); - excludedFiles.add("kt5112.kt"); - excludedFiles.add("kt326.kt"); // Commented excludedFiles.add("kt1213.kt"); // Commented diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java index badbff196fc..202053b1d23 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java @@ -154,6 +154,11 @@ public class AsmUtil { return Type.getType(internalName.substring(1)); } + @NotNull + public static Method method(@NotNull String name, @NotNull Type returnType, @NotNull Type... parameterTypes) { + return new Method(name, Type.getMethodDescriptor(returnType, parameterTypes)); + } + public static boolean isAbstractMethod(FunctionDescriptor functionDescriptor, OwnerKind kind) { return (functionDescriptor.getModality() == Modality.ABSTRACT || isInterface(functionDescriptor.getContainingDeclaration())) @@ -785,4 +790,12 @@ public class AsmUtil { return PackagePartClassUtils.getPackagePartInternalName(containingFile); } + public static void putJavaLangClassInstance(@NotNull InstructionAdapter v, @NotNull Type type) { + if (isPrimitive(type)) { + v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;"); + } + else { + v.aconst(type); + } + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 8e9f9862f95..af203a1a0a0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -49,6 +49,8 @@ import org.jetbrains.jet.lang.resolve.constants.IntegerValueConstant; import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; +import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor; import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor; import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature; import org.jetbrains.jet.lang.resolve.name.Name; @@ -68,7 +70,6 @@ import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.*; import static org.jetbrains.jet.codegen.AsmUtil.*; -import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; import static org.jetbrains.jet.codegen.JvmCodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*; @@ -76,6 +77,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedInClosure; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass; +import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER; import static org.jetbrains.org.objectweb.asm.Opcodes.*; @@ -2410,19 +2412,90 @@ public class ExpressionCodegen extends JetVisitor implem @Override public StackValue visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression, StackValue data) { - // TODO: properties + ResolvedCall resolvedCall = resolvedCall(expression.getCallableReference()); FunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression); - assert functionDescriptor != null : "Callable reference is not resolved to descriptor: " + expression.getText(); + if (functionDescriptor != null) { + CallableReferenceGenerationStrategy strategy = new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall); + ClosureCodegen closureCodegen = new ClosureCodegen(state, expression, functionDescriptor, null, context, + KotlinSyntheticClass.Kind.CALLABLE_REFERENCE_WRAPPER, + this, strategy, getParentCodegen()); + closureCodegen.gen(); + return closureCodegen.putInstanceOnStack(v, this); + } - CallableReferenceGenerationStrategy strategy = - new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall(expression.getCallableReference())); - ClosureCodegen closureCodegen = new ClosureCodegen(state, expression, functionDescriptor, null, context, - KotlinSyntheticClass.Kind.CALLABLE_REFERENCE_WRAPPER, - this, strategy, getParentCodegen()); + VariableDescriptor variableDescriptor = bindingContext.get(VARIABLE, expression); + if (variableDescriptor != null) { + VariableDescriptor descriptor = (VariableDescriptor) resolvedCall.getResultingDescriptor(); - closureCodegen.gen(); + DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); + if (containingDeclaration instanceof PackageFragmentDescriptor) { + return generateTopLevelPropertyReference(descriptor); + } + else if (containingDeclaration instanceof ClassDescriptor) { + return generateMemberPropertyReference(descriptor); + } + else { + throw new UnsupportedOperationException("Unsupported callable reference container: " + containingDeclaration); + } + } - return closureCodegen.putInstanceOnStack(v, this); + throw new UnsupportedOperationException("Unsupported callable reference expression: " + expression.getText()); + } + + @NotNull + private StackValue generateTopLevelPropertyReference(@NotNull VariableDescriptor descriptor) { + PackageFragmentDescriptor containingPackage = (PackageFragmentDescriptor) descriptor.getContainingDeclaration(); + String packageClassInternalName = PackageClassUtils.getPackageClassInternalName(containingPackage.getFqName()); + + ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter(); + Method factoryMethod; + if (receiverParameter != null) { + Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE, getType(Class.class)}; + factoryMethod = descriptor.isVar() + ? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes) + : method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes); + } + else { + Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE}; + factoryMethod = descriptor.isVar() + ? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes) + : method("topLevelVariable", K_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes); + } + + v.visitLdcInsn(descriptor.getName().asString()); + v.getstatic(packageClassInternalName, JvmAbi.KOTLIN_PACKAGE_FIELD_NAME, K_PACKAGE_IMPL_TYPE.getDescriptor()); + + if (receiverParameter != null) { + putJavaLangClassInstance(v, typeMapper.mapType(receiverParameter)); + } + + v.invokestatic(REFLECTION_INTERNAL_PACKAGE, factoryMethod.getName(), factoryMethod.getDescriptor(), false); + + return StackValue.onStack(factoryMethod.getReturnType()); + } + + @NotNull + private StackValue generateMemberPropertyReference(@NotNull VariableDescriptor descriptor) { + ClassDescriptor containingClass = (ClassDescriptor) descriptor.getContainingDeclaration(); + Type classAsmType = typeMapper.mapClass(containingClass); + + if (containingClass instanceof JavaClassDescriptor) { + v.aconst(classAsmType); + v.invokestatic(REFLECTION_INTERNAL_PACKAGE, "foreignKotlinClass", + Type.getMethodDescriptor(K_CLASS_IMPL_TYPE, getType(Class.class)), false); + } + else { + v.getstatic(classAsmType.getInternalName(), JvmAbi.KOTLIN_CLASS_FIELD_NAME, K_CLASS_IMPL_TYPE.getDescriptor()); + } + + Method factoryMethod = descriptor.isVar() + ? method("mutableMemberProperty", K_MUTABLE_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE) + : method("memberProperty", K_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE); + + v.visitLdcInsn(descriptor.getName().asString()); + v.invokevirtual(K_CLASS_IMPL_TYPE.getInternalName(), factoryMethod.getName(), factoryMethod.getDescriptor(), false); + + return StackValue.onStack(factoryMethod.getReturnType()); } private static class CallableReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GeneratedClassLoader.java b/compiler/backend/src/org/jetbrains/jet/codegen/GeneratedClassLoader.java index 0a0e865c863..70e6627821a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GeneratedClassLoader.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GeneratedClassLoader.java @@ -22,6 +22,7 @@ import org.jetbrains.jet.OutputFile; import java.net.URL; import java.net.URLClassLoader; import java.util.List; +import java.util.jar.Manifest; public class GeneratedClassLoader extends URLClassLoader { private ClassFileFactory state; @@ -39,6 +40,13 @@ public class GeneratedClassLoader extends URLClassLoader { OutputFile outputFile = state.get(classFilePath); if (outputFile != null) { byte[] bytes = outputFile.asByteArray(); + int lastDot = name.lastIndexOf('.'); + if (lastDot >= 0) { + String pkgName = name.substring(0, lastDot); + if (getPackage(pkgName) == null) { + definePackage(pkgName, new Manifest(), null); + } + } return defineClass(name, bytes, 0, bytes.length); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 6650d907bfb..2dc17723740 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -72,8 +72,7 @@ import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.descriptors.serialization.NameSerializationUtil.createNameResolver; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*; -import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE; -import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.DelegationToTraitImpl; import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; @@ -209,6 +208,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { writeInnerClasses(); AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor, null); + + generateReflectionObjectFieldIfNeeded(); } @Override @@ -429,7 +430,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { @Override protected void generateSyntheticParts() { - generateDelegatedPropertyMetadataArray(); + generatePropertyMetadataArrayFieldIfNeeded(classAsmType); generateFieldForSingleton(); @@ -463,11 +464,19 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { generateToArray(); - genClosureFields(context.closure, v, state.getTypeMapper()); + genClosureFields(context.closure, v, typeMapper); } - private void generateDelegatedPropertyMetadataArray() { - generatePropertyMetadataArrayFieldIfNeeded(classAsmType); + private void generateReflectionObjectFieldIfNeeded() { + if (isAnnotationClass(descriptor)) { + // There's a bug in JDK 6 and 7 that prevents us from generating a static field in an annotation class: + // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6857918 + // TODO: make reflection work on annotation classes somehow + return; + } + + generateReflectionObjectField(state, classAsmType, v, method("kClassFromKotlin", K_CLASS_IMPL_TYPE, getType(Class.class)), + JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v); } private boolean isGenericToArrayPresent() { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java index b491052aabb..910cd303da0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java @@ -43,6 +43,7 @@ import org.jetbrains.jet.storage.NotNullLazyValue; import org.jetbrains.org.objectweb.asm.MethodVisitor; import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; +import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.ArrayList; import java.util.Collections; @@ -50,12 +51,12 @@ import java.util.List; import static org.jetbrains.jet.codegen.AsmUtil.boxType; import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; -import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; -import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.TraitImpl; -import static org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin.NO_ORIGIN; import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED; import static org.jetbrains.jet.lang.resolve.BindingContext.VARIABLE; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; +import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; +import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.TraitImpl; +import static org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin.NO_ORIGIN; import static org.jetbrains.org.objectweb.asm.Opcodes.*; public abstract class MemberCodegen extends ParentCodegenAware { @@ -316,6 +317,25 @@ public abstract class MemberCodegen delegatedProperties = new ArrayList(); for (JetDeclaration declaration : ((JetDeclarationContainer) element).getDeclarations()) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java index c46ae090f6b..2356350d5fc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java @@ -56,27 +56,35 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.org.objectweb.asm.AnnotationVisitor; import org.jetbrains.org.objectweb.asm.MethodVisitor; import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; +import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.*; import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses; +import static org.jetbrains.jet.codegen.AsmUtil.method; import static org.jetbrains.jet.descriptors.serialization.NameSerializationUtil.createNameResolver; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.K_PACKAGE_IMPL_TYPE; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType; import static org.jetbrains.jet.lang.resolve.java.PackageClassUtils.getPackageClassFqName; import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.*; +import static org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin.NO_ORIGIN; import static org.jetbrains.org.objectweb.asm.Opcodes.*; public class PackageCodegen { - private final GenerationState state; private final ClassBuilderOnDemand v; + private final GenerationState state; private final Collection files; + private final Type packageClassType; private final PackageFragmentDescriptor packageFragment; private final PackageFragmentDescriptor compiledPackageFragment; private final List previouslyCompiledCallables; - public PackageCodegen(@NotNull GenerationState state, @NotNull Collection files, @NotNull final FqName fqName) { + public PackageCodegen(@NotNull GenerationState state, @NotNull Collection files, @NotNull FqName fqName) { this.state = state; this.files = files; this.packageFragment = getOnlyPackageFragment(fqName); + this.packageClassType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(getPackageClassFqName(fqName)); this.compiledPackageFragment = getCompiledPackageFragment(fqName); this.previouslyCompiledCallables = filterDeserializedCallables(compiledPackageFragment); @@ -88,14 +96,13 @@ public class PackageCodegen { Collection files = PackageCodegen.this.files; JetFile sourceFile = getRepresentativePackageFile(files); - String className = AsmUtil.internalNameByFqNameWithoutInnerClasses(getPackageClassFqName(fqName)); - ClassBuilder v = PackageCodegen.this.state.getFactory() - .newVisitor( - PackageFacade(packageFragment == null ? compiledPackageFragment : packageFragment), - Type.getObjectType(className), PackagePartClassUtils.getPackageFilesWithCallables(files)); + ClassBuilder v = PackageCodegen.this.state.getFactory().newVisitor( + PackageFacade(packageFragment == null ? compiledPackageFragment : packageFragment), + packageClassType, PackagePartClassUtils.getPackageFilesWithCallables(files) + ); v.defineClass(sourceFile, V1_6, ACC_PUBLIC | ACC_FINAL, - className, + packageClassType.getInternalName(), null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY @@ -216,18 +223,36 @@ public class PackageCodegen { } } - generateDelegationsToPreviouslyCompiled(generateCallableMemberTasks); + if (!generateCallableMemberTasks.isEmpty()) { + generatePackageFacadeClass(generateCallableMemberTasks, bindings); + } + } - if (generateCallableMemberTasks.isEmpty()) return; + private void generatePackageFacadeClass( + @NotNull Map tasks, + @NotNull List bindings + ) { + generateKotlinPackageReflectionField(); - for (CallableMemberDescriptor member : Ordering.from(MemberComparator.INSTANCE).sortedCopy(generateCallableMemberTasks.keySet())) { - generateCallableMemberTasks.get(member).run(); + generateDelegationsToPreviouslyCompiled(tasks); + + for (CallableMemberDescriptor member : Ordering.from(MemberComparator.INSTANCE).sortedCopy(tasks.keySet())) { + tasks.get(member).run(); } bindings.add(v.getSerializationBindings()); writeKotlinPackageAnnotationIfNeeded(JvmSerializationBindings.union(bindings)); } + private void generateKotlinPackageReflectionField() { + MethodVisitor mv = v.newMethod(NO_ORIGIN, ACC_STATIC, "", "()V", null, null); + Method method = method("kPackage", K_PACKAGE_IMPL_TYPE, getType(Class.class)); + InstructionAdapter iv = new InstructionAdapter(mv); + MemberCodegen.generateReflectionObjectField(state, packageClassType, v, method, JvmAbi.KOTLIN_PACKAGE_FIELD_NAME, iv); + iv.areturn(Type.VOID_TYPE); + FunctionCodegen.endVisit(mv, "package facade static initializer", null); + } + private void writeKotlinPackageAnnotationIfNeeded(@NotNull JvmSerializationBindings bindings) { if (state.getClassBuilderMode() != ClassBuilderMode.FULL) { return; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegenUtil.java index 4cbaceed56b..c1871be9e64 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegenUtil.java @@ -266,6 +266,9 @@ public class InlineCodegenUtil { } public static boolean isCapturedFieldName(@NotNull String fieldName) { - return fieldName.startsWith(CAPTURED_FIELD_PREFIX) || THIS$0.equals(fieldName) || RECEIVER$0.equals(fieldName); + // TODO: improve this heuristic + return (fieldName.startsWith(CAPTURED_FIELD_PREFIX) && !fieldName.equals(JvmAbi.KOTLIN_CLASS_FIELD_NAME)) || + THIS$0.equals(fieldName) || + RECEIVER$0.equals(fieldName); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java index d1b3b660cb6..cc2c8c52be2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java @@ -19,8 +19,6 @@ package org.jetbrains.jet.codegen.intrinsics; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.org.objectweb.asm.Type; -import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.lang.psi.JetCallExpression; @@ -28,11 +26,12 @@ import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.List; -import static org.jetbrains.jet.codegen.AsmUtil.boxType; -import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; +import static org.jetbrains.jet.codegen.AsmUtil.putJavaLangClassInstance; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType; public class JavaClassFunction extends IntrinsicMethod { @@ -51,13 +50,7 @@ public class JavaClassFunction extends IntrinsicMethod { assert resolvedCall != null; JetType returnType = resolvedCall.getResultingDescriptor().getReturnType(); assert returnType != null; - Type type = codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType()); - if (isPrimitive(type)) { - v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;"); - } - else { - v.aconst(type); - } + putJavaLangClassInstance(v, codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType())); return getType(Class.class); } diff --git a/compiler/cli/bin/kotlinc-js.bat b/compiler/cli/bin/kotlinc-js.bat index 94f88d39908..1e10d6b228d 100644 --- a/compiler/cli/bin/kotlinc-js.bat +++ b/compiler/cli/bin/kotlinc-js.bat @@ -42,7 +42,7 @@ if "%_PROFILE_PRELOADER%"=="time" ( org.jetbrains.jet.preloading.Preloader "%_KOTLIN_HOME%\lib\kotlin-compiler.jar;%_KOTLIN_HOME%\lib\kotlin-runtime.jar" ^ org.jetbrains.jet.cli.js.K2JSCompiler 4096 %_PROFILE_PRELOADER% %* ) -exit %ERRORLEVEL% +exit /b %ERRORLEVEL% goto end rem ########################################################################## diff --git a/compiler/cli/bin/kotlinc-jvm.bat b/compiler/cli/bin/kotlinc-jvm.bat index 0d7591e5490..b8c86a00438 100644 --- a/compiler/cli/bin/kotlinc-jvm.bat +++ b/compiler/cli/bin/kotlinc-jvm.bat @@ -42,7 +42,7 @@ if "%_PROFILE_PRELOADER%"=="time" ( org.jetbrains.jet.preloading.Preloader "%_KOTLIN_HOME%\lib\kotlin-compiler.jar;%_KOTLIN_HOME%\lib\kotlin-runtime.jar" ^ org.jetbrains.jet.cli.jvm.K2JVMCompiler 4096 %_PROFILE_PRELOADER% %* ) -exit %ERRORLEVEL% +exit /b %ERRORLEVEL% goto end rem ########################################################################## diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index 21ec18286c0..3219774c4b2 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -57,8 +57,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { new ImportPath("java.lang.*"), new ImportPath("kotlin.*"), new ImportPath("kotlin.jvm.*"), - new ImportPath("kotlin.io.*"), - new ImportPath("kotlin.reflect.*") + new ImportPath("kotlin.io.*") ); public static class JvmSetup extends BasicSetup { diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java index 873dff87312..0f65adb0d8b 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java @@ -38,8 +38,26 @@ public class AsmTypeConstants { public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadata"); public static final Type PROPERTY_METADATA_IMPL_TYPE = Type.getObjectType(BUILT_INS_PACKAGE_FQ_NAME + "/PropertyMetadataImpl"); + public static final Type K_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMemberProperty"); + public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMutableMemberProperty"); + + public static final Type K_CLASS_IMPL_TYPE = reflectInternal("KClassImpl"); + public static final Type K_PACKAGE_IMPL_TYPE = reflectInternal("KPackageImpl"); + public static final Type K_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KTopLevelVariableImpl"); + public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KMutableTopLevelVariableImpl"); + public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelExtensionPropertyImpl"); + public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelExtensionPropertyImpl"); + + public static final String REFLECTION_INTERNAL_PACKAGE = reflectInternal("InternalPackage").getInternalName(); + public static final Type OBJECT_REF_TYPE = Type.getObjectType("kotlin/jvm/internal/Ref$ObjectRef"); + @NotNull + private static Type reflectInternal(@NotNull String className) { + return Type.getObjectType("kotlin/reflect/jvm/internal/" + className); + } + + @NotNull public static Type getType(@NotNull Class javaClass) { Type type = TYPES_MAP.get(javaClass); if (type == null) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt index 9a0d57bdd8c..a1e53d6b063 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt @@ -21,11 +21,10 @@ import org.jetbrains.jet.lang.descriptors.* import org.jetbrains.jet.lang.resolve.name.FqName import org.jetbrains.jet.lang.resolve.name.Name import org.jetbrains.jet.lang.resolve.scopes.JetScope +import org.jetbrains.jet.lang.types.* import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.descriptors.annotations.Annotations -import org.jetbrains.jet.lang.types.JetType -import org.jetbrains.jet.lang.types.JetTypeImpl -import org.jetbrains.jet.lang.types.ErrorUtils +import java.util.ArrayList private val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect") @@ -40,10 +39,23 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { ?: ErrorUtils.createErrorClass(KOTLIN_REFLECT_FQ_NAME.child(name).asString()) } + private object ClassLookup { + fun get(types: ReflectionTypes, property: PropertyMetadata): ClassDescriptor { + return types.find(property.name.capitalize()) + } + } + public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n") public fun getKExtensionFunction(n: Int): ClassDescriptor = find("KExtensionFunction$n") public fun getKMemberFunction(n: Int): ClassDescriptor = find("KMemberFunction$n") + public val kTopLevelVariable: ClassDescriptor by ClassLookup + public val kMutableTopLevelVariable: ClassDescriptor by ClassLookup + public val kMemberProperty: ClassDescriptor by ClassLookup + public val kMutableMemberProperty: ClassDescriptor by ClassLookup + public val kTopLevelExtensionProperty: ClassDescriptor by ClassLookup + public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup + public fun getKFunctionType( annotations: Annotations, receiverType: JetType?, @@ -51,26 +63,47 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { returnType: JetType, extensionFunction: Boolean ): JetType { - val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType) - val classDescriptor = correspondingKFunctionClass(receiverType, extensionFunction, parameterTypes.size) + val arity = parameterTypes.size() + val classDescriptor = + if (extensionFunction) getKExtensionFunction(arity) + else if (receiverType != null) getKMemberFunction(arity) + else getKFunction(arity) - return if (ErrorUtils.isError(classDescriptor)) - classDescriptor.getDefaultType() - else - JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) + if (ErrorUtils.isError(classDescriptor)) { + return classDescriptor.getDefaultType() + } + + val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType) + return JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) } - private fun correspondingKFunctionClass( + public fun getKPropertyType( + annotations: Annotations, receiverType: JetType?, - extensionFunction: Boolean, - numberOfParameters: Int - ): ClassDescriptor { - if (extensionFunction) { - return getKExtensionFunction(numberOfParameters) + returnType: JetType, + extensionProperty: Boolean, + mutable: Boolean + ): JetType { + val classDescriptor = if (mutable) when { + extensionProperty -> kMutableTopLevelExtensionProperty + receiverType != null -> kMutableMemberProperty + else -> kMutableTopLevelVariable } + else when { + extensionProperty -> kTopLevelExtensionProperty + receiverType != null -> kMemberProperty + else -> kTopLevelVariable + } + + if (ErrorUtils.isError(classDescriptor)) { + return classDescriptor.getDefaultType() + } + + val arguments = ArrayList(2) if (receiverType != null) { - return getKMemberFunction(numberOfParameters) + arguments.add(TypeProjectionImpl(receiverType)) } - return getKFunction(numberOfParameters) + arguments.add(TypeProjectionImpl(returnType)) + return JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 976d1b5ab19..59cbb914568 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.Annotations; import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.impl.LocalVariableDescriptor; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator; @@ -472,7 +473,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetSimpleNameExpression reference = expression.getCallableReference(); boolean[] result = new boolean[1]; - FunctionDescriptor descriptor = resolveCallableReferenceTarget(lhsType, context, expression, result); + CallableDescriptor descriptor = resolveCallableReferenceTarget(lhsType, context, expression, result); if (!result[0]) { context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); @@ -481,8 +482,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter(); ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject(); - if (receiverParameter != null && expectedThisObject != null) { - context.trace.report(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED.on(reference, descriptor)); + if (receiverParameter != null && expectedThisObject != null && descriptor instanceof CallableMemberDescriptor) { + context.trace.report(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED.on(reference, (CallableMemberDescriptor) descriptor)); return null; } @@ -493,14 +494,37 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { else if (expectedThisObject != null) { receiverType = expectedThisObject.getType(); } + boolean isExtension = receiverParameter != null; + if (descriptor instanceof FunctionDescriptor) { + return createFunctionReferenceType(expression, context, (FunctionDescriptor) descriptor, receiverType, isExtension); + } + else if (descriptor instanceof PropertyDescriptor) { + return createPropertyReferenceType(expression, context, (PropertyDescriptor) descriptor, receiverType, isExtension); + } + else if (descriptor instanceof VariableDescriptor) { + context.trace.report(UNSUPPORTED.on(reference, "References to variables aren't supported yet")); + return null; + } + + throw new UnsupportedOperationException("Callable reference resolved to an unsupported descriptor: " + descriptor); + } + + @Nullable + private JetType createFunctionReferenceType( + @NotNull JetCallableReferenceExpression expression, + @NotNull ExpressionTypingContext context, + @NotNull FunctionDescriptor descriptor, + @Nullable JetType receiverType, + boolean isExtension + ) { //noinspection ConstantConditions JetType type = components.reflectionTypes.getKFunctionType( Annotations.EMPTY, receiverType, getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType(), - receiverParameter != null + isExtension ); if (type.isError()) { @@ -511,7 +535,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { AnonymousFunctionDescriptor functionDescriptor = new AnonymousFunctionDescriptor( context.scope.getContainingDeclaration(), Annotations.EMPTY, - CallableMemberDescriptor.Kind.DECLARATION); + CallableMemberDescriptor.Kind.DECLARATION + ); FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, type, null, Modality.FINAL, Visibilities.PUBLIC); @@ -521,7 +546,32 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } @Nullable - private FunctionDescriptor resolveCallableReferenceTarget( + private JetType createPropertyReferenceType( + @NotNull JetCallableReferenceExpression expression, + @NotNull ExpressionTypingContext context, + @NotNull PropertyDescriptor descriptor, + @Nullable JetType receiverType, + boolean isExtension + ) { + JetType type = components.reflectionTypes.getKPropertyType(Annotations.EMPTY, receiverType, descriptor.getType(), isExtension, + descriptor.isVar()); + + if (type.isError()) { + context.trace.report(REFLECTION_TYPES_NOT_LOADED.on(expression.getDoubleColonTokenReference())); + return null; + } + + LocalVariableDescriptor localVariable = + new LocalVariableDescriptor(context.scope.getContainingDeclaration(), Annotations.EMPTY, Name.special(""), + type, /* mutable = */ false); + + context.trace.record(VARIABLE, expression, localVariable); + + return type; + } + + @Nullable + private CallableDescriptor resolveCallableReferenceTarget( @Nullable JetType lhsType, @NotNull ExpressionTypingContext context, @NotNull JetCallableReferenceExpression expression, @@ -542,7 +592,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ReceiverValue receiver = new TransientReceiver(lhsType); TemporaryTraceAndCache temporaryWithReceiver = TemporaryTraceAndCache.create( context, "trace to resolve callable reference with receiver", reference); - FunctionDescriptor descriptor = resolveCallableNotCheckingArguments( + CallableDescriptor descriptor = resolveCallableNotCheckingArguments( reference, receiver, context.replaceTraceAndCache(temporaryWithReceiver), result); if (result[0]) { temporaryWithReceiver.commit(); @@ -552,7 +602,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetScope staticScope = getStaticNestedClassesScope((ClassDescriptor) classifier); TemporaryTraceAndCache temporaryForStatic = TemporaryTraceAndCache.create( context, "trace to resolve callable reference in static scope", reference); - FunctionDescriptor possibleStaticNestedClassConstructor = resolveCallableNotCheckingArguments(reference, NO_RECEIVER, + CallableDescriptor possibleStaticNestedClassConstructor = resolveCallableNotCheckingArguments(reference, NO_RECEIVER, context.replaceTraceAndCache(temporaryForStatic).replaceScope(staticScope), result); if (result[0]) { temporaryForStatic.commit(); @@ -563,7 +613,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } @Nullable - private FunctionDescriptor resolveCallableNotCheckingArguments( + private CallableDescriptor resolveCallableNotCheckingArguments( @NotNull JetSimpleNameExpression reference, @NotNull ReceiverValue receiver, @NotNull ExpressionTypingContext context, @@ -571,22 +621,41 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ) { Call call = CallMaker.makeCall(reference, receiver, null, reference, ThrowingList.instance()); - TemporaryBindingTrace trace = TemporaryBindingTrace.create(context.trace, "trace to resolve as function", reference); - - ExpressionTypingContext contextForResolve = context.replaceBindingTrace(trace).replaceExpectedType(NO_EXPECTED_TYPE); + TemporaryTraceAndCache funTrace = TemporaryTraceAndCache.create(context, "trace to resolve callable reference as function", + reference); ResolvedCall function = components.expressionTypingServices.getCallExpressionResolver() - .getResolvedCallForFunction(call, reference, contextForResolve, CheckValueArgumentsMode.DISABLED, result); - if (!result[0]) return null; + .getResolvedCallForFunction(call, reference, context.replaceTraceAndCache(funTrace).replaceExpectedType(NO_EXPECTED_TYPE), + CheckValueArgumentsMode.DISABLED, result); + if (result[0]) { + funTrace.commit(); - if (function instanceof VariableAsFunctionResolvedCall) { - // TODO: KProperty - context.trace.report(UNSUPPORTED.on(reference, "References to variables aren't supported yet")); - context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); - return null; + if (function instanceof VariableAsFunctionResolvedCall) { + context.trace.report(UNSUPPORTED.on(reference, "References to variables aren't supported yet")); + return null; + } + + return function != null ? function.getResultingDescriptor() : null; } - trace.commit(); - return function != null ? function.getResultingDescriptor() : null; + TemporaryTraceAndCache varTrace = TemporaryTraceAndCache.create(context, "trace to resolve callable reference as variable", + reference); + OverloadResolutionResults variableResults = + components.expressionTypingServices.getCallResolver().resolveSimpleProperty( + BasicCallResolutionContext.create(context.replaceTraceAndCache(varTrace).replaceExpectedType(NO_EXPECTED_TYPE), + call, CheckValueArgumentsMode.DISABLED) + ); + if (!variableResults.isNothing()) { + ResolvedCall variable = + OverloadResolutionResultsUtil.getResultingCall(variableResults, context.contextDependency); + + varTrace.commit(); + if (variable != null) { + result[0] = true; + return variable.getResultingDescriptor(); + } + } + + return null; } @Override diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java index f9c87e96f20..6b544d4500e 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java @@ -20,15 +20,14 @@ import org.junit.Test; import java.io.File; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertEquals; public class CompilerSmokeTest extends KotlinIntegrationTestBase { - @Test public void compileAndRunHelloApp() throws Exception { String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar"; - assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar)); + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar)); runJava("hello.run", "-cp", jar, "Hello.HelloPackage"); } @@ -36,7 +35,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase { public void compileAndRunHelloAppFQMain() throws Exception { String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar"; - assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar)); + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar)); runJava("hello.run", "-cp", jar, "Hello.HelloPackage"); } @@ -44,7 +43,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase { public void compileAndRunHelloAppVarargMain() throws Exception { String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar"; - assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar)); + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar)); runJava("hello.run", "-cp", jar, "Hello.HelloPackage"); } diff --git a/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.java b/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.java new file mode 100644 index 00000000000..48056198e02 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.java @@ -0,0 +1,3 @@ +public class publicFinalField { + public final String field = "OK"; +} diff --git a/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt b/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt new file mode 100644 index 00000000000..7cc41f66006 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt @@ -0,0 +1 @@ +fun box() = (publicFinalField::field).get(publicFinalField()) diff --git a/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.java b/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.java new file mode 100644 index 00000000000..b675de28fdb --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.java @@ -0,0 +1,3 @@ +public class publicMutableField { + public int field = 239; +} diff --git a/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.kt b/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.kt new file mode 100644 index 00000000000..563afaaf69b --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.kt @@ -0,0 +1,11 @@ +import publicMutableField as A + +fun box(): String { + val a = A() + val f = A::field + if (f.get(a) != 239) return "Fail 1: ${f.get(a)}" + f[a] = 42 + if (f.get(a) != 42) return "Fail 2: ${f.get(a)}" + if (f.get(a) != 42) return "Fail 2: ${f.get(a)}" + return "OK" +} diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.java b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.java new file mode 100644 index 00000000000..0256b2f75f7 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.java @@ -0,0 +1 @@ +public class jClass2kClass {} diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.kt b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.kt new file mode 100644 index 00000000000..414ae0ca5e1 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.kt @@ -0,0 +1,11 @@ +import jClass2kClass as J + +import kotlin.reflect.jvm.* +import kotlin.test.assertEquals + +fun box(): String { + val j = javaClass() + assertEquals(j, j.kotlin.java) + + return "OK" +} diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.java b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.java new file mode 100644 index 00000000000..0377951bd4b --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.java @@ -0,0 +1,9 @@ +public class javaFields { + public final int i; + public String s; + + public javaFields(int i, String s) { + this.i = i; + this.s = s; + } +} diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt new file mode 100644 index 00000000000..a5de7e5bf12 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt @@ -0,0 +1,43 @@ +import javaFields as J + +import java.lang.reflect.* +import kotlin.reflect.* +import kotlin.reflect.jvm.* + +fun box(): String { + val i = J::i + val s = J::s + + // Check that correct reflection objects are created + assert(i.javaClass.getSimpleName() == "KForeignMemberProperty", "Fail i class") + assert(s.javaClass.getSimpleName() == "KMutableForeignMemberProperty", "Fail s class") + + // Check that no Method objects are created for such properties + assert(i.javaGetter == null, "Fail i getter") + assert(s.javaGetter == null, "Fail s getter") + assert(s.javaSetter == null, "Fail s setter") + + // Check that correct Field objects are created + val ji = i.javaField!! + val js = s.javaField!! + assert(Modifier.isFinal(ji.getModifiers()), "Fail i final") + assert(!Modifier.isFinal(js.getModifiers()), "Fail s final") + + // Check that those Field objects work as expected + val a = J(42, "abc") + assert(ji.get(a) == 42, "Fail ji get") + assert(js.get(a) == "abc", "Fail js get") + js.set(a, "def") + assert(js.get(a) == "def", "Fail js set") + assert(a.s == "def", "Fail js access") + + // Check that valid Kotlin reflection objects are created by those Field objects + val ki = ji.kotlin as KMemberProperty + val ks = js.kotlin as KMutableMemberProperty + assert(ki.get(a) == 42, "Fail ki get") + assert(ks.get(a) == "def", "Fail ks get") + ks.set(a, "ghi") + assert(ks.get(a) == "ghi", "Fail ks set") + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithJava/.empty b/compiler/testData/codegen/boxWithJava/.empty deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/J.java b/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/J.java new file mode 100644 index 00000000000..9e92f8601ef --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/J.java @@ -0,0 +1,3 @@ +public class J extends K { + public final int value = 42; +} diff --git a/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/K.kt b/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/K.kt new file mode 100644 index 00000000000..79a425eb69b --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/K.kt @@ -0,0 +1,7 @@ +open class K + +fun box(): String { + val f = J::value + val a = J() + return if (f.get(a) == 42) "OK" else "Fail: ${f[a]}" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/accessViaSubclass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/accessViaSubclass.kt new file mode 100644 index 00000000000..eb2a0728db2 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/accessViaSubclass.kt @@ -0,0 +1,9 @@ +abstract class Base { + val result = "OK" +} + +class Derived : Base() + +fun box(): String { + return (Base::result).get(Derived()) +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt new file mode 100644 index 00000000000..5c52e97b42a --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt @@ -0,0 +1,22 @@ +val four: Int by NumberDecrypter + +class A { + val two: Int by NumberDecrypter +} + +object NumberDecrypter { + fun get(instance: Any?, data: PropertyMetadata) = when (data.name) { + "four" -> 4 + "two" -> 2 + else -> throw AssertionError() + } +} + +fun box(): String { + val x = ::four.get() + if (x != 4) return "Fail x: $x" + val a = A() + val y = A::two.get(a) + if (y != 2) return "Fail y: $y" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegatedMutable.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegatedMutable.kt new file mode 100644 index 00000000000..e7a364cb432 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/delegatedMutable.kt @@ -0,0 +1,22 @@ +var result: String by Delegate + +object Delegate { + var value = "lol" + + fun get(instance: Any?, data: PropertyMetadata): String { + return value + } + + fun set(instance: Any?, data: PropertyMetadata, newValue: String) { + value = newValue + } +} + +fun box(): String { + val f = ::result + if (f.get() != "lol") return "Fail 1: {$f.get()}" + Delegate.value = "rofl" + if (f.get() != "rofl") return "Fail 2: {$f.get()}" + f.set("OK") + return f.get() +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt new file mode 100644 index 00000000000..0030d8026c3 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt @@ -0,0 +1,14 @@ +// Name of the getter should be 'getaBcde' according to JavaBean conventions +var aBcde: Int = 239 + +fun box(): String { + val x = (::aBcde).get() + if (x != 239) return "Fail x: $x" + + (::aBcde).set(42) + + val y = (::aBcde).get() + if (y != 42) return "Fail y: $y" + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt new file mode 100644 index 00000000000..d83348c141c --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt @@ -0,0 +1,13 @@ +import kotlin.reflect.KMemberProperty + +class A { + class object { + val ref: KMemberProperty = A::foo + } + + val foo: String = "OK" +} + +fun box(): String { + return A.ref.get(A()) +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt new file mode 100644 index 00000000000..fd45085df67 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt @@ -0,0 +1,9 @@ +fun box(): String { + class Local { + var result = "Fail" + } + + val l = Local() + (Local::result).set(l, "OK") + return (Local::result).get(l) +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt new file mode 100644 index 00000000000..d892efcba29 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt @@ -0,0 +1,9 @@ +open class Base { + open val foo = "Base" +} + +class Derived : Base() { + override val foo = "OK" +} + +fun box() = (Base::foo).get(Derived()) diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt new file mode 100644 index 00000000000..74399986a8f --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt @@ -0,0 +1,29 @@ +import kotlin.reflect.IllegalAccessException +import kotlin.reflect.KMemberProperty +import kotlin.reflect.jvm.accessible + +class Result { + private val value = "OK" + + fun ref(): KMemberProperty = ::value +} + +fun box(): String { + val p = Result().ref() + try { + p.get(Result()) + return "Fail: private property is accessible by default" + } catch(e: IllegalAccessException) { } + + p.accessible = true + + val r = p.get(Result()) + + p.accessible = false + try { + p.get(Result()) + return "Fail: setAccessible(false) had no effect" + } catch(e: IllegalAccessException) { } + + return r +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt new file mode 100644 index 00000000000..42fde2a640f --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt @@ -0,0 +1,31 @@ +import kotlin.reflect.IllegalAccessException +import kotlin.reflect.KMutableMemberProperty +import kotlin.reflect.jvm.accessible + +class A { + private var value = 0 + + fun ref(): KMutableMemberProperty = ::value +} + +fun box(): String { + val a = A() + val p = a.ref() + try { + p.set(a, 1) + return "Fail: private property is accessible by default" + } catch(e: IllegalAccessException) { } + + p.accessible = true + + p.set(a, 2) + p.get(a) + + p.accessible = false + try { + p.set(a, 3) + return "Fail: setAccessible(false) had no effect" + } catch(e: IllegalAccessException) { } + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/protectedClassVar.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/protectedClassVar.kt new file mode 100644 index 00000000000..35237e8c153 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/protectedClassVar.kt @@ -0,0 +1,29 @@ +import kotlin.reflect.IllegalAccessException +import kotlin.reflect.jvm.accessible + +class A(param: String) { + protected var v: String = param + + fun ref() = ::v +} + +fun box(): String { + val a = A(":(") + val f = a.ref() + + try { + f.get(a) + return "Fail: protected property getter is accessible by default" + } catch (e: IllegalAccessException) { } + + try { + f.set(a, ":D") + return "Fail: protected property setter is accessible by default" + } catch (e: IllegalAccessException) { } + + f.accessible = true + + f.set(a, ":)") + + return if (f[a] != ":)") "Fail: ${f[a]}" else "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/publicClassValAccessible.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/publicClassValAccessible.kt new file mode 100644 index 00000000000..3fe95c7c7e0 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/publicClassValAccessible.kt @@ -0,0 +1,12 @@ +import kotlin.reflect.jvm.accessible + +class Result { + public val value: String = "OK" +} + +fun box(): String { + val p = Result::value + p.accessible = false + // setAccessible(false) should have no effect on the accessibility of a public reflection object + return p.get(Result()) +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleExtension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleExtension.kt new file mode 100644 index 00000000000..7e6b5c92df1 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleExtension.kt @@ -0,0 +1,12 @@ +val String.id: String + get() = this + +fun box(): String { + val pr = String::id + + if (pr["123"] != "123") return "Fail value: ${pr["123"]}" + + if (pr.name != "id") return "Fail name: ${pr.name}" + + return pr.get("OK") +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMember.kt new file mode 100644 index 00000000000..39bf36a0707 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMember.kt @@ -0,0 +1,9 @@ +class A(val x: Int) + +fun box(): String { + val p = A::x + if (p.get(A(42)) != 42) return "Fail 1" + if (p.get(A(-1)) != -1) return "Fail 2" + if (p.name != "x") return "Fail 3" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableExtension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableExtension.kt new file mode 100644 index 00000000000..0d5c562bcff --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableExtension.kt @@ -0,0 +1,18 @@ +var storage = 0 + +var Int.foo: Int + get() { + return this + storage + } + set(value) { + storage = this + value + } + +fun box(): String { + val pr = Int::foo + if (pr.get(42) != 42) return "Fail 1: ${pr[42]}" + pr.set(200, 39) + if (pr.get(-239) != 0) return "Fail 2: ${pr[-239]}" + if (storage != 239) return "Fail 3: $storage" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableMember.kt new file mode 100644 index 00000000000..a187f252008 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableMember.kt @@ -0,0 +1,16 @@ +data class Box(var value: String) + +fun box(): String { + val o = Box("lorem") + val prop = Box::value + + if (prop.get(o) != "lorem") return "Fail 1: ${prop[o]}" + prop.set(o, "ipsum") + if (prop.get(o) != "ipsum") return "Fail 2: ${prop[o]}" + if (o.value != "ipsum") return "Fail 3: ${o.value}" + o.value = "dolor" + if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}" + if ("$o" != "Box(value=dolor)") return "Fail 5: $o" + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableTopLevel.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableTopLevel.kt new file mode 100644 index 00000000000..46abcebe5f9 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableTopLevel.kt @@ -0,0 +1,12 @@ +data class Box(val value: String) + +var pr = Box("first") + +fun box(): String { + val property = ::pr + if (property.get() != Box("first")) return "Fail value: ${property.get()}" + if (property.name != "pr") return "Fail name: ${property.name}" + property.set(Box("second")) + if (property.get().value != "second") return "Fail value 2: ${property.get()}" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleTopLevel.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleTopLevel.kt new file mode 100644 index 00000000000..818327da26f --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleTopLevel.kt @@ -0,0 +1,10 @@ +data class Box(val value: String) + +val foo = Box("lol") + +fun box(): String { + val property = ::foo + if (property.get() != Box("lol")) return "Fail value: ${property.get()}" + if (property.name != "foo") return "Fail name: ${property.name}" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/empty.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/empty.kt new file mode 100644 index 00000000000..4c91756b263 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/empty.kt @@ -0,0 +1,22 @@ +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun box(): String { + val map = HashPMap.empty()!! + + assertEquals(0, map.size()) + + assertFalse(map.containsKey("")) + assertFalse(map.containsKey("abacaba")) + assertEquals(null, map[""]) + assertEquals(null, map["lol"]) + + // Check that doesn't create a new map + assertEquals(map, map.minus("")) + + // Check that all empty()s are equal + val other = HashPMap.empty()!! + assertEquals(map, other) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/manyNumbers.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/manyNumbers.kt new file mode 100644 index 00000000000..408928f3331 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/manyNumbers.kt @@ -0,0 +1,47 @@ +import java.util.* +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun digitSum(number: Int): Int { + var x = number + var ans = 0 + while (x != 0) { + ans += x % 10 + x /= 10 + } + return ans +} + +val N = 1000000 + +fun box(): String { + var map = HashPMap.empty()!! + + for (x in 1..N) { + map = map.plus(x, digitSum(x))!! + } + + assertEquals(N, map.size()) + + // Check in reverse order just in case + for (x in N downTo 1) { + assertTrue(map.containsKey(x), "Not found: $x") + assertEquals(digitSum(x), map[x], "Incorrect value for $x") + } + + // Delete in random order + val list = (1..N).toCollection(ArrayList()) + Collections.shuffle(list, Random(42)) + for (x in list) { + map = map.minus(x)!! + } + + assertEquals(0, map.size()) + + for (x in 1..N) { + assertFalse(map.containsKey(x), "Incorrectly found: $x") + assertEquals(null, map[x], "Incorrectly found value for $x") + } + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithDifferent.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithDifferent.kt new file mode 100644 index 00000000000..7d06e9be51c --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithDifferent.kt @@ -0,0 +1,28 @@ +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun box(): String { + var map = HashPMap.empty()!! + + map = map.plus("lol", 42)!! + map = map.plus("lol", 239)!! + + assertEquals(1, map.size()) + assertTrue(map.containsKey("lol")) + assertFalse(map.containsKey("")) + assertEquals(239, map["lol"]) + assertEquals(null, map[""]) + + map = map.plus("", 0)!! + map = map.plus("", 2.71828)!! + map = map.plus("lol", 42)!! + map = map.plus("", 3.14)!! + + assertEquals(2, map.size()) + assertTrue(map.containsKey("lol")) + assertTrue(map.containsKey("")) + assertEquals(42, map["lol"]) + assertEquals(3.14, map[""]) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithEqual.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithEqual.kt new file mode 100644 index 00000000000..d94f22ff6f3 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithEqual.kt @@ -0,0 +1,28 @@ +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun box(): String { + var map = HashPMap.empty()!! + + map = map.plus("lol", 42)!! + map = map.plus("lol", 42)!! + + assertEquals(1, map.size()) + assertTrue(map.containsKey("lol")) + assertFalse(map.containsKey("")) + assertEquals(42, map["lol"]) + assertEquals(null, map[""]) + + map = map.plus("", 0)!! + map = map.plus("", 0)!! + map = map.plus("lol", 42)!! + map = map.plus("", 0)!! + + assertEquals(2, map.size()) + assertTrue(map.containsKey("lol")) + assertTrue(map.containsKey("")) + assertEquals(42, map["lol"]) + assertEquals(0, map[""]) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusGet.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusGet.kt new file mode 100644 index 00000000000..d9debf6fa77 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusGet.kt @@ -0,0 +1,24 @@ +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun box(): String { + var map = HashPMap.empty()!! + + map = map.plus("lol", 42)!! + + assertEquals(1, map.size()) + assertTrue(map.containsKey("lol")) + assertFalse(map.containsKey("")) + assertEquals(42, map["lol"]) + assertEquals(null, map[""]) + + map = map.plus("", 0)!! + + assertEquals(2, map.size()) + assertTrue(map.containsKey("lol")) + assertTrue(map.containsKey("")) + assertEquals(42, map["lol"]) + assertEquals(0, map[""]) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusMinus.kt b/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusMinus.kt new file mode 100644 index 00000000000..affdcff09ea --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusMinus.kt @@ -0,0 +1,23 @@ +import kotlin.reflect.jvm.internal.pcollections.HashPMap +import kotlin.test.* + +fun box(): String { + var map = HashPMap.empty()!! + + map = map.plus("lol", 42)!! + map = map.minus("lol")!! + + assertEquals(0, map.size()) + assertFalse(map.containsKey("lol")) + assertEquals(null, map["lol"]) + + map = map.plus("abc", "a")!! + map = map.minus("abc")!! + map = map.plus("abc", "d")!! + + assertEquals(1, map.size()) + assertTrue(map.containsKey("abc")) + assertEquals("d", map["abc"]) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/classInLambda.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/classInLambda.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/classInLambda.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/classInLambda.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/objectInLambda.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/objectInLambda.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/objectInLambda.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/objectInLambda.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInConstructor.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInConstructor.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInConstructor.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInConstructor.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInFunction.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInFunction.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInFunction.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInFunction.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLambda.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLambda.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLambda.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLambda.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalClass.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalClass.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalClass.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalFunction.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalFunction.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalFunction.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalFunction.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunction.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunction.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunction.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunction.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInLocalClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInLocalClass.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInLocalClass.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInLocalClass.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInNestedClass.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInNestedClass.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInNestedClass.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInNestedClass.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInObjectExpression.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInObjectExpression.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInObjectExpression.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInObjectExpression.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPackage.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPackage.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPackage.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPackage.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertyGetter.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertyGetter.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertyGetter.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertyGetter.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertySetter.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertySetter.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertySetter.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertySetter.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt b/compiler/testData/codegen/boxWithStdlib/reflection/genericSignature/kt5112.kt similarity index 100% rename from compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt rename to compiler/testData/codegen/boxWithStdlib/reflection/genericSignature/kt5112.kt diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt new file mode 100644 index 00000000000..9d470a193d0 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt @@ -0,0 +1,27 @@ +import kotlin.reflect.jvm.* +import kotlin.test.assertEquals + +class K(var value: Long) + +var K.ext: Double + get() = value.toDouble() + set(value) { + this.value = value.toLong() + } + +fun box(): String { + val p = K::ext + + val getter = p.javaGetter!! + val setter = p.javaSetter!! + + assertEquals(getter, Class.forName("_DefaultPackage").getMethod("getExt", javaClass())) + assertEquals(setter, Class.forName("_DefaultPackage").getMethod("setExt", javaClass(), javaClass())) + + val k = K(42L) + assert(getter.invoke(null, k) == 42.0, "Fail k getter") + setter.invoke(null, k, -239.0) + assert(getter.invoke(null, k) == -239.0, "Fail k setter") + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt new file mode 100644 index 00000000000..e39bb09d767 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt @@ -0,0 +1,23 @@ +import kotlin.reflect.jvm.* +import kotlin.test.assertEquals + +class K(var value: Long) + +fun box(): String { + val p = K::value + + assert(p.javaField != null, "Fail p field") + + val getter = p.javaGetter!! + val setter = p.javaSetter!! + + assertEquals(getter, javaClass().getMethod("getValue")) + assertEquals(setter, javaClass().getMethod("setValue", javaClass())) + + val k = K(42L) + assert(getter.invoke(k) == 42L, "Fail k getter") + setter.invoke(k, -239L) + assert(getter.invoke(k) == -239L, "Fail k setter") + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/package.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/package.kt new file mode 100644 index 00000000000..07d168a5a55 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/package.kt @@ -0,0 +1,13 @@ +package test + +import kotlin.reflect.jvm.* +import kotlin.test.* + +fun box(): String { + val facadeJClass = Class.forName("test.TestPackage") as Class + + assertEquals(facadeJClass, facadeJClass.kotlinPackage.javaFacade) + assertEquals(facadeJClass, facadeJClass.kotlin.java) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt new file mode 100644 index 00000000000..ada90d5c564 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt @@ -0,0 +1,23 @@ +import kotlin.reflect.jvm.* +import kotlin.test.assertEquals + +var topLevel = "123" + +fun box(): String { + val p = ::topLevel + + // TODO: uncomment when fields are loaded from package parts + // assert(p.javaField != null, "Fail p field") + + val getter = p.javaGetter!! + val setter = p.javaSetter!! + + assertEquals(getter, Class.forName("_DefaultPackage").getMethod("getTopLevel")) + assertEquals(setter, Class.forName("_DefaultPackage").getMethod("setTopLevel", javaClass())) + + assert(getter.invoke(null) == "123", "Fail k getter") + setter.invoke(null, "456") + assert(getter.invoke(null) == "456", "Fail k setter") + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/classToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/classToString.kt new file mode 100644 index 00000000000..6692de70e1f --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/classToString.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.reflect.jvm.kotlin + +class A + +fun box(): String { + val p = javaClass().kotlin + if ("$p" != "class A") return "Fail: $p" + + val s = javaClass().kotlin + if ("$s" != "class java.lang.String") return "Fail: $s" + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/defaultPackageToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/defaultPackageToString.kt new file mode 100644 index 00000000000..cc711bc7d8d --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/defaultPackageToString.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.reflect.jvm.kotlinPackage + +fun box(): String { + val p = Class.forName("_DefaultPackage").kotlinPackage + if ("$p" != "package ") return "Fail: $p" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/equalsHashCode.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/equalsHashCode.kt new file mode 100644 index 00000000000..476b185d961 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/equalsHashCode.kt @@ -0,0 +1,29 @@ +import kotlin.test.* + +val top = 42 +var top2 = -23 + +val Int.intExt: Int get() = this +val Char.charExt: Int get() = this.toInt() + +class A(var mem: String) +class B(var mem: String) + + +fun checkEqual(x: Any, y: Any) { + assertEquals(x, y) + assertEquals(x.hashCode(), y.hashCode(), "Elements are equal but their hash codes are not: ${x.hashCode()} != ${y.hashCode()}") +} + +fun box(): String { + checkEqual(::top, ::top) + checkEqual(::top2, ::top2) + checkEqual(Int::intExt, Int::intExt) + checkEqual(A::mem, A::mem) + + assertFalse(::top == ::top2) + assertFalse(Int::intExt == Char::charExt) + assertFalse(A::mem == B::mem) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt new file mode 100644 index 00000000000..2fc67171bc3 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt @@ -0,0 +1,66 @@ +import kotlin.reflect.KExtensionProperty +import kotlin.test.assertEquals + +fun check(expected: String, p: KExtensionProperty<*, *>) { + var s = p.toString() + // Strip "val" or "var" + s = s.substring(4) + // Strip property name, leave only receiver class + s = s.substring(0, s.lastIndexOf('.')) + + assertEquals(expected, s) +} + +val Boolean.x: Any get() = this +val Char.x: Any get() = this +val Byte.x: Any get() = this +val Short.x: Any get() = this +val Int.x: Any get() = this +val Float.x: Any get() = this +val Long.x: Any get() = this +val Double.x: Any get() = this + +val BooleanArray.x: Any get() = this +val CharArray.x: Any get() = this +val ByteArray.x: Any get() = this +val ShortArray.x: Any get() = this +val IntArray.x: Any get() = this +val FloatArray.x: Any get() = this +val LongArray.x: Any get() = this +val DoubleArray.x: Any get() = this + +val Array.a1: Any get() = this +val Array.a2: Any get() = this +val Array>.a3: Any get() = this +val Array.a4: Any get() = this + +val Map.m: Any get() = this + +fun box(): String { + check("kotlin.Boolean", Boolean::x) + check("kotlin.Char", Char::x) + check("kotlin.Byte", Byte::x) + check("kotlin.Short", Short::x) + check("kotlin.Int", Int::x) + check("kotlin.Float", Float::x) + check("kotlin.Long", Long::x) + check("kotlin.Double", Double::x) + + check("kotlin.BooleanArray", BooleanArray::x) + check("kotlin.CharArray", CharArray::x) + check("kotlin.ByteArray", ByteArray::x) + check("kotlin.ShortArray", ShortArray::x) + check("kotlin.IntArray", IntArray::x) + check("kotlin.FloatArray", FloatArray::x) + check("kotlin.LongArray", LongArray::x) + check("kotlin.DoubleArray", DoubleArray::x) + + check("kotlin.Array", Array::a1) + check("kotlin.Array", Array::a2) + check("kotlin.Array>", Array>::a3) + check("kotlin.Array", Array::a4) + + check("java.util.Map", Map::m) + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageForJavaStaticToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageForJavaStaticToString.kt new file mode 100644 index 00000000000..2d015d38f17 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageForJavaStaticToString.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.reflect.jvm.kotlinPackage + +fun box(): String { + val p = javaClass().kotlinPackage + if ("$p" != "package java.lang.String") return "Fail: $p" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageToString.kt new file mode 100644 index 00000000000..0f60b75b211 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageToString.kt @@ -0,0 +1,10 @@ +package test.foo.bar + +import kotlin.test.* +import kotlin.reflect.jvm.kotlinPackage + +fun box(): String { + val p = Class.forName("test.foo.bar.BarPackage").kotlinPackage + if ("$p" != "package test.foo.bar") return "Fail: $p" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/propertyToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/propertyToString.kt new file mode 100644 index 00000000000..2a1e96b7574 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/propertyToString.kt @@ -0,0 +1,26 @@ +package test + +import kotlin.test.assertEquals + +val top = 42 +var top2 = -23 + +val String.ext: Int get() = 0 +var IntRange?.ext2: Int get() = 0; set(value) {} + +class A(val mem: String) +class B(var mem: String) + +fun assertToString(s: String, x: Any) { + assertEquals(s, x.toString()) +} + +fun box(): String { + assertToString("val top", ::top) + assertToString("var top2", ::top2) + assertToString("val java.lang.String.ext", String::ext) + assertToString("var kotlin.IntRange.ext2", IntRange::ext2) + assertToString("val test.A.mem", A::mem) + assertToString("var test.B.mem", B::mem) + return "OK" +} diff --git a/compiler/testData/codegen/bytecodeText/kt2202.kt b/compiler/testData/codegen/bytecodeText/kt2202.kt index 2d62a6e896b..e2bc119b688 100644 --- a/compiler/testData/codegen/bytecodeText/kt2202.kt +++ b/compiler/testData/codegen/bytecodeText/kt2202.kt @@ -18,4 +18,4 @@ class B { } // 0 INVOKEVIRTUAL -// 4 INVOKESPECIAL +// 2 INVOKESPECIAL [AB]\. diff --git a/compiler/testData/codegen/bytecodeText/privateDefaultArgs.kt b/compiler/testData/codegen/bytecodeText/privateDefaultArgs.kt index 699df18dff9..633b067a1be 100644 --- a/compiler/testData/codegen/bytecodeText/privateDefaultArgs.kt +++ b/compiler/testData/codegen/bytecodeText/privateDefaultArgs.kt @@ -13,4 +13,4 @@ fun box(): String { } // 0 INVOKEVIRTUAL -// 3 INVOKESPECIAL +// 2 INVOKESPECIAL B\.foo diff --git a/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt b/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt index efa50fe6ebf..32e6000ec7a 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/KotlinPropertyAsAnnotationParameter.B.kt @@ -3,8 +3,10 @@ import java.lang.annotation.RetentionPolicy import a.* Ann(i, s, f, d, l, b, bool, c, str) +class MyClass1 + Ann(i2, s2, f2, d2, l2, b2, bool2, c2, str2) -class MyClass +class MyClass2 Retention(RetentionPolicy.RUNTIME) annotation class Ann( @@ -20,7 +22,7 @@ annotation class Ann( ) fun main(args: Array) { - MyClass() + // Trigger annotation loading + (MyClass1() as java.lang.Object).getClass().getAnnotations() + (MyClass2() as java.lang.Object).getClass().getAnnotations() } - - diff --git a/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.A.kt b/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.A.kt new file mode 100644 index 00000000000..ea68a0dea53 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.A.kt @@ -0,0 +1,6 @@ +package a + +public var topLevel: Int = 42 + +public val String.extension: Long + get() = length.toLong() diff --git a/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.B.kt b/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.B.kt new file mode 100644 index 00000000000..5a9e82e1b29 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/PropertyReference.B.kt @@ -0,0 +1,14 @@ +import a.* + +fun main(args: Array) { + val f = ::topLevel + val x1 = f.get() + if (x1 != 42) throw AssertionError("Fail x1: $x1") + f.set(239) + val x2 = f.get() + if (x2 != 239) throw AssertionError("Fail x2: $x2") + + val g = String::extension + val y1 = g.get("abcde") + if (y1 != 5L) throw AssertionError("Fail y1: $y1") +} diff --git a/compiler/testData/diagnostics/tests/j+k/kt3311.kt b/compiler/testData/diagnostics/tests/j+k/kt3311.kt new file mode 100644 index 00000000000..7874ea5c2f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt3311.kt @@ -0,0 +1,19 @@ +// FILE: Super.java +public class Super { + public boolean foo; + public boolean bar; + + public void setFoo(boolean foo) { + this.foo = foo; + } +} + +// FILE: b.kt +public class Sub: Super() { +} + +fun main(args: Array) { + val x = Sub() + x.foo = true + x.bar = true +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromClass.kt index 11bb1bd83fc..462064ebe54 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A { fun main() { val x = ::A diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtension.kt index c23a053d56d..fcbf938987f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A class B diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtensionInClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtensionInClass.kt index fa6faa6831e..3b8fe60c2ba 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromExtensionInClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A class B { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromTopLevel.kt index e1df8095685..8ce80f50e2b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/constructorFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A fun main() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageClass.kt index 025c7684eea..52f172c7abf 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageClass.kt @@ -12,6 +12,8 @@ class A { package other +import kotlin.reflect.* + import first.A fun main() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageExtension.kt index 1e7843a21a2..f38f0066a55 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageExtension.kt @@ -12,6 +12,8 @@ fun A.baz() {} package other +import kotlin.reflect.KExtensionFunction0 + import first.A import first.foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageTopLevel.kt index b00730fd8d5..9ae2ffb4b6f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/differentPackageTopLevel.kt @@ -10,6 +10,8 @@ fun baz() = "OK" package other +import kotlin.reflect.* + import first.foo import first.bar import first.baz diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromClass.kt index 1d0677bd72b..28a873e4de2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun main() { val x = ::foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtension.kt index 36ded52ce56..14c0c8d8e07 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun A.main() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtensionInClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtensionInClass.kt index 6140d60cfa3..c3007c9c8d1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromExtensionInClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class B class A { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromTopLevel.kt index ce3c841e007..65b9ae17169 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun A.foo() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionOnNullable.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionOnNullable.kt index f6fb90d4f42..2651906c74d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionOnNullable.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/extensionOnNullable.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun foo() {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/genericClassFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/genericClassFromTopLevel.kt index 3486f124379..2d8d3ebcb59 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/genericClassFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/genericClassFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + class A(val t: T) { fun foo(): T = t } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromClass.kt index 72a822aefa6..d9054508aab 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + class A { inner class Inner diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromExtension.kt index 41425e238cb..c5d6df1fda4 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + class A { inner class Inner } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromTopLevel.kt index 578e4af8c80..e34e9399877 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/innerConstructorFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + class A { inner class Inner } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructor.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructor.kt index 17b77ce4c47..68c1740041f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructor.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + fun main() { class A diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromExtensionInLocalClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromExtensionInLocalClass.kt index 51b7e12ce2c..4ef1b50c476 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromExtensionInLocalClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromExtensionInLocalClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + fun main() { class A diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalClass.kt index 9b9803bf138..0bcab8a24d6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + fun main() { class A diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalExtension.kt index 8265c3f8b34..3f14d265479 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localConstructorFromLocalExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + fun main() { class A diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFun.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFun.kt index 635d0f5dad0..14620b7956e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFun.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFun.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + fun main() { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromExtensionInLocalClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromExtensionInLocalClass.kt index c9667d03acc..bdcd5d1a5ff 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromExtensionInLocalClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromExtensionInLocalClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun main() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalClass.kt index 75887872fee..63bda446c3a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + fun main() { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalExtension.kt index e98cf12bdb7..38f840c4c01 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/localNamedFunFromLocalExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun main() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedName.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedName.kt index 58aec0eb4db..0ab329ba58b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedName.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedName.kt @@ -8,6 +8,8 @@ class D { // FILE: b.kt +import kotlin.reflect.KMemberFunction0 + fun main() { val x = a.b.c.D::foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedNameGeneric.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedNameGeneric.kt index 78b70bd0dbd..2c7a0a4113d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedNameGeneric.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/longQualifiedNameGeneric.kt @@ -8,6 +8,8 @@ class D { // FILE: b.kt +import kotlin.reflect.KMemberFunction2 + fun main() { val x = a.b.c.D::foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromClass.kt index 1cf9d13122f..ff31682084e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtension.kt index 4b49761e193..548a84bf43b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtensionInClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtensionInClass.kt index 8dc01bad473..83705355ae4 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromExtensionInClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromTopLevel.kt index a54d91d3d42..22162d65a52 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/memberFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A { fun foo() {} fun bar(x: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromClass.kt index a51da3e20b5..2cdcc7910eb 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A { class Nested diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromExtension.kt index c874250ee53..007cf137c21 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A { class Nested } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromTopLevel.kt index 9bf36c2d77a..d464aa9de07 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/nestedConstructorFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KFunction0 + class A { class Nested } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsExtension.kt index 273da3b2b73..b3e8a6756af 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + class A { fun foo() = 42 } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsTopLevel.kt index bb33818fe4b..b6f1f6a9d49 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/noAmbiguityMemberVsTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.KMemberFunction0 + fun foo() {} class A { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/renameOnImport.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/renameOnImport.kt index 1dae56d6c7b..d71da504022 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/renameOnImport.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/renameOnImport.kt @@ -12,6 +12,8 @@ fun A.baz(x: String) {} // FILE: b.kt +import kotlin.reflect.* + import other.foo as foofoo import other.A as AA import other.baz as bazbaz diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromClass.kt index 7c3660f0ce3..25908ce1b8b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + fun foo() {} fun bar(x: Int) {} fun baz() = "OK" diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtension.kt index f18c7b46a44..c39d37b241d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtension.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun foo() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtensionInClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtensionInClass.kt index bffbab043f6..7d717d2d4e6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromExtensionInClass.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + class A fun foo() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromTopLevel.kt index fc7d114c8bf..f3d0b9a7bd3 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/function/topLevelFromTopLevel.kt @@ -1,3 +1,5 @@ +import kotlin.reflect.* + fun foo() {} fun bar(x: Int) {} fun baz() = "OK" diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/abstractPropertyViaSubclasses.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/abstractPropertyViaSubclasses.kt new file mode 100644 index 00000000000..55c17425814 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/abstractPropertyViaSubclasses.kt @@ -0,0 +1,34 @@ +import kotlin.reflect.KMemberProperty + +trait Base { + val x: Any +} + +class A : Base { + override val x: String = "" +} + +open class B : Base { + override val x: Number = 1.0 +} + +class C : B() { + override val x: Int = 42 +} + +fun test() { + val base = Base::x + base : KMemberProperty + base.get(A()) : Any + base.get(B()) : Number + base.get(C()) : Int + + val a = A::x + a : KMemberProperty + a.get(A()) : String + a.get(B()) : Number + + val b = B::x + b : KMemberProperty + b.get(C()) : Int +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/accessViaSubclass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/accessViaSubclass.kt new file mode 100644 index 00000000000..8c533fbc044 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/accessViaSubclass.kt @@ -0,0 +1,13 @@ +import kotlin.reflect.KMemberProperty + +open class Base { + val foo: Int = 42 +} + +open class Derived : Base() + +fun test() { + val o = Base::foo + o : KMemberProperty + o.get(Derived()) : Int +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/classFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/classFromClass.kt new file mode 100644 index 00000000000..f4686a586d8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/classFromClass.kt @@ -0,0 +1,10 @@ +import kotlin.reflect.* + +class A(var g: A) { + val f: Int = 0 + + fun test() { + ::f : KMemberProperty + ::g : KMutableMemberProperty + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromClass.kt new file mode 100644 index 00000000000..a15f054d3ff --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromClass.kt @@ -0,0 +1,13 @@ +import kotlin.reflect.* + +class A { + fun test() { + ::foo : KExtensionProperty + ::bar : KMutableExtensionProperty + } +} + +val A.foo: String get() = "" +var A.bar: Int + get() = 42 + set(value) { } diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt new file mode 100644 index 00000000000..3fcedb39072 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt @@ -0,0 +1,27 @@ +import kotlin.reflect.* + +val String.countCharacters: Int + get() = length + +var Int.meaning: Long + get() = 42L + set(value) {} + +fun test() { + val f = String::countCharacters + + f : KTopLevelExtensionProperty + f : KExtensionProperty + f : KMutableExtensionProperty + f.get("abc") : Int + f.set("abc", 0) + + val g = Int::meaning + + g : KTopLevelExtensionProperty + g : KExtensionProperty + g : KMutableTopLevelExtensionProperty + g : KMutableExtensionProperty + g.get(0) : Long + g.set(1, 0L) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionPropertyOnNullable.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionPropertyOnNullable.kt new file mode 100644 index 00000000000..10c3c1de770 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionPropertyOnNullable.kt @@ -0,0 +1,8 @@ +val Any?.meaning: Int + get() = 42 + +fun test() { + val f = Any?::meaning + f.get(null) : Int + f.get("") : Int +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/genericClass.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/genericClass.kt new file mode 100644 index 00000000000..9b1ff0d1b05 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/genericClass.kt @@ -0,0 +1,14 @@ +import kotlin.reflect.KMemberProperty + +class A(val t: T) { + val foo: T = t +} + +fun bar() { + val x = A::foo + x : KMemberProperty, String> + x : KMemberProperty, Any?> + + val y = A<*>::foo + y : KMemberProperty, Any?> +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaInstanceField.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaInstanceField.kt new file mode 100644 index 00000000000..18ec86372b4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaInstanceField.kt @@ -0,0 +1,25 @@ +// FILE: JavaClass.java + +public class JavaClass { + public final int publicFinal; + public long publicMutable; + + protected final double protectedFinal; + protected char protectedMutable; + + private final String privateFinal; + private Object privateMutable; +} + +// FILE: test.kt + +import kotlin.reflect.* + +fun test() { + JavaClass::publicFinal : KMemberProperty + JavaClass::publicMutable : KMutableMemberProperty + JavaClass::protectedFinal : KMemberProperty + JavaClass::protectedMutable : KMutableMemberProperty + JavaClass::privateFinal : KMemberProperty + JavaClass::privateMutable : KMutableMemberProperty +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaStaticFieldViaImport.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaStaticFieldViaImport.kt new file mode 100644 index 00000000000..51bb4a55793 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaStaticFieldViaImport.kt @@ -0,0 +1,27 @@ +// FILE: JavaClass.java + +public class JavaClass { + public static final String publicFinal; + public static volatile Object publicMutable; + + protected static final double protectedFinal; + protected static char protectedMutable; + + private static final JavaClass privateFinal; + private static Throwable privateMutable; +} + +// FILE: test.kt + +import JavaClass.* + +import kotlin.reflect.* + +fun test() { + ::publicFinal : KTopLevelProperty + ::publicMutable : KMutableTopLevelProperty + ::protectedFinal : KProperty + ::protectedMutable : KMutableProperty + ::privateFinal : KProperty + ::privateMutable : KMutableProperty +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/localVariable.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/localVariable.kt new file mode 100644 index 00000000000..5550b022d63 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/localVariable.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun test(param: String) { + val a = ::param + + val local = "local" + val b = ::local + + val lambda = { -> } + val g = ::lambda +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromExtension.kt new file mode 100644 index 00000000000..624022a2b87 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromExtension.kt @@ -0,0 +1,21 @@ +import kotlin.reflect.* + +class A { + val foo: Unit = Unit.VALUE + var bar: String = "" + var self: A + get() = this + set(value) { } +} + +fun A.test() { + val x = ::foo + val y = ::bar + val z = ::self + + x : KMemberProperty + y : KMutableMemberProperty + z : KMutableMemberProperty + + y.set(z.get(A()), x.get(A()).toString()) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromTopLevel.kt new file mode 100644 index 00000000000..a95d1dbfc39 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromTopLevel.kt @@ -0,0 +1,23 @@ +import kotlin.reflect.* + +class A { + val foo: Int = 42 + var bar: String = "" +} + +fun test() { + val p = A::foo + + p : KMemberProperty + p : KMutableMemberProperty + p.get(A()) : Int + p.get() + p.set(A(), 239) + + val q = A::bar + + q : KMemberProperty + q : KMutableMemberProperty + q.get(A()): String + q.set(A(), "q") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt new file mode 100644 index 00000000000..8069c3ae562 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt @@ -0,0 +1,33 @@ +import kotlin.reflect.* + +var x: Int = 42 +val y: String get() = "y" + +fun testX() { + val xx = ::x + xx : KMutableTopLevelProperty + xx : KMutableTopLevelVariable + xx : KTopLevelProperty + xx : KTopLevelVariable + xx : KMutableProperty + xx : KMutableVariable + xx : KProperty + xx : KCallable + + xx.name : String + xx.get() : Int + xx.set(239) +} + +fun testY() { + val yy = ::y + yy : KMutableTopLevelProperty + yy : KTopLevelVariable + yy : KMutableProperty + yy : KProperty + yy : KCallable + + yy.name : String + yy.get() : String + yy.set("yy") +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 6495690ade4..a119e222184 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5012,6 +5012,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/j+k/kt3307.kt"); } + @TestMetadata("kt3311.kt") + public void testKt3311() throws Exception { + doTest("compiler/testData/diagnostics/tests/j+k/kt3311.kt"); + } + @TestMetadata("mutableIterator.kt") public void testMutableIterator() throws Exception { doTest("compiler/testData/diagnostics/tests/j+k/mutableIterator.kt"); diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestWithStdLibGenerated.java index ed8963048ac..7bc1d1161ba 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestWithStdLibGenerated.java @@ -105,7 +105,7 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/callableReference") - @InnerTestClasses({CallableReference.Function.class}) + @InnerTestClasses({CallableReference.Function.class, CallableReference.Property.class}) public static class CallableReference extends AbstractJetDiagnosticsTestWithStdLib { public void testAllFilesPresentInCallableReference() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/testsWithStdLib/callableReference"), Pattern.compile("^(.+)\\.kt$"), true); @@ -359,10 +359,84 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/callableReference/property") + public static class Property extends AbstractJetDiagnosticsTestWithStdLib { + @TestMetadata("abstractPropertyViaSubclasses.kt") + public void testAbstractPropertyViaSubclasses() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/abstractPropertyViaSubclasses.kt"); + } + + @TestMetadata("accessViaSubclass.kt") + public void testAccessViaSubclass() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/accessViaSubclass.kt"); + } + + public void testAllFilesPresentInProperty() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/testsWithStdLib/callableReference/property"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("classFromClass.kt") + public void testClassFromClass() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/classFromClass.kt"); + } + + @TestMetadata("extensionFromClass.kt") + public void testExtensionFromClass() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromClass.kt"); + } + + @TestMetadata("extensionFromTopLevel.kt") + public void testExtensionFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt"); + } + + @TestMetadata("extensionPropertyOnNullable.kt") + public void testExtensionPropertyOnNullable() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionPropertyOnNullable.kt"); + } + + @TestMetadata("genericClass.kt") + public void testGenericClass() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/genericClass.kt"); + } + + @TestMetadata("javaInstanceField.kt") + public void testJavaInstanceField() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaInstanceField.kt"); + } + + @TestMetadata("javaStaticFieldViaImport.kt") + public void testJavaStaticFieldViaImport() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/javaStaticFieldViaImport.kt"); + } + + @TestMetadata("localVariable.kt") + public void testLocalVariable() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/localVariable.kt"); + } + + @TestMetadata("memberFromExtension.kt") + public void testMemberFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromExtension.kt"); + } + + @TestMetadata("memberFromTopLevel.kt") + public void testMemberFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/memberFromTopLevel.kt"); + } + + @TestMetadata("topLevelFromTopLevel.kt") + public void testTopLevelFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt"); + } + + } + public static Test innerSuite() { TestSuite suite = new TestSuite("CallableReference"); suite.addTestSuite(CallableReference.class); suite.addTestSuite(Function.class); + suite.addTestSuite(Property.class); return suite; } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index a03cf5e89e4..242c52c6794 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -40,11 +40,7 @@ public class PropertyGenTest extends CodegenTestCase { public void testPrivateVal() throws Exception { loadFile(); - Class aClass = generateClass("PrivateVal"); - Field[] fields = aClass.getDeclaredFields(); - assertEquals(1, fields.length); // prop - Field field = fields[0]; - assertEquals("prop", field.getName()); + generateClass("PrivateVal").getDeclaredField("prop"); } public void testPrivateVar() throws Exception { diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/AbstractBlackBoxCodegenTest.java b/compiler/tests/org/jetbrains/jet/codegen/generated/AbstractBlackBoxCodegenTest.java index 637e5a27c34..bc086effe2a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/AbstractBlackBoxCodegenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/AbstractBlackBoxCodegenTest.java @@ -97,7 +97,8 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase { File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java")); myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests( - ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory)); + ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory + )); loadFile(ktFile); blackBox(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java index ba89e324887..ae1fa6b0a62 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxAgainstJava") -@InnerTestClasses({BlackBoxAgainstJavaCodegenTestGenerated.Annotations.class, BlackBoxAgainstJavaCodegenTestGenerated.CallableReference.class, BlackBoxAgainstJavaCodegenTestGenerated.Constructor.class, BlackBoxAgainstJavaCodegenTestGenerated.Delegation.class, BlackBoxAgainstJavaCodegenTestGenerated.Enum.class, BlackBoxAgainstJavaCodegenTestGenerated.Functions.class, BlackBoxAgainstJavaCodegenTestGenerated.InnerClass.class, BlackBoxAgainstJavaCodegenTestGenerated.Property.class, BlackBoxAgainstJavaCodegenTestGenerated.Sam.class, BlackBoxAgainstJavaCodegenTestGenerated.StaticFun.class, BlackBoxAgainstJavaCodegenTestGenerated.Visibility.class}) +@InnerTestClasses({BlackBoxAgainstJavaCodegenTestGenerated.Annotations.class, BlackBoxAgainstJavaCodegenTestGenerated.CallableReference.class, BlackBoxAgainstJavaCodegenTestGenerated.Constructor.class, BlackBoxAgainstJavaCodegenTestGenerated.Delegation.class, BlackBoxAgainstJavaCodegenTestGenerated.Enum.class, BlackBoxAgainstJavaCodegenTestGenerated.Functions.class, BlackBoxAgainstJavaCodegenTestGenerated.InnerClass.class, BlackBoxAgainstJavaCodegenTestGenerated.Property.class, BlackBoxAgainstJavaCodegenTestGenerated.Reflection.class, BlackBoxAgainstJavaCodegenTestGenerated.Sam.class, BlackBoxAgainstJavaCodegenTestGenerated.StaticFun.class, BlackBoxAgainstJavaCodegenTestGenerated.Visibility.class}) public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBoxAgainstJava() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxAgainstJava"), Pattern.compile("^(.+)\\.kt$"), true); @@ -86,6 +86,16 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/constructor.kt"); } + @TestMetadata("publicFinalField.kt") + public void testPublicFinalField() throws Exception { + doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt"); + } + + @TestMetadata("publicMutableField.kt") + public void testPublicMutableField() throws Exception { + doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.kt"); + } + } @TestMetadata("compiler/testData/codegen/boxAgainstJava/constructor") @@ -226,6 +236,39 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/reflection") + @InnerTestClasses({Reflection.Mapping.class}) + public static class Reflection extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInReflection() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxAgainstJava/reflection"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/testData/codegen/boxAgainstJava/reflection/mapping") + public static class Mapping extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInMapping() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxAgainstJava/reflection/mapping"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("jClass2kClass.kt") + public void testJClass2kClass() throws Exception { + doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/reflection/mapping/jClass2kClass.kt"); + } + + @TestMetadata("javaFields.kt") + public void testJavaFields() throws Exception { + doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Reflection"); + suite.addTestSuite(Reflection.class); + suite.addTestSuite(Mapping.class); + return suite; + } + } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/sam") @InnerTestClasses({Sam.Adapters.class}) public static class Sam extends AbstractBlackBoxCodegenTest { @@ -599,6 +642,7 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod suite.addTestSuite(Functions.class); suite.addTestSuite(InnerClass.class); suite.addTestSuite(Property.class); + suite.addTest(Reflection.innerSuite()); suite.addTest(Sam.innerSuite()); suite.addTestSuite(StaticFun.class); suite.addTest(Visibility.innerSuite()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 612db880d58..525144c9800 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -36,4 +36,9 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithJava"), Pattern.compile("^([^\\.]+)$"), false); } + @TestMetadata("referenceToJavaFieldOfKotlinSubclass") + public void testReferenceToJavaFieldOfKotlinSubclass() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/referenceToJavaFieldOfKotlinSubclass/"); + } + } diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 840c767b4fd..411dd47a771 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxWithStdlib") -@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.Evaluate.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformNames.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Reflection.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class, BlackBoxWithStdlibCodegenTestGenerated.ToArray.class, BlackBoxWithStdlibCodegenTestGenerated.Vararg.class, BlackBoxWithStdlibCodegenTestGenerated.When.class}) +@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.Evaluate.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.HashPMap.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformNames.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Reflection.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class, BlackBoxWithStdlibCodegenTestGenerated.ToArray.class, BlackBoxWithStdlibCodegenTestGenerated.Vararg.class, BlackBoxWithStdlibCodegenTestGenerated.When.class}) public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBoxWithStdlib() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib"), Pattern.compile("^(.+)\\.kt$"), true); @@ -99,7 +99,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } @TestMetadata("compiler/testData/codegen/boxWithStdlib/callableReference") - @InnerTestClasses({CallableReference.Function.class}) + @InnerTestClasses({CallableReference.Function.class, CallableReference.Property.class}) public static class CallableReference extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInCallableReference() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/callableReference"), Pattern.compile("^(.+)\\.kt$"), true); @@ -418,10 +418,104 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property") + public static class Property extends AbstractBlackBoxCodegenTest { + @TestMetadata("accessViaSubclass.kt") + public void testAccessViaSubclass() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/accessViaSubclass.kt"); + } + + public void testAllFilesPresentInProperty() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/callableReference/property"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("delegated.kt") + public void testDelegated() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt"); + } + + @TestMetadata("delegatedMutable.kt") + public void testDelegatedMutable() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/delegatedMutable.kt"); + } + + @TestMetadata("javaBeanConvention.kt") + public void testJavaBeanConvention() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt"); + } + + @TestMetadata("kClassInstanceIsInitializedFirst.kt") + public void testKClassInstanceIsInitializedFirst() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt"); + } + + @TestMetadata("localClassVar.kt") + public void testLocalClassVar() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt"); + } + + @TestMetadata("overriddenInSubclass.kt") + public void testOverriddenInSubclass() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt"); + } + + @TestMetadata("privateClassVal.kt") + public void testPrivateClassVal() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt"); + } + + @TestMetadata("privateClassVar.kt") + public void testPrivateClassVar() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt"); + } + + @TestMetadata("protectedClassVar.kt") + public void testProtectedClassVar() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/protectedClassVar.kt"); + } + + @TestMetadata("publicClassValAccessible.kt") + public void testPublicClassValAccessible() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/publicClassValAccessible.kt"); + } + + @TestMetadata("simpleExtension.kt") + public void testSimpleExtension() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleExtension.kt"); + } + + @TestMetadata("simpleMember.kt") + public void testSimpleMember() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMember.kt"); + } + + @TestMetadata("simpleMutableExtension.kt") + public void testSimpleMutableExtension() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableExtension.kt"); + } + + @TestMetadata("simpleMutableMember.kt") + public void testSimpleMutableMember() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableMember.kt"); + } + + @TestMetadata("simpleMutableTopLevel.kt") + public void testSimpleMutableTopLevel() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleMutableTopLevel.kt"); + } + + @TestMetadata("simpleTopLevel.kt") + public void testSimpleTopLevel() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/simpleTopLevel.kt"); + } + + } + public static Test innerSuite() { TestSuite suite = new TestSuite("CallableReference"); suite.addTestSuite(CallableReference.class); suite.addTest(Function.innerSuite()); + suite.addTestSuite(Property.class); return suite; } } @@ -860,6 +954,44 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/hashPMap") + public static class HashPMap extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInHashPMap() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/hashPMap"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("empty.kt") + public void testEmpty() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/empty.kt"); + } + + @TestMetadata("manyNumbers.kt") + public void testManyNumbers() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/manyNumbers.kt"); + } + + @TestMetadata("rewriteWithDifferent.kt") + public void testRewriteWithDifferent() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithDifferent.kt"); + } + + @TestMetadata("rewriteWithEqual.kt") + public void testRewriteWithEqual() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithEqual.kt"); + } + + @TestMetadata("simplePlusGet.kt") + public void testSimplePlusGet() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusGet.kt"); + } + + @TestMetadata("simplePlusMinus.kt") + public void testSimplePlusMinus() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusMinus.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/jdkAnnotations") public static class JdkAnnotations extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInJdkAnnotations() throws Exception { @@ -1249,99 +1381,194 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection") - @InnerTestClasses({Reflection.InsideLambda.class, Reflection.Lambda.class}) + @InnerTestClasses({Reflection.Enclosing.class, Reflection.GenericSignature.class, Reflection.Mapping.class, Reflection.MethodsFromAny.class}) public static class Reflection extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInReflection() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection"), Pattern.compile("^(.+)\\.kt$"), true); } - @TestMetadata("kt5112.kt") - public void testKt5112() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt"); + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing") + @InnerTestClasses({Enclosing.InsideLambda.class, Enclosing.Lambda.class}) + public static class Enclosing extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInEnclosing() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/enclosing"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda") + public static class InsideLambda extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInInsideLambda() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("classInLambda.kt") + public void testClassInLambda() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/classInLambda.kt"); + } + + @TestMetadata("objectInLambda.kt") + public void testObjectInLambda() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/insideLambda/objectInLambda.kt"); + } + + } + + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda") + public static class Lambda extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInLambda() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("lambdaInConstructor.kt") + public void testLambdaInConstructor() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInConstructor.kt"); + } + + @TestMetadata("lambdaInFunction.kt") + public void testLambdaInFunction() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInFunction.kt"); + } + + @TestMetadata("lambdaInLambda.kt") + public void testLambdaInLambda() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLambda.kt"); + } + + @TestMetadata("lambdaInLocalClass.kt") + public void testLambdaInLocalClass() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalClass.kt"); + } + + @TestMetadata("lambdaInLocalFunction.kt") + public void testLambdaInLocalFunction() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInLocalFunction.kt"); + } + + @TestMetadata("lambdaInMemberFunction.kt") + public void testLambdaInMemberFunction() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunction.kt"); + } + + @TestMetadata("lambdaInMemberFunctionInLocalClass.kt") + public void testLambdaInMemberFunctionInLocalClass() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInLocalClass.kt"); + } + + @TestMetadata("lambdaInMemberFunctionInNestedClass.kt") + public void testLambdaInMemberFunctionInNestedClass() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInMemberFunctionInNestedClass.kt"); + } + + @TestMetadata("lambdaInObjectExpression.kt") + public void testLambdaInObjectExpression() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInObjectExpression.kt"); + } + + @TestMetadata("lambdaInPackage.kt") + public void testLambdaInPackage() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPackage.kt"); + } + + @TestMetadata("lambdaInPropertyGetter.kt") + public void testLambdaInPropertyGetter() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertyGetter.kt"); + } + + @TestMetadata("lambdaInPropertySetter.kt") + public void testLambdaInPropertySetter() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/lambda/lambdaInPropertySetter.kt"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Enclosing"); + suite.addTestSuite(Enclosing.class); + suite.addTestSuite(InsideLambda.class); + suite.addTestSuite(Lambda.class); + return suite; + } } - @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/insideLambda") - public static class InsideLambda extends AbstractBlackBoxCodegenTest { - public void testAllFilesPresentInInsideLambda() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/insideLambda"), Pattern.compile("^(.+)\\.kt$"), true); + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/genericSignature") + public static class GenericSignature extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInGenericSignature() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/genericSignature"), Pattern.compile("^(.+)\\.kt$"), true); } - @TestMetadata("classInLambda.kt") - public void testClassInLambda() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/classInLambda.kt"); - } - - @TestMetadata("objectInLambda.kt") - public void testObjectInLambda() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/insideLambda/objectInLambda.kt"); + @TestMetadata("kt5112.kt") + public void testKt5112() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/genericSignature/kt5112.kt"); } } - @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/lambda") - public static class Lambda extends AbstractBlackBoxCodegenTest { - public void testAllFilesPresentInLambda() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/lambda"), Pattern.compile("^(.+)\\.kt$"), true); + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/mapping") + public static class Mapping extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInMapping() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/mapping"), Pattern.compile("^(.+)\\.kt$"), true); } - @TestMetadata("lambdaInConstructor.kt") - public void testLambdaInConstructor() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInConstructor.kt"); + @TestMetadata("extensionProperty.kt") + public void testExtensionProperty() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt"); } - @TestMetadata("lambdaInFunction.kt") - public void testLambdaInFunction() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInFunction.kt"); + @TestMetadata("memberProperty.kt") + public void testMemberProperty() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt"); } - @TestMetadata("lambdaInLambda.kt") - public void testLambdaInLambda() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLambda.kt"); + @TestMetadata("package.kt") + public void testPackage() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/mapping/package.kt"); } - @TestMetadata("lambdaInLocalClass.kt") - public void testLambdaInLocalClass() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalClass.kt"); + @TestMetadata("topLevelProperty.kt") + public void testTopLevelProperty() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt"); } - @TestMetadata("lambdaInLocalFunction.kt") - public void testLambdaInLocalFunction() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInLocalFunction.kt"); + } + + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny") + public static class MethodsFromAny extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInMethodsFromAny() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), true); } - @TestMetadata("lambdaInMemberFunction.kt") - public void testLambdaInMemberFunction() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunction.kt"); + @TestMetadata("classToString.kt") + public void testClassToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/classToString.kt"); } - @TestMetadata("lambdaInMemberFunctionInLocalClass.kt") - public void testLambdaInMemberFunctionInLocalClass() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInLocalClass.kt"); + @TestMetadata("defaultPackageToString.kt") + public void testDefaultPackageToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/defaultPackageToString.kt"); } - @TestMetadata("lambdaInMemberFunctionInNestedClass.kt") - public void testLambdaInMemberFunctionInNestedClass() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInMemberFunctionInNestedClass.kt"); + @TestMetadata("equalsHashCode.kt") + public void testEqualsHashCode() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/equalsHashCode.kt"); } - @TestMetadata("lambdaInObjectExpression.kt") - public void testLambdaInObjectExpression() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInObjectExpression.kt"); + @TestMetadata("extensionPropertyReceiverToString.kt") + public void testExtensionPropertyReceiverToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt"); } - @TestMetadata("lambdaInPackage.kt") - public void testLambdaInPackage() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPackage.kt"); + @TestMetadata("packageForJavaStaticToString.kt") + public void testPackageForJavaStaticToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageForJavaStaticToString.kt"); } - @TestMetadata("lambdaInPropertyGetter.kt") - public void testLambdaInPropertyGetter() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertyGetter.kt"); + @TestMetadata("packageToString.kt") + public void testPackageToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/packageToString.kt"); } - @TestMetadata("lambdaInPropertySetter.kt") - public void testLambdaInPropertySetter() throws Exception { - doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/lambda/lambdaInPropertySetter.kt"); + @TestMetadata("propertyToString.kt") + public void testPropertyToString() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/propertyToString.kt"); } } @@ -1349,8 +1576,10 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode public static Test innerSuite() { TestSuite suite = new TestSuite("Reflection"); suite.addTestSuite(Reflection.class); - suite.addTestSuite(InsideLambda.class); - suite.addTestSuite(Lambda.class); + suite.addTest(Enclosing.innerSuite()); + suite.addTestSuite(GenericSignature.class); + suite.addTestSuite(Mapping.class); + suite.addTestSuite(MethodsFromAny.class); return suite; } } @@ -1610,6 +1839,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode suite.addTest(DataClasses.innerSuite()); suite.addTestSuite(Evaluate.class); suite.addTestSuite(FullJdk.class); + suite.addTestSuite(HashPMap.class); suite.addTestSuite(JdkAnnotations.class); suite.addTestSuite(PlatformNames.class); suite.addTest(Ranges.innerSuite()); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstKotlinTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstKotlinTest.java index 899551591e1..e5b95bc318d 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstKotlinTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstKotlinTest.java @@ -28,6 +28,7 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.codegen.ClassFileFactory; import org.jetbrains.jet.codegen.GenerationUtils; import org.jetbrains.jet.codegen.InlineTestUtil; +import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; @@ -108,7 +109,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit private void invokeMain() throws Exception { URLClassLoader classLoader = new URLClassLoader( - new URL[]{ aDir.toURI().toURL(), bDir.toURI().toURL() }, + new URL[]{ aDir.toURI().toURL(), bDir.toURI().toURL(), ForTestCompileRuntime.runtimeJarForTests().toURI().toURL() }, AbstractCompileKotlinAgainstKotlinTest.class.getClassLoader() ); Class clazz = classLoader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT)); @@ -118,7 +119,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit private void invokeBox() throws Exception { URLClassLoader classLoader = new URLClassLoader( - new URL[]{ bDir.toURI().toURL(), aDir.toURI().toURL() }, + new URL[]{ bDir.toURI().toURL(), aDir.toURI().toURL(), ForTestCompileRuntime.runtimeJarForTests().toURI().toURL() }, AbstractCompileKotlinAgainstKotlinTest.class.getClassLoader() ); Class clazz = classLoader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT)); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java index fcece966531..aa7a31d4f0c 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java @@ -106,6 +106,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl doTest("compiler/testData/compileKotlinAgainstKotlin/PlatformNames.A.kt"); } + @TestMetadata("PropertyReference.A.kt") + public void testPropertyReference() throws Exception { + doTest("compiler/testData/compileKotlinAgainstKotlin/PropertyReference.A.kt"); + } + @TestMetadata("Simple.A.kt") public void testSimple() throws Exception { doTest("compiler/testData/compileKotlinAgainstKotlin/Simple.A.kt"); diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetCodeConformanceTest.java b/compiler/tests/org/jetbrains/jet/parsing/JetCodeConformanceTest.java index 7c092def797..534f6719e38 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetCodeConformanceTest.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetCodeConformanceTest.java @@ -36,6 +36,8 @@ public class JetCodeConformanceTest extends TestCase { private static final Pattern SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)"); private static final List EXCLUDED_FILES_AND_DIRS = Arrays.asList( new File("android.tests.dependencies"), + new File("core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections"), + new File("libraries/tools/runtime/target/copied-sources"), new File("dependencies"), new File("examples"), new File("js/js.translator/qunit/qunit.js"), diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java index 49e8d8f3874..4cb17862e6c 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java @@ -45,6 +45,8 @@ public final class JvmAbi { public static final String CLASS_OBJECT_FIELD = "object$"; public static final FqName K_OBJECT = new FqName("kotlin.jvm.internal.KObject"); + public static final String KOTLIN_CLASS_FIELD_NAME = "$kotlinClass"; + public static final String KOTLIN_PACKAGE_FIELD_NAME = "$kotlinPackage"; public static boolean isClassObjectFqName(@NotNull FqName fqName) { return fqName.lastSegmentIs(Name.identifier(CLASS_OBJECT_CLASS_NAME)); diff --git a/core/reflection/src/kotlin/reflect/KCallable.kt b/core/reflection/src/kotlin/reflect/KCallable.kt new file mode 100644 index 00000000000..7c2cea54c38 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KCallable.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KCallable { + public val name: String +} diff --git a/core/reflection/src/kotlin/reflect/KClass.kt b/core/reflection/src/kotlin/reflect/KClass.kt new file mode 100644 index 00000000000..300a7415841 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KClass.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KClass diff --git a/core/reflection/src/kotlin/reflect/KExtensionProperty.kt b/core/reflection/src/kotlin/reflect/KExtensionProperty.kt new file mode 100644 index 00000000000..a2791873ccb --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KExtensionProperty.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KExtensionProperty : KProperty { + public fun get(receiver: T): R +} + +public trait KMutableExtensionProperty : KExtensionProperty, KMutableProperty { + public fun set(receiver: T, value: R) +} diff --git a/core/reflection/src/kotlin/reflect/KMemberProperty.kt b/core/reflection/src/kotlin/reflect/KMemberProperty.kt new file mode 100644 index 00000000000..2c7f46d2e05 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KMemberProperty.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KMemberProperty : KProperty { + public fun get(receiver: T): R +} + +public trait KMutableMemberProperty : KMemberProperty, KMutableProperty { + public fun set(receiver: T, value: R) +} diff --git a/core/reflection/src/kotlin/reflect/KPackage.kt b/core/reflection/src/kotlin/reflect/KPackage.kt new file mode 100644 index 00000000000..cb176d1543c --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KPackage.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KPackage diff --git a/core/reflection/src/kotlin/reflect/KProperty.kt b/core/reflection/src/kotlin/reflect/KProperty.kt new file mode 100644 index 00000000000..8253bb0669b --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KProperty.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KProperty : KCallable + +public trait KMutableProperty : KProperty diff --git a/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt b/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt new file mode 100644 index 00000000000..9771d4ffbbd --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KTopLevelExtensionProperty : KExtensionProperty, KTopLevelProperty + +public trait KMutableTopLevelExtensionProperty : KTopLevelExtensionProperty, KMutableExtensionProperty, KMutableTopLevelProperty diff --git a/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt b/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt new file mode 100644 index 00000000000..2a10126ba66 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KTopLevelProperty : KProperty + +public trait KMutableTopLevelProperty : KTopLevelProperty, KMutableProperty diff --git a/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt b/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt new file mode 100644 index 00000000000..c7239c73b07 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KTopLevelVariable : KVariable, KTopLevelProperty + +public trait KMutableTopLevelVariable : KTopLevelVariable, KMutableVariable, KMutableTopLevelProperty diff --git a/core/reflection/src/kotlin/reflect/KVariable.kt b/core/reflection/src/kotlin/reflect/KVariable.kt new file mode 100644 index 00000000000..4c8fcbb4851 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KVariable.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2014 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.reflect + +public trait KVariable : KProperty { + public fun get(): R +} + +public trait KMutableVariable : KVariable, KMutableProperty { + public fun set(value: R) +} diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt new file mode 100644 index 00000000000..8fd8b0176d4 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2014 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.jvm.internal + +import java.lang.annotation.* + +Retention(RetentionPolicy.RUNTIME) +public annotation class Intrinsic(val value: String) diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java index 585ceea8ef2..efaee67176e 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java @@ -49,7 +49,7 @@ public class Intrinsics { public static void checkFieldIsNotNull(Object value, String className, String fieldName) { if (value == null) { IllegalStateException exception = - new IllegalStateException("Field specified as non-null contains null: " + className + "." + fieldName); + new IllegalStateException("Field specified as non-null is null: " + className + "." + fieldName); throw sanitizeStackTrace(exception); } } @@ -64,7 +64,7 @@ public class Intrinsics { String methodName = caller.getMethodName(); IllegalArgumentException exception = - new IllegalArgumentException("Parameter specified as non-null contains null: " + + new IllegalArgumentException("Parameter specified as non-null is null: " + "method " + className + "." + methodName + ", parameter " + paramName); throw sanitizeStackTrace(exception); diff --git a/core/runtime.jvm/src/kotlin/reflect/exceptions.kt b/core/runtime.jvm/src/kotlin/reflect/exceptions.kt new file mode 100644 index 00000000000..141196da129 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/exceptions.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2014 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.reflect + +suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +public class IllegalAccessException(cause: java.lang.IllegalAccessException) : Exception() { + { + (this as java.lang.Throwable).initCause(cause) + } +} + +suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +public class NoSuchPropertyException(cause: Exception) : Exception() { + { + (this as java.lang.Throwable).initCause(cause) + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt new file mode 100644 index 00000000000..99ccfa51476 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import kotlin.reflect.KCallable + +trait KCallableImpl : KCallable diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt new file mode 100644 index 00000000000..9e8dee8842e --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import kotlin.reflect.* +import kotlin.jvm.internal.KotlinClass +import kotlin.jvm.internal.KotlinSyntheticClass + +enum class KClassOrigin { + BUILT_IN + KOTLIN + FOREIGN +} + +private val KOTLIN_CLASS_ANNOTATION_CLASS = javaClass() +private val KOTLIN_SYNTHETIC_CLASS_ANNOTATION_CLASS = javaClass() + +class KClassImpl(val jClass: Class, isKnownToBeKotlin: Boolean) : KClass { + // TODO: write metadata to local classes + private val origin: KClassOrigin = + if (isKnownToBeKotlin || + jClass.isAnnotationPresent(KOTLIN_CLASS_ANNOTATION_CLASS) || + jClass.isAnnotationPresent(KOTLIN_SYNTHETIC_CLASS_ANNOTATION_CLASS) + ) { + KClassOrigin.KOTLIN + } + else { + KClassOrigin.FOREIGN + // TODO: built-in classes + } + + fun memberProperty(name: String): KMemberProperty = + if (origin identityEquals KClassOrigin.KOTLIN) { + KMemberPropertyImpl(name, this) + } + else { + KForeignMemberProperty(name, this) + } + + fun mutableMemberProperty(name: String): KMutableMemberProperty = + if (origin identityEquals KClassOrigin.KOTLIN) { + KMutableMemberPropertyImpl(name, this) + } + else { + KMutableForeignMemberProperty(name, this) + } + + override fun equals(other: Any?): Boolean = + other is KClassImpl<*> && jClass == other.jClass + + override fun hashCode(): Int = + jClass.hashCode() + + override fun toString(): String = + jClass.toString() +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KForeignMemberProperty.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KForeignMemberProperty.kt new file mode 100644 index 00000000000..50b0541b1d8 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KForeignMemberProperty.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.* +import kotlin.reflect.* + +open class KForeignMemberProperty( + public override val name: String, + protected val owner: KClassImpl +) : KMemberProperty, KPropertyImpl { + override val field: Field = try { + owner.jClass.getField(name) + } + catch (e: NoSuchFieldException) { + throw NoSuchPropertyException(e) + } + + override val getter: Method? get() = null + + override fun get(receiver: T): R { + try { + return field.get(receiver) as R + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun equals(other: Any?): Boolean = + other is KForeignMemberProperty<*, *> && name == other.name && owner == other.owner + + override fun hashCode(): Int = + name.hashCode() * 31 + owner.hashCode() + + // TODO: include visibility, return type + override fun toString(): String = + "val ${owner.jClass.getName()}.$name" +} + +class KMutableForeignMemberProperty( + name: String, + owner: KClassImpl +) : KMutableMemberProperty, KMutablePropertyImpl, KForeignMemberProperty(name, owner) { + override val setter: Method? get() = null + + override fun set(receiver: T, value: R) { + try { + field.set(receiver, value) + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun toString(): String = + "var ${owner.jClass.getName()}.$name" +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt new file mode 100644 index 00000000000..bd19fe400b2 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.* +import kotlin.reflect.* + +// TODO: properties of built-in classes + +open class KMemberPropertyImpl( + public override val name: String, + protected val owner: KClassImpl +) : KMemberProperty, KPropertyImpl { + override val field: Field? + get() = try { + owner.jClass.getDeclaredField(name) + } + catch (e: NoSuchFieldException) { + null + } + + // TODO: extract, make lazy (weak?), use our descriptors knowledge + override val getter: Method = try { + owner.jClass.getMaybeDeclaredMethod(getterName(name)) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun get(receiver: T): R { + try { + return getter(receiver) as R + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun equals(other: Any?): Boolean = + other is KMemberPropertyImpl<*, *> && name == other.name && owner == other.owner + + override fun hashCode(): Int = + name.hashCode() * 31 + owner.hashCode() + + // TODO: include visibility, return type + override fun toString(): String = + "val ${owner.jClass.getName()}.$name" +} + +class KMutableMemberPropertyImpl( + name: String, + owner: KClassImpl +) : KMutableMemberProperty, KMutablePropertyImpl, KMemberPropertyImpl(name, owner) { + override val setter: Method = try { + owner.jClass.getMaybeDeclaredMethod(setterName(name), getter.getReturnType()!!) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun set(receiver: T, value: R) { + try { + setter(receiver, value) + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun toString(): String = + "var ${owner.jClass.getName()}.$name" +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt new file mode 100644 index 00000000000..4a5e182b304 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import kotlin.reflect.KPackage +import kotlin.jvm.internal.KotlinPackage + +private val KOTLIN_PACKAGE_ANNOTATION_CLASS = javaClass() + +class KPackageImpl(val jClass: Class<*>) : KPackage { + override fun equals(other: Any?): Boolean = + other is KPackageImpl && jClass == other.jClass + + override fun hashCode(): Int = + jClass.hashCode() + + suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + override fun toString(): String { + val name = jClass.getName() as java.lang.String + return if (jClass.isAnnotationPresent(KOTLIN_PACKAGE_ANNOTATION_CLASS)) { + // Cast to Any is needed to suppress the error: "Operator '==' cannot be applied to 'java.lang.String' and 'kotlin.String'" + if ((name : Any) == "_DefaultPackage") { + "package " + } + else { + val lastDot = name.lastIndexOf(".") + if (lastDot >= 0) { + "package ${name.substring(0, lastDot)}" + } + else "package $name" + } + } + else "package $name" + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt new file mode 100644 index 00000000000..76b1e61f29f --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.* +import kotlin.reflect.* + +trait KPropertyImpl : KProperty, KCallableImpl { + val field: Field? + + val getter: Method? +} + + +trait KMutablePropertyImpl : KMutableProperty, KPropertyImpl { + val setter: Method? +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt new file mode 100644 index 00000000000..e60ecc9ae20 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.* +import kotlin.reflect.* + +open class KTopLevelExtensionPropertyImpl( + public override val name: String, + protected val owner: KPackageImpl, + protected val receiverClass: Class +) : KTopLevelExtensionProperty, KPropertyImpl { + override val field: Field? get() = null + + // TODO: extract, make lazy (weak?), use our descriptors knowledge, support Java fields + override val getter: Method = try { + owner.jClass.getMethod(getterName(name), receiverClass) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun get(receiver: T): R { + try { + return getter(null, receiver) as R + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun equals(other: Any?): Boolean = + other is KTopLevelExtensionPropertyImpl<*, *> && name == other.name && owner == other.owner && receiverClass == other.receiverClass + + override fun hashCode(): Int = + (name.hashCode() * 31 + owner.hashCode()) * 31 + receiverClass.hashCode() + + // TODO: include visibility, return type, maybe package + override fun toString(): String = + "val ${mapJavaClassToKotlin(receiverClass.getName())}.$name" +} + +class KMutableTopLevelExtensionPropertyImpl( + name: String, + owner: KPackageImpl, + receiverClass: Class +) : KMutableTopLevelExtensionProperty, KMutablePropertyImpl, KTopLevelExtensionPropertyImpl(name, owner, receiverClass) { + override val setter: Method = try { + owner.jClass.getMethod(setterName(name), receiverClass, getter.getReturnType()!!) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun set(receiver: T, value: R) { + try { + setter.invoke(null, receiver, value) + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun toString(): String = + "var ${mapJavaClassToKotlin(receiverClass.getName())}.$name" +} + +suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +private fun mapJavaClassToKotlin(name: String): String { + if (Character.isLowerCase(name[0])) { + return when (name) { + "boolean" -> "kotlin.Boolean" + "char" -> "kotlin.Char" + "byte" -> "kotlin.Byte" + "short" -> "kotlin.Short" + "int" -> "kotlin.Int" + "float" -> "kotlin.Float" + "long" -> "kotlin.Long" + "double" -> "kotlin.Double" + else -> name + } + } + if (name[0] == '[') { + val element = (name as java.lang.String).substring(1) + return when (element[0]) { + 'Z' -> "kotlin.BooleanArray" + 'C' -> "kotlin.CharArray" + 'B' -> "kotlin.ByteArray" + 'S' -> "kotlin.ShortArray" + 'I' -> "kotlin.IntArray" + 'F' -> "kotlin.FloatArray" + 'J' -> "kotlin.LongArray" + 'D' -> "kotlin.DoubleArray" + 'L' -> "kotlin.Array<${mapJavaClassToKotlin((element as java.lang.String).substring(1, element.length() - 1))}>" + else -> "kotlin.Array<${mapJavaClassToKotlin(element)}>" + } + } + return name +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt new file mode 100644 index 00000000000..8fa6a06609b --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt @@ -0,0 +1,79 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.* +import kotlin.reflect.* + +open class KTopLevelVariableImpl( + public override val name: String, + protected val owner: KPackageImpl +) : KTopLevelVariable, KVariableImpl { + // TODO: load the field from the corresponding package part + override val field: Field? get() = null + + // TODO: extract, make lazy (weak?), use our descriptors knowledge, support Java fields + override val getter: Method = try { + owner.jClass.getMethod(getterName(name)) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun get(): R { + try { + return getter(null) as R + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun equals(other: Any?): Boolean = + other is KTopLevelVariableImpl<*> && name == other.name && owner == other.owner + + override fun hashCode(): Int = + name.hashCode() * 31 + owner.hashCode() + + // TODO: include visibility, return type, maybe package + override fun toString(): String = + "val $name" +} + +class KMutableTopLevelVariableImpl( + name: String, + owner: KPackageImpl +) : KMutableTopLevelVariable, KMutableVariableImpl, KTopLevelVariableImpl(name, owner) { + override val setter: Method = try { + owner.jClass.getMethod(setterName(name), getter.getReturnType()!!) + } + catch (e: NoSuchMethodException) { + throw NoSuchPropertyException(e) + } + + override fun set(value: R) { + try { + setter.invoke(null, value) + } + catch (e: java.lang.IllegalAccessException) { + throw kotlin.reflect.IllegalAccessException(e) + } + } + + override fun toString(): String = + "var $name" +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt new file mode 100644 index 00000000000..1dacc258385 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import kotlin.reflect.* + +trait KVariableImpl : KVariable, KPropertyImpl + +trait KMutableVariableImpl : KMutableVariable, KVariableImpl, KMutablePropertyImpl diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt new file mode 100644 index 00000000000..86d5d7d5bcf --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import kotlin.reflect.* + +fun kClass(jClass: Class): KClassImpl = + KClassImpl(jClass, false) + +fun kClassFromKotlin(jClass: Class): KClassImpl = + KClassImpl(jClass, true) + +fun kPackage(jClass: Class<*>): KPackageImpl = + KPackageImpl(jClass) + +fun topLevelVariable(name: String, owner: KPackageImpl): KTopLevelVariableImpl = + KTopLevelVariableImpl(name, owner) + +fun mutableTopLevelVariable(name: String, owner: KPackageImpl): KMutableTopLevelVariableImpl = + KMutableTopLevelVariableImpl(name, owner) + +fun topLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class): KTopLevelExtensionPropertyImpl = + KTopLevelExtensionPropertyImpl(name, owner, receiver) + +fun mutableTopLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class): KMutableTopLevelExtensionPropertyImpl = + KMutableTopLevelExtensionPropertyImpl(name, owner, receiver) diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/foreignKClasses.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/foreignKClasses.kt new file mode 100644 index 00000000000..acf8b1eb01b --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/foreignKClasses.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.ref.WeakReference +import kotlin.reflect.jvm.internal.pcollections.HashPMap + +// TODO: collect nulls periodically +// Key of the map is Class.getName(), each value is either a WeakReference> or an Array>>. +// Arrays are needed because the same class can be loaded by different class loaders, which results in different Class instances. +// This variable is not volatile intentionally: we don't care if there's a data race on it and some KClass instances will be lost. +// We do care however about general performance on read access to it, thus no synchronization is done here whatsoever +private var FOREIGN_K_CLASSES = HashPMap.empty() + +// This function is invoked on each reflection access to Java classes, properties, etc. Performance is critical here. +fun foreignKotlinClass(jClass: Class): KClassImpl { + val name = jClass.getName() + val cached = FOREIGN_K_CLASSES[name] + if (cached is WeakReference<*>) { + val kClass = cached.get() as KClassImpl? + if (kClass?.jClass == jClass) { + return kClass!! + } + } + else if (cached != null) { + // If the cached value is not a weak reference, it's an array of weak references + cached as Array>> + for (ref in cached) { + val kClass = ref.get() + if (kClass?.jClass == jClass) { + return kClass!! + } + } + + // This is the most unlikely case: we found a cached array of references of length at least 2 (can't be 1 because + // the single element would be cached instead), and none of those classes is the one we're looking for + val size = cached.size + // Don't use Array constructor because it creates a lambda + val newArray = arrayOfNulls>>(size + 1) + // Don't use Arrays.copyOf because it works reflectively + System.arraycopy(cached, 0, newArray, 0, size) + val newKClass = kClass(jClass) + newArray[size] = WeakReference(newKClass) + FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, newArray) + return newKClass + } + + val newKClass = kClass(jClass) + FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, WeakReference(newKClass)) + return newKClass +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java new file mode 100644 index 00000000000..a541e1e9206 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java @@ -0,0 +1,118 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal.pcollections; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * A simple persistent stack of non-null values. + *

+ * This implementation is thread-safe, although its iterators may not be. + */ +final class ConsPStack implements Iterable { + private static final ConsPStack EMPTY = new ConsPStack(); + + @SuppressWarnings("unchecked") + public static ConsPStack empty() { + return (ConsPStack) EMPTY; + } + + private final E first; + private final ConsPStack rest; + private final int size; + + private ConsPStack() { // EMPTY constructor + size = 0; + first = null; + rest = null; + } + + private ConsPStack(E first, ConsPStack rest) { + this.first = first; + this.rest = rest; + this.size = 1 + rest.size; + } + + public E get(int index) { + if (index < 0 || index > size) throw new IndexOutOfBoundsException(); + + try { + return iterator(index).next(); + } catch (NoSuchElementException e) { + throw new IndexOutOfBoundsException("Index: " + index); + } + } + + @Override + public Iterator iterator() { + return iterator(0); + } + + public int size() { + return size; + } + + private Iterator iterator(final int index) { + return new Iterator() { + ConsPStack next = subList(index); + + @Override + public boolean hasNext() { + return next.size > 0; + } + + @Override + public E next() { + E e = next.first; + next = next.rest; + return e; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + public ConsPStack plus(E e) { + return new ConsPStack(e, this); + } + + private ConsPStack minus(Object e) { + if (size == 0) return this; + if (first.equals(e)) // found it + return rest; // don't recurse (only remove one) + // otherwise keep looking: + ConsPStack newRest = rest.minus(e); + if (newRest == rest) return this; + return new ConsPStack(first, newRest); + } + + public ConsPStack minus(int i) { + return minus(get(i)); + } + + private ConsPStack subList(int start) { + if (start < 0 || start > size) + throw new IndexOutOfBoundsException(); + if (start == 0) + return this; + return rest.subList(start - 1); + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java new file mode 100644 index 00000000000..473b2d6d922 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal.pcollections; + +import org.jetbrains.annotations.NotNull; + +/** + * A persistent map from non-null keys to non-null values. + */ +public final class HashPMap { + private static final HashPMap EMPTY = new HashPMap(IntTreePMap.>>empty(), 0); + + @SuppressWarnings("unchecked") + @NotNull + public static HashPMap empty() { + return (HashPMap) HashPMap.EMPTY; + } + + private final IntTreePMap>> intMap; + private final int size; + + private HashPMap(IntTreePMap>> intMap, int size) { + this.intMap = intMap; + this.size = size; + } + + public int size() { + return size; + } + + public boolean containsKey(Object key) { + return keyIndexIn(getEntries(key.hashCode()), key) != -1; + } + + public V get(Object key) { + ConsPStack> entries = getEntries(key.hashCode()); + for (MapEntry entry : entries) + if (entry.key.equals(key)) + return entry.value; + return null; + } + + @NotNull + public HashPMap plus(K key, V value) { + ConsPStack> entries = getEntries(key.hashCode()); + int size0 = entries.size(); + int i = keyIndexIn(entries, key); + if (i != -1) entries = entries.minus(i); + entries = entries.plus(new MapEntry(key, value)); + return new HashPMap(intMap.plus(key.hashCode(), entries), size - size0 + entries.size()); + } + + @NotNull + public HashPMap minus(Object key) { + ConsPStack> entries = getEntries(key.hashCode()); + int i = keyIndexIn(entries, key); + if (i == -1) // key not in this + return this; + entries = entries.minus(i); + if (entries.size() == 0) // get rid of the entire hash entry + return new HashPMap(intMap.minus(key.hashCode()), size - 1); + // otherwise replace hash entry with new smaller one: + return new HashPMap(intMap.plus(key.hashCode(), entries), size - 1); + } + + private ConsPStack> getEntries(int hash) { + ConsPStack> entries = intMap.get(hash); + if (entries == null) return ConsPStack.empty(); + return entries; + } + + private static int keyIndexIn(ConsPStack> entries, Object key) { + int i = 0; + for (MapEntry entry : entries) { + if (entry.key.equals(key)) + return i; + i++; + } + return -1; + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTree.java b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTree.java new file mode 100644 index 00000000000..d39167fedc1 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTree.java @@ -0,0 +1,264 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal.pcollections; + +/** + * A non-public utility class for persistent balanced tree maps with integer keys. + *

+ * To allow for efficiently increasing all keys above a certain value or decreasing + * all keys below a certain value, the keys values are stored relative to their parent. + * This makes this map a good backing for fast insertion and removal of indices in a + * vector. + *

+ * This implementation is thread-safe except for its iterators. + *

+ * Other than that, this tree is based on the Glasgow Haskell Compiler's Data.Map implementation, + * which in turn is based on "size balanced binary trees" as described by: + *

+ * Stephen Adams, "Efficient sets: a balancing act", + * Journal of Functional Programming 3(4):553-562, October 1993, + * http://www.swiss.ai.mit.edu/~adams/BB/. + *

+ * J. Nievergelt and E.M. Reingold, "Binary search trees of bounded balance", + * SIAM journal of computing 2(1), March 1973. + * + * @author harold + */ +final class IntTree { + // marker value: + static final IntTree EMPTYNODE = new IntTree(); + + // we use longs so relative keys can express all ints + // (e.g. if this has key -10 and right has 'absolute' key MAXINT, + // then its relative key is MAXINT+10 which overflows) + // there might be some way to deal with this based on left-verse-right logic, + // but that sounds like a mess. + private final long key; + private final V value; // null value means this is empty node + private final IntTree left, right; + private final int size; + + private IntTree() { + size = 0; + key = 0; + value = null; + left = null; + right = null; + } + + private IntTree(long key, V value, IntTree left, IntTree right) { + this.key = key; + this.value = value; + this.left = left; + this.right = right; + size = 1 + left.size + right.size; + } + + private IntTree withKey(long newKey) { + if (size == 0 || newKey == key) return this; + return new IntTree(newKey, value, left, right); + } + + boolean containsKey(long key) { + if (size == 0) + return false; + if (key < this.key) + return left.containsKey(key - this.key); + if (key > this.key) + return right.containsKey(key - this.key); + // otherwise key==this.key: + return true; + } + + V get(long key) { + if (size == 0) + return null; + if (key < this.key) + return left.get(key - this.key); + if (key > this.key) + return right.get(key - this.key); + // otherwise key==this.key: + return value; + } + + IntTree plus(long key, V value) { + if (size == 0) + return new IntTree(key, value, this, this); + if (key < this.key) + return rebalanced(left.plus(key - this.key, value), right); + if (key > this.key) + return rebalanced(left, right.plus(key - this.key, value)); + // otherwise key==this.key, so we simply replace this, with no effect on balance: + if (value == this.value) + return this; + return new IntTree(key, value, left, right); + } + + IntTree minus(long key) { + if (size == 0) + return this; + if (key < this.key) + return rebalanced(left.minus(key - this.key), right); + if (key > this.key) + return rebalanced(left, right.minus(key - this.key)); + + // otherwise key==this.key, so we are killing this node: + + if (left.size == 0) // we can just become right node + // make key 'absolute': + return right.withKey(right.key + this.key); + if (right.size == 0) // we can just become left node + return left.withKey(left.key + this.key); + + // otherwise replace this with the next key (i.e. the smallest key to the right): + + // TODO have minNode() instead of minKey to avoid having to call get() + // TODO get node from larger subtree, i.e. if left.size>right.size use left.maxNode() + // TODO have faster minusMin() instead of just using minus() + + long newKey = right.minKey() + this.key; + //(right.minKey() is relative to this; adding this.key makes it 'absolute' + // where 'absolute' really means relative to the parent of this) + + V newValue = right.get(newKey - this.key); + // now that we've got the new stuff, take it out of the right subtree: + IntTree newRight = right.minus(newKey - this.key); + + // lastly, make the subtree keys relative to newKey (currently they are relative to this.key): + newRight = newRight.withKey((newRight.key + this.key) - newKey); + // left is definitely not empty: + IntTree newLeft = left.withKey((left.key + this.key) - newKey); + + return rebalanced(newKey, newValue, newLeft, newRight); + } + + /** + * Changes every key k>=key to k+delta. + *

+ * This method will create an _invalid_ tree if delta<0 + * and the distance between the smallest k>=key in this + * and the largest j + * In other words, this method must not result in any change + * in the order of the keys in this, since the tree structure is + * not being changed at all. + */ + IntTree changeKeysAbove(long key, int delta) { + if (size == 0 || delta == 0) + return this; + + if (this.key >= key) + // adding delta to this.key changes the keys of _all_ children of this, + // so we now need to un-change the children of this smaller than key, + // all of which are to the left. note that we still use the 'old' relative key...: + return new IntTree(this.key + delta, value, left.changeKeysBelow(key - this.key, -delta), right); + + // otherwise, doesn't apply yet, look to the right: + IntTree newRight = right.changeKeysAbove(key - this.key, delta); + if (newRight == right) return this; + return new IntTree(this.key, value, left, newRight); + } + + /** + * Changes every key k + * This method will create an _invalid_ tree if delta>0 + * and the distance between the largest k=key in this is delta or less. + *

+ * In other words, this method must not result in any overlap or change + * in the order of the keys in this, since the tree _structure_ is + * not being changed at all. + */ + IntTree changeKeysBelow(long key, int delta) { + if (size == 0 || delta == 0) + return this; + + if (this.key < key) + // adding delta to this.key changes the keys of _all_ children of this, + // so we now need to un-change the children of this larger than key, + // all of which are to the right. note that we still use the 'old' relative key...: + return new IntTree(this.key + delta, value, left, right.changeKeysAbove(key - this.key, -delta)); + + // otherwise, doesn't apply yet, look to the left: + IntTree newLeft = left.changeKeysBelow(key - this.key, delta); + if (newLeft == left) return this; + return new IntTree(this.key, value, newLeft, right); + } + + // min key in this: + private long minKey() { + if (left.size == 0) + return key; + // make key 'absolute' (i.e. relative to the parent of this): + return left.minKey() + this.key; + } + + private IntTree rebalanced(IntTree newLeft, IntTree newRight) { + if (newLeft == left && newRight == right) + return this; // already balanced + return rebalanced(key, value, newLeft, newRight); + } + + private static final int OMEGA = 5; + private static final int ALPHA = 2; + + // rebalance a tree that is off-balance by at most 1: + private static IntTree rebalanced(long key, V value, IntTree left, IntTree right) { + if (left.size + right.size > 1) { + if (left.size >= OMEGA * right.size) { // rotate to the right + IntTree ll = left.left, lr = left.right; + if (lr.size < ALPHA * ll.size) // single rotation + return new IntTree(left.key + key, left.value, + ll, + new IntTree(-left.key, value, + lr.withKey(lr.key + left.key), + right)); + else { // double rotation: + IntTree lrl = lr.left, lrr = lr.right; + return new IntTree(lr.key + left.key + key, lr.value, + new IntTree(-lr.key, left.value, + ll, + lrl.withKey(lrl.key + lr.key)), + new IntTree(-left.key - lr.key, value, + lrr.withKey(lrr.key + lr.key + left.key), + right)); + } + } else if (right.size >= OMEGA * left.size) { // rotate to the left + IntTree rl = right.left, rr = right.right; + if (rl.size < ALPHA * rr.size) // single rotation + return new IntTree(right.key + key, right.value, + new IntTree(-right.key, value, + left, + rl.withKey(rl.key + right.key)), + rr); + else { // double rotation: + IntTree rll = rl.left, rlr = rl.right; + return new IntTree(rl.key + right.key + key, rl.value, + new IntTree(-right.key - rl.key, value, + left, + rll.withKey(rll.key + rl.key + right.key)), + new IntTree(-rl.key, right.value, + rlr.withKey(rlr.key + rl.key), + rr)); + } + } + } + // otherwise already balanced enough: + return new IntTree(key, value, left, right); + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTreePMap.java b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTreePMap.java new file mode 100644 index 00000000000..040f5464b43 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/IntTreePMap.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal.pcollections; + +/** + * An efficient persistent map from integer keys to non-null values. + */ +final class IntTreePMap { + private static final IntTreePMap EMPTY = new IntTreePMap(IntTree.EMPTYNODE); + + @SuppressWarnings("unchecked") + public static IntTreePMap empty() { + return (IntTreePMap) EMPTY; + } + + private final IntTree root; + + private IntTreePMap(IntTree root) { + this.root = root; + } + + private IntTreePMap withRoot(IntTree root) { + if (root == this.root) return this; + return new IntTreePMap(root); + } + + public V get(int key) { + return root.get(key); + } + + public IntTreePMap plus(int key, V value) { + return withRoot(root.plus(key, value)); + } + + public IntTreePMap minus(int key) { + return withRoot(root.minus(key)); + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/MapEntry.java b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/MapEntry.java new file mode 100644 index 00000000000..08d1b8288c9 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/pcollections/MapEntry.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal.pcollections; + +final class MapEntry implements java.io.Serializable { + private static final long serialVersionUID = 7138329143949025153L; + + public final K key; + public final V value; + + public MapEntry(K key, V value) { + this.key = key; + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof MapEntry)) return false; + MapEntry e = (MapEntry) o; + return (key == null ? e.key == null : key.equals(e.key)) && + (value == null ? e.value == null : value.equals(e.value)); + } + + @Override + public int hashCode() { + return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()); + } + + @Override + public String toString() { + return key + "=" + value; + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/util.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/util.kt new file mode 100644 index 00000000000..0fbf5803908 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/util.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2014 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.reflect.jvm.internal + +import java.lang.reflect.Method +import kotlin.jvm.internal.Intrinsic + +// TODO: use stdlib? +suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +private fun String.capitalizeWithJavaBeanConvention(): String { + // The code is a bit crooked because otherwise there are overload resolution ambiguities caused by the fact + // that we compile it with the built-ins both in source and as a compiled library + val l = length + if (l > 1 && Character.isUpperCase(get(1))) return this + val first = get(0) + this as java.lang.String + return "" + Character.toUpperCase(first) + substring(1, l) +} + +private fun getterName(propertyName: String): String = "get" + propertyName.capitalizeWithJavaBeanConvention() +private fun setterName(propertyName: String): String = "set" + propertyName.capitalizeWithJavaBeanConvention() + + +// A local copy of javaClass() from stdlib is needed because there's no dependency on stdlib in runtime.jvm +[Intrinsic("kotlin.javaClass.function")] +fun javaClass(): Class = throw UnsupportedOperationException() + + +private fun Class<*>.getMaybeDeclaredMethod(name: String, vararg parameterTypes: Class<*>): Method { + try { + return getMethod(name, *parameterTypes) + } + catch (e: NoSuchMethodException) { + // This is needed to support private methods + return getDeclaredMethod(name, *parameterTypes) + } +} diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/mapping.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/mapping.kt new file mode 100644 index 00000000000..b40f1d6c24c --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/mapping.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2014 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.reflect.jvm + +import java.lang.reflect.* +import kotlin.reflect.* +import kotlin.reflect.jvm.internal.* + +// Kotlin reflection -> Java reflection + +public val KClass.java: Class + get() = (this as KClassImpl).jClass + +public val KPackage.javaFacade: Class<*> + get() = (this as KPackageImpl).jClass + + +public val KProperty<*>.javaGetter: Method? + get() = (this as? KPropertyImpl<*>)?.getter + +public val KMutableProperty<*>.javaSetter: Method? + get() = (this as? KMutablePropertyImpl<*>)?.setter + + +// TODO: val KTopLevelVariable<*>.javaField: Field + +public val KTopLevelVariable<*>.javaGetter: Method + get() = (this as KTopLevelVariableImpl<*>).getter + +public val KMutableTopLevelVariable<*>.javaSetter: Method + get() = (this as KMutableTopLevelVariableImpl<*>).setter + + +public val KTopLevelExtensionProperty<*, *>.javaGetter: Method + get() = (this as KTopLevelExtensionPropertyImpl<*, *>).getter + +public val KMutableTopLevelExtensionProperty<*, *>.javaSetter: Method + get() = (this as KMutableTopLevelExtensionPropertyImpl<*, *>).setter + + +public val KMemberProperty<*, *>.javaField: Field? + get() = (this as KPropertyImpl<*>).field + + +// Java reflection -> Kotlin reflection + +public val Class.kotlin: KClass + get() = kClass(this) + +public val Class<*>.kotlinPackage: KPackage + get() = kPackage(this) + + +public val Field.kotlin: KProperty<*> + get() { + val clazz = getDeclaringClass() + val name = getName()!! + val modifiers = getModifiers() + val static = Modifier.isStatic(modifiers) + val final = Modifier.isFinal(modifiers) + if (static) { + val kPackage = kPackage(clazz) + return if (final) topLevelVariable(name, kPackage) else mutableTopLevelVariable(name, kPackage) + } + else { + val kClass = kClass(clazz as Class) + return if (final) kClass.memberProperty(name) else kClass.mutableMemberProperty(name) + } + } + diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/properties.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/properties.kt new file mode 100644 index 00000000000..20df3d6b801 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/properties.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2014 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.reflect.jvm + +import kotlin.reflect.* +import kotlin.reflect.jvm.internal.* + +public var KProperty.accessible: Boolean + get() { + return when (this) { + is KMutableMemberPropertyImpl<*, R> -> getter.isAccessible() && setter.isAccessible() + is KMemberPropertyImpl<*, R> -> getter.isAccessible() + is KForeignMemberProperty<*, R> -> field.isAccessible() + else -> { + // Non-member properties always have public visibility on JVM, thus accessible has no effect on them + true + } + } + } + set(value) { + when (this) { + is KMutableMemberPropertyImpl<*, R> -> { + getter.setAccessible(value) + setter.setAccessible(value) + } + is KMemberPropertyImpl<*, R> -> { + getter.setAccessible(value) + } + is KForeignMemberProperty<*, R> -> { + field.setAccessible(value) + } + } + } diff --git a/idea/testData/debugger/tinyApp/outs/memberFunFromTopLevel.out b/idea/testData/debugger/tinyApp/outs/memberFunFromTopLevel.out index c2e52ded0b3..4f55a285f35 100644 --- a/idea/testData/debugger/tinyApp/outs/memberFunFromTopLevel.out +++ b/idea/testData/debugger/tinyApp/outs/memberFunFromTopLevel.out @@ -1,7 +1,7 @@ -LineBreakpoint created at memberFunFromTopLevel.kt:11 +LineBreakpoint created at memberFunFromTopLevel.kt:13 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!RT_JAR! memberFunFromTopLevel.MemberFunFromTopLevelPackage Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' -memberFunFromTopLevel.kt:10 +memberFunFromTopLevel.kt:12 memberFunFromTopLevel.kt:4 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' diff --git a/idea/testData/debugger/tinyApp/outs/memberGetterFromTopLevel.out b/idea/testData/debugger/tinyApp/outs/memberGetterFromTopLevel.out index 72ee47c8875..7699e7232f3 100644 --- a/idea/testData/debugger/tinyApp/outs/memberGetterFromTopLevel.out +++ b/idea/testData/debugger/tinyApp/outs/memberGetterFromTopLevel.out @@ -1,7 +1,7 @@ -LineBreakpoint created at memberGetterFromTopLevel.kt:13 +LineBreakpoint created at memberGetterFromTopLevel.kt:15 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!RT_JAR! memberGetterFromTopLevel.MemberGetterFromTopLevelPackage Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' -memberGetterFromTopLevel.kt:12 +memberGetterFromTopLevel.kt:14 memberGetterFromTopLevel.kt:5 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' diff --git a/idea/testData/debugger/tinyApp/src/stepInto/memberFunFromTopLevel.kt b/idea/testData/debugger/tinyApp/src/stepInto/memberFunFromTopLevel.kt index 0ab3d10e410..6dfc6d4cb91 100644 --- a/idea/testData/debugger/tinyApp/src/stepInto/memberFunFromTopLevel.kt +++ b/idea/testData/debugger/tinyApp/src/stepInto/memberFunFromTopLevel.kt @@ -7,6 +7,8 @@ class A { } fun main(args: Array) { + A() + //Breakpoint! A().bar() } diff --git a/idea/testData/debugger/tinyApp/src/stepInto/memberGetterFromTopLevel.kt b/idea/testData/debugger/tinyApp/src/stepInto/memberGetterFromTopLevel.kt index 328316b07ef..13f8d06f27a 100644 --- a/idea/testData/debugger/tinyApp/src/stepInto/memberGetterFromTopLevel.kt +++ b/idea/testData/debugger/tinyApp/src/stepInto/memberGetterFromTopLevel.kt @@ -9,6 +9,8 @@ class A { } fun main(args: Array) { + A() + //Breakpoint! A().bar } diff --git a/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTest.java b/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTest.java index ec46b8e1073..842ad2a83aa 100644 --- a/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTest.java +++ b/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTest.java @@ -267,8 +267,8 @@ public class KotlinJpsBuildTest extends AbstractKotlinJpsBuildTestCase { // Check that outputs are located properly File facadeWithA = findFileInOutputDir(findModule("module1"), "test/TestPackage.class"); File facadeWithB = findFileInOutputDir(findModule("module2"), "test/TestPackage.class"); - assertSameElements(getMethodsOfClass(facadeWithA), "a", "getA"); - assertSameElements(getMethodsOfClass(facadeWithB), "b", "getB", "setB"); + assertSameElements(getMethodsOfClass(facadeWithA), "", "a", "getA"); + assertSameElements(getMethodsOfClass(facadeWithB), "", "b", "getB", "setB"); checkWhen(touch("module1/src/a.kt"), null, packageClasses("module1", "module1/src/a.kt", "test.TestPackage")); checkWhen(touch("module2/src/b.kt"), null, packageClasses("module2", "module2/src/b.kt", "test.TestPackage")); diff --git a/jps-plugin/testData/general/CircularDependenciesSamePackage/module1/src/a.kt b/jps-plugin/testData/general/CircularDependenciesSamePackage/module1/src/a.kt index 4987d3f36ec..8311da66012 100644 --- a/jps-plugin/testData/general/CircularDependenciesSamePackage/module1/src/a.kt +++ b/jps-plugin/testData/general/CircularDependenciesSamePackage/module1/src/a.kt @@ -4,4 +4,4 @@ fun a() { } -val a = "" \ No newline at end of file +val a = "" diff --git a/jps-plugin/testData/general/CircularDependenciesSamePackage/module2/src/b.kt b/jps-plugin/testData/general/CircularDependenciesSamePackage/module2/src/b.kt index 1dcef1df913..b04c387135d 100644 --- a/jps-plugin/testData/general/CircularDependenciesSamePackage/module2/src/b.kt +++ b/jps-plugin/testData/general/CircularDependenciesSamePackage/module2/src/b.kt @@ -4,4 +4,4 @@ fun b() { } -var b = "" \ No newline at end of file +var b = b() diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java index 0b01f55f84b..bfdd2a91803 100644 --- a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java +++ b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java @@ -49,8 +49,7 @@ public final class AnalyzerFacadeForJS { public static final List DEFAULT_IMPORTS = ImmutableList.of( new ImportPath("js.*"), new ImportPath("java.lang.*"), - new ImportPath("kotlin.*"), - new ImportPath("kotlin.reflect.*") + new ImportPath("kotlin.*") ); private AnalyzerFacadeForJS() { diff --git a/libraries/stdlib/src/kotlin/jvm/internal/Intrinsic.kt b/libraries/stdlib/src/kotlin/jvm/internal/Intrinsic.kt deleted file mode 100644 index 05fc4ad46c8..00000000000 --- a/libraries/stdlib/src/kotlin/jvm/internal/Intrinsic.kt +++ /dev/null @@ -1,6 +0,0 @@ -package kotlin.jvm.internal - -import java.lang.annotation.* - -Retention(RetentionPolicy.RUNTIME) -annotation class Intrinsic(val value: String) diff --git a/license/third_party/pcollections_LICENSE.txt b/license/third_party/pcollections_LICENSE.txt new file mode 100644 index 00000000000..345a0dad954 --- /dev/null +++ b/license/third_party/pcollections_LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2008 Harold Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.