From 2c7ec8a7aeed03a9891f880502e04af58bcfd9f5 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 31 Jul 2014 13:19:35 +0400 Subject: [PATCH] KT-5531 Introduce separate 'kotlin.internal.mode' property and use it to trigger red/black rectangles and debug information in error tooltips #KT-5531 fixed --- idea/src/META-INF/plugin.xml | 4 ++ .../KotlinInternalModeToggleAction.kt | 42 +++++++++++++++++++ .../highlighter/DebugInfoAnnotator.java | 3 +- .../jet/plugin/highlighter/JetPsiChecker.java | 5 ++- 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/actions/internal/KotlinInternalModeToggleAction.kt diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index f23a6d3b2d0..02757a03dde 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -103,6 +103,10 @@ + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/actions/internal/KotlinInternalModeToggleAction.kt b/idea/src/org/jetbrains/jet/plugin/actions/internal/KotlinInternalModeToggleAction.kt new file mode 100644 index 00000000000..7f931785703 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/actions/internal/KotlinInternalModeToggleAction.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2014 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.actions.internal + +import com.intellij.openapi.actionSystem.ToggleAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.ide.util.PropertiesComponent +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer + +public class KotlinInternalModeToggleAction: ToggleAction("Kotlin Internal Mode", "Show debug highlighting", null) { + public class object { + val INTERNAL_MODE_PROPERTY = "kotlin.internal.mode.enabled" + + public fun isEnabled(): Boolean { + return PropertiesComponent.getInstance()!!.getBoolean(INTERNAL_MODE_PROPERTY, false) + } + } + + override fun isSelected(e: AnActionEvent?): Boolean { + return isEnabled() + } + + override fun setSelected(e: AnActionEvent?, state: Boolean) { + PropertiesComponent.getInstance()!!.setValue(INTERNAL_MODE_PROPERTY, "$state") + + DaemonCodeAnalyzer.getInstance(e!!.getProject())!!.settingsChanged() + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java index 1b2698b6096..854d690e8a8 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java @@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.plugin.JetPluginUtil; +import org.jetbrains.jet.plugin.actions.internal.KotlinInternalModeToggleAction; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; /** @@ -36,7 +37,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; public class DebugInfoAnnotator implements Annotator { public static boolean isDebugInfoEnabled() { - return ApplicationManager.getApplication().isInternal(); + return KotlinInternalModeToggleAction.OBJECT$.isEnabled(); } @Override diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 1b7ead53549..cfd19b8ffb2 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -46,6 +46,7 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.Diagnostics; import org.jetbrains.jet.plugin.JetPluginUtil; +import org.jetbrains.jet.plugin.actions.internal.KotlinInternalModeToggleAction; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import org.jetbrains.jet.plugin.quickfix.JetIntentionActionsFactory; import org.jetbrains.jet.plugin.quickfix.QuickFixes; @@ -263,7 +264,7 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension { @NotNull private static String getMessage(@NotNull Diagnostic diagnostic) { String message = IdeErrorMessages.RENDERER.render(diagnostic); - if (ApplicationManager.getApplication().isInternal() || ApplicationManager.getApplication().isUnitTestMode()) { + if (KotlinInternalModeToggleAction.OBJECT$.isEnabled() || ApplicationManager.getApplication().isUnitTestMode()) { String factoryName = diagnostic.getFactory().getName(); if (message.startsWith("")) { message = String.format("[%s] %s", factoryName, message.substring("".length())); @@ -280,7 +281,7 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension { @NotNull private static String getDefaultMessage(@NotNull Diagnostic diagnostic) { String message = DefaultErrorMessages.RENDERER.render(diagnostic); - if (ApplicationManager.getApplication().isInternal() || ApplicationManager.getApplication().isUnitTestMode()) { + if (KotlinInternalModeToggleAction.OBJECT$.isEnabled() || ApplicationManager.getApplication().isUnitTestMode()) { return String.format("[%s] %s", diagnostic.getFactory().getName(), message); } return message;