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:
Alexander Udalov
2012-08-31 14:52:00 +04:00
parent 95dddadb36
commit 410922c58d
6 changed files with 45 additions and 32 deletions
@@ -378,4 +378,13 @@ public class CodegenUtil {
}
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,
JetDeclarationWithBody fun
) {
if (functionDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
throw new IllegalStateException("must not generate code for fake overrides");
}
checkMustGenerateCode(functionDescriptor);
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
@@ -171,9 +171,7 @@ public class PropertyCodegen extends GenerationStateAware {
}
public void generateDefaultGetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
throw new IllegalStateException("must not generate code for fake overrides");
}
checkMustGenerateCode(propertyDescriptor);
if (kind == OwnerKind.TRAIT_IMPL) {
return;
@@ -277,9 +275,7 @@ public class PropertyCodegen extends GenerationStateAware {
}
public void generateDefaultSetter(PropertyDescriptor propertyDescriptor, int flags, PsiElement origin) {
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
throw new IllegalStateException("must not generate code for fake overrides");
}
checkMustGenerateCode(propertyDescriptor);
if (kind == OwnerKind.TRAIT_IMPL) {
return;
@@ -38,10 +38,11 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
DECLARATION,
FAKE_OVERRIDE,
DELEGATION,
SYNTHESIZED
;
public boolean isReal() {
return this == DECLARATION || this == DELEGATION;
return this == DECLARATION || this == DELEGATION || this == SYNTHESIZED;
}
}
@@ -222,7 +222,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
superBuilder.addFunctionDescriptor(functionDescriptor);
functions.add(functionDescriptor);
if (functionDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
if (functionDescriptor.getKind().isReal()) {
declaredCallableMembers.add(functionDescriptor);
}
allCallableMembers.add(functionDescriptor);
@@ -260,7 +260,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
superBuilder.addPropertyDescriptor(propertyDescriptor);
properties.add(propertyDescriptor);
if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
if (propertyDescriptor.getKind().isReal()) {
declaredCallableMembers.add(propertyDescriptor);
}
allCallableMembers.add(propertyDescriptor);
@@ -26,6 +26,7 @@ import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -152,32 +153,40 @@ public class BindingContextUtils {
@Nullable
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
if (callable.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
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());
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
return null;
}
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) {
if (callable.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
List<PsiElement> r = new ArrayList<PsiElement>();
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
for (CallableMemberDescriptor overridden : overriddenDescriptors) {
r.addAll(callableDescriptorToDeclarations(context, overridden));
}
return r;
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
return Collections.emptyList();
}
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