From 5a50423ae57e5e38c5ab0a77fdfbf2249866ed81 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 1 Jun 2015 20:06:36 +0300 Subject: [PATCH] Converted to Kotlin --- .../actions/ShowExpressionTypeAction.java | 75 ------------------- .../idea/actions/ShowExpressionTypeAction.kt | 70 +++++++++++++++++ 2 files changed, 70 insertions(+), 75 deletions(-) delete mode 100644 idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.java create mode 100644 idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.java b/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.java deleted file mode 100644 index 22dfde881c4..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2010-2015 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.kotlin.idea.actions; - -import com.intellij.codeInsight.CodeInsightUtilBase; -import com.intellij.codeInsight.hint.HintManager; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import org.jetbrains.kotlin.idea.JetLanguage; -import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; -import org.jetbrains.kotlin.psi.JetExpression; -import org.jetbrains.kotlin.psi.JetFile; -import org.jetbrains.kotlin.renderer.DescriptorRenderer; -import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.types.JetType; - -public class ShowExpressionTypeAction extends AnAction { - @Override - public void actionPerformed(AnActionEvent e) { - Editor editor = e.getData(PlatformDataKeys.EDITOR); - PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); - assert editor != null && psiFile != null; - JetExpression expression; - BindingContext bindingContext = ResolvePackage.analyzeFully((JetFile) psiFile); - if (editor.getSelectionModel().hasSelection()) { - int startOffset = editor.getSelectionModel().getSelectionStart(); - int endOffset = editor.getSelectionModel().getSelectionEnd(); - expression = CodeInsightUtilBase.findElementInRange(psiFile, startOffset, endOffset, - JetExpression.class, JetLanguage.INSTANCE); - } - else { - int offset = editor.getCaretModel().getOffset(); - expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(offset), JetExpression.class); - while (expression != null && bindingContext.getType(expression) == null) { - expression = PsiTreeUtil.getParentOfType(expression, JetExpression.class); - } - if (expression != null) { - editor.getSelectionModel().setSelection(expression.getTextRange().getStartOffset(), - expression.getTextRange().getEndOffset()); - } - } - if (expression != null) { - JetType type = bindingContext.getType(expression); - if (type != null) { - HintManager.getInstance().showInformationHint(editor, "" + DescriptorRenderer.HTML.renderType(type) + ""); - } - } - } - - @Override - public void update(AnActionEvent e) { - Editor editor = e.getData(PlatformDataKeys.EDITOR); - PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); - e.getPresentation().setEnabled(editor != null && psiFile instanceof JetFile); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.kt new file mode 100644 index 00000000000..fcf5a4c9773 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/actions/ShowExpressionTypeAction.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2015 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.kotlin.idea.actions + +import com.intellij.codeInsight.CodeInsightUtilCore +import com.intellij.codeInsight.hint.HintManager +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiFile +import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.idea.JetLanguage +import org.jetbrains.kotlin.idea.caches.resolve.* +import org.jetbrains.kotlin.psi.JetExpression +import org.jetbrains.kotlin.psi.JetFile +import org.jetbrains.kotlin.renderer.DescriptorRenderer +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.types.JetType + +public class ShowExpressionTypeAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val editor = e.getData(CommonDataKeys.EDITOR) + val psiFile = e.getData(CommonDataKeys.PSI_FILE) + assert(editor != null && psiFile != null) + var expression: JetExpression? + val bindingContext = (psiFile as JetFile).analyzeFully() + if (editor!!.getSelectionModel().hasSelection()) { + val startOffset = editor.getSelectionModel().getSelectionStart() + val endOffset = editor.getSelectionModel().getSelectionEnd() + expression = CodeInsightUtilCore.findElementInRange(psiFile, startOffset, endOffset, javaClass(), JetLanguage.INSTANCE) + } + else { + val offset = editor.getCaretModel().getOffset() + expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(offset), javaClass()) + while (expression != null && bindingContext.getType(expression) == null) { + expression = PsiTreeUtil.getParentOfType(expression, javaClass()) + } + if (expression != null) { + editor.getSelectionModel().setSelection(expression.getTextRange().getStartOffset(), expression.getTextRange().getEndOffset()) + } + } + if (expression != null) { + val type = bindingContext.getType(expression) + if (type != null) { + HintManager.getInstance().showInformationHint(editor, "" + DescriptorRenderer.HTML.renderType(type) + "") + } + } + } + + override fun update(e: AnActionEvent?) { + val editor = e!!.getData(CommonDataKeys.EDITOR) + val psiFile = e.getData(CommonDataKeys.PSI_FILE) + e.getPresentation().setEnabled(editor != null && psiFile is JetFile) + } +}