Use OperatorNameConventions constants instead of hardcoded literals

This commit is contained in:
Alexander Udalov
2016-11-02 13:18:47 +03:00
parent 61767bb0ea
commit 0d4bd2a673
8 changed files with 23 additions and 15 deletions
@@ -94,6 +94,7 @@ import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS;
import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt;
import org.jetbrains.kotlin.util.OperatorNameConventions;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Opcodes;
@@ -4152,7 +4153,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(INDEXED_LVALUE_SET, expression);
ResolvedCall<FunctionDescriptor> resolvedGetCall = bindingContext.get(INDEXED_LVALUE_GET, expression);
boolean isGetter = "get".equals(operationDescriptor.getName().asString());
boolean isGetter = OperatorNameConventions.GET.equals(operationDescriptor.getName());
Callable callable = resolveToCallable(operationDescriptor, false, isGetter ? resolvedGetCall : resolvedSetCall);
Callable callableMethod = resolveToCallableMethod(operationDescriptor, false);
@@ -57,6 +57,7 @@ import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils.*
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.*
class ControlFlowInformationProvider private constructor(
@@ -647,13 +648,13 @@ class ControlFlowInformationProvider private constructor(
val functionDescriptor =
trace.get(DECLARATION_TO_DESCRIPTOR, owner) as? FunctionDescriptor
?: throw AssertionError(owner.text)
val functionName = functionDescriptor.name.asString()
val functionName = functionDescriptor.name
if (isMain
|| functionDescriptor.isOverridableOrOverrides
|| owner.hasModifier(KtTokens.OVERRIDE_KEYWORD)
|| "getValue" == functionName
|| "setValue" == functionName
|| "propertyDelegated" == functionName) {
|| OperatorNameConventions.GET_VALUE == functionName
|| OperatorNameConventions.SET_VALUE == functionName
|| OperatorNameConventions.PROPERTY_DELEGATED == functionName) {
return
}
report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt)
@@ -257,7 +257,7 @@ public class CallResolver {
Call.CallType callType = context.call.getCallType();
if (callType == Call.CallType.ARRAY_GET_METHOD || callType == Call.CallType.ARRAY_SET_METHOD) {
Name name = Name.identifier(callType == Call.CallType.ARRAY_GET_METHOD ? "get" : "set");
Name name = callType == Call.CallType.ARRAY_GET_METHOD ? OperatorNameConventions.GET : OperatorNameConventions.SET;
KtArrayAccessExpression arrayAccessExpression = (KtArrayAccessExpression) context.call.getCallElement();
return computeTasksAndResolveCall(
context, name, arrayAccessExpression,
@@ -1691,7 +1691,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
? CallMaker.makeArrayGetCall(receiver, arrayAccessExpression, Call.CallType.ARRAY_GET_METHOD)
: CallMaker.makeArraySetCall(receiver, arrayAccessExpression, rightHandSide, Call.CallType.ARRAY_SET_METHOD);
OverloadResolutionResults<FunctionDescriptor> functionResults = components.callResolver.resolveCallWithGivenName(
context, call, arrayAccessExpression, Name.identifier(isGet ? "get" : "set"));
context, call, arrayAccessExpression, isGet ? OperatorNameConventions.GET : OperatorNameConventions.SET);
List<KtExpression> indices = arrayAccessExpression.getIndexExpressions();
// The accumulated data flow info of all index expressions is saved on the last index
@@ -33,13 +33,12 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.HashSet
import java.util.*
class KotlinRecursiveCallLineMarkerProvider() : LineMarkerProvider {
override fun getLineMarkerInfo(element: PsiElement) = null
@@ -159,7 +158,7 @@ private fun getCallNameFromPsi(element: KtElement): Name? {
}
}
is KtArrayAccessExpression ->
return Name.identifier("get")
return OperatorNameConventions.GET
is KtThisExpression ->
if (element.getParent() is KtCallExpression) {
return OperatorNameConventions.INVOKE
@@ -167,4 +166,4 @@ private fun getCallNameFromPsi(element: KtElement): Name? {
}
return null
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Parame
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.*
object CreateGetFunctionActionFactory : CreateGetSetFunctionActionFactory(isGet = true) {
@@ -32,6 +33,8 @@ object CreateGetFunctionActionFactory : CreateGetSetFunctionActionFactory(isGet
val arrayType = TypeInfo(arrayExpr, Variance.IN_VARIANCE)
val parameters = element.indexExpressions.map { ParameterInfo(TypeInfo(it, Variance.IN_VARIANCE)) }
val returnType = TypeInfo(element, Variance.OUT_VARIANCE)
return FunctionInfo("get", arrayType, returnType, Collections.emptyList(), parameters, isOperator = true)
return FunctionInfo(
OperatorNameConventions.GET.asString(), arrayType, returnType, Collections.emptyList(), parameters, isOperator = true
)
}
}
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.util.OperatorNameConventions
object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUsageFactory<KtExpression>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtExpression? {
@@ -62,7 +63,7 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
if (isApplicableForAccessor(propertyDescriptor.getter)) {
val getterInfo = FunctionInfo(
name = "getValue",
name = OperatorNameConventions.GET_VALUE.asString(),
receiverTypeInfo = accessorReceiverType,
returnTypeInfo = TypeInfo(propertyType, Variance.OUT_VARIANCE),
parameterInfos = listOf(thisRefParam, metadataParam),
@@ -74,7 +75,7 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
if (propertyDescriptor.isVar && isApplicableForAccessor(propertyDescriptor.setter)) {
val newValueParam = ParameterInfo(TypeInfo(propertyType, Variance.IN_VARIANCE))
val setterInfo = FunctionInfo(
name = "setValue",
name = OperatorNameConventions.SET_VALUE.asString(),
receiverTypeInfo = accessorReceiverType,
returnTypeInfo = TypeInfo(builtIns.unitType, Variance.OUT_VARIANCE),
parameterInfos = listOf(thisRefParam, metadataParam, newValueParam),
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.*
object CreateSetFunctionActionFactory : CreateGetSetFunctionActionFactory(isGet = false) {
@@ -61,6 +62,8 @@ object CreateSetFunctionActionFactory : CreateGetSetFunctionActionFactory(isGet
parameters.add(ParameterInfo(valType, "value"))
val returnType = TypeInfo(builtIns.unitType, Variance.OUT_VARIANCE)
return FunctionInfo("set", arrayType, returnType, Collections.emptyList(), parameters, isOperator = true)
return FunctionInfo(
OperatorNameConventions.SET.asString(), arrayType, returnType, Collections.emptyList(), parameters, isOperator = true
)
}
}