Refactoring: Unify getClassOrObject() and getContainingClassOrObject() functions in constructor PSI

This commit is contained in:
Alexey Sedunov
2015-06-09 16:39:39 +03:00
parent 1ab90c7814
commit bbc644f4c8
11 changed files with 14 additions and 16 deletions
@@ -31,7 +31,7 @@ object KDocFinder {
var psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
// KDoc for primary constructor is located inside of its class KDoc
if (psiDeclaration is JetPrimaryConstructor) {
psiDeclaration = psiDeclaration.getClassOrObject()
psiDeclaration = psiDeclaration.getContainingClassOrObject()
}
if (psiDeclaration is JetDeclaration) {
@@ -104,7 +104,7 @@ private fun PsiElement.isConstructorOf(unwrappedCandidate: PsiElement) =
// call to Java constructor
(this is PsiMethod && isConstructor() && getContainingClass() == unwrappedCandidate) ||
// call to Kotlin constructor
(this is JetConstructor<*> && getClassOrObject() == unwrappedCandidate)
(this is JetConstructor<*> && getContainingClassOrObject() == unwrappedCandidate)
fun AbstractJetReference<out JetExpression>.renameImplicitConventionalCall(newName: String?): JetExpression {
if (newName == null) return expression
@@ -88,7 +88,7 @@ fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean
if (descriptor !is ConstructorDescriptor) return false
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor.getContainingDeclaration())
return declaration == jetClassOrObject || (declaration is JetConstructor<*> && declaration.getClassOrObject() == jetClassOrObject)
return declaration == jetClassOrObject || (declaration is JetConstructor<*> && declaration.getContainingClassOrObject() == jetClassOrObject)
}
checkJavaUsage() || checkKotlinUsage()
@@ -120,7 +120,7 @@ public fun PsiElement.processDelegationCallConstructorUsages(scope: SearchScope,
private fun PsiElement.processDelegationCallKotlinConstructorUsages(scope: SearchScope, process: (JetConstructorDelegationCall) -> Unit) {
val element = unwrapped
val klass = when (element) {
is JetConstructor<*> -> element.getClassOrObject()
is JetConstructor<*> -> element.getContainingClassOrObject()
is JetClass -> element
else -> return
}
@@ -61,7 +61,7 @@ public class JetFunctionPresenter implements ItemPresentationProvider<JetFunctio
@Override
public String getLocationString() {
if (function instanceof JetConstructor) {
FqName name = ((JetConstructor) function).getClassOrObject().getFqName();
FqName name = ((JetConstructor) function).getContainingClassOrObject().getFqName();
return name != null ? String.format("(in %s)", name) : "";
}
@@ -54,7 +54,7 @@ public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction<Jet
if (reference != null) {
PsiElement target = reference.resolve();
if (target instanceof JetSecondaryConstructor) {
target = ((JetSecondaryConstructor) target).getClassOrObject();
target = ((JetSecondaryConstructor) target).getContainingClassOrObject();
}
if (target instanceof JetClass && QuickFixUtil.canModifyElement(target)) {
classDeclaration = (JetClass) target;
@@ -62,7 +62,7 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: JetSecon
object InsertThisDelegationCallFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) = diagnostic.createIntentionForFirstParentOfType<JetSecondaryConstructor> {
secondaryConstructor ->
if (secondaryConstructor.getClassOrObject().getConstructorsCount() <= 1 ||
if (secondaryConstructor.getContainingClassOrObject().getConstructorsCount() <= 1 ||
!secondaryConstructor.hasImplicitDelegationCall()) return null
return InsertDelegationCallQuickfix(isThis = true, element = secondaryConstructor)
@@ -75,7 +75,7 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: JetSecon
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val secondaryConstructor = diagnostic.getPsiElement().getNonStrictParentOfType<JetSecondaryConstructor>() ?: return null
if (!secondaryConstructor.hasImplicitDelegationCall()) return null
val klass = secondaryConstructor.getClassOrObject() as? JetClass ?: return null
val klass = secondaryConstructor.getContainingClassOrObject() as? JetClass ?: return null
if (klass.hasPrimaryConstructor()) return null
return InsertDelegationCallQuickfix(isThis = false, element = secondaryConstructor)