Mark value arguments in case of empty delegation call

It's useful for quickfixes for these diagnostics
This commit is contained in:
Denis Zharkov
2015-03-23 19:42:51 +03:00
parent 1a2167e062
commit d0c72c2c3d
6 changed files with 11 additions and 10 deletions
@@ -168,7 +168,8 @@ public interface Errors {
DiagnosticFactory0.create(ERROR); DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<PsiElement> PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> EXPLICIT_DELEGATION_CALL_REQUIRED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<JetConstructorDelegationCall> EXPLICIT_DELEGATION_CALL_REQUIRED =
DiagnosticFactory0.create(ERROR, PositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL);
// Trait-specific // Trait-specific
@@ -420,7 +420,8 @@ public object PositioningStrategies {
override fun mark(element: JetConstructorDelegationCall): List<TextRange> { override fun mark(element: JetConstructorDelegationCall): List<TextRange> {
if (element.isEmpty()) { if (element.isEmpty()) {
val constructor = element.getStrictParentOfType<JetSecondaryConstructor>()!! val constructor = element.getStrictParentOfType<JetSecondaryConstructor>()!!
return markElement(constructor.getConstructorKeyword()) val valueParameterList = constructor.getValueParameterList() ?: return markElement(constructor)
return markRange(constructor.getConstructorKeyword(), valueParameterList.getLastChild())
} }
return markElement(element.getCalleeExpression() ?: element) return markElement(element.getCalleeExpression() ?: element)
} }
@@ -82,8 +82,7 @@ public class TracingStrategyForEmptyConstructorDelegationCall(
} }
private fun reportError(trace: BindingTrace) { private fun reportError(trace: BindingTrace) {
val declaration = delegationCall.getParent() as JetSecondaryConstructor trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(delegationCall))
trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(declaration.getConstructorKeyword()))
} }
// Underlying methods should not be called because such errors are impossible // Underlying methods should not be called because such errors are impossible
@@ -2,7 +2,7 @@
open class B0(x: Int) open class B0(x: Int)
class A0 : B0 { class A0 : B0 {
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor<!>() <!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor()<!>
constructor(x: Int) : super(<!NO_VALUE_FOR_PARAMETER!>)<!> constructor(x: Int) : super(<!NO_VALUE_FOR_PARAMETER!>)<!>
} }
@@ -14,7 +14,7 @@ open class B1 {
} }
class A1 : B1 { class A1 : B1 {
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor<!>() <!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor()<!>
constructor(x: Int) : <!OVERLOAD_RESOLUTION_AMBIGUITY!>super<!>() constructor(x: Int) : <!OVERLOAD_RESOLUTION_AMBIGUITY!>super<!>()
} }
@@ -26,7 +26,7 @@ open class B2 {
} }
class A2 : B2 { class A2 : B2 {
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor<!>() <!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor()<!>
constructor(x: Int) : <!NONE_APPLICABLE!>super<!>() constructor(x: Int) : <!NONE_APPLICABLE!>super<!>()
} }
@@ -37,6 +37,6 @@ open class B3 {
} }
class A3 : B3 { class A3 : B3 {
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor<!>() <!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor()<!>
constructor(x: Int) : <!INVISIBLE_MEMBER!>super<!>() constructor(x: Int) : <!INVISIBLE_MEMBER!>super<!>()
} }
@@ -1,6 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
class A(x: Int) { class A(x: Int) {
<!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor<!>() <!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor()<!>
} }
open class B(x: Int) open class B(x: Int)
class C(x: Int) : B(x) { class C(x: Int) : B(x) {
@@ -6,5 +6,5 @@ open class B(x: Double) {
trait C trait C
class A : B, C { class A : B, C {
constructor(): <!NONE_APPLICABLE!>super<!>(' ') constructor(): <!NONE_APPLICABLE!>super<!>(' ')
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor<!>(x: Int) <!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor(x: Int)<!>
} }