KtDeclaration.containingClassOrObject now works correctly for primary constructor and its parameters #KT-11982 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
454a8474f1
commit
a12faf5baf
@@ -415,8 +415,17 @@ fun KtDeclaration.modalityModifier() = modifierFromTokenSet(MODALITY_MODIFIERS)
|
||||
fun KtStringTemplateExpression.isPlain() = entries.all { it is KtLiteralStringTemplateEntry }
|
||||
fun KtStringTemplateExpression.isPlainWithEscapes() = entries.all { it is KtLiteralStringTemplateEntry || it is KtEscapeStringTemplateEntry }
|
||||
|
||||
// Correct for class members only (including constructors and nested classes)
|
||||
// Returns null e.g. for member function parameters, member function locals, property accessors
|
||||
val KtDeclaration.containingClassOrObject: KtClassOrObject?
|
||||
get() = (parent as? KtClassBody)?.parent as? KtClassOrObject
|
||||
get() = parent.let {
|
||||
when (it) {
|
||||
is KtClassBody -> it.parent as? KtClassOrObject
|
||||
is KtClassOrObject -> it
|
||||
is KtParameterList -> (it.parent as? KtPrimaryConstructor)?.getContainingClassOrObject()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun KtExpression.getOutermostParenthesizerOrThis(): KtExpression {
|
||||
return (parentsWithSelf.zip(parents)).firstOrNull {
|
||||
|
||||
+16
@@ -71,4 +71,20 @@
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant modality modifier</problem_class>
|
||||
<description>Redundant modality modifier</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantModalityModifier.kt</file>
|
||||
<line>46</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantModalityModifier.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant modality modifier</problem_class>
|
||||
<description>Redundant modality modifier</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantModalityModifier.kt</file>
|
||||
<line>53</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantModalityModifier.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant modality modifier</problem_class>
|
||||
<description>Redundant modality modifier</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+12
@@ -40,3 +40,15 @@ interface Derived : Interface {
|
||||
// Redundant
|
||||
final class Nested
|
||||
}
|
||||
// Derived abstract class
|
||||
abstract class AbstractDerived1(override final val gav: Int) : Interface {
|
||||
// Redundant
|
||||
override open fun foo() {}
|
||||
}
|
||||
// Derived abstract class
|
||||
abstract class AbstractDerived2 : Interface {
|
||||
// Final
|
||||
override final fun foo() {}
|
||||
// Redundant
|
||||
override open val gav = 13
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user