Refactor: Make LightMemberOrigin an interface, extract one implementation
This commit is contained in:
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,13 +34,13 @@ public class ClsWrapperStubPsiFactory extends StubPsiFactory {
|
|||||||
private final StubPsiFactory delegate = new ClsStubPsiFactory();
|
private final StubPsiFactory delegate = new ClsStubPsiFactory();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static LightMemberOrigin getMemberOrigin(@NotNull PsiMember member) {
|
public static LightMemberOriginForDeclaration getMemberOrigin(@NotNull PsiMember member) {
|
||||||
if (member instanceof ClsRepositoryPsiElement<?>) {
|
if (member instanceof ClsRepositoryPsiElement<?>) {
|
||||||
StubElement stubElement = ((ClsRepositoryPsiElement<?>) member).getStub();
|
StubElement stubElement = ((ClsRepositoryPsiElement<?>) member).getStub();
|
||||||
if (stubElement instanceof UserDataHolder) {
|
if (stubElement instanceof UserDataHolder) {
|
||||||
LightElementOrigin origin = ((UserDataHolder) stubElement).getUserData(ORIGIN);
|
LightElementOrigin origin = ((UserDataHolder) stubElement).getUserData(ORIGIN);
|
||||||
if (origin instanceof LightMemberOrigin) {
|
if (origin instanceof LightMemberOriginForDeclaration) {
|
||||||
return (LightMemberOrigin) origin;
|
return (LightMemberOriginForDeclaration) origin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
|||||||
return ArraysKt.map(getDelegate().getMethods(), new Function1<PsiMethod, PsiMethod>() {
|
return ArraysKt.map(getDelegate().getMethods(), new Function1<PsiMethod, PsiMethod>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiMethod invoke(PsiMethod method) {
|
public PsiMethod invoke(PsiMethod method) {
|
||||||
LightMemberOrigin origin = ClsWrapperStubPsiFactory.getMemberOrigin(method);
|
LightMemberOriginForDeclaration origin = ClsWrapperStubPsiFactory.getMemberOrigin(method);
|
||||||
KtDeclaration originalElement = origin != null ? origin.getOriginalElement() : null;
|
KtDeclaration originalElement = origin != null ? origin.getOriginalElement() : null;
|
||||||
if (originalElement instanceof KtPropertyAccessor) {
|
if (originalElement instanceof KtPropertyAccessor) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -40,13 +40,24 @@ interface LightElementOrigin {
|
|||||||
fun JvmDeclarationOrigin.toLightMemberOrigin(): LightElementOrigin {
|
fun JvmDeclarationOrigin.toLightMemberOrigin(): LightElementOrigin {
|
||||||
val originalElement = element
|
val originalElement = element
|
||||||
return when (originalElement) {
|
return when (originalElement) {
|
||||||
is KtDeclaration -> LightMemberOrigin(originalElement, originKind)
|
|
||||||
is KtAnnotationEntry -> DefaultLightElementOrigin(originalElement)
|
is KtAnnotationEntry -> DefaultLightElementOrigin(originalElement)
|
||||||
|
is KtDeclaration -> LightMemberOriginForDeclaration(originalElement, originKind)
|
||||||
else -> LightElementOrigin.None
|
else -> LightElementOrigin.None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class LightMemberOrigin(override val originalElement: KtDeclaration, override val originKind: JvmDeclarationOriginKind) : LightElementOrigin
|
interface LightMemberOrigin : LightElementOrigin {
|
||||||
|
override val originalElement: KtDeclaration?
|
||||||
|
override val originKind: JvmDeclarationOriginKind
|
||||||
|
|
||||||
|
fun copy(): LightMemberOrigin
|
||||||
|
}
|
||||||
|
|
||||||
|
data class LightMemberOriginForDeclaration(override val originalElement: KtDeclaration, override val originKind: JvmDeclarationOriginKind) : LightMemberOrigin {
|
||||||
|
override fun copy(): LightMemberOrigin {
|
||||||
|
return LightMemberOriginForDeclaration(originalElement.copy() as KtDeclaration, originKind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data class DefaultLightElementOrigin(override val originalElement: PsiElement?) : LightElementOrigin {
|
data class DefaultLightElementOrigin(override val originalElement: PsiElement?) : LightElementOrigin {
|
||||||
override val originKind: JvmDeclarationOriginKind? get() = null
|
override val originKind: JvmDeclarationOriginKind? get() = null
|
||||||
@@ -55,5 +66,3 @@ data class DefaultLightElementOrigin(override val originalElement: PsiElement?)
|
|||||||
fun PsiElement?.toLightClassOrigin(): LightElementOrigin {
|
fun PsiElement?.toLightClassOrigin(): LightElementOrigin {
|
||||||
return if (this != null) DefaultLightElementOrigin(this) else LightElementOrigin.None
|
return if (this != null) DefaultLightElementOrigin(this) else LightElementOrigin.None
|
||||||
}
|
}
|
||||||
|
|
||||||
fun LightMemberOrigin.copy() = LightMemberOrigin(originalElement.copy() as KtDeclaration, originKind)
|
|
||||||
Reference in New Issue
Block a user