Pulled getUnsubstitutedPrimaryConstructor method to ClassDescriptor.
Removed ClassDescriptorFromSource. Implemented method in inheritors.
This commit is contained in:
+7
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
@@ -50,6 +51,12 @@ public class ClassDescriptorFromJvmBytecode extends MutableClassDescriptorLite {
|
||||
return scopeForConstructorResolve.getConstructors();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return scopeForConstructorResolve.getPrimaryConstructor();
|
||||
}
|
||||
|
||||
public void setScopeForConstructorResolve(@NotNull JavaClassNonStaticMembersScope scopeForConstructorResolve) {
|
||||
this.scopeForConstructorResolve = scopeForConstructorResolve;
|
||||
}
|
||||
|
||||
+25
-3
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.scope;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
@@ -27,6 +28,7 @@ import java.util.Collection;
|
||||
public final class JavaClassNonStaticMembersScope extends JavaClassMembersScope {
|
||||
|
||||
private Collection<ConstructorDescriptor> constructors = null;
|
||||
private ConstructorDescriptor primaryConstructor = null;
|
||||
@NotNull
|
||||
private final ClassDescriptor descriptor;
|
||||
|
||||
@@ -42,9 +44,29 @@ public final class JavaClassNonStaticMembersScope extends JavaClassMembersScope
|
||||
|
||||
@NotNull
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
if (constructors == null) {
|
||||
this.constructors = getResolver().resolveConstructors(declarationProvider, descriptor);
|
||||
}
|
||||
initConstructorsIfNeeded();
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConstructorDescriptor getPrimaryConstructor() {
|
||||
initConstructorsIfNeeded();
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
private void initConstructorsIfNeeded() {
|
||||
if (constructors == null) {
|
||||
constructors = getResolver().resolveConstructors(declarationProvider, descriptor);
|
||||
|
||||
for (ConstructorDescriptor constructor : constructors) {
|
||||
if (constructor.isPrimary()) {
|
||||
if (primaryConstructor != null) {
|
||||
throw new IllegalStateException(
|
||||
"Class has more than one primary constructor: " + primaryConstructor + "\n" + constructor);
|
||||
}
|
||||
primaryConstructor = constructor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,4 +75,7 @@ public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor,
|
||||
|
||||
@NotNull
|
||||
ReceiverParameterDescriptor getThisAsReceiverParameter();
|
||||
|
||||
@Nullable
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptorFromSource {
|
||||
public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptor {
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private JetScope memberDeclarations;
|
||||
|
||||
+7
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -196,4 +197,10 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
public JetScope getUnsubstitutedInnerClassesScope() {
|
||||
return original.getUnsubstitutedInnerClassesScope();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return original.getUnsubstitutedPrimaryConstructor();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -36,7 +36,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class MutableClassDescriptor extends MutableClassDescriptorLite implements ClassDescriptorFromSource {
|
||||
public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
|
||||
@@ -81,12 +81,13 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
|
||||
if (constructorDescriptor.isPrimary()) {
|
||||
boolean primary = constructorDescriptor.isPrimary();
|
||||
if (primary) {
|
||||
setUpScopeForInitializers(constructorDescriptor);
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : constructorDescriptor.getValueParameters()) {
|
||||
JetParameter parameter = (JetParameter) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), valueParameterDescriptor);
|
||||
assert parameter != null;
|
||||
if (parameter.getValOrVarNode() == null || !constructorDescriptor.isPrimary()) {
|
||||
if (parameter.getValOrVarNode() == null) {
|
||||
getWritableScopeForInitializers().addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ public class DeclarationsChecker {
|
||||
private void checkEnumEntry(JetClass aClass, ClassDescriptor classDescriptor) {
|
||||
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration().getContainingDeclaration();
|
||||
assert declaration instanceof ClassDescriptor;
|
||||
ClassDescriptorFromSource enumClass = (ClassDescriptorFromSource) declaration;
|
||||
ClassDescriptor enumClass = (ClassDescriptor) declaration;
|
||||
assert enumClass.getKind() == ClassKind.ENUM_CLASS;
|
||||
|
||||
List<JetDelegationSpecifier> delegationSpecifiers = aClass.getDelegationSpecifiers();
|
||||
|
||||
@@ -48,7 +48,7 @@ import static org.jetbrains.jet.lang.resolve.ModifiersChecker.*;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDescriptor, ClassDescriptorFromSource {
|
||||
public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDescriptor, ClassDescriptor {
|
||||
|
||||
private static final Predicate<Object> ONLY_ENUM_ENTRIES = Predicates.instanceOf(JetEnumEntry.class);
|
||||
private static final Predicate<JetType> VALID_SUPERTYPE = new Predicate<JetType>() {
|
||||
|
||||
@@ -282,8 +282,7 @@ public final class BindingUtils {
|
||||
|
||||
public static ConstructorDescriptor getConstructor(@NotNull BindingContext bindingContext,
|
||||
@NotNull JetClassOrObject declaration) {
|
||||
ConstructorDescriptor primaryConstructor =
|
||||
((ClassDescriptorFromSource) getClassDescriptor(bindingContext, declaration)).getUnsubstitutedPrimaryConstructor();
|
||||
ConstructorDescriptor primaryConstructor = getClassDescriptor(bindingContext, declaration).getUnsubstitutedPrimaryConstructor();
|
||||
assert primaryConstructor != null : message(declaration, "Traits do not have initialize methods");
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user