mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
-53
@@ -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;
|
||||
}
|
||||
}
|
||||
+66
-4
@@ -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<Long, ClassLoader> 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<URL> findResources(String name) throws IOException {
|
||||
return getClass().getClassLoader().getResources(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -27,10 +27,8 @@
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.XmlRpcServerImpl$XmlRpcRequestHandler"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.ProjectSetRequestHandler"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.DiffHttpService"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.ActivateApplicationHttpService"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.OpenFileHttpService"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.AboutHttpService"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.ide.JetBrainsProtocolHandlerHttpService"/>
|
||||
<httpRequestHandler implementation="org.jetbrains.builtInWebServer.BuiltInWebServer"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="org.jetbrains">
|
||||
|
||||
@@ -140,7 +140,7 @@ public class EnvironmentUtil {
|
||||
return flattenEnvironment(getEnvironmentMap());
|
||||
}
|
||||
|
||||
public static String[] flattenEnvironment(Map<String, String> environment) {
|
||||
public static String[] flattenEnvironment(@NotNull Map<String, String> environment) {
|
||||
String[] array = new String[environment.size()];
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String> 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);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class BeforeDefault {
|
||||
enum Status { ACTIVE, INACTIVE, ERROR }
|
||||
|
||||
private int foo (Status status) {
|
||||
switch (status)<caret> {
|
||||
case ACTIVE:
|
||||
return 0;
|
||||
case INACTIVE:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user