ClassDescriptorFromSoruce

getUnsubstitutedPrimaryConstructor is needed only when analyzing source.
Primary constructor only exists in source code.
This commit is contained in:
Stepan Koltsov
2012-06-16 00:22:22 +04:00
parent 2a91e15384
commit 0b697847b2
10 changed files with 51 additions and 27 deletions
@@ -529,7 +529,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
closure.superCall = (JetDelegatorToSuperCall) superCall;
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) superCall).getCalleeExpression().getConstructorReferenceExpression());
if (declarationDescriptor instanceof ClassDescriptor) {
declarationDescriptor = ((ClassDescriptor)declarationDescriptor).getUnsubstitutedPrimaryConstructor();
declarationDescriptor = ((ClassDescriptorFromSource) declarationDescriptor).getUnsubstitutedPrimaryConstructor();
}
ConstructorDescriptor superConstructor = (ConstructorDescriptor) declarationDescriptor;
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, OwnerKind.IMPLEMENTATION, typeMapper.hasThis0(superConstructor.getContainingDeclaration()));
@@ -41,9 +41,6 @@ public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor,
@NotNull
Set<ConstructorDescriptor> getConstructors();
@Nullable
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2012 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.descriptors;
import org.jetbrains.annotations.Nullable;
/**
* @author Stepan Koltsov
*/
public interface ClassDescriptorFromSource extends ClassDescriptor {
@Nullable
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
}
@@ -32,7 +32,7 @@ import java.util.*;
/**
* @author abreslav
*/
public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements ClassDescriptor {
public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements ClassDescriptorFromSource {
private TypeConstructor typeConstructor;
private JetScope memberDeclarations;
@@ -121,11 +121,6 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
return r;
}
@Override
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
return original.getUnsubstitutedPrimaryConstructor();
}
@Override
public List<AnnotationDescriptor> getAnnotations() {
return original.getAnnotations();
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -36,7 +37,9 @@ import java.util.Set;
/**
* @author abreslav
*/
public class MutableClassDescriptor extends MutableClassDescriptorLite {
public class MutableClassDescriptor extends MutableClassDescriptorLite implements ClassDescriptorFromSource {
private ConstructorDescriptor primaryConstructor;
private final Set<CallableMemberDescriptor> declaredCallableMembers = Sets.newHashSet();
private final Set<CallableMemberDescriptor> allCallableMembers = Sets.newHashSet(); // includes fake overrides
private final Set<PropertyDescriptor> properties = Sets.newHashSet();
@@ -84,6 +87,20 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
}
}
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor, BindingTrace trace) {
assert this.primaryConstructor == null : "Primary constructor assigned twice " + this;
this.primaryConstructor = constructorDescriptor;
addConstructor(constructorDescriptor, trace);
}
@Override
@Nullable
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
return primaryConstructor;
}
@NotNull
public Set<SimpleFunctionDescriptor> getFunctions() {
return functions;
@@ -38,7 +38,6 @@ import java.util.*;
*/
public class MutableClassDescriptorLite extends ClassDescriptorBase
implements WithDeferredResolve {
private ConstructorDescriptor primaryConstructor;
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
private List<AnnotationDescriptor> annotations = Lists.newArrayList();
@@ -206,18 +205,6 @@ public class MutableClassDescriptorLite extends ClassDescriptorBase
}
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor, BindingTrace trace) {
assert this.primaryConstructor == null : "Primary constructor assigned twice " + this;
this.primaryConstructor = constructorDescriptor;
addConstructor(constructorDescriptor, trace);
}
@Override
@Nullable
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
return primaryConstructor;
}
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, @Nullable BindingTrace trace) {
assert constructorDescriptor.getContainingDeclaration() == this;
constructors.add(constructorDescriptor);
@@ -377,7 +377,7 @@ public class DeclarationsChecker {
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration().getContainingDeclaration();
assert declaration instanceof ClassDescriptor;
ClassDescriptor enumClass = (ClassDescriptor) declaration;
ClassDescriptorFromSource enumClass = (ClassDescriptorFromSource) declaration;
assert enumClass.getKind() == ClassKind.ENUM_CLASS;
List<JetDelegationSpecifier> delegationSpecifiers = aClass.getDelegationSpecifiers();
@@ -35,7 +35,7 @@ import java.util.*;
/**
* @author abreslav
*/
public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDescriptor {
public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDescriptorFromSource {
private final ResolveSession resolveSession;
private final ClassMemberDeclarationProvider declarationProvider;
@@ -354,7 +354,7 @@ public final class BindingUtils {
public static ConstructorDescriptor getConstructor(@NotNull BindingContext bindingContext,
@NotNull JetClassOrObject declaration) {
ConstructorDescriptor primaryConstructor =
getClassDescriptor(bindingContext, declaration).getUnsubstitutedPrimaryConstructor();
((ClassDescriptorFromSource) getClassDescriptor(bindingContext, declaration)).getUnsubstitutedPrimaryConstructor();
assert primaryConstructor != null : "Traits do not have initialize methods.";
return primaryConstructor;
}