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() {
return getInitializer() != null;
}
@NotNull
public KtProperty getProperty() {
return (KtProperty) getParent();
}
}
@@ -160,10 +160,7 @@ public object LightClassUtil {
}
if (declaration is KtPropertyAccessor) {
val propertyParent = declaration.parent
assert(propertyParent is KtProperty) { "JetProperty is expected to be parent of accessor" }
declaration = propertyParent as KtProperty
declaration = declaration.property
}
if (declaration is KtConstructor<*>) {
@@ -97,8 +97,8 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
}
override fun visitPropertyAccessor(accessor: KtPropertyAccessor) {
val parent = accessor.getParent() as KtProperty
val propertyDescriptor = getDescriptor(parent, container) as PropertyDescriptor
val property = accessor.property
val propertyDescriptor = getDescriptor(property, container) as PropertyDescriptor
if (accessor.isGetter()) {
descriptors.add(propertyDescriptor.getGetter()!!)
}
@@ -35,7 +35,7 @@ public class KotlinBasicStepMethodFilter(
myTargetMethodName = when (resolvedElement) {
is KtAnonymousInitializer -> "<init>"
is KtConstructor<*> -> "<init>"
is KtPropertyAccessor -> JvmAbi.getterName((resolvedElement.parent as KtProperty).name!!)
is KtPropertyAccessor -> JvmAbi.getterName((resolvedElement.property).name!!)
else -> resolvedElement.name!!
}
}
@@ -53,8 +53,7 @@ public class ChangeVariableMutabilityFix(element: KtNamedDeclaration, private va
public val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val accessor = diagnostic.psiElement as KtPropertyAccessor
val property = accessor.parent as KtProperty
return ChangeVariableMutabilityFix(property, true)
return ChangeVariableMutabilityFix(accessor.property, true)
}
}
@@ -354,7 +354,7 @@ public fun <T> chooseContainerElement(
object : PsiElementListCellRenderer<PsiElement>() {
private fun PsiElement.renderName(): String {
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()) {
return "Companion object of ${getStrictParentOfType<KtClassOrObject>()?.renderName() ?: "<anonymous>"}"