Code cleanup
This commit is contained in:
+15
-15
@@ -71,7 +71,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
val originalDescriptor = (if (symbolDescriptor is CallableMemberDescriptor)
|
val originalDescriptor = (if (symbolDescriptor is CallableMemberDescriptor)
|
||||||
DescriptorUtils.unwrapFakeOverride(symbolDescriptor)
|
DescriptorUtils.unwrapFakeOverride(symbolDescriptor)
|
||||||
else
|
else
|
||||||
symbolDescriptor).getOriginal()
|
symbolDescriptor).original
|
||||||
return analyzeOriginal(annotation, originalDescriptor, resolutionFacade)
|
return analyzeOriginal(annotation, originalDescriptor, resolutionFacade)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
val importFqNames = annotation.imports
|
val importFqNames = annotation.imports
|
||||||
.filter { FqNameUnsafe.isValid(it) }
|
.filter { FqNameUnsafe.isValid(it) }
|
||||||
.map { FqNameUnsafe(it) }
|
.map { FqNameUnsafe(it) }
|
||||||
.filter { it.isSafe() }
|
.filter { it.isSafe }
|
||||||
.mapTo(LinkedHashSet<FqName>()) { it.toSafe() }
|
.mapTo(LinkedHashSet<FqName>()) { it.toSafe() }
|
||||||
|
|
||||||
val explicitlyImportedSymbols = importFqNames.flatMap { resolutionFacade.resolveImportReference(symbolDescriptor.module, it) }
|
val explicitlyImportedSymbols = importFqNames.flatMap { resolutionFacade.resolveImportReference(symbolDescriptor.module, it) }
|
||||||
@@ -106,7 +106,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
|
|
||||||
if (typeArgsToAdd.isNotEmpty()) {
|
if (typeArgsToAdd.isNotEmpty()) {
|
||||||
for ((callExpr, typeArgs) in typeArgsToAdd) {
|
for ((callExpr, typeArgs) in typeArgsToAdd) {
|
||||||
callExpr.addAfter(typeArgs, callExpr.getCalleeExpression())
|
callExpr.addAfter(typeArgs, callExpr.calleeExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reanalyze expression - new usages of type parameters may be added
|
// reanalyze expression - new usages of type parameters may be added
|
||||||
@@ -123,19 +123,19 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expression.getReceiverExpression() == null) {
|
if (expression.getReceiverExpression() == null) {
|
||||||
if (target is ValueParameterDescriptor && target.getContainingDeclaration() == symbolDescriptor) {
|
if (target is ValueParameterDescriptor && target.containingDeclaration == symbolDescriptor) {
|
||||||
expression.putCopyableUserData(PARAMETER_USAGE_KEY, target.getName())
|
expression.putCopyableUserData(PARAMETER_USAGE_KEY, target.name)
|
||||||
}
|
}
|
||||||
else if (target is TypeParameterDescriptor && target.getContainingDeclaration() == symbolDescriptor) {
|
else if (target is TypeParameterDescriptor && target.containingDeclaration == symbolDescriptor) {
|
||||||
expression.putCopyableUserData(TYPE_PARAMETER_USAGE_KEY, target.getName())
|
expression.putCopyableUserData(TYPE_PARAMETER_USAGE_KEY, target.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolvedCall = expression.getResolvedCall(bindingContext)
|
val resolvedCall = expression.getResolvedCall(bindingContext)
|
||||||
if (resolvedCall != null && resolvedCall.getStatus().isSuccess()) {
|
if (resolvedCall != null && resolvedCall.status.isSuccess) {
|
||||||
val receiver = if (resolvedCall.getResultingDescriptor().isExtension)
|
val receiver = if (resolvedCall.resultingDescriptor.isExtension)
|
||||||
resolvedCall.getExtensionReceiver()
|
resolvedCall.extensionReceiver
|
||||||
else
|
else
|
||||||
resolvedCall.getDispatchReceiver()
|
resolvedCall.dispatchReceiver
|
||||||
if (receiver is ThisReceiver) {
|
if (receiver is ThisReceiver) {
|
||||||
val receiverExpression = receiver.asExpression(scope.asJetScope(), psiFactory)
|
val receiverExpression = receiver.asExpression(scope.asJetScope(), psiFactory)
|
||||||
if (receiverExpression != null) {
|
if (receiverExpression != null) {
|
||||||
@@ -147,8 +147,8 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add receivers in reverse order because arguments of a call were processed after the callee's name
|
// add receivers in reverse order because arguments of a call were processed after the callee's name
|
||||||
for ((expr, receiverExpression) in receiversToAdd.reverse()) {
|
for ((expr, receiverExpression) in receiversToAdd.reversed()) {
|
||||||
val expressionToReplace = expr.getParent() as? JetCallExpression ?: expr
|
val expressionToReplace = expr.parent as? JetCallExpression ?: expr
|
||||||
val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace))
|
val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace))
|
||||||
if (expressionToReplace == expression) {
|
if (expressionToReplace == expression) {
|
||||||
expression = newExpr
|
expression = newExpr
|
||||||
@@ -165,7 +165,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
resolutionFacade: ResolutionFacade
|
resolutionFacade: ResolutionFacade
|
||||||
): BindingContext {
|
): BindingContext {
|
||||||
val traceContext = BindingTraceContext()
|
val traceContext = BindingTraceContext()
|
||||||
resolutionFacade.getFrontendService(symbolDescriptor.module, javaClass<ExpressionTypingServices>())
|
resolutionFacade.getFrontendService(symbolDescriptor.module, ExpressionTypingServices::class.java)
|
||||||
.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, traceContext, false)
|
.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, traceContext, false)
|
||||||
return traceContext.bindingContext
|
return traceContext.bindingContext
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
|
|
||||||
is PropertyDescriptor ->
|
is PropertyDescriptor ->
|
||||||
JetScopeUtils.getPropertyDeclarationInnerScope(descriptor,
|
JetScopeUtils.getPropertyDeclarationInnerScope(descriptor,
|
||||||
getResolutionScope(descriptor.getContainingDeclaration(), ownerDescriptor, additionalScopes),
|
getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes),
|
||||||
RedeclarationHandler.DO_NOTHING)
|
RedeclarationHandler.DO_NOTHING)
|
||||||
is LocalVariableDescriptor -> {
|
is LocalVariableDescriptor -> {
|
||||||
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as JetDeclaration
|
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as JetDeclaration
|
||||||
|
|||||||
Reference in New Issue
Block a user