Add annotation for parameter name in signatures

This commit is contained in:
e5l
2017-08-11 16:45:48 +03:00
committed by Leonid Stashevsky
parent 8201ff3006
commit 62e87c873c
37 changed files with 766 additions and 18 deletions
@@ -22,10 +22,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.annotations.*;
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.UtilKt;
import org.jetbrains.kotlin.load.java.structure.JavaMethod;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
@@ -66,10 +67,12 @@ public class SignaturesPropagationData {
JavaMethodDescriptor autoMethodDescriptor =
createAutoMethodDescriptor(containingClass, method, autoReturnType, autoValueParameters, autoTypeParameters);
boolean hasStableParameterNames = autoValueParameters.stream().allMatch(it -> UtilKt.getParameterNameAnnotation(it) != null);
superFunctions = getSuperFunctionsForMethod(method, autoMethodDescriptor, containingClass);
modifiedValueParameters = superFunctions.isEmpty()
? new ValueParameters(null, autoValueParameters, /* stableParameterNames = */false)
: modifyValueParametersAccordingToSuperMethods(autoValueParameters);
? new ValueParameters(null, autoValueParameters, hasStableParameterNames)
: modifyValueParametersAccordingToSuperMethods(autoValueParameters, hasStableParameterNames);
}
@NotNull
@@ -118,7 +121,10 @@ public class SignaturesPropagationData {
signatureErrors.add(error);
}
private ValueParameters modifyValueParametersAccordingToSuperMethods(@NotNull List<ValueParameterDescriptor> parameters) {
private ValueParameters modifyValueParametersAccordingToSuperMethods(
@NotNull List<ValueParameterDescriptor> parameters,
boolean annotatedWithParameterName
) {
KotlinType resultReceiverType = null;
List<ValueParameterDescriptor> resultParameters = new ArrayList<>(parameters.size());
@@ -159,12 +165,15 @@ public class SignaturesPropagationData {
}
}
AnnotationDescriptor currentName = UtilKt.getParameterNameAnnotation(originalParam);
boolean shouldTakeOldName = currentName == null && stableName != null;
resultParameters.add(new ValueParameterDescriptorImpl(
originalParam.getContainingDeclaration(),
null,
shouldBeExtension ? originalIndex - 1 : originalIndex,
originalParam.getAnnotations(),
stableName != null ? stableName : originalParam.getName(),
shouldTakeOldName ? stableName : originalParam.getName(),
altType,
originalParam.declaresDefaultValue(),
originalParam.isCrossinline(),
@@ -175,7 +184,8 @@ public class SignaturesPropagationData {
}
}
boolean hasStableParameterNames = CollectionsKt.any(superFunctions, CallableDescriptor::hasStableParameterNames);
boolean hasStableParameterNames =
annotatedWithParameterName || CollectionsKt.any(superFunctions, CallableDescriptor::hasStableParameterNames);
return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
}