JavaCallableMemberDescriptor.hasSynthesizedParameterNames() introduced

This commit is contained in:
Andrey Breslav
2014-04-29 15:37:06 +04:00
parent 9482706b81
commit 4181bcc319
6 changed files with 48 additions and 9 deletions
@@ -19,4 +19,5 @@ package org.jetbrains.jet.lang.resolve.java.descriptor;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
public interface JavaCallableMemberDescriptor extends CallableMemberDescriptor {
boolean hasSynthesizedParameterNames();
}
@@ -24,8 +24,9 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
private Boolean hasStableParameterNames;
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl implements JavaCallableMemberDescriptor {
private Boolean hasStableParameterNames = null;
private Boolean hasSynthesizedParameterNames = null;
private JavaConstructorDescriptor(
@NotNull ClassDescriptor containingDeclaration,
@@ -55,6 +56,16 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
this.hasStableParameterNames = hasStableParameterNames;
}
@Override
public boolean hasSynthesizedParameterNames() {
assert hasSynthesizedParameterNames != null : "hasSynthesizedParameterNames was not set: " + this;
return hasSynthesizedParameterNames;
}
public void setHasSynthesizedParameterNames(boolean hasSynthesizedParameterNames) {
this.hasSynthesizedParameterNames = hasSynthesizedParameterNames;
}
@NotNull
@Override
protected JavaConstructorDescriptor createSubstitutedCopy(
@@ -71,6 +82,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
JavaConstructorDescriptor result =
new JavaConstructorDescriptor((ClassDescriptor) newOwner, this, Annotations.EMPTY /* TODO */, isPrimary);
result.setHasStableParameterNames(hasStableParameterNames());
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
return result;
}
}
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implements JavaCallableMemberDescriptor {
private Boolean hasStableParameterNames = null;
private Boolean hasSynthesizedParameterNames = null;
private JavaMethodDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@@ -58,6 +59,16 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
this.hasStableParameterNames = hasStableParameterNames;
}
@Override
public boolean hasSynthesizedParameterNames() {
assert hasSynthesizedParameterNames != null : "hasSynthesizedParameterNames was not set: " + this;
return hasSynthesizedParameterNames;
}
public void setHasSynthesizedParameterNames(boolean hasSynthesizedParameterNames) {
this.hasSynthesizedParameterNames = hasSynthesizedParameterNames;
}
@NotNull
@Override
protected FunctionDescriptorImpl createSubstitutedCopy(
@@ -73,6 +84,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
kind
);
result.setHasStableParameterNames(hasStableParameterNames());
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
return result;
}
}
@@ -34,4 +34,9 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
) {
super(containingDeclaration, null, annotations, Modality.FINAL, visibility, isVar, name, Kind.DECLARATION);
}
@Override
public boolean hasSynthesizedParameterNames() {
return false;
}
}
@@ -78,7 +78,7 @@ public class LazyJavaClassMemberScope(
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
constructor, false, null, null, valueParameters, Collections.emptyList(), false)
constructor, false, null, null, valueParameters.descriptors, Collections.emptyList(), false)
constructorDescriptor.initialize(
classDescriptor.getTypeConstructor().getParameters(),
@@ -87,6 +87,7 @@ public class LazyJavaClassMemberScope(
isStaticClass
)
constructorDescriptor.setHasStableParameterNames(effectiveSignature.hasStableParameterNames())
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
@@ -110,6 +111,7 @@ public class LazyJavaClassMemberScope(
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
else Collections.emptyList<ValueParameterDescriptor>()
constructorDescriptor.setHasSynthesizedParameterNames(false)
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor), jClass.isStatic())
constructorDescriptor.setHasStableParameterNames(true)
@@ -124,12 +124,13 @@ public abstract class LazyJavaMemberScope(
val effectiveSignature: ExternalSignatureResolver.AlternativeMethodSignature
if (_containingDeclaration is PackageFragmentDescriptor) {
superFunctions = Collections.emptyList()
effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(method, false, returnType, null, valueParameters,
methodTypeParameters, false)
effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
method, false, returnType, null, valueParameters.descriptors, methodTypeParameters, false)
signatureErrors = effectiveSignature.getErrors()
}
else if (_containingDeclaration is ClassDescriptor) {
val propagated = c.externalSignatureResolver.resolvePropagatedSignature(method, _containingDeclaration, returnType, null, valueParameters, methodTypeParameters)
val propagated = c.externalSignatureResolver.resolvePropagatedSignature(
method, _containingDeclaration, returnType, null, valueParameters.descriptors, methodTypeParameters)
superFunctions = propagated.getSuperMethods()
effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
method, !superFunctions.isEmpty(), propagated.getReturnType(),
@@ -154,6 +155,7 @@ public abstract class LazyJavaMemberScope(
)
functionDescriptorImpl.setHasStableParameterNames(effectiveSignature.hasStableParameterNames())
functionDescriptorImpl.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
if (record) {
c.javaResolverCache.recordMethod(method, functionDescriptorImpl)
@@ -164,12 +166,14 @@ public abstract class LazyJavaMemberScope(
return functionDescriptorImpl
}
protected class ResolvedValueParameters(val descriptors: List<ValueParameterDescriptor>, val hasSynthesizedNames: Boolean)
protected fun resolveValueParameters(
c: LazyJavaResolverContextWithTypes,
function: FunctionDescriptor,
jValueParameters: List<JavaValueParameter>
): List<ValueParameterDescriptor> {
return jValueParameters.withIndices_tmp().map_tmp {
): ResolvedValueParameters {
var synthesizedNames = false
val descriptors = jValueParameters.withIndices_tmp().map_tmp {
pair ->
val (index, javaParameter) = pair
@@ -203,7 +207,9 @@ public abstract class LazyJavaMemberScope(
}
else {
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
javaParameter.getName() ?: Name.identifier("p$index")
val javaName = javaParameter.getName()
if (javaName == null) synthesizedNames = true
javaName ?: Name.identifier("p$index")
}
ValueParameterDescriptorImpl(
@@ -217,6 +223,7 @@ public abstract class LazyJavaMemberScope(
varargElementType
)
}.toList()
return ResolvedValueParameters(descriptors, synthesizedNames)
}
private fun resolveSamAdapter(original: SimpleFunctionDescriptor): SimpleFunctionDescriptor? {