Get rid of SAM_ADAPTER_FUNCTION_TO_ORIGINAL
Use SAM adapters hierarchy instead
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -43,7 +42,6 @@ public class JavaBindingContext {
|
||||
new BasicWritableSlice<DeclarationDescriptor, List<String>>(Slices.ONLY_REWRITE_TO_EQUAL, true);
|
||||
|
||||
public static final WritableSlice<SimpleFunctionDescriptor, ClassDescriptorFromJvmBytecode> SAM_CONSTRUCTOR_TO_INTERFACE = Slices.createSimpleSlice();
|
||||
public static final WritableSlice<FunctionDescriptor, FunctionDescriptor> SAM_ADAPTER_FUNCTION_TO_ORIGINAL = Slices.createSimpleSlice();
|
||||
|
||||
private JavaBindingContext() {
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.lang.resolve.java.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
|
||||
public interface SamAdapterDescriptor<D extends FunctionDescriptor> extends FunctionDescriptor {
|
||||
@NotNull
|
||||
D getDeclaration();
|
||||
}
|
||||
+1
-1
@@ -226,7 +226,7 @@ public final class JavaConstructorResolver {
|
||||
@Nullable
|
||||
private ConstructorDescriptor resolveSamAdapter(@NotNull ConstructorDescriptor original) {
|
||||
return isSamAdapterNecessary(original)
|
||||
? recordSamAdapter(original, createSamAdapterConstructor(original), trace)
|
||||
? (ConstructorDescriptor) recordSamAdapter(original, createSamAdapterConstructor(original), trace)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.java.JavaBindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaMethodDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSignatureData;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesPropagationData;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
||||
@@ -321,7 +322,7 @@ public final class JavaFunctionResolver {
|
||||
@Nullable
|
||||
private SimpleFunctionDescriptor resolveSamAdapter(@NotNull SimpleFunctionDescriptor original) {
|
||||
return isSamAdapterNecessary(original)
|
||||
? recordSamAdapter(original, createSamAdapterFunction(original), trace)
|
||||
? (SimpleFunctionDescriptor) recordSamAdapter(original, createSamAdapterFunction(original), trace)
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -388,9 +389,13 @@ public final class JavaFunctionResolver {
|
||||
return constructorFunction;
|
||||
}
|
||||
|
||||
static <F extends FunctionDescriptor> F recordSamAdapter(F original, F adapterFunction, BindingTrace trace) {
|
||||
trace.record(JavaBindingContext.SAM_ADAPTER_FUNCTION_TO_ORIGINAL, adapterFunction, original);
|
||||
trace.record(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, adapterFunction, original);
|
||||
return adapterFunction;
|
||||
@NotNull
|
||||
/* package */ static <F extends FunctionDescriptor> SamAdapterDescriptor<F> recordSamAdapter(
|
||||
@NotNull F original,
|
||||
@NotNull SamAdapterDescriptor<F> adapter,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
trace.record(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, adapter, original);
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.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.SamAdapterDescriptor;
|
||||
|
||||
/* package */ class SamAdapterConstructorDescriptor extends ConstructorDescriptorImpl
|
||||
implements SamAdapterDescriptor<ConstructorDescriptor> {
|
||||
private final ConstructorDescriptor declaration;
|
||||
|
||||
public SamAdapterConstructorDescriptor(@NotNull ConstructorDescriptor declaration) {
|
||||
super(declaration.getContainingDeclaration(), declaration.getAnnotations(), declaration.isPrimary(), Kind.SYNTHESIZED);
|
||||
this.declaration = declaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor getDeclaration() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.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.SamAdapterDescriptor;
|
||||
|
||||
/* package */ class SamAdapterFunctionDescriptor extends SimpleFunctionDescriptorImpl
|
||||
implements SamAdapterDescriptor<SimpleFunctionDescriptor> {
|
||||
private final SimpleFunctionDescriptor declaration;
|
||||
|
||||
public SamAdapterFunctionDescriptor(@NotNull SimpleFunctionDescriptor declaration) {
|
||||
super(declaration.getContainingDeclaration(), declaration.getAnnotations(), declaration.getName(), Kind.SYNTHESIZED);
|
||||
this.declaration = declaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor getDeclaration() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -56,18 +56,14 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
return null;
|
||||
}
|
||||
|
||||
SimpleFunctionDescriptor fun = declarationOrSynthesized.first;
|
||||
if (fun.getKind() != CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||
SimpleFunctionDescriptorImpl fun = (SimpleFunctionDescriptorImpl) declarationOrSynthesized.first.getOriginal();
|
||||
if (!(fun instanceof SamAdapterFunctionDescriptor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SimpleFunctionDescriptor originalOfSynthesized = ((SimpleFunctionDescriptorImpl) fun.getOriginal())
|
||||
.getOriginalOfSynthesized();
|
||||
if (originalOfSynthesized == null) {
|
||||
return null;
|
||||
}
|
||||
SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getDeclaration();
|
||||
|
||||
return ((SimpleFunctionDescriptor) originalOfSynthesized.substitute(TypeSubstitutor.create(declarationOrSynthesized.second)));
|
||||
return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.second)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+13
-24
@@ -22,12 +22,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSupertypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*;
|
||||
@@ -188,15 +188,9 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createSamAdapterFunction(@NotNull final SimpleFunctionDescriptor original) {
|
||||
final SimpleFunctionDescriptorImpl result = new SimpleFunctionDescriptorImpl(
|
||||
original.getContainingDeclaration(),
|
||||
original.getAnnotations(),
|
||||
original.getName(),
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
original
|
||||
);
|
||||
FunctionInitializer initializer = new FunctionInitializer() {
|
||||
public static SamAdapterDescriptor<SimpleFunctionDescriptor> createSamAdapterFunction(@NotNull final SimpleFunctionDescriptor original) {
|
||||
final SamAdapterFunctionDescriptor result = new SamAdapterFunctionDescriptor(original);
|
||||
return initSamAdapter(original, result, new FunctionInitializer() {
|
||||
@Override
|
||||
public void initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@@ -214,19 +208,13 @@ public class SingleAbstractMethodUtils {
|
||||
false
|
||||
);
|
||||
}
|
||||
};
|
||||
return initSamAdapter(original, result, initializer);
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptor createSamAdapterConstructor(@NotNull final ConstructorDescriptor original) {
|
||||
final ConstructorDescriptorImpl result = new ConstructorDescriptorImpl(
|
||||
original.getContainingDeclaration(),
|
||||
original.getAnnotations(),
|
||||
original.isPrimary(),
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED
|
||||
);
|
||||
FunctionInitializer initializer = new FunctionInitializer() {
|
||||
public static SamAdapterDescriptor<ConstructorDescriptor> createSamAdapterConstructor(@NotNull final ConstructorDescriptor original) {
|
||||
final SamAdapterConstructorDescriptor result = new SamAdapterConstructorDescriptor(original);
|
||||
return initSamAdapter(original, result, new FunctionInitializer() {
|
||||
@Override
|
||||
public void initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@@ -240,13 +228,13 @@ public class SingleAbstractMethodUtils {
|
||||
original.getExpectedThisObject() == ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER
|
||||
);
|
||||
}
|
||||
};
|
||||
return initSamAdapter(original, result, initializer);
|
||||
});
|
||||
}
|
||||
|
||||
private static <F extends FunctionDescriptor> F initSamAdapter(
|
||||
@NotNull
|
||||
private static <F extends FunctionDescriptor> SamAdapterDescriptor<F> initSamAdapter(
|
||||
@NotNull F original,
|
||||
@NotNull F adapter,
|
||||
@NotNull SamAdapterDescriptor<F> adapter,
|
||||
@NotNull FunctionInitializer initializer
|
||||
) {
|
||||
TypeParameters typeParameters = recreateAndInitializeTypeParameters(original.getTypeParameters(), adapter);
|
||||
@@ -276,6 +264,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
initializer.initialize(typeParameters.descriptors, valueParameters, returnType);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user