CallableMemberDescriptor.Kind.SYNTHESIZED
Introduce CallableMemberDescriptor.Kind.SYNTHESIZED for members which neither are declared nor do appear as overrides of anything, but rather are generated by the compiler.
This commit is contained in:
@@ -378,4 +378,13 @@ public class CodegenUtil {
|
|||||||
}
|
}
|
||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkMustGenerateCode(CallableMemberDescriptor descriptor) {
|
||||||
|
if (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
|
throw new IllegalStateException("must not generate code for fake overrides");
|
||||||
|
}
|
||||||
|
if (descriptor.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
|
throw new IllegalStateException("code generation for synthesized members should be handled separately");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
FunctionDescriptor functionDescriptor,
|
FunctionDescriptor functionDescriptor,
|
||||||
JetDeclarationWithBody fun
|
JetDeclarationWithBody fun
|
||||||
) {
|
) {
|
||||||
if (functionDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
checkMustGenerateCode(functionDescriptor);
|
||||||
throw new IllegalStateException("must not generate code for fake overrides");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
|
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
|
||||||
|
|
||||||
|
|||||||
@@ -171,9 +171,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateDefaultGetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
|
public void generateDefaultGetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
|
||||||
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
checkMustGenerateCode(propertyDescriptor);
|
||||||
throw new IllegalStateException("must not generate code for fake overrides");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
return;
|
return;
|
||||||
@@ -277,9 +275,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateDefaultSetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
|
public void generateDefaultSetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
|
||||||
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
checkMustGenerateCode(propertyDescriptor);
|
||||||
throw new IllegalStateException("must not generate code for fake overrides");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-1
@@ -38,10 +38,11 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
|
|||||||
DECLARATION,
|
DECLARATION,
|
||||||
FAKE_OVERRIDE,
|
FAKE_OVERRIDE,
|
||||||
DELEGATION,
|
DELEGATION,
|
||||||
|
SYNTHESIZED
|
||||||
;
|
;
|
||||||
|
|
||||||
public boolean isReal() {
|
public boolean isReal() {
|
||||||
return this == DECLARATION || this == DELEGATION;
|
return this == DECLARATION || this == DELEGATION || this == SYNTHESIZED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -222,7 +222,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
|||||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||||
superBuilder.addFunctionDescriptor(functionDescriptor);
|
superBuilder.addFunctionDescriptor(functionDescriptor);
|
||||||
functions.add(functionDescriptor);
|
functions.add(functionDescriptor);
|
||||||
if (functionDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
if (functionDescriptor.getKind().isReal()) {
|
||||||
declaredCallableMembers.add(functionDescriptor);
|
declaredCallableMembers.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
allCallableMembers.add(functionDescriptor);
|
allCallableMembers.add(functionDescriptor);
|
||||||
@@ -260,7 +260,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
|||||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
superBuilder.addPropertyDescriptor(propertyDescriptor);
|
superBuilder.addPropertyDescriptor(propertyDescriptor);
|
||||||
properties.add(propertyDescriptor);
|
properties.add(propertyDescriptor);
|
||||||
if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
if (propertyDescriptor.getKind().isReal()) {
|
||||||
declaredCallableMembers.add(propertyDescriptor);
|
declaredCallableMembers.add(propertyDescriptor);
|
||||||
}
|
}
|
||||||
allCallableMembers.add(propertyDescriptor);
|
allCallableMembers.add(propertyDescriptor);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
|||||||
import org.jetbrains.jet.util.slicedmap.Slices;
|
import org.jetbrains.jet.util.slicedmap.Slices;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -152,32 +153,40 @@ public class BindingContextUtils {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
||||||
if (callable.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
|
return null;
|
||||||
if (overriddenDescriptors.size() != 1) {
|
|
||||||
// TODO evil code
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"cannot find declaration: fake descriptor" +
|
|
||||||
" has more then one overridden descriptor: " + callable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return callableDescriptorToDeclaration(context, overriddenDescriptors.iterator().next());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return doGetDescriptorToDeclaration(context, callable.getOriginal());
|
if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
|
||||||
|
return doGetDescriptorToDeclaration(context, callable.getOriginal());
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
|
||||||
|
if (overriddenDescriptors.size() != 1) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"cannot find declaration: fake descriptor has more than one overridden descriptor: " + callable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return callableDescriptorToDeclaration(context, overriddenDescriptors.iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private static List<PsiElement> callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
private static List<PsiElement> callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
||||||
if (callable.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
List<PsiElement> r = new ArrayList<PsiElement>();
|
return Collections.emptyList();
|
||||||
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
|
|
||||||
for (CallableMemberDescriptor overridden : overriddenDescriptors) {
|
|
||||||
r.addAll(callableDescriptorToDeclarations(context, overridden));
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
PsiElement psiElement = doGetDescriptorToDeclaration(context, callable);
|
|
||||||
return psiElement != null ? Lists.newArrayList(psiElement) : Lists.<PsiElement>newArrayList();
|
if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
|
||||||
|
PsiElement psiElement = doGetDescriptorToDeclaration(context, callable);
|
||||||
|
return psiElement != null ? Lists.newArrayList(psiElement) : Lists.<PsiElement>newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PsiElement> r = new ArrayList<PsiElement>();
|
||||||
|
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
|
||||||
|
for (CallableMemberDescriptor overridden : overriddenDescriptors) {
|
||||||
|
r.addAll(callableDescriptorToDeclarations(context, overridden));
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
Reference in New Issue
Block a user