Initial implementation of platformStatic

This commit is contained in:
Michael Bogdanov
2014-09-01 15:12:31 +04:00
parent 7bbedd9685
commit e26d635633
36 changed files with 718 additions and 47 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.lang.descriptors.*;
@@ -165,11 +166,13 @@ public class AsmUtil {
&& !isStaticMethod(kind, functionDescriptor);
}
public static boolean isStaticMethod(OwnerKind kind, FunctionDescriptor functionDescriptor) {
return isStatic(kind) || JetTypeMapper.isAccessor(functionDescriptor);
public static boolean isStaticMethod(OwnerKind kind, CallableMemberDescriptor functionDescriptor) {
return isStaticKind(kind) ||
JetTypeMapper.isAccessor(functionDescriptor) ||
JvmCodegenUtil.isPlatformStaticInObject(functionDescriptor);
}
public static boolean isStatic(OwnerKind kind) {
public static boolean isStaticKind(OwnerKind kind) {
return kind == OwnerKind.PACKAGE || kind == OwnerKind.TRAIT_IMPL;
}
@@ -791,4 +794,10 @@ public class AsmUtil {
public static Type getArrayOf(@NotNull String internalClassName) {
return Type.getType("[L" + internalClassName + ";");
}
public static int getReceiverIndex(@NotNull CodegenContext context, @NotNull CallableMemberDescriptor descriptor) {
OwnerKind kind = context.getContextKind();
//Trait always should have this descriptor
return kind != OwnerKind.TRAIT_IMPL && isStaticMethod(kind, descriptor) ? 0 : 1;
}
}
@@ -1390,7 +1390,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
JetType captureReceiver = closure.getCaptureReceiverType();
if (captureReceiver != null) {
Type asmType = typeMapper.mapType(captureReceiver);
StackValue.Local capturedReceiver = StackValue.local(context.isStatic() ? 0 : 1, asmType);
StackValue.Local capturedReceiver = StackValue.local(AsmUtil.getReceiverIndex(context, context.getContextDescriptor()), asmType);
callGenerator.putCapturedValueOnStack(capturedReceiver, capturedReceiver.type, paramIndex++);
}
}
@@ -2305,7 +2305,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
public StackValue generateThisOrOuter(@NotNull ClassDescriptor calleeContainingClass, boolean isSuper) {
boolean isSingleton = calleeContainingClass.getKind().isSingleton();
if (isSingleton) {
if (context.hasThisDescriptor() && context.getThisDescriptor().equals(calleeContainingClass)) {
if (context.hasThisDescriptor() &&
context.getThisDescriptor().equals(calleeContainingClass) &&
!isPlatformStaticInObject(context.getContextDescriptor())) {
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
}
else {
@@ -149,6 +149,12 @@ public class FunctionCodegen extends ParentCodegenAware {
generateBridges(functionDescriptor);
if (JvmCodegenUtil.isPlatformStaticInClassObject(functionDescriptor)) {
MemberCodegen<?> codegen = getParentCodegen().getParentCodegen();
((ImplementationBodyCodegen) codegen).addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state));
}
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES || isAbstractMethod(functionDescriptor, methodContextKind)) {
generateLocalVariableTable(
mv,
@@ -294,7 +300,8 @@ public class FunctionCodegen extends ParentCodegenAware {
generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (PackageFacadeContext) context.getParentContext());
}
else {
FrameMap frameMap = createFrameMap(parentCodegen.state, functionDescriptor, signature, isStatic(context.getContextKind()));
FrameMap frameMap = createFrameMap(parentCodegen.state, functionDescriptor, signature, isStaticMethod(context.getContextKind(),
functionDescriptor));
Label methodEntry = new Label();
mv.visitLabel(methodEntry);
@@ -582,7 +589,7 @@ public class FunctionCodegen extends ParentCodegenAware {
endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor));
}
else {
generateDefaultImpl(owner, signature, functionDescriptor, isStatic(kind), mv, loadStrategy, function);
generateDefaultImpl(owner, signature, functionDescriptor, isStaticMethod(kind, functionDescriptor), mv, loadStrategy, function);
}
}
}
@@ -791,7 +798,7 @@ public class FunctionCodegen extends ParentCodegenAware {
final ClassDescriptor toClass,
final StackValue field,
final JvmMethodSignature jvmDelegateMethodSignature,
final JvmMethodSignature jvmOverriddenMethodSignature
final JvmMethodSignature jvmDelegatingMethodSignature
) {
generateMethod(
OtherOrigin(functionDescriptor), jvmDelegateMethodSignature, functionDescriptor,
@@ -804,7 +811,7 @@ public class FunctionCodegen extends ParentCodegenAware {
@NotNull MethodContext context,
@NotNull MemberCodegen<?> parentCodegen
) {
Method overriddenMethod = jvmOverriddenMethodSignature.getAsmMethod();
Method overriddenMethod = jvmDelegatingMethodSignature.getAsmMethod();
Method delegateMethod = jvmDelegateMethodSignature.getAsmMethod();
Type[] argTypes = delegateMethod.getArgumentTypes();
@@ -20,9 +20,7 @@ import com.google.common.collect.Lists;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayUtil;
import kotlin.Function0;
import kotlin.Function1;
import kotlin.KotlinPackage;
import kotlin.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.backend.common.CodegenUtil;
@@ -94,6 +92,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private List<PropertyAndDefaultValue> classObjectPropertiesToCopy;
private List<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>> additionalTasks;
public ImplementationBodyCodegen(
@NotNull JetClassOrObject aClass,
@NotNull ClassContext context,
@@ -103,6 +103,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
) {
super(aClass, context, v, state, parentCodegen);
this.classAsmType = typeMapper.mapClass(descriptor);
additionalTasks = new ArrayList<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>>();
}
@Override
@@ -1731,6 +1732,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
classObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
}
@Override
protected void done() {
for (Function2<ImplementationBodyCodegen, ClassBuilder, Unit> task : additionalTasks) {
task.invoke(this, v);
}
super.done();
}
private static class PropertyAndDefaultValue {
public final PropertyDescriptor descriptor;
public final Object defaultValue;
@@ -1740,4 +1750,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
this.defaultValue = defaultValue;
}
}
public void addAdditionalTask(Function2<ImplementationBodyCodegen, ClassBuilder, Unit> additionalTask) {
additionalTasks.add(additionalTask);
}
}
@@ -301,4 +301,18 @@ public class JvmCodegenUtil {
? ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty()
: descriptor;
}
public static boolean isPlatformStaticInObject(CallableDescriptor descriptor) {
if (DescriptorUtils.isObject(descriptor.getContainingDeclaration())) {
return KotlinBuiltIns.getInstance().isPlatformStatic(descriptor);
}
return false;
}
public static boolean isPlatformStaticInClassObject(CallableDescriptor descriptor) {
if (DescriptorUtils.isClassObject(descriptor.getContainingDeclaration())) {
return KotlinBuiltIns.getInstance().isPlatformStatic(descriptor);
}
return false;
}
}
@@ -106,7 +106,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
protected abstract void generateKotlinAnnotation();
private void done() {
protected void done() {
if (clInit != null) {
clInit.v.visitInsn(RETURN);
FunctionCodegen.endVisit(clInit.v, "static initializer", element);
@@ -376,4 +376,9 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
public String getClassName() {
return v.getThisName();
}
@NotNull
public FieldOwnerContext<?> getContext() {
return context;
}
}
@@ -0,0 +1,63 @@
/*
* 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 org.jetbrains.jet.codegen
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.lang.psi.JetNamedFunction
import org.jetbrains.jet.codegen.state.JetTypeMapper
import org.jetbrains.jet.codegen.context.CodegenContext
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.jet.lang.resolve.java.diagnostics.OtherOrigin
import org.jetbrains.jet.codegen.state.GenerationState
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodParameterKind
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.lang.psi.JetClassOrObject
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin
class PlatformStaticGenerator(
val descriptor: FunctionDescriptor,
val declarationOrigin: JvmDeclarationOrigin,
val state: GenerationState
) : Function2<ImplementationBodyCodegen, ClassBuilder, Unit> {
override fun invoke(p1: ImplementationBodyCodegen, p2: ClassBuilder) {
val typeMapper = state.getTypeMapper()
val callable = typeMapper.mapToCallableMethod(descriptor, false, p1.getContext())
val asmMethod = callable.getAsmMethod()
val methodVisitor = p2.newMethod(OtherOrigin(declarationOrigin.element, declarationOrigin.descriptor), Opcodes.ACC_STATIC or AsmUtil.getMethodAsmFlags(descriptor, OwnerKind.IMPLEMENTATION), asmMethod.getName()!!, asmMethod.getDescriptor()!!, null, null)
AnnotationCodegen.forMethod(methodVisitor, typeMapper)!!.genAnnotations(descriptor, asmMethod.getReturnType())
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
methodVisitor.visitCode();
val iv = InstructionAdapter(methodVisitor)
val classDescriptor = descriptor.getContainingDeclaration() as ClassDescriptor
val singletonValue = StackValue.singleton(classDescriptor, typeMapper)!!
singletonValue.put(singletonValue.`type`, iv);
var index = 0;
for (paramType in asmMethod.getArgumentTypes()) {
iv.load(index, paramType);
index += paramType.getSize();
}
callable.invokeWithoutAssertions(iv)
iv.areturn(asmMethod.getReturnType());
methodVisitor.visitEnd();
}
}
}
@@ -1127,22 +1127,23 @@ public abstract class StackValue {
ReceiverValue thisObject = resolvedCall.getThisObject();
ReceiverValue receiverArgument = resolvedCall.getReceiverArgument();
int depth;
int depth = 0;
if (thisObject.exists()) {
if (receiverArgument.exists()) {
//noinspection ConstantConditions
Type resultType =
callableMethod != null ?
callableMethod.getOwner() :
codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
if (!JvmCodegenUtil.isPlatformStaticInObject(descriptor)) {
if (receiverArgument.exists()) {
//noinspection ConstantConditions
Type resultType =
callableMethod != null ?
callableMethod.getOwner() :
codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
codegen.generateReceiverValue(thisObject, resultType);
codegen.generateReceiverValue(thisObject, resultType);
}
else {
genReceiver(v, thisObject, type, null, 0);
}
depth = 1;
}
else {
genReceiver(v, thisObject, type, null, 0);
}
depth = 1;
}
else if (isLocalFunCall(callableMethod)) {
assert receiver == none() || receiverArgument.exists() :
@@ -1153,9 +1154,6 @@ public abstract class StackValue {
depth = 1;
}
else {
depth = 0;
}
if (putReceiverArgumentOnStack && receiverArgument.exists()) {
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), depth);
@@ -260,13 +260,6 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
return accessor;
}
public StackValue getReceiverExpression(JetTypeMapper typeMapper) {
assert getCallableDescriptorWithReceiver() != null;
@SuppressWarnings("ConstantConditions")
Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getReceiverParameter().getType());
return hasThisDescriptor() ? StackValue.local(1, asmType) : StackValue.local(0, asmType);
}
public abstract boolean isStatic();
protected void initOuterExpression(@NotNull final JetTypeMapper typeMapper, @NotNull final ClassDescriptor classDescriptor) {
@@ -18,14 +18,20 @@ package org.jetbrains.jet.codegen.context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.AsmUtil;
import org.jetbrains.jet.codegen.JvmCodegenUtil;
import org.jetbrains.jet.codegen.OwnerKind;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.binding.MutableClosure;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.Type;
public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
private final boolean isInliningLambda;
@@ -50,6 +56,13 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
return super.getParentContext();
}
public StackValue getReceiverExpression(JetTypeMapper typeMapper) {
assert getCallableDescriptorWithReceiver() != null;
@SuppressWarnings("ConstantConditions")
Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getReceiverParameter().getType());
return StackValue.local(AsmUtil.getReceiverIndex(this, getContextDescriptor()), asmType);
}
@Override
public StackValue lookupInContext(DeclarationDescriptor d, @Nullable StackValue result, GenerationState state, boolean ignoreNoOuter) {
if (getContextDescriptor() == d) {
@@ -183,7 +183,7 @@ public class InlineCodegen implements CallGenerator {
MethodContext methodContext = context.getParentContext().intoFunction(functionDescriptor);
MemberCodegen<?> parentCodegen = codegen.getParentCodegen();
if (callDefault) {
boolean isStatic = isStatic(context.getContextKind());
boolean isStatic = AsmUtil.isStaticMethod(context.getContextKind(), functionDescriptor);
FunctionCodegen.generateDefaultImplBody(
methodContext, jvmSignature, functionDescriptor, isStatic, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
(JetNamedFunction) element, parentCodegen, state
@@ -62,7 +62,7 @@ import java.util.List;
import java.util.Map;
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
import static org.jetbrains.jet.codegen.AsmUtil.isStatic;
import static org.jetbrains.jet.codegen.AsmUtil.isStaticMethod;
import static org.jetbrains.jet.codegen.JvmCodegenUtil.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedInClosure;
@@ -447,7 +447,7 @@ public class JetTypeMapper {
thisClass = mapClass(currentOwner);
}
else {
if (isAccessor(functionDescriptor)) {
if (isAccessor(functionDescriptor) || isPlatformStaticInObject(functionDescriptor)) {
invokeOpcode = INVOKESTATIC;
}
else if (isInterface) {
@@ -632,7 +632,7 @@ public class JetTypeMapper {
Type ownerType = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context, getOutDirectory()));
String descriptor = getDefaultDescriptor(jvmSignature, functionDescriptor.getReceiverParameter() != null);
boolean isConstructor = "<init>".equals(jvmSignature.getName());
if (!isStatic(kind) && !isConstructor) {
if (!isStaticMethod(kind, functionDescriptor) && !isConstructor) {
descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor());
}
@@ -0,0 +1,28 @@
open class B {
val p = "OK"
}
class BB : B()
trait Z<T :B > {
fun T.getString() : String {
return p
}
fun test(s: T) : String {
return s.extension()
}
private fun T.extension(): String {
return getString()
}
}
object Z2 : Z<BB> {
}
fun box() : String {
return Z2.test(BB())
}
@@ -0,0 +1,28 @@
import java.lang.String;
import java.lang.annotation.Annotation;
class Test {
public static String test1() throws NoSuchMethodException {
Annotation[] test1s = A.class.getMethod("test1").getAnnotations();
for (Annotation test : test1s) {
String name = test.toString();
if (name.contains("testAnnotation")) {
return "OK";
}
}
return "fail";
}
public static String test2() throws NoSuchMethodException {
Annotation[] test2s = B.class.getMethod("test1").getAnnotations();
for (Annotation test : test2s) {
String name = test.toString();
if (name.contains("testAnnotation")) {
return "OK";
}
}
return "fail";
}
}
@@ -0,0 +1,28 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class testAnnotation
class A {
class object {
val b: String = "OK"
platformStatic testAnnotation fun test1() = b
}
}
object B {
val b: String = "OK"
platformStatic testAnnotation fun test1() = b
}
fun box(): String {
if (Test.test1() != "OK") return "fail 1"
if (Test.test2() != "OK") return "fail 2"
return "OK"
}
@@ -0,0 +1,15 @@
class Test {
public static String test1() {
return A.test1();
}
public static String test2() {
return A.test2();
}
public static String test3() {
return A.test3("JAVA");
}
}
@@ -0,0 +1,22 @@
class A {
class object {
val b: String = "OK"
platformStatic fun test1() = b
platformStatic fun test2() = b
platformStatic fun String.test3() = this + b
}
}
fun box(): String {
if (Test.test1() != "OK") return "fail 1"
if (Test.test2() != "OK") return "fail 2"
if (Test.test3() != "JAVAOK") return "fail 3"
return "OK"
}
@@ -0,0 +1,15 @@
class Test {
public static String test1() {
return A.test1();
}
public static String test2() {
return A.test2();
}
public static String test3() {
return A.test3("JAVA");
}
}
@@ -0,0 +1,20 @@
object A {
val b: String = "OK"
platformStatic fun test1() = b
platformStatic fun test2() = b
platformStatic fun String.test3() = this + b
}
fun box(): String {
if (Test.test1() != "OK") return "fail 1"
if (Test.test2() != "OK") return "fail 2"
if (Test.test3() != "JAVAOK") return "fail 3"
return "OK"
}
@@ -0,0 +1,36 @@
object A {
val b: String = "OK"
platformStatic fun test1() : String {
return b
}
platformStatic fun test2() : String {
return test1()
}
fun test3(): String {
return "1".test5()
}
platformStatic fun test4(): String {
return "1".test5()
}
platformStatic fun String.test5() : String {
return this + b
}
}
fun box(): String {
if (A.(A::test1)() != "OK") return "fail 1"
if (A.(A::test2)() != "OK") return "fail 2"
if (A.(A::test3)() != "1OK") return "fail 3"
if (A.(A::test4)() != "1OK") return "fail 4"
return "OK"
}
@@ -0,0 +1,38 @@
object A {
val b: String = "OK"
platformStatic fun test1() : String {
return {b}()
}
platformStatic fun test2() : String {
return {test1()}()
}
fun test3(): String {
return {"1".test5()}()
}
platformStatic fun test4(): String {
return {"1".test5()}()
}
platformStatic fun String.test5() : String {
return {this + b}()
}
}
fun box(): String {
if (A.test1() != "OK") return "fail 1"
if (A.test2() != "OK") return "fail 2"
if (A.test3() != "1OK") return "fail 3"
if (A.test4() != "1OK") return "fail 4"
if (with(A) {"1".test5()} != "1OK") return "fail 5"
return "OK"
}
@@ -0,0 +1,31 @@
class B(var s: Int = 0) {
}
object A {
fun test1(v: B) {
v += B(1000)
}
platformStatic fun B.plusAssign(b: B) {
this.s += b.s
}
}
fun box(): String {
val b1 = B(11)
with(A) {
b1 += B(1000)
}
if (b1.s != 1011) return "fail 1"
val b = B(11)
A.test1(b)
if (b.s != 1011) return "fail 2"
return "OK"
}
@@ -0,0 +1,14 @@
object A {
platformStatic fun test(b: String = "OK") : String {
return b
}
}
fun box(): String {
if (A.test() != "OK") return "fail 1"
return "OK"
}
@@ -0,0 +1,24 @@
object AX {
platformStatic fun aStatic(): String {
return AX.b()
}
fun aNonStatic(): String {
return AX.b()
}
platformStatic fun b(): String {
return "OK"
}
}
fun box() : String {
if (AX.aStatic() != "OK") return "fail 1"
if (AX.aNonStatic() != "OK") return "fail 1"
return "OK"
}
@@ -0,0 +1,14 @@
object A {
platformStatic inline fun test(b: String = "OK") : String {
return b
}
}
fun box(): String {
if (A.test() != "OK") return "fail 1"
return "OK"
}
@@ -0,0 +1,38 @@
object A {
val b: String = "OK"
platformStatic fun test1() : String {
return b
}
platformStatic fun test2() : String {
return test1()
}
fun test3(): String {
return "1".test5()
}
platformStatic fun test4(): String {
return "1".test5()
}
platformStatic fun String.test5() : String {
return this + b
}
}
fun box(): String {
if (A.test1() != "OK") return "fail 1"
if (A.test2() != "OK") return "fail 2"
if (A.test3() != "1OK") return "fail 3"
if (A.test4() != "1OK") return "fail 4"
if (with(A) {"1".test5()} != "1OK") return "fail 5"
return "OK"
}
@@ -0,0 +1,11 @@
package test;
class Test {
public static void main(String[] args) {
A.test1();
A.test2();
A.test4("");
}
}
@@ -0,0 +1,36 @@
package test
class A {
class object {
val b: String = "OK"
platformStatic fun test1() {
b
test2()
test3()
"".test4()
}
platformStatic fun test2() {
b
}
fun test3() {
}
platformStatic fun String.test4() {
b
}
}
}
fun main(args: Array<String>) {
A.test1()
A.test2()
A.test3()
with(A) {
A.test1()
}
}
@@ -0,0 +1,11 @@
package test;
class Test {
public static void main(String[] args) {
A.test1();
A.test2();
A.test4("");
}
}
@@ -0,0 +1,34 @@
package test
object A {
val b: String = "OK"
platformStatic fun test1() {
b
test2()
test3()
"".test4()
}
platformStatic fun test2() {
b
}
fun test3() {
}
platformStatic fun String.test4() {
b
}
}
fun main(args: Array<String>) {
A.test1()
A.test2()
A.test3()
with(A) {
A.test1()
}
}
@@ -6062,6 +6062,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("traitWithPrivateExtension.kt")
public void testTraitWithPrivateExtension() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/traitWithPrivateExtension.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/codegen/box/traits/withRequired")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
@@ -32,10 +32,11 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxWithJava")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.PlatformStatic.class})
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInBoxWithJava() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava"), Pattern.compile("^([^\\.]+)$"), false);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava"), Pattern.compile("^([^\\.]+)$"), true);
}
@TestMetadata("referenceToJavaFieldOfKotlinSubclass")
@@ -44,4 +45,33 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava(fileName);
}
@TestMetadata("compiler/testData/codegen/boxWithJava/platformStatic")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({})
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public static class PlatformStatic extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInPlatformStatic() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava/platformStatic"), Pattern.compile("^([^\\.]+)$"), true);
}
@TestMetadata("annotations")
public void testAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/platformStatic/annotations/");
doTestWithJava(fileName);
}
@TestMetadata("classObject")
public void testClassObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/platformStatic/classObject/");
doTestWithJava(fileName);
}
@TestMetadata("object")
public void testObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/platformStatic/object/");
doTestWithJava(fileName);
}
}
}
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxWithStdlib")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.BoxingOptimization.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.DefaultArguments.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, BlackBoxWithStdlibCodegenTestGenerated.WhenEnumOptimization.class, BlackBoxWithStdlibCodegenTestGenerated.WhenStringOptimization.class})
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.BoxingOptimization.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.DefaultArguments.class, BlackBoxWithStdlibCodegenTestGenerated.Evaluate.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.HashPMap.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformNames.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformStatic.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Reflection.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class, BlackBoxWithStdlibCodegenTestGenerated.ToArray.class, BlackBoxWithStdlibCodegenTestGenerated.Vararg.class, BlackBoxWithStdlibCodegenTestGenerated.When.class, BlackBoxWithStdlibCodegenTestGenerated.WhenEnumOptimization.class, BlackBoxWithStdlibCodegenTestGenerated.WhenStringOptimization.class})
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInBoxWithStdlib() throws Exception {
@@ -1430,6 +1430,58 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public static class PlatformStatic extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInPlatformStatic() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/platformStatic"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("callableRef.kt")
public void testCallableRef() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("closure.kt")
public void testClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/closure.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("convention.kt")
public void testConvention() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/convention.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("default.kt")
public void testDefault() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/default.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("explicitObject.kt")
public void testExplicitObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/explicitObject.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("inline.kt")
public void testInline() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/inline.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/simple.kt");
doTestWithStdlib(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/ranges")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({Ranges.Expression.class, Ranges.Literal.class})
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("compiler/testData/compileJavaAgainstKotlin")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({CompileJavaAgainstKotlinTestGenerated.Class.class, CompileJavaAgainstKotlinTestGenerated.Method.class, CompileJavaAgainstKotlinTestGenerated.Property.class, CompileJavaAgainstKotlinTestGenerated.StaticFields.class})
@InnerTestClasses({CompileJavaAgainstKotlinTestGenerated.Class.class, CompileJavaAgainstKotlinTestGenerated.Method.class, CompileJavaAgainstKotlinTestGenerated.PlatformStatic.class, CompileJavaAgainstKotlinTestGenerated.Property.class, CompileJavaAgainstKotlinTestGenerated.StaticFields.class})
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAgainstKotlinTest {
public void testAllFilesPresentInCompileJavaAgainstKotlin() throws Exception {
@@ -420,6 +420,28 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
}
@TestMetadata("compiler/testData/compileJavaAgainstKotlin/platformStatic")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public static class PlatformStatic extends AbstractCompileJavaAgainstKotlinTest {
public void testAllFilesPresentInPlatformStatic() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/platformStatic"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("simpleClassObject.kt")
public void testSimpleClassObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/platformStatic/simpleClassObject.kt");
doTest(fileName);
}
@TestMetadata("simpleObject.kt")
public void testSimpleObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/platformStatic/simpleObject.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/compileJavaAgainstKotlin/property")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({Property.PlatformName.class})
@@ -334,7 +334,7 @@ public class KotlinBuiltIns {
}
@NotNull
public ClassDescriptor getPlatforStaticAnnotationClass() {
public ClassDescriptor getPlatformStaticAnnotationClass() {
return getBuiltInClassByName("platformStatic");
}
@@ -868,7 +868,7 @@ public class KotlinBuiltIns {
}
public boolean isPlatformStatic(@NotNull CallableDescriptor callableDescriptor) {
return containsAnnotation(callableDescriptor, getPlatforStaticAnnotationClass());
return containsAnnotation(callableDescriptor, getPlatformStaticAnnotationClass());
}
public boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
@@ -177,7 +177,7 @@ fun main(args: Array<String>) {
}
testClass(javaClass<AbstractBlackBoxCodegenTest>(), "BlackBoxWithJavaCodegenTestGenerated") {
model("codegen/boxWithJava", testMethod = "doTestWithJava", extension = null, recursive = false)
model("codegen/boxWithJava", testMethod = "doTestWithJava", extension = null, recursive = true, excludeParentDirs = true)
}
testClass(javaClass<AbstractBlackBoxCodegenTest>(), "BlackBoxWithStdlibCodegenTestGenerated") {