Add and use KtPropertyAccessor#getProperty()

This commit is contained in:
Pavel V. Talanov
2015-12-28 16:03:22 +03:00
parent d511059cfa
commit 4f5f56e4a5
6 changed files with 11 additions and 10 deletions
@@ -143,4 +143,9 @@ public class KtPropertyAccessor extends KtDeclarationStub<KotlinPropertyAccessor
public boolean hasInitializer() { public boolean hasInitializer() {
return getInitializer() != null; return getInitializer() != null;
} }
@NotNull
public KtProperty getProperty() {
return (KtProperty) getParent();
}
} }
@@ -160,10 +160,7 @@ public object LightClassUtil {
} }
if (declaration is KtPropertyAccessor) { if (declaration is KtPropertyAccessor) {
val propertyParent = declaration.parent declaration = declaration.property
assert(propertyParent is KtProperty) { "JetProperty is expected to be parent of accessor" }
declaration = propertyParent as KtProperty
} }
if (declaration is KtConstructor<*>) { if (declaration is KtConstructor<*>) {
@@ -97,8 +97,8 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
} }
override fun visitPropertyAccessor(accessor: KtPropertyAccessor) { override fun visitPropertyAccessor(accessor: KtPropertyAccessor) {
val parent = accessor.getParent() as KtProperty val property = accessor.property
val propertyDescriptor = getDescriptor(parent, container) as PropertyDescriptor val propertyDescriptor = getDescriptor(property, container) as PropertyDescriptor
if (accessor.isGetter()) { if (accessor.isGetter()) {
descriptors.add(propertyDescriptor.getGetter()!!) descriptors.add(propertyDescriptor.getGetter()!!)
} }
@@ -35,7 +35,7 @@ public class KotlinBasicStepMethodFilter(
myTargetMethodName = when (resolvedElement) { myTargetMethodName = when (resolvedElement) {
is KtAnonymousInitializer -> "<init>" is KtAnonymousInitializer -> "<init>"
is KtConstructor<*> -> "<init>" is KtConstructor<*> -> "<init>"
is KtPropertyAccessor -> JvmAbi.getterName((resolvedElement.parent as KtProperty).name!!) is KtPropertyAccessor -> JvmAbi.getterName((resolvedElement.property).name!!)
else -> resolvedElement.name!! else -> resolvedElement.name!!
} }
} }
@@ -53,8 +53,7 @@ public class ChangeVariableMutabilityFix(element: KtNamedDeclaration, private va
public val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() { public val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? { override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val accessor = diagnostic.psiElement as KtPropertyAccessor val accessor = diagnostic.psiElement as KtPropertyAccessor
val property = accessor.parent as KtProperty return ChangeVariableMutabilityFix(accessor.property, true)
return ChangeVariableMutabilityFix(property, true)
} }
} }
@@ -354,7 +354,7 @@ public fun <T> chooseContainerElement(
object : PsiElementListCellRenderer<PsiElement>() { object : PsiElementListCellRenderer<PsiElement>() {
private fun PsiElement.renderName(): String { private fun PsiElement.renderName(): String {
if (this is KtPropertyAccessor) { if (this is KtPropertyAccessor) {
return (parent as KtProperty).renderName() + if (isGetter) ".get" else ".set" return property.renderName() + if (isGetter) ".get" else ".set"
} }
if (this is KtObjectDeclaration && this.isCompanion()) { if (this is KtObjectDeclaration && this.isCompanion()) {
return "Companion object of ${getStrictParentOfType<KtClassOrObject>()?.renderName() ?: "<anonymous>"}" return "Companion object of ${getStrictParentOfType<KtClassOrObject>()?.renderName() ?: "<anonymous>"}"