Disallow named arguments for SAM adapters
SAM adapters are Java functions, and named arguments are not allowed for Java functions #KT-5022 Fixed
This commit is contained in:
+6
-5
@@ -28,13 +28,14 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
private Boolean hasStableParameterNames = null;
|
||||
private Boolean hasSynthesizedParameterNames = null;
|
||||
|
||||
private JavaConstructorDescriptor(
|
||||
protected JavaConstructorDescriptor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary
|
||||
boolean isPrimary,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, original, annotations, isPrimary, Kind.DECLARATION);
|
||||
super(containingDeclaration, original, annotations, isPrimary, kind);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -43,7 +44,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary
|
||||
) {
|
||||
return new JavaConstructorDescriptor(containingDeclaration, null, annotations, isPrimary);
|
||||
return new JavaConstructorDescriptor(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +81,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
"kind: " + kind);
|
||||
}
|
||||
JavaConstructorDescriptor result =
|
||||
new JavaConstructorDescriptor((ClassDescriptor) newOwner, this, Annotations.EMPTY /* TODO */, isPrimary);
|
||||
new JavaConstructorDescriptor((ClassDescriptor) newOwner, this, Annotations.EMPTY /* TODO */, isPrimary, kind);
|
||||
result.setHasStableParameterNames(hasStableParameterNames());
|
||||
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
||||
return result;
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
private Boolean hasStableParameterNames = null;
|
||||
private Boolean hasSynthesizedParameterNames = null;
|
||||
|
||||
private JavaMethodDescriptor(
|
||||
protected JavaMethodDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@Nullable SimpleFunctionDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
|
||||
+2
-1
@@ -19,5 +19,6 @@ package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SynthesizedCallableMemberDescriptor;
|
||||
|
||||
public interface SamAdapterDescriptor<D extends FunctionDescriptor> extends FunctionDescriptor, SynthesizedCallableMemberDescriptor<D> {
|
||||
public interface SamAdapterDescriptor<D extends FunctionDescriptor>
|
||||
extends FunctionDescriptor, JavaCallableMemberDescriptor, SynthesizedCallableMemberDescriptor<D> {
|
||||
}
|
||||
|
||||
+4
-4
@@ -60,7 +60,7 @@ public class LazyJavaClassMemberScope(
|
||||
val constructor = resolveConstructor(jCtor, getContainingDeclaration(), jClass.isStatic())
|
||||
val samAdapter = resolveSamAdapter(constructor)
|
||||
if (samAdapter != null) {
|
||||
(samAdapter as ConstructorDescriptorImpl).setReturnType(containingDeclaration.getDefaultType())
|
||||
samAdapter.setReturnType(containingDeclaration.getDefaultType())
|
||||
listOf(constructor, samAdapter)
|
||||
}
|
||||
else
|
||||
@@ -108,13 +108,13 @@ public class LazyJavaClassMemberScope(
|
||||
return MethodSignatureData(effectiveSignature, superFunctions, propagated.getErrors() + effectiveSignature.getErrors())
|
||||
}
|
||||
|
||||
private fun resolveSamAdapter(original: ConstructorDescriptor): ConstructorDescriptor? {
|
||||
private fun resolveSamAdapter(original: JavaConstructorDescriptor): JavaConstructorDescriptor? {
|
||||
return if (SingleAbstractMethodUtils.isSamAdapterNecessary(original))
|
||||
SingleAbstractMethodUtils.createSamAdapterConstructor(original) as ConstructorDescriptor
|
||||
SingleAbstractMethodUtils.createSamAdapterConstructor(original) as JavaConstructorDescriptor
|
||||
else null
|
||||
}
|
||||
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): ConstructorDescriptor {
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): JavaConstructorDescriptor {
|
||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ false)
|
||||
|
||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
||||
|
||||
+4
-4
@@ -75,7 +75,7 @@ public abstract class LazyJavaMemberScope(
|
||||
(name: Name): Collection<FunctionDescriptor>
|
||||
->
|
||||
val methods = memberIndex().findMethodsByName(name)
|
||||
val functions = LinkedHashSet(
|
||||
val functions = LinkedHashSet<SimpleFunctionDescriptor>(
|
||||
methods.stream()
|
||||
// values() and valueOf() are added manually, see LazyJavaClassDescriptor::getClassObjectDescriptor()
|
||||
.filter{ m -> !DescriptorResolverUtils.shouldBeInEnumClassObject(m) }
|
||||
@@ -110,7 +110,7 @@ public abstract class LazyJavaMemberScope(
|
||||
abstract fun resolveMethodSignature(method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>,
|
||||
returnType: JetType, valueParameters: ResolvedValueParameters): MethodSignatureData
|
||||
|
||||
fun resolveMethodToFunctionDescriptor(method: JavaMethod, record: Boolean = true): SimpleFunctionDescriptor {
|
||||
fun resolveMethodToFunctionDescriptor(method: JavaMethod, record: Boolean = true): JavaMethodDescriptor {
|
||||
|
||||
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(_containingDeclaration, c.resolveAnnotations(method), method.getName())
|
||||
|
||||
@@ -216,9 +216,9 @@ public abstract class LazyJavaMemberScope(
|
||||
return ResolvedValueParameters(descriptors, synthesizedNames)
|
||||
}
|
||||
|
||||
private fun resolveSamAdapter(original: SimpleFunctionDescriptor): SimpleFunctionDescriptor? {
|
||||
private fun resolveSamAdapter(original: JavaMethodDescriptor): JavaMethodDescriptor? {
|
||||
return if (SingleAbstractMethodUtils.isSamAdapterNecessary(original))
|
||||
SingleAbstractMethodUtils.createSamAdapterFunction(original) as SimpleFunctionDescriptor
|
||||
SingleAbstractMethodUtils.createSamAdapterFunction(original) as JavaMethodDescriptor
|
||||
else null
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -17,22 +17,22 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.sam;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
||||
|
||||
/* package */ class SamAdapterConstructorDescriptor extends ConstructorDescriptorImpl
|
||||
implements SamAdapterDescriptor<ConstructorDescriptor> {
|
||||
private final ConstructorDescriptor declaration;
|
||||
/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor implements SamAdapterDescriptor<JavaConstructorDescriptor> {
|
||||
private final JavaConstructorDescriptor declaration;
|
||||
|
||||
public SamAdapterConstructorDescriptor(@NotNull ConstructorDescriptor declaration) {
|
||||
public SamAdapterConstructorDescriptor(@NotNull JavaConstructorDescriptor declaration) {
|
||||
super(declaration.getContainingDeclaration(), null, declaration.getAnnotations(), declaration.isPrimary(), Kind.SYNTHESIZED);
|
||||
this.declaration = declaration;
|
||||
setHasStableParameterNames(declaration.hasStableParameterNames());
|
||||
setHasSynthesizedParameterNames(declaration.hasSynthesizedParameterNames());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor getBaseForSynthesized() {
|
||||
public JavaConstructorDescriptor getBaseForSynthesized() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -17,22 +17,22 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.sam;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaMethodDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
||||
|
||||
/* package */ class SamAdapterFunctionDescriptor extends SimpleFunctionDescriptorImpl
|
||||
implements SamAdapterDescriptor<SimpleFunctionDescriptor> {
|
||||
private final SimpleFunctionDescriptor declaration;
|
||||
/* package */ class SamAdapterFunctionDescriptor extends JavaMethodDescriptor implements SamAdapterDescriptor<JavaMethodDescriptor> {
|
||||
private final JavaMethodDescriptor declaration;
|
||||
|
||||
public SamAdapterFunctionDescriptor(@NotNull SimpleFunctionDescriptor declaration) {
|
||||
public SamAdapterFunctionDescriptor(@NotNull JavaMethodDescriptor declaration) {
|
||||
super(declaration.getContainingDeclaration(), null, declaration.getAnnotations(), declaration.getName(), Kind.SYNTHESIZED);
|
||||
this.declaration = declaration;
|
||||
setHasStableParameterNames(declaration.hasStableParameterNames());
|
||||
setHasSynthesizedParameterNames(declaration.hasSynthesizedParameterNames());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor getBaseForSynthesized() {
|
||||
public JavaMethodDescriptor getBaseForSynthesized() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -22,9 +22,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -180,7 +178,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SamAdapterDescriptor<SimpleFunctionDescriptor> createSamAdapterFunction(@NotNull final SimpleFunctionDescriptor original) {
|
||||
public static SamAdapterDescriptor<JavaMethodDescriptor> createSamAdapterFunction(@NotNull final JavaMethodDescriptor original) {
|
||||
final SamAdapterFunctionDescriptor result = new SamAdapterFunctionDescriptor(original);
|
||||
return initSamAdapter(original, result, new FunctionInitializer() {
|
||||
@Override
|
||||
@@ -203,7 +201,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SamAdapterDescriptor<ConstructorDescriptor> createSamAdapterConstructor(@NotNull final ConstructorDescriptor original) {
|
||||
public static SamAdapterDescriptor<JavaConstructorDescriptor> createSamAdapterConstructor(@NotNull final JavaConstructorDescriptor original) {
|
||||
final SamAdapterConstructorDescriptor result = new SamAdapterConstructorDescriptor(original);
|
||||
return initSamAdapter(original, result, new FunctionInitializer() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user