change the origin of light methods for property accessors to the property itself

This commit is contained in:
Dmitry Jemerov
2015-08-28 14:00:59 +02:00
parent e283dbb8f4
commit 37c40c9a23
8 changed files with 89 additions and 14 deletions
@@ -149,6 +149,9 @@ public abstract class KotlinWrappingLightClass extends AbstractLightClass implem
@Override
public PsiMethod invoke(PsiMethod method) {
JetDeclaration declaration = ClsWrapperStubPsiFactory.getOriginalDeclaration(method);
if (declaration instanceof JetPropertyAccessor) {
declaration = PsiTreeUtil.getParentOfType(declaration, JetProperty.class);
}
if (declaration != null) {
return !isTraitFakeOverride(declaration) ?
@@ -146,7 +146,18 @@ public class LightClassUtil {
@Nullable
public static PsiMethod getLightClassAccessorMethod(@NotNull JetPropertyAccessor accessor) {
return getPsiMethodWrapper(accessor);
JetProperty property = PsiTreeUtil.getParentOfType(accessor, JetProperty.class);
if (property == null) {
return null;
}
List<PsiMethod> wrappers = getPsiMethodWrappers(property, true);
for (PsiMethod wrapper : wrappers) {
if ((accessor.isGetter() && !wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX)) ||
(accessor.isSetter() && wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX))) {
return wrapper;
}
}
return null;
}
@Nullable
@@ -331,13 +342,13 @@ public class LightClassUtil {
for (PsiMethod wrapper : wrappers) {
if (wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
assert setterWrapper == null : String.format(
assert setterWrapper == null || setterWrapper == specialSetter: String.format(
"Setter accessor isn't expected to be reassigned (old: %s, new: %s)", setterWrapper, wrapper);
setterWrapper = wrapper;
}
else {
assert getterWrapper == null : String.format(
assert getterWrapper == null || getterWrapper == specialGetter: String.format(
"Getter accessor isn't expected to be reassigned (old: %s, new: %s)", getterWrapper, wrapper);
getterWrapper = wrapper;