From d491f0337e818692a449d8ecffea5b8da5490f51 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 18 Oct 2013 17:42:21 +0400 Subject: [PATCH] Translate KotlinFindUsagesHandlerFactory to Kotlin --- .../KotlinFindUsagesHandlerFactory.java | 78 ------------------- .../KotlinFindUsagesHandlerFactory.kt | 62 +++++++++++++++ 2 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.java create mode 100644 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.kt diff --git a/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.java b/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.java deleted file mode 100644 index 4c358f5993b..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2010-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.findUsages; - -import com.intellij.find.findUsages.FindUsagesHandler; -import com.intellij.find.findUsages.FindUsagesHandlerFactory; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetClass; -import org.jetbrains.jet.lang.psi.JetDeclaration; -import org.jetbrains.jet.plugin.findUsages.options.KotlinClassFindUsagesOptions; -import org.jetbrains.jet.plugin.findUsages.options.KotlinMethodFindUsagesOptions; -import org.jetbrains.jet.lang.psi.JetNamedFunction; -import org.jetbrains.jet.plugin.findUsages.handlers.KotlinFindClassUsagesHandler; -import org.jetbrains.jet.plugin.findUsages.handlers.KotlinFindFunctionUsagesHandler; -import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil; - -import java.util.List; - -public class KotlinFindUsagesHandlerFactory extends FindUsagesHandlerFactory { - private final KotlinMethodFindUsagesOptions findMethodOptions; - private final KotlinClassFindUsagesOptions findClassOptions; - - public KotlinFindUsagesHandlerFactory(@NotNull Project project) { - findMethodOptions = new KotlinMethodFindUsagesOptions(project); - findClassOptions = new KotlinClassFindUsagesOptions(project); - } - - public final KotlinMethodFindUsagesOptions getFindMethodOptions() { - return findMethodOptions; - } - - public KotlinClassFindUsagesOptions getFindClassOptions() { - return findClassOptions; - } - - @Override - public boolean canFindUsages(@NotNull PsiElement element) { - return element instanceof JetClass || element instanceof JetNamedFunction; - } - - @Override - public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) { - if (element instanceof JetClass) { - return new KotlinFindClassUsagesHandler((JetClass) element, this); - } - if (element instanceof JetNamedFunction) { - if (!forHighlightUsages) { - List methods = - JetRefactoringUtil.checkSuperMethods((JetDeclaration) element, null, "super.methods.action.key.find.usages"); - - if (methods == null || methods.isEmpty()) return FindUsagesHandler.NULL_HANDLER; - if (methods.size() > 1) { - return new KotlinFindFunctionUsagesHandler((JetNamedFunction) element, methods, this); - } - return new KotlinFindFunctionUsagesHandler((JetNamedFunction) methods.get(0), this); - } - - return new KotlinFindFunctionUsagesHandler((JetNamedFunction) element, this); - } - throw new IllegalArgumentException("unexpected element type: " + element); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.kt b/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.kt new file mode 100644 index 00000000000..a64d45e53f7 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindUsagesHandlerFactory.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.findUsages + +import com.intellij.find.findUsages.FindUsagesHandler +import com.intellij.find.findUsages.FindUsagesHandlerFactory +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import org.jetbrains.jet.lang.psi.JetClass +import org.jetbrains.jet.lang.psi.JetDeclaration +import org.jetbrains.jet.plugin.findUsages.options.KotlinClassFindUsagesOptions +import org.jetbrains.jet.plugin.findUsages.options.KotlinMethodFindUsagesOptions +import org.jetbrains.jet.lang.psi.JetNamedFunction +import org.jetbrains.jet.plugin.findUsages.handlers.KotlinFindClassUsagesHandler +import org.jetbrains.jet.plugin.findUsages.handlers.KotlinFindFunctionUsagesHandler +import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil + +public class KotlinFindUsagesHandlerFactory(project: Project) : FindUsagesHandlerFactory() { + val findMethodOptions = KotlinMethodFindUsagesOptions(project) + val findClassOptions = KotlinClassFindUsagesOptions(project) + + public override fun canFindUsages(element: PsiElement): Boolean = + element is JetClass || element is JetNamedFunction + + public override fun createFindUsagesHandler(element: PsiElement, forHighlightUsages: Boolean): FindUsagesHandler { + when(element) { + is JetClass -> + return KotlinFindClassUsagesHandler(element, this) + + is JetNamedFunction -> { + return if (forHighlightUsages) KotlinFindFunctionUsagesHandler(element, this) + else JetRefactoringUtil.checkSuperMethods(element, null, "super.methods.action.key.find.usages")?.let { methods -> + when (methods.size()) { + 0 -> null + 1 -> + KotlinFindFunctionUsagesHandler(methods.get(0) as JetNamedFunction, this) + else -> + KotlinFindFunctionUsagesHandler(element as JetNamedFunction, methods, this) + } + } ?: FindUsagesHandler.NULL_HANDLER + } + + else -> + throw IllegalArgumentException("unexpected element type: " + element) + } + } + +}