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");
|
||||
* 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();
|
||||
|
||||
@Nullable
|
||||
public static LightMemberOrigin getMemberOrigin(@NotNull PsiMember member) {
|
||||
public static LightMemberOriginForDeclaration getMemberOrigin(@NotNull PsiMember member) {
|
||||
if (member instanceof ClsRepositoryPsiElement<?>) {
|
||||
StubElement stubElement = ((ClsRepositoryPsiElement<?>) member).getStub();
|
||||
if (stubElement instanceof UserDataHolder) {
|
||||
LightElementOrigin origin = ((UserDataHolder) stubElement).getUserData(ORIGIN);
|
||||
if (origin instanceof LightMemberOrigin) {
|
||||
return (LightMemberOrigin) origin;
|
||||
if (origin instanceof LightMemberOriginForDeclaration) {
|
||||
return (LightMemberOriginForDeclaration) origin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
||||
return ArraysKt.map(getDelegate().getMethods(), new Function1<PsiMethod, PsiMethod>() {
|
||||
@Override
|
||||
public PsiMethod invoke(PsiMethod method) {
|
||||
LightMemberOrigin origin = ClsWrapperStubPsiFactory.getMemberOrigin(method);
|
||||
LightMemberOriginForDeclaration origin = ClsWrapperStubPsiFactory.getMemberOrigin(method);
|
||||
KtDeclaration originalElement = origin != null ? origin.getOriginalElement() : null;
|
||||
if (originalElement instanceof KtPropertyAccessor) {
|
||||
//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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,13 +40,24 @@ interface LightElementOrigin {
|
||||
fun JvmDeclarationOrigin.toLightMemberOrigin(): LightElementOrigin {
|
||||
val originalElement = element
|
||||
return when (originalElement) {
|
||||
is KtDeclaration -> LightMemberOrigin(originalElement, originKind)
|
||||
is KtAnnotationEntry -> DefaultLightElementOrigin(originalElement)
|
||||
is KtDeclaration -> LightMemberOriginForDeclaration(originalElement, originKind)
|
||||
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 {
|
||||
override val originKind: JvmDeclarationOriginKind? get() = null
|
||||
@@ -54,6 +65,4 @@ data class DefaultLightElementOrigin(override val originalElement: PsiElement?)
|
||||
|
||||
fun PsiElement?.toLightClassOrigin(): LightElementOrigin {
|
||||
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