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/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java index 0ba849a48078..c4ed7782241a 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; @@ -34,7 +35,10 @@ 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; import java.util.concurrent.Future; @@ -234,18 +238,76 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { static class AllPluginsLoader extends ClassLoader { static final AllPluginsLoader INSTANCE = new AllPluginsLoader(); + 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 { - 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); } + + @Override + protected URL findResource(String name) { + return getClass().getClassLoader().getResource(name); + } + + @Override + protected Enumeration findResources(String name) throws IOException { + return getClass().getClassLoader().getResources(name); + } } } 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()); } - } 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) { 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 @@ - - 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); 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