Get rid of isConstructorOfStaticNestedClass()
This value can always be computed in ConstructorDescriptorImpl#initialize
This commit is contained in:
+3
-7
@@ -167,13 +167,9 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
public static ConstructorDescriptorImpl createConstructor(
|
||||
@NotNull ScriptDescriptor scriptDescriptor, @NotNull List<ValueParameterDescriptor> valueParameters
|
||||
) {
|
||||
return ConstructorDescriptorImpl.create(scriptDescriptor.getClassDescriptor(), Annotations.EMPTY, true, SourceElement.NO_SOURCE)
|
||||
.initialize(
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
valueParameters,
|
||||
Visibilities.PUBLIC,
|
||||
false
|
||||
);
|
||||
return ConstructorDescriptorImpl
|
||||
.create(scriptDescriptor.getClassDescriptor(), Annotations.EMPTY, true, SourceElement.NO_SOURCE)
|
||||
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1277,12 +1277,9 @@ public class DescriptorResolver {
|
||||
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
ConstructorDescriptorImpl constructor = constructorDescriptor.initialize(
|
||||
typeParameters,
|
||||
resolveValueParameters(
|
||||
constructorDescriptor,
|
||||
parameterScope,
|
||||
valueParameters, trace),
|
||||
resolveVisibilityFromModifiers(modifierList, getDefaultConstructorVisibility(classDescriptor)),
|
||||
isConstructorOfStaticNestedClass(constructorDescriptor));
|
||||
resolveValueParameters(constructorDescriptor, parameterScope, valueParameters, trace),
|
||||
resolveVisibilityFromModifiers(modifierList, getDefaultConstructorVisibility(classDescriptor))
|
||||
);
|
||||
if (isAnnotationClass(classDescriptor)) {
|
||||
CompileTimeConstantUtils.checkConstructorParametersType(valueParameters, trace);
|
||||
}
|
||||
|
||||
+1
-1
@@ -281,7 +281,7 @@ public class TaskPrioritizer {
|
||||
@NotNull Call call
|
||||
) {
|
||||
for (D extension : descriptors) {
|
||||
if (DescriptorUtils.isConstructorOfStaticNestedClass(extension)) {
|
||||
if (extension instanceof ConstructorDescriptor && DescriptorUtils.isStaticNestedClass(extension.getContainingDeclaration())) {
|
||||
// We don't want static nested classes' constructors to be resolved with expectedThisObject
|
||||
continue;
|
||||
}
|
||||
|
||||
+4
-5
@@ -56,7 +56,7 @@ public class LazyJavaClassMemberScope(
|
||||
internal val _constructors = c.storageManager.createLazyValue {
|
||||
jClass.getConstructors().flatMap {
|
||||
jCtor ->
|
||||
val constructor = resolveConstructor(jCtor, getContainingDeclaration(), jClass.isStatic())
|
||||
val constructor = resolveConstructor(jCtor, getContainingDeclaration())
|
||||
val samAdapter = resolveSamAdapter(constructor)
|
||||
if (samAdapter != null) {
|
||||
samAdapter.setReturnType(containingDeclaration.getDefaultType())
|
||||
@@ -113,7 +113,7 @@ public class LazyJavaClassMemberScope(
|
||||
else null
|
||||
}
|
||||
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): JavaConstructorDescriptor {
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor): JavaConstructorDescriptor {
|
||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||
classDescriptor, Annotations.EMPTY, /* isPrimary = */ false, c.sourceElementFactory.source(constructor)
|
||||
)
|
||||
@@ -125,8 +125,7 @@ public class LazyJavaClassMemberScope(
|
||||
constructorDescriptor.initialize(
|
||||
classDescriptor.getTypeConstructor().getParameters(),
|
||||
effectiveSignature.getValueParameters(),
|
||||
constructor.getVisibility(),
|
||||
isStaticClass
|
||||
constructor.getVisibility()
|
||||
)
|
||||
constructorDescriptor.setHasStableParameterNames(effectiveSignature.hasStableParameterNames())
|
||||
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
|
||||
@@ -157,7 +156,7 @@ public class LazyJavaClassMemberScope(
|
||||
else Collections.emptyList<ValueParameterDescriptor>()
|
||||
constructorDescriptor.setHasSynthesizedParameterNames(false)
|
||||
|
||||
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor), jClass.isStatic())
|
||||
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor))
|
||||
constructorDescriptor.setHasStableParameterNames(true)
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||
c.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
||||
|
||||
+1
-6
@@ -210,12 +210,7 @@ public class SingleAbstractMethodUtils {
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@Nullable JetType returnType
|
||||
) {
|
||||
result.initialize(
|
||||
typeParameters,
|
||||
valueParameters,
|
||||
original.getVisibility(),
|
||||
original.getExpectedThisObject() == ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER
|
||||
);
|
||||
result.initialize(typeParameters, valueParameters, original.getVisibility());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+9
-8
@@ -59,19 +59,20 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
public ConstructorDescriptorImpl initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isStatic
|
||||
@NotNull Visibility visibility
|
||||
) {
|
||||
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters,
|
||||
unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
||||
super.initialize(null, calculateExpectedThisObject(), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ReceiverParameterDescriptor getExpectedThisObject(@NotNull ClassDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
return ((ClassDescriptor) containingDeclaration).getThisAsReceiverParameter();
|
||||
private ReceiverParameterDescriptor calculateExpectedThisObject() {
|
||||
ClassDescriptor classDescriptor = getContainingDeclaration();
|
||||
if (classDescriptor.isInner()) {
|
||||
DeclarationDescriptor classContainer = classDescriptor.getContainingDeclaration();
|
||||
if (classContainer instanceof ClassDescriptor) {
|
||||
return ((ClassDescriptor) classContainer).getThisAsReceiverParameter();
|
||||
}
|
||||
}
|
||||
return NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DescriptorFactory {
|
||||
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass, @NotNull SourceElement source) {
|
||||
super(containingClass, null, Annotations.EMPTY, true, Kind.DECLARATION, source);
|
||||
initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||
getDefaultConstructorVisibility(containingClass), true);
|
||||
getDefaultConstructorVisibility(containingClass));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -315,10 +315,6 @@ public class DescriptorUtils {
|
||||
return receiverParameterDescriptor == null ? null : receiverParameterDescriptor.getType();
|
||||
}
|
||||
|
||||
public static boolean isConstructorOfStaticNestedClass(@Nullable CallableDescriptor descriptor) {
|
||||
return descriptor instanceof ConstructorDescriptor && isStaticNestedClass(descriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if descriptor is a class inside another class and does not have access to the outer class
|
||||
*/
|
||||
|
||||
@@ -233,7 +233,7 @@ public class ErrorUtils {
|
||||
|
||||
ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE);
|
||||
errorConstructor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||
Visibilities.INTERNAL, false);
|
||||
Visibilities.INTERNAL);
|
||||
JetScope memberScope = createErrorScope(getName().asString());
|
||||
errorConstructor.setReturnType(
|
||||
new ErrorTypeImpl(
|
||||
|
||||
+1
-3
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.descriptors.impl.PropertyGetterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertySetterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -192,8 +191,7 @@ public class MemberDeserializer {
|
||||
descriptor.initialize(
|
||||
classDescriptor.getTypeConstructor().getParameters(),
|
||||
local.getDeserializer().valueParameters(proto, AnnotatedCallableKind.FUNCTION),
|
||||
visibility(Flags.VISIBILITY.get(proto.getFlags())),
|
||||
DescriptorUtils.isConstructorOfStaticNestedClass(descriptor)
|
||||
visibility(Flags.VISIBILITY.get(proto.getFlags()))
|
||||
);
|
||||
descriptor.setReturnType(local.getTypeDeserializer().type(proto.getReturnType()));
|
||||
return descriptor;
|
||||
|
||||
@@ -85,7 +85,7 @@ private class MissingDependencyErrorClassDescriptor(containing: DeclarationDescr
|
||||
|
||||
{
|
||||
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE)
|
||||
emptyConstructor.initialize(listOf(), listOf(), Visibilities.INTERNAL, false)
|
||||
emptyConstructor.initialize(listOf(), listOf(), Visibilities.INTERNAL)
|
||||
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
|
||||
initialize(JetScope.EMPTY, setOf(emptyConstructor), emptyConstructor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user