From 953e48dbbd896ce22da2c3f76ff71baf5f8086d3 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 19 Apr 2016 22:11:02 +0300 Subject: [PATCH 1/7] SmartEnterProcessor#commit method restored to fix binary compatibility with Kotlin plugin (KT-11844) --- .../editorActions/smartEnter/SmartEnterProcessor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java b/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java index 30876b125a6e..a5563ecccbfe 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java @@ -72,12 +72,15 @@ public abstract class SmartEnterProcessor { return PsiDocumentManager.getInstance(project).hasUncommitedDocuments(); } - public static void commit(@NotNull final Editor editor) { + protected void commit(@NotNull final Editor editor) { + commitDocument(editor); + } + + public static void commitDocument(@NotNull Editor editor) { final Project project = editor.getProject(); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); //some psi operations may block the document, unblock here PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); } - } From 3707337e0e7b052c06263c399e45e0bdc3570aef Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 19 Apr 2016 22:29:02 +0200 Subject: [PATCH 2/7] add missing test data --- .../siyeh/ipp/enumswitch/BeforeFallthrough.java | 13 +++++++++++++ .../ipp/enumswitch/BeforeFallthrough_after.java | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough.java create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough_after.java diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough.java new file mode 100644 index 000000000000..acffdd1ac1cf --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough.java @@ -0,0 +1,13 @@ +class BeforeDefault { + enum Status { ACTIVE, INACTIVE, ERROR } + + private int foo (Status status) { + switch (status) { + case ACTIVE: + return 0; + case INACTIVE: + default: + return 1; + } + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough_after.java new file mode 100644 index 000000000000..1eed8a4000b3 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/BeforeFallthrough_after.java @@ -0,0 +1,15 @@ +class BeforeDefault { + enum Status { ACTIVE, INACTIVE, ERROR } + + private int foo (Status status) { + switch (status) { + case ACTIVE: + return 0; + case ERROR: + break; + case INACTIVE: + default: + return 1; + } + } +} \ No newline at end of file From a58836b8ce1539b81857bc76c33f651d6afaf7f2 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 19 Apr 2016 22:49:29 +0200 Subject: [PATCH 3/7] Cleanup (formatting) --- platform/util/src/com/intellij/util/EnvironmentUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/util/src/com/intellij/util/EnvironmentUtil.java b/platform/util/src/com/intellij/util/EnvironmentUtil.java index 33d3c70a26bd..63f73237d149 100644 --- a/platform/util/src/com/intellij/util/EnvironmentUtil.java +++ b/platform/util/src/com/intellij/util/EnvironmentUtil.java @@ -140,7 +140,7 @@ public class EnvironmentUtil { return flattenEnvironment(getEnvironmentMap()); } - public static String[] flattenEnvironment(Map environment) { + public static String[] flattenEnvironment(@NotNull Map environment) { String[] array = new String[environment.size()]; int i = 0; for (Map.Entry entry : environment.entrySet()) { @@ -167,7 +167,7 @@ public class EnvironmentUtil { File envFile = FileUtil.createTempFile("intellij-shell-env.", ".tmp", false); try { - String[] command = {shell, "-l", "-i", "-c", "'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'"}; + String[] command = {shell, "-l", "-i", "-c", ("'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'")}; LOG.info("loading shell env: " + StringUtil.join(command, " ")); ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true); From 20d0949c12d96aa2e95f4bad7cead4a47c588d16 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 20 Apr 2016 00:31:52 +0300 Subject: [PATCH 4/7] display elapsed time --- .../com/intellij/execution/console/RunIdeConsoleAction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/RunIdeConsoleAction.java b/platform/lang-impl/src/com/intellij/execution/console/RunIdeConsoleAction.java index 23ed62462061..577c0814f9bd 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/RunIdeConsoleAction.java +++ b/platform/lang-impl/src/com/intellij/execution/console/RunIdeConsoleAction.java @@ -140,12 +140,14 @@ public class RunIdeConsoleAction extends DumbAwareAction { prepareEngine(project, engine, descriptor); try { + long ts = System.currentTimeMillis(); //myHistoryController.getModel().addToHistory(command); consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT); consoleView.print("\n", ConsoleViewContentType.USER_INPUT); String script = profile == null ? command : profile + "\n" + command; Object o = engine.eval(script); - consoleView.print("=> " + o, ConsoleViewContentType.NORMAL_OUTPUT); + String prefix = "["+(StringUtil.formatDuration(System.currentTimeMillis() - ts))+"]"; + consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT); consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); } catch (Throwable e) { From 3c8730cf4c1496af27c39fd2c0c720a6173c0360 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 20 Apr 2016 00:33:11 +0300 Subject: [PATCH 5/7] AllPluginsLoader: classloader performance --- .../Jsr223IdeScriptEngineManagerImpl.java | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java index 0ba849a48078..bf6cfb6a0106 100644 --- a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java +++ b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java @@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.ClassLoaderUtil; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.openapi.util.text.StringHash; import com.intellij.util.Function; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; @@ -35,6 +36,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.List; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -234,17 +236,61 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { static class AllPluginsLoader extends ClassLoader { static final AllPluginsLoader INSTANCE = new AllPluginsLoader(); + final Map myLuckyGuess = ContainerUtil.newConcurrentMap(); + @Override protected Class findClass(String name) throws ClassNotFoundException { - for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) { - ClassLoader l = descriptor.getPluginClassLoader(); - if (l == null) continue; + //long ts = System.currentTimeMillis(); + + int p0 = name.indexOf("$"); + int p1 = p0 > 0 ? name.indexOf("$", p0 + 1) : -1; + String base = p0 > 0 ? name.substring(0, Math.max(p0, p1)) : name; + long hash = StringHash.calc(base); + + ClassLoader loader = myLuckyGuess.get(hash); + if (loader == this) throw new ClassNotFoundException(name); + + Class c = null; + if (loader != null) { try { - return l.loadClass(name); + c = loader.loadClass(name); } catch (ClassNotFoundException ignored) { } } + if (c == null) { + boolean first = true; + for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) { + ClassLoader l = descriptor.getPluginClassLoader(); + if (l == null || l == loader) continue; + try { + l.loadClass(base); + + if (first) { + myLuckyGuess.put(hash, l); + } + first = false; + try { + c = l.loadClass(name); + break; + } + catch (ClassNotFoundException e) { + if (p0 > 0) break; + if (name.startsWith("java.") || name.startsWith("groovy.")) break; + } + } + catch (ClassNotFoundException ignored) { + } + } + if (first && loader == null) { + myLuckyGuess.put(hash, this); + } + } + + //LOG.info("AllPluginsLoader [" + StringUtil.formatDuration(System.currentTimeMillis() - ts) + "]: " + (c != null ? "+" : "-") + name); + if (c != null) return c; + myLuckyGuess.put(StringHash.calc(name), this); + throw new ClassNotFoundException(name); } } From cca2f67e8613ae329f71ae40eab78280760d9df4 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 19 Apr 2016 23:55:44 +0200 Subject: [PATCH 6/7] remove unused http services --- .../ide/ActivateApplicationHttpService.java | 58 ------------------- .../JetBrainsProtocolHandlerHttpService.java | 53 ----------------- .../src/META-INF/built-in-server.xml | 2 - 3 files changed, 113 deletions(-) delete mode 100644 platform/built-in-server/src/org/jetbrains/ide/ActivateApplicationHttpService.java delete mode 100644 platform/built-in-server/src/org/jetbrains/ide/JetBrainsProtocolHandlerHttpService.java diff --git a/platform/built-in-server/src/org/jetbrains/ide/ActivateApplicationHttpService.java b/platform/built-in-server/src/org/jetbrains/ide/ActivateApplicationHttpService.java deleted file mode 100644 index 27fc0ee28dda..000000000000 --- a/platform/built-in-server/src/org/jetbrains/ide/ActivateApplicationHttpService.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jetbrains.ide; - -import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.openapi.wm.IdeFrame; -import com.intellij.ui.AppIcon; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.QueryStringDecoder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.io.IOException; - -/** - * @author Konstantin Bulenkov - */ -public class ActivateApplicationHttpService extends RestService { - @NotNull - @Override - protected String getServiceName() { - return "show"; - } - - @Override - protected boolean isMethodSupported(@NotNull HttpMethod method) { - return method == HttpMethod.GET; - } - - @Nullable - @Override - public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) - throws IOException { - final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame(); - if (frame instanceof Window) { - sendOk(request, context); - Runnable runnable = new Runnable() { - @Override - public void run() { - Window window = (Window)frame; - window.toFront(); - window.requestFocusInWindow(); - - AppIcon.getInstance().requestFocus(frame); - - } - }; - //noinspection SSBasedInspection - SwingUtilities.invokeLater(runnable); - return "Success"; - } - sendStatus(HttpResponseStatus.NOT_FOUND, false, context.channel()); - return "Can't find IDE Frame"; - } -} diff --git a/platform/built-in-server/src/org/jetbrains/ide/JetBrainsProtocolHandlerHttpService.java b/platform/built-in-server/src/org/jetbrains/ide/JetBrainsProtocolHandlerHttpService.java deleted file mode 100644 index b6005cce57eb..000000000000 --- a/platform/built-in-server/src/org/jetbrains/ide/JetBrainsProtocolHandlerHttpService.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.jetbrains.ide; - -import com.google.gson.stream.JsonReader; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.JBProtocolCommand; -import com.intellij.openapi.application.JetBrainsProtocolHandler; -import com.intellij.openapi.application.ModalityState; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.QueryStringDecoder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; - -/** - * @author Konstantin Bulenkov - */ -public class JetBrainsProtocolHandlerHttpService extends RestService { - private static final String URL_PARAM_NAME = "url"; - - @NotNull - @Override - protected String getServiceName() { - return "internal"; - } - - @Override - protected boolean isMethodSupported(@NotNull HttpMethod method) { - return method == HttpMethod.POST; - } - - @Nullable - @Override - public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException { - final JsonReader reader = createJsonReader(request); - reader.beginObject(); - final String name = reader.nextName(); - final String url = reader.nextString(); - reader.endObject(); - - activateLastFocusedFrame(); - - if (URL_PARAM_NAME.equals(name) && url != null && url.startsWith(JetBrainsProtocolHandler.PROTOCOL)) { - JetBrainsProtocolHandler.processJetBrainsLauncherParameters(url); - ApplicationManager.getApplication().invokeLater(JBProtocolCommand::handleCurrentCommand, ModalityState.any()); - } - - sendOk(request, context); - return null; - } -} diff --git a/platform/platform-resources/src/META-INF/built-in-server.xml b/platform/platform-resources/src/META-INF/built-in-server.xml index 63a623f6086a..b38e318efdef 100644 --- a/platform/platform-resources/src/META-INF/built-in-server.xml +++ b/platform/platform-resources/src/META-INF/built-in-server.xml @@ -27,10 +27,8 @@ - - From b2d053ad931f38fd40c932cf0915d454793bb162 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 20 Apr 2016 04:34:13 +0300 Subject: [PATCH 7/7] AllPluginsLoader: classloader performance + clojure fix --- .../script/Jsr223IdeScriptEngineManagerImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java index bf6cfb6a0106..c4ed7782241a 100644 --- a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java +++ b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java @@ -35,6 +35,8 @@ import javax.script.ScriptEngineManager; import java.io.IOException; import java.io.Reader; import java.io.Writer; +import java.net.URL; +import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -238,6 +240,10 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { final Map myLuckyGuess = ContainerUtil.newConcurrentMap(); + public AllPluginsLoader() { + // Groovy performance: do not specify parent loader to enable our luckyGuesser + } + @Override protected Class findClass(String name) throws ClassNotFoundException { //long ts = System.currentTimeMillis(); @@ -293,5 +299,15 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { throw new ClassNotFoundException(name); } + + @Override + protected URL findResource(String name) { + return getClass().getClassLoader().getResource(name); + } + + @Override + protected Enumeration findResources(String name) throws IOException { + return getClass().getClassLoader().getResources(name); + } } }