Top level functions inside module should be invoked using package$src class
This commit is contained in:
@@ -270,6 +270,14 @@ public class CodegenUtil {
|
|||||||
&& context.getContextKind() != OwnerKind.TRAIT_IMPL);
|
&& context.getContextKind() != OwnerKind.TRAIT_IMPL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCallInsideSameModuleAsDeclared(CallableMemberDescriptor declarationDescriptor, CodegenContext context) {
|
||||||
|
if (context == CodegenContext.STATIC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
DeclarationDescriptor contextDescriptor = context.getContextDescriptor();
|
||||||
|
return DescriptorUtils.isInSameModule(declarationDescriptor, contextDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasAbstractMembers(@NotNull ClassDescriptor classDescriptor) {
|
public static boolean hasAbstractMembers(@NotNull ClassDescriptor classDescriptor) {
|
||||||
return ContainerUtil.exists(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
|
return ContainerUtil.exists(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
|
||||||
new Condition<DeclarationDescriptor>() {
|
new Condition<DeclarationDescriptor>() {
|
||||||
|
|||||||
@@ -1721,6 +1721,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
PropertyDescriptor initialDescriptor = propertyDescriptor;
|
PropertyDescriptor initialDescriptor = propertyDescriptor;
|
||||||
propertyDescriptor = initialDescriptor.getOriginal();
|
propertyDescriptor = initialDescriptor.getOriginal();
|
||||||
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
|
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
|
||||||
|
boolean isInsideModule = isCallInsideSameModuleAsDeclared(propertyDescriptor, context);
|
||||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||||
Method getter = null;
|
Method getter = null;
|
||||||
Method setter = null;
|
Method setter = null;
|
||||||
@@ -1794,7 +1795,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
boolean isInterface;
|
boolean isInterface;
|
||||||
if (isStatic) {
|
if (isStatic) {
|
||||||
isInterface = overridesTrait;
|
isInterface = overridesTrait;
|
||||||
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind());
|
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind(), isInsideModule);
|
||||||
|
|
||||||
getterInvokeOpcode = INVOKESTATIC;
|
getterInvokeOpcode = INVOKESTATIC;
|
||||||
setterInvokeOpcode = INVOKESTATIC;
|
setterInvokeOpcode = INVOKESTATIC;
|
||||||
@@ -1807,7 +1808,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
getterInvokeOpcode = getOpcodeForPropertyDescriptorWithoutAccessor(propertyDescriptor);
|
getterInvokeOpcode = getOpcodeForPropertyDescriptorWithoutAccessor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetter(), isSuper, isInsideClass, contextKind());
|
callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetter(), isSuper, isInsideClass, isInsideModule, contextKind());
|
||||||
getterInvokeOpcode = callableGetter.getInvokeOpcode();
|
getterInvokeOpcode = callableGetter.getInvokeOpcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1815,13 +1816,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
setterInvokeOpcode = getOpcodeForPropertyDescriptorWithoutAccessor(propertyDescriptor);
|
setterInvokeOpcode = getOpcodeForPropertyDescriptorWithoutAccessor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableSetter = typeMapper.mapToCallableMethod(propertyDescriptor.getSetter(), isSuper, isInsideClass, contextKind());
|
callableSetter = typeMapper.mapToCallableMethod(propertyDescriptor.getSetter(), isSuper, isInsideClass, isInsideModule, contextKind());
|
||||||
setterInvokeOpcode = callableSetter.getInvokeOpcode();
|
setterInvokeOpcode = callableSetter.getInvokeOpcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
CallableMethod callableMethod = callableGetter != null ? callableGetter : callableSetter;
|
CallableMethod callableMethod = callableGetter != null ? callableGetter : callableSetter;
|
||||||
if (callableMethod == null) {
|
if (callableMethod == null) {
|
||||||
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind());
|
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind(), isInsideModule);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
owner = isFakeOverride && !overridesTrait && !isInterface(initialDescriptor.getContainingDeclaration())
|
owner = isFakeOverride && !overridesTrait && !isInterface(initialDescriptor.getContainingDeclaration())
|
||||||
@@ -2034,7 +2035,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
callableMethod = typeMapper.asCallableMethod(invoke);
|
callableMethod = typeMapper.asCallableMethod(invoke);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableMethod = typeMapper.mapToCallableMethod(fd, superCall, isCallInsideSameClassAsDeclared(fd, context), OwnerKind.IMPLEMENTATION);
|
callableMethod = typeMapper.mapToCallableMethod(fd, superCall,
|
||||||
|
isCallInsideSameClassAsDeclared(fd, context),
|
||||||
|
isCallInsideSameModuleAsDeclared(fd, context),
|
||||||
|
OwnerKind.IMPLEMENTATION);
|
||||||
}
|
}
|
||||||
return callableMethod;
|
return callableMethod;
|
||||||
}
|
}
|
||||||
@@ -3105,6 +3109,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
descriptor,
|
descriptor,
|
||||||
false,
|
false,
|
||||||
isCallInsideSameClassAsDeclared(descriptor, context),
|
isCallInsideSameClassAsDeclared(descriptor, context),
|
||||||
|
isCallInsideSameModuleAsDeclared(descriptor, context),
|
||||||
OwnerKind.IMPLEMENTATION);
|
OwnerKind.IMPLEMENTATION);
|
||||||
invokeMethodWithArguments(callableMethod, expression, StackValue.none());
|
invokeMethodWithArguments(callableMethod, expression, StackValue.none());
|
||||||
return type;
|
return type;
|
||||||
@@ -3207,6 +3212,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
operationDescriptor,
|
operationDescriptor,
|
||||||
false,
|
false,
|
||||||
isCallInsideSameClassAsDeclared(operationDescriptor, context),
|
isCallInsideSameClassAsDeclared(operationDescriptor, context),
|
||||||
|
isCallInsideSameModuleAsDeclared(operationDescriptor, context),
|
||||||
OwnerKind.IMPLEMENTATION);
|
OwnerKind.IMPLEMENTATION);
|
||||||
|
|
||||||
boolean isGetter = accessor.getSignature().getAsmMethod().getName().equals("get");
|
boolean isGetter = accessor.getSignature().getAsmMethod().getName().equals("get");
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
functionDescriptor,
|
functionDescriptor,
|
||||||
false,
|
false,
|
||||||
isCallInsideSameClassAsDeclared(functionDescriptor, owner),
|
isCallInsideSameClassAsDeclared(functionDescriptor, owner),
|
||||||
|
isCallInsideSameModuleAsDeclared(functionDescriptor, owner),
|
||||||
owner.getContextKind()).getSignature();
|
owner.getContextKind()).getSignature();
|
||||||
generateMethod(f, method, true, null, functionDescriptor);
|
generateMethod(f, method, true, null, functionDescriptor);
|
||||||
}
|
}
|
||||||
@@ -345,7 +346,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
MethodVisitor mv
|
MethodVisitor mv
|
||||||
) {
|
) {
|
||||||
if (jvmSignature == null) {
|
if (jvmSignature == null) {
|
||||||
jvmSignature = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false, false, OwnerKind.IMPLEMENTATION).getSignature();
|
jvmSignature = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false, false, false, OwnerKind.IMPLEMENTATION).getSignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
|
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
|
||||||
|
|||||||
@@ -791,7 +791,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
typeMapper.mapSignature(original.getName(), original).getAsmMethod();
|
typeMapper.mapSignature(original.getName(), original).getAsmMethod();
|
||||||
Type[] argTypes = method.getArgumentTypes();
|
Type[] argTypes = method.getArgumentTypes();
|
||||||
|
|
||||||
String owner = typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName();
|
String owner = typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION, isCallInsideSameModuleAsDeclared(original, context)).getInternalName();
|
||||||
MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, bridge.getName().getName(),
|
MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, bridge.getName().getName(),
|
||||||
method.getDescriptor(), null, null);
|
method.getDescriptor(), null, null);
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
@@ -849,12 +849,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
iv.load(0, OBJECT_TYPE);
|
iv.load(0, OBJECT_TYPE);
|
||||||
boolean hasBackingField = Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, original));
|
boolean hasBackingField = Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, original));
|
||||||
|
boolean isInsideModule = isCallInsideSameModuleAsDeclared(original, context);
|
||||||
if (original.getVisibility() == Visibilities.PRIVATE && hasBackingField) {
|
if (original.getVisibility() == Visibilities.PRIVATE && hasBackingField) {
|
||||||
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(),
|
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION, isInsideModule).getInternalName(), original.getName().getName(),
|
||||||
originalMethod.getReturnType().getDescriptor());
|
originalMethod.getReturnType().getDescriptor());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(),
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION, isInsideModule).getInternalName(),
|
||||||
originalMethod.getName(), originalMethod.getDescriptor());
|
originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,12 +892,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
//noinspection AssignmentToForLoopParameter
|
//noinspection AssignmentToForLoopParameter
|
||||||
reg += argType.getSize();
|
reg += argType.getSize();
|
||||||
}
|
}
|
||||||
|
boolean isInsideModule = isCallInsideSameModuleAsDeclared(original, context);
|
||||||
if (original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL) {
|
if (original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL) {
|
||||||
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(),
|
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION, isInsideModule).getInternalName(), original.getName().getName(),
|
||||||
originalMethod.getArgumentTypes()[0].getDescriptor());
|
originalMethod.getArgumentTypes()[0].getDescriptor());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(),
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION, isInsideModule).getInternalName(),
|
||||||
originalMethod.getName(), originalMethod.getDescriptor());
|
originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1354,6 +1356,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
inheritedFun,
|
inheritedFun,
|
||||||
false,
|
false,
|
||||||
isCallInsideSameClassAsDeclared(inheritedFun, context),
|
isCallInsideSameClassAsDeclared(inheritedFun, context),
|
||||||
|
isCallInsideSameModuleAsDeclared(inheritedFun, context),
|
||||||
OwnerKind.IMPLEMENTATION).getSignature();
|
OwnerKind.IMPLEMENTATION).getSignature();
|
||||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||||
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
||||||
@@ -1588,7 +1591,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
codegen.gen(initializer, type);
|
codegen.gen(initializer, type);
|
||||||
// @todo write directly to the field. Fix test excloset.jet::test6
|
// @todo write directly to the field. Fix test excloset.jet::test6
|
||||||
JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
|
JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION, isCallInsideSameModuleAsDeclared(propertyDescriptor, codegen.context));
|
||||||
Type propType = typeMapper.mapType(jetType);
|
Type propType = typeMapper.mapType(jetType);
|
||||||
StackValue.property(propertyDescriptor, owner, owner,
|
StackValue.property(propertyDescriptor, owner, owner,
|
||||||
propType, false, false, false, null, null, 0, 0, state).store(propType, iv);
|
propType, false, false, false, null, null, 0, 0, state).store(propType, iv);
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
iv.visitFieldInsn(
|
iv.visitFieldInsn(
|
||||||
kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD,
|
kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD,
|
||||||
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
typeMapper.getOwner(propertyDescriptor, kind, isCallInsideSameModuleAsDeclared(propertyDescriptor, context)).getInternalName(),
|
||||||
propertyDescriptor.getName().getName(),
|
propertyDescriptor.getName().getName(),
|
||||||
type.getDescriptor());
|
type.getDescriptor());
|
||||||
iv.areturn(type);
|
iv.areturn(type);
|
||||||
@@ -296,7 +296,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
iv.load(paramCode, type);
|
iv.load(paramCode, type);
|
||||||
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD,
|
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD,
|
||||||
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
typeMapper.getOwner(propertyDescriptor, kind, isCallInsideSameModuleAsDeclared(propertyDescriptor, context)).getInternalName(),
|
||||||
propertyDescriptor.getName().getName(),
|
propertyDescriptor.getName().getName(),
|
||||||
type.getDescriptor());
|
type.getDescriptor());
|
||||||
|
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
public JvmClassName getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
|
||||||
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
||||||
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||||
return jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration, descriptor);
|
return jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
@@ -122,7 +122,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JvmClassName jvmClassNameForNamespace(@NotNull NamespaceDescriptor namespace, @NotNull DeclarationDescriptor descriptor) {
|
private JvmClassName jvmClassNameForNamespace(
|
||||||
|
@NotNull NamespaceDescriptor namespace,
|
||||||
|
@NotNull DeclarationDescriptor descriptor,
|
||||||
|
boolean insideModule
|
||||||
|
) {
|
||||||
|
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
|
|
||||||
@@ -147,15 +151,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
r.append("/");
|
r.append("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof PropertyDescriptor) {
|
JetFile file = BindingContextUtils.getContainingFile(bindingContext, descriptor);
|
||||||
JetFile file = BindingContextUtils.getContainingFile(bindingContext, descriptor);
|
if (insideModule && file != null) {
|
||||||
if (file != null) {
|
String internalName = NamespaceCodegen.getNamespacePartInternalName(file);
|
||||||
String internalName = NamespaceCodegen.getNamespacePartInternalName(file);
|
r.append(internalName.substring(r.length()));
|
||||||
r.append(internalName.substring(r.length()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
r.append(PackageClassUtils.getPackageClassName(namespace.getFqName()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
r.append(PackageClassUtils.getPackageClassName(namespace.getFqName()));
|
r.append(PackageClassUtils.getPackageClassName(namespace.getFqName()));
|
||||||
@@ -450,6 +449,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
@NotNull FunctionDescriptor functionDescriptor,
|
@NotNull FunctionDescriptor functionDescriptor,
|
||||||
boolean superCall,
|
boolean superCall,
|
||||||
boolean isInsideClass,
|
boolean isInsideClass,
|
||||||
|
boolean isInsideModule,
|
||||||
OwnerKind kind
|
OwnerKind kind
|
||||||
) {
|
) {
|
||||||
final DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
final DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
||||||
@@ -464,7 +464,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
JvmClassName thisClass;
|
JvmClassName thisClass;
|
||||||
if (functionParent instanceof NamespaceDescriptor) {
|
if (functionParent instanceof NamespaceDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent, functionDescriptor);
|
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent, functionDescriptor, isInsideModule);
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
thisClass = null;
|
thisClass = null;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun Int.test1() {}
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
1.test1()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC _DefaultPackage\$src\$1\$[\-]*[0-9]*\.test1 \(I\)V
|
||||||
|
// 1 INVOKESTATIC _DefaultPackage\$src\$1\$[\-]*[0-9]*\.test2 \(\)V
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
fun test1() {}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC a/APackage\$src\$1\$[\-]*[0-9]*\.test1 \(\)V
|
||||||
|
// 1 INVOKESTATIC b/BPackage\$src\$2\$[\-]*[0-9]*\.test2 \(\)V
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
import a.test1
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
test1()
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test1() {}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC _DefaultPackage\$src\$1\$[\-]*[0-9]*\.test1 \(\)V
|
||||||
|
// 1 INVOKESTATIC _DefaultPackage\$src\$2\$[\-]*[0-9]*\.test2 \(\)V
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun test2() {
|
||||||
|
test1()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun test1() {}
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
test1()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC _DefaultPackage\$src\$1\$[\-]*[0-9]*\.test1 \(\)V
|
||||||
|
// 1 INVOKESTATIC _DefaultPackage\$src\$1\$[\-]*[0-9]*\.test2 \(\)V
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
val prop = 1
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC a/APackage\$src\$1\$[\-]*[0-9]*\.getProp \(\)I
|
||||||
|
// 1 GETSTATIC a/APackage\$src\$1\$[\-]*[0-9]*\.prop \: I
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
import a.prop
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
prop
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
val prop: Int = 0
|
||||||
|
get() {
|
||||||
|
return $prop + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC a/APackage\$src\$1\$[\-]*[0-9]*\.getProp \(\)I
|
||||||
|
// 1 GETSTATIC a/APackage\$src\$1\$[\-]*[0-9]*\.prop \: I
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
import a.prop
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
prop
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
import a.test1
|
||||||
|
import a.prop
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
test1()
|
||||||
|
prop
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1 a/APackage\.test1 \(\)V
|
||||||
|
// 1 a/APackage\.getProp \(\)I
|
||||||
Binary file not shown.
@@ -38,14 +38,14 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase {
|
|||||||
countAndCompareActualOccurrences(expected);
|
countAndCompareActualOccurrences(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countAndCompareActualOccurrences(@NotNull List<OccurrenceInfo> expectedOccurrences) {
|
protected void countAndCompareActualOccurrences(@NotNull List<OccurrenceInfo> expectedOccurrences) {
|
||||||
StringBuilder expected = new StringBuilder();
|
StringBuilder expected = new StringBuilder();
|
||||||
StringBuilder actual = new StringBuilder();
|
StringBuilder actual = new StringBuilder();
|
||||||
|
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
for (OccurrenceInfo info : expectedOccurrences) {
|
for (OccurrenceInfo info : expectedOccurrences) {
|
||||||
expected.append(info.numberOfOccurrences).append(" ").append(info.needle).append("\n");
|
expected.append(info.numberOfOccurrences).append(" ").append(info.needle).append("\n");
|
||||||
int actualCount = StringUtil.getOccurrenceCount(text, info.needle);
|
int actualCount = StringUtil.findMatches(text, Pattern.compile("(" + info.needle + ")")).size();
|
||||||
actual.append(actualCount).append(" ").append(info.needle).append("\n");
|
actual.append(actualCount).append(" ").append(info.needle).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<OccurrenceInfo> readExpectedOccurrences(@NotNull String filename) throws Exception {
|
protected List<OccurrenceInfo> readExpectedOccurrences(@NotNull String filename) throws Exception {
|
||||||
List<OccurrenceInfo> result = new ArrayList<OccurrenceInfo>();
|
List<OccurrenceInfo> result = new ArrayList<OccurrenceInfo>();
|
||||||
String[] lines = FileUtil.loadFile(new File(filename), true).split("\n");
|
String[] lines = FileUtil.loadFile(new File(filename), true).split("\n");
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class OccurrenceInfo {
|
protected static class OccurrenceInfo {
|
||||||
private final int numberOfOccurrences;
|
private final int numberOfOccurrences;
|
||||||
private final String needle;
|
private final String needle;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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 com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.util.Processor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.ConfigurationKind;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.TestJdkKind;
|
||||||
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractTopLevelMembersInvocationTest extends AbstractBytecodeTextTest {
|
||||||
|
|
||||||
|
public void doTest(@NotNull String filename) throws Exception {
|
||||||
|
final List<String> sourceFiles = new ArrayList<String>(2);
|
||||||
|
final List<File> classPath = new ArrayList<File>(1);
|
||||||
|
|
||||||
|
FileUtil.processFilesRecursively(new File(filename), new Processor<File>() {
|
||||||
|
@Override
|
||||||
|
public boolean process(File file) {
|
||||||
|
if (file.getName().endsWith(".kt")) {
|
||||||
|
sourceFiles.add(file.getPath().substring("compiler/testData/codegen/".length()));
|
||||||
|
}
|
||||||
|
else if (file.getName().endsWith(".jar")) {
|
||||||
|
classPath.add(file);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert !sourceFiles.isEmpty() : getTestName(true) + " should contains at least one .kt file";
|
||||||
|
Collections.sort(sourceFiles);
|
||||||
|
|
||||||
|
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, Arrays.asList(JetTestUtils.getAnnotationsJar()), classPath));
|
||||||
|
|
||||||
|
loadFiles(sourceFiles.toArray(new String[sourceFiles.size()]));
|
||||||
|
|
||||||
|
List<OccurrenceInfo> expected = readExpectedOccurrences("compiler/testData/codegen/" + sourceFiles.get(0));
|
||||||
|
countAndCompareActualOccurrences(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -159,7 +159,8 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testCastOnStack() throws Exception {
|
public void testCastOnStack() throws Exception {
|
||||||
loadText("fun foo(): Double = System.currentTimeMillis().toDouble()");
|
loadText("fun foo(): Double = System.currentTimeMillis().toDouble()");
|
||||||
final Method main = generateFunction();
|
final Class<?> mainClass = generateNamespaceSrcClass();
|
||||||
|
final Method main = mainClass.getDeclaredMethod("foo");
|
||||||
double currentTimeMillis = (double) System.currentTimeMillis();
|
double currentTimeMillis = (double) System.currentTimeMillis();
|
||||||
double result = (Double) main.invoke(null);
|
double result = (Double) main.invoke(null);
|
||||||
double delta = Math.abs(currentTimeMillis - result);
|
double delta = Math.abs(currentTimeMillis - result);
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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 junit.framework.Assert;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.test.InnerTestClasses;
|
||||||
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.codegen.AbstractTopLevelMembersInvocationTest;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("compiler/testData/codegen/topLevelMemberInvocation")
|
||||||
|
public class TopLevelMembersInvocationTestGenerated extends AbstractTopLevelMembersInvocationTest {
|
||||||
|
public void testAllFilesPresentInTopLevelMemberInvocation() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/topLevelMemberInvocation"), Pattern.compile("^(.+)$"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/extensionFunction");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionDifferentPackage")
|
||||||
|
public void testFunctionDifferentPackage() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/functionDifferentPackage");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionInMultiFileNamespace")
|
||||||
|
public void testFunctionInMultiFileNamespace() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/functionInMultiFileNamespace");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionSamePackage")
|
||||||
|
public void testFunctionSamePackage() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/functionSamePackage");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("property")
|
||||||
|
public void testProperty() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/property");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propertyWithGetter")
|
||||||
|
public void testPropertyWithGetter() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/propertyWithGetter");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("twoModules")
|
||||||
|
public void testTwoModules() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/topLevelMemberInvocation/twoModules");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
|
|||||||
import org.jetbrains.jet.checkers.AbstractJetPsiCheckerTest;
|
import org.jetbrains.jet.checkers.AbstractJetPsiCheckerTest;
|
||||||
import org.jetbrains.jet.codegen.AbstractBytecodeTextTest;
|
import org.jetbrains.jet.codegen.AbstractBytecodeTextTest;
|
||||||
import org.jetbrains.jet.codegen.AbstractCheckLocalVariablesTableTest;
|
import org.jetbrains.jet.codegen.AbstractCheckLocalVariablesTableTest;
|
||||||
|
import org.jetbrains.jet.codegen.AbstractTopLevelMembersInvocationTest;
|
||||||
import org.jetbrains.jet.codegen.defaultConstructor.AbstractDefaultConstructorCodegenTest;
|
import org.jetbrains.jet.codegen.defaultConstructor.AbstractDefaultConstructorCodegenTest;
|
||||||
import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest;
|
import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest;
|
||||||
import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
|
import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
|
||||||
@@ -105,6 +106,13 @@ public class GenerateTests {
|
|||||||
testModel("compiler/testData/codegen/bytecodeText")
|
testModel("compiler/testData/codegen/bytecodeText")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
generateTest(
|
||||||
|
"compiler/tests/",
|
||||||
|
"TopLevelMembersInvocationTestGenerated",
|
||||||
|
AbstractTopLevelMembersInvocationTest.class,
|
||||||
|
new SimpleTestClassModel(new File("compiler/testData/codegen/topLevelMemberInvocation"), false, Pattern.compile("^(.+)$"), "doTest")
|
||||||
|
);
|
||||||
|
|
||||||
generateTest(
|
generateTest(
|
||||||
"compiler/tests/",
|
"compiler/tests/",
|
||||||
"CheckLocalVariablesTableTestGenerated",
|
"CheckLocalVariablesTableTestGenerated",
|
||||||
|
|||||||
Reference in New Issue
Block a user