FIR: Don't use AnnotationUseSiteTarget.PROPERTY_GETTER when computing
deprecation from a callable reference use site. Also fixed positioning of DEPRECATION(_ERROR) diagnostics on variable assignments.
This commit is contained in:
committed by
TeamCityServer
parent
b8ed46066e
commit
42abc4a3af
+1
-1
@@ -37,7 +37,7 @@ object FirDeprecationChecker : FirBasicExpressionChecker() {
|
||||
val reference = resolvable.calleeReference as? FirResolvedNamedReference ?: return
|
||||
val referencedSymbol = reference.resolvedSymbol
|
||||
|
||||
reportDeprecationIfNeeded(expression.source, referencedSymbol, expression, context, reporter)
|
||||
reportDeprecationIfNeeded(reference.source, referencedSymbol, expression, context, reporter)
|
||||
}
|
||||
|
||||
internal fun reportDeprecationIfNeeded(
|
||||
|
||||
+6
@@ -584,6 +584,12 @@ object LightTreePositioningStrategies {
|
||||
tree: FlyweightCapableTreeStructure<LighterASTNode>
|
||||
): List<TextRange> {
|
||||
when {
|
||||
node.tokenType == KtNodeTypes.BINARY_EXPRESSION && tree.findDescendantByType(node, KtTokens.EQ) != null -> {
|
||||
// Look for reference in LHS of variable assignment.
|
||||
tree.findExpressionDeep(node)?.let {
|
||||
return markElement(it, startOffset, endOffset, tree, node)
|
||||
}
|
||||
}
|
||||
node.tokenType == KtNodeTypes.CALL_EXPRESSION || node.tokenType == KtNodeTypes.CONSTRUCTOR_DELEGATION_CALL -> {
|
||||
return markElement(tree.referenceExpression(node, locateReferencedName) ?: node, startOffset, endOffset, tree, node)
|
||||
}
|
||||
|
||||
@@ -33,14 +33,16 @@ fun FirBasedSymbol<*>.getDeprecation(callSite: FirElement?): DeprecationInfo? {
|
||||
val deprecationInfos = mutableListOf<DeprecationInfo>()
|
||||
when (this) {
|
||||
is FirPropertySymbol ->
|
||||
if (callSite is FirVariableAssignment) {
|
||||
deprecationInfos.addIfNotNull(
|
||||
getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY_SETTER, AnnotationUseSiteTarget.PROPERTY)
|
||||
)
|
||||
} else {
|
||||
deprecationInfos.addIfNotNull(
|
||||
getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY_GETTER, AnnotationUseSiteTarget.PROPERTY)
|
||||
)
|
||||
when (callSite) {
|
||||
is FirVariableAssignment ->
|
||||
deprecationInfos.addIfNotNull(
|
||||
getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY_SETTER, AnnotationUseSiteTarget.PROPERTY)
|
||||
)
|
||||
is FirPropertyAccessExpression ->
|
||||
deprecationInfos.addIfNotNull(
|
||||
getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY_GETTER, AnnotationUseSiteTarget.PROPERTY)
|
||||
)
|
||||
else -> deprecationInfos.addIfNotNull(getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY))
|
||||
}
|
||||
else -> deprecationInfos.addIfNotNull(getDeprecationForCallSite())
|
||||
}
|
||||
|
||||
+4
@@ -896,6 +896,10 @@ object PositioningStrategies {
|
||||
*/
|
||||
class FindReferencePositioningStrategy(val locateReferencedName: Boolean) : PositioningStrategy<PsiElement>() {
|
||||
override fun mark(element: PsiElement): List<TextRange> {
|
||||
if (element is KtBinaryExpression && element.operationToken == KtTokens.EQ) {
|
||||
// Look for reference in LHS of variable assignment.
|
||||
element.left?.let { return mark(it) }
|
||||
}
|
||||
var result: PsiElement = when (element) {
|
||||
is KtQualifiedExpression -> {
|
||||
when (val selectorExpression = element.selectorExpression) {
|
||||
|
||||
+3
-3
@@ -96,16 +96,16 @@ fun use(
|
||||
diff: Diff
|
||||
) {
|
||||
warningDeprecated.<!DEPRECATION!>p<!>
|
||||
warningDeprecated.p <!DEPRECATION!>=<!> 1
|
||||
warningDeprecated.<!DEPRECATION!>p<!> = 1
|
||||
|
||||
errorDeprecated.<!DEPRECATION_ERROR!>p<!>
|
||||
errorDeprecated.p <!DEPRECATION_ERROR!>=<!> 1
|
||||
errorDeprecated.<!DEPRECATION_ERROR!>p<!> = 1
|
||||
|
||||
getterDeprecated.<!DEPRECATION!>p<!>
|
||||
getterDeprecated.p = 1
|
||||
|
||||
setterDeprecated.p
|
||||
setterDeprecated.p <!DEPRECATION!>=<!> 1
|
||||
setterDeprecated.<!DEPRECATION!>p<!> = 1
|
||||
|
||||
hiddenDeprecated.<!UNRESOLVED_REFERENCE!>p<!>
|
||||
hiddenDeprecated.<!UNRESOLVED_REFERENCE!>p<!> = 1
|
||||
|
||||
+3
-3
@@ -96,16 +96,16 @@ fun use(
|
||||
diff: Diff
|
||||
) {
|
||||
warningDeprecated.<!DEPRECATION!>p<!>
|
||||
warningDeprecated.p <!DEPRECATION!>=<!> 1
|
||||
warningDeprecated.<!DEPRECATION!>p<!> = 1
|
||||
|
||||
errorDeprecated.<!DEPRECATION_ERROR!>p<!>
|
||||
errorDeprecated.p <!DEPRECATION_ERROR!>=<!> 1
|
||||
errorDeprecated.<!DEPRECATION_ERROR!>p<!> = 1
|
||||
|
||||
getterDeprecated.<!DEPRECATION!>p<!>
|
||||
getterDeprecated.p = 1
|
||||
|
||||
setterDeprecated.p
|
||||
setterDeprecated.p <!DEPRECATION!>=<!> 1
|
||||
setterDeprecated.<!DEPRECATION!>p<!> = 1
|
||||
|
||||
hiddenDeprecated.<!UNRESOLVED_REFERENCE!>p<!>
|
||||
hiddenDeprecated.<!UNRESOLVED_REFERENCE!>p<!> = 1
|
||||
|
||||
@@ -37,30 +37,30 @@ class PropertyHolder {
|
||||
}
|
||||
|
||||
fun PropertyHolder.extFunction() {
|
||||
test2 <!DEPRECATION!>=<!> "ext"
|
||||
<!DEPRECATION!>test2<!> = "ext"
|
||||
<!DEPRECATION!>test1<!>
|
||||
}
|
||||
|
||||
fun fn() {
|
||||
PropertyHolder().<!DEPRECATION!>test1<!>
|
||||
PropertyHolder().<!DEPRECATION!>test2<!>
|
||||
PropertyHolder().test2 <!DEPRECATION!>=<!> ""
|
||||
PropertyHolder().<!DEPRECATION!>test2<!> = ""
|
||||
|
||||
PropertyHolder().<!DEPRECATION!>test3<!>
|
||||
PropertyHolder().test3 = ""
|
||||
|
||||
PropertyHolder().test4
|
||||
PropertyHolder().test4 <!DEPRECATION!>=<!> ""
|
||||
PropertyHolder().<!DEPRECATION!>test4<!> = ""
|
||||
|
||||
val a = PropertyHolder().<!DEPRECATION!>x<!>
|
||||
val b = PropertyHolder().<!DEPRECATION!>name<!>
|
||||
PropertyHolder().name <!DEPRECATION!>=<!> "value"
|
||||
PropertyHolder().<!DEPRECATION!>name<!> = "value"
|
||||
|
||||
val d = PropertyHolder().valDelegate
|
||||
PropertyHolder().varDelegate = 1
|
||||
}
|
||||
|
||||
fun literals() {
|
||||
PropertyHolder::<!DEPRECATION!>test1<!>
|
||||
PropertyHolder::test1
|
||||
PropertyHolder::<!DEPRECATION!>name<!>
|
||||
}
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
class PropertyHolder {
|
||||
@Deprecated("")
|
||||
val a1 = 1
|
||||
|
||||
@property:Deprecated("")
|
||||
var a2 = ""
|
||||
|
||||
@get:Deprecated("")
|
||||
public val withGetter: String = ""
|
||||
|
||||
@set:Deprecated("")
|
||||
public var withSetter: String = ""
|
||||
}
|
||||
|
||||
fun fn() {
|
||||
val holder = PropertyHolder()
|
||||
|
||||
holder.<!DEPRECATION!>a1<!>
|
||||
holder.<!DEPRECATION!>a2<!>
|
||||
holder.<!DEPRECATION!>withGetter<!>
|
||||
holder.withSetter <!DEPRECATION!>=<!> "A"
|
||||
}
|
||||
|
||||
fun literals() {
|
||||
PropertyHolder::<!DEPRECATION!>a1<!>
|
||||
PropertyHolder::<!DEPRECATION!>a2<!>
|
||||
PropertyHolder::<!DEPRECATION!>withGetter<!>
|
||||
PropertyHolder::withSetter
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
class PropertyHolder {
|
||||
|
||||
@@ -21,7 +21,7 @@ open class A {
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>test<!>()
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>z<!>
|
||||
zVar
|
||||
zVar <!PROTECTED_CALL_FROM_PUBLIC_INLINE!>=<!> "123"
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>zVar<!> = "123"
|
||||
}
|
||||
|
||||
internal inline fun callFromInternal() {
|
||||
|
||||
@@ -21,7 +21,7 @@ open class A {
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>test<!>()
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>z<!>
|
||||
zVar
|
||||
zVar <!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>=<!> "123"
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>zVar<!> = "123"
|
||||
}
|
||||
|
||||
internal inline fun callFromInternal() {
|
||||
|
||||
+5
-5
@@ -7,12 +7,12 @@ fun foo(javaClass: JavaClass) {
|
||||
javaClass.<!DEPRECATION!>something2<!>++
|
||||
|
||||
javaClass.something3
|
||||
javaClass.something3 <!DEPRECATION!>=<!> 1
|
||||
javaClass.something3<!DEPRECATION!>++<!>
|
||||
javaClass.<!DEPRECATION!>something3<!> = 1
|
||||
javaClass.<!DEPRECATION!>something3<!>++
|
||||
|
||||
javaClass.<!DEPRECATION!>something4<!>
|
||||
javaClass.something4 <!DEPRECATION!>=<!> 1
|
||||
javaClass.<!DEPRECATION!>something4<!><!DEPRECATION!>++<!>
|
||||
javaClass.<!DEPRECATION!>something4<!> = 1
|
||||
javaClass.<!DEPRECATION, DEPRECATION!>something4<!>++
|
||||
|
||||
javaClass.something5
|
||||
javaClass.something5 = 1
|
||||
@@ -45,4 +45,4 @@ public class JavaClass {
|
||||
* @deprecated Ha-ha-ha
|
||||
*/
|
||||
public void setSomething5(int value) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user