From f6f23366234d5c5f2e54bac379c95a6e31c5d21c Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 5 Sep 2011 18:55:48 +0400 Subject: [PATCH 01/14] MergingUpdateQueue: finishActivity on dispose() --- .../intellij/util/ui/update/MergingUpdateQueue.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java index 32a4b2d7e553..0b394fc99941 100644 --- a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java +++ b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java @@ -130,6 +130,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { } } myScheduledUpdates.clear(); + finishActivity(); } } @@ -166,6 +167,9 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { } myActive = false; + + finishActivity(); + clearWaiter(); } @@ -203,7 +207,10 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { public void flush() { synchronized (myScheduledUpdates) { - if (myScheduledUpdates.isEmpty()) return; + if (myScheduledUpdates.isEmpty()) { + finishActivity(); + return; + } } flush(true); } @@ -375,6 +382,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { public void dispose() { myDisposed = true; myActive = false; + finishActivity(); clearWaiter(); } From f46f6dec9be8d2f389110a20703c188dc3ffb9e2 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 5 Sep 2011 18:56:59 +0400 Subject: [PATCH 02/14] funcTests plyaback refactoring - %includeCall + some playback ui fixes --- .../intellij/openapi/util/ActionCallback.java | 22 ++++- .../project1/module1/scripts/include/init.ijs | 5 +- .../ide/navigationToolbar/NavBarPanel.java | 2 + .../debugger/extensions/PlaybackDebugger.java | 28 ++++-- .../ide/actionMacro/ActionMacroManager.java | 6 +- .../openapi/ui/playback/PlaybackContext.java | 36 ++++--- .../openapi/ui/playback/PlaybackRunner.java | 59 +++++++----- .../ui/playback/commands/AbstractCommand.java | 12 +-- .../ui/playback/commands/ActionCommand.java | 13 ++- .../ui/playback/commands/AssertFocused.java | 10 +- .../ui/playback/commands/CallCommand.java | 50 +++++++--- .../ui/playback/commands/CdCommand.java | 4 +- .../ui/playback/commands/DelayCommand.java | 2 +- .../ui/playback/commands/ErrorCommand.java | 2 +- .../playback/commands/KeyCodeTypeCommand.java | 8 +- .../playback/commands/KeyShortcutCommand.java | 2 +- .../ui/playback/commands/PrintCommand.java | 2 +- .../ui/playback/commands/StopCommand.java | 2 +- .../commands/ToggleActionCommand.java | 8 +- .../ui/playback/util/ProjectPlaybackCall.java | 94 +++++++++++++++++++ .../WindowSystemPlaybackCall.java} | 82 +--------------- 21 files changed, 278 insertions(+), 171 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/ui/playback/util/ProjectPlaybackCall.java rename platform/platform-impl/src/com/intellij/openapi/ui/playback/{PlaybackCallFacade.java => util/WindowSystemPlaybackCall.java} (63%) diff --git a/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java b/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java index 3e8a07cf3e48..9944715e13d7 100644 --- a/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java +++ b/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java @@ -211,15 +211,27 @@ public class ActionCallback implements Disposable { public final void run() { if (!isProcessed()) { setRejected(); - if (myAllocation != null) { - LOG.error(myMessage, myAllocation); - } else { - LOG.error(myMessage); - } + dumpError(); onTimeout(); } } + protected void dumpError() { + if (myAllocation != null) { + LOG.error(myMessage, myAllocation); + } else { + LOG.error(myMessage); + } + } + + public String getMessage() { + return myMessage; + } + + public Throwable getAllocation() { + return myAllocation; + } + @Override public void dispose() { super.dispose(); diff --git a/platform/funcTests/project1/module1/scripts/include/init.ijs b/platform/funcTests/project1/module1/scripts/include/init.ijs index b3b3953b37e0..cdd9d68963d3 100644 --- a/platform/funcTests/project1/module1/scripts/include/init.ijs +++ b/platform/funcTests/project1/module1/scripts/include/init.ijs @@ -1 +1,4 @@ -%cd {script.dir}/../../../.. \ No newline at end of file +%importCall com.intellij.openapi.ui.playback.util.WindowSystemPlaybackCall +%importCall com.intellij.openapi.ui.playback.util.ProjectPlaybackCall + +%cd {script.dir}/../../../.. diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index 2892d2d062e9..9dab946cfe31 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -124,6 +124,8 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis Disposer.register(project, this); } + + public boolean isNodePopupActive() { return myNodePopup != null && myNodePopup.isVisible(); } diff --git a/platform/lang-impl/src/com/intellij/ui/debugger/extensions/PlaybackDebugger.java b/platform/lang-impl/src/com/intellij/ui/debugger/extensions/PlaybackDebugger.java index df5572f51875..24cf371ea4aa 100644 --- a/platform/lang-impl/src/com/intellij/ui/debugger/extensions/PlaybackDebugger.java +++ b/platform/lang-impl/src/com/intellij/ui/debugger/extensions/PlaybackDebugger.java @@ -398,11 +398,11 @@ public class PlaybackDebugger implements UiDebuggerExtension, PlaybackRunner.Sta }; if (myRunner == null) { - message("Script stopped", -1); + _message("Script stopped", -1); return; } - message("Starting script...", -1); + _message("Starting script...", -1); try { sleep(1000); @@ -411,20 +411,26 @@ public class PlaybackDebugger implements UiDebuggerExtension, PlaybackRunner.Sta if (myRunner == null) { - message("Script stopped", -1); + _message("Script stopped", -1); return; } + final PlaybackRunner runner = myRunner; + myRunner.run().doWhenProcessed(new Runnable() { public void run() { - myRunner = null; + if (runner == myRunner) { + myRunner = null; + } } }); } }.start(); } - public void error(final String text, final int currentLine) { + public void error(PlaybackRunner runner, final String text, final int currentLine) { + if (myRunner != runner) return; + UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { addError(text, currentLine); @@ -432,7 +438,13 @@ public class PlaybackDebugger implements UiDebuggerExtension, PlaybackRunner.Sta }); } - public void message(final String text, final int currentLine) { + public void message(PlaybackRunner runner, final String text, final int currentLine) { + if (myRunner != runner) return; + + _message(text, currentLine); + } + + private void _message(final String text, final int currentLine) { UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { addInfo(text, currentLine, MESSAGE_COLOR); @@ -441,7 +453,9 @@ public class PlaybackDebugger implements UiDebuggerExtension, PlaybackRunner.Sta } @Override - public void code(final String text, final int currentLine) { + public void code(PlaybackRunner runner, final String text, final int currentLine) { + if (myRunner != runner) return; + UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { addInfo(text, currentLine, CODE_COLOR); diff --git a/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java b/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java index 7c94d5afb676..2ebb9a4da94d 100644 --- a/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java +++ b/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java @@ -206,16 +206,16 @@ public class ActionMacroManager implements ExportableApplicationComponent, Named } final PlaybackRunner runner = new PlaybackRunner(script.toString(), new PlaybackRunner.StatusCallback.Edt() { - public void errorEdt(String text, int curentLine) { + public void errorEdt(PlaybackRunner runner, String text, int curentLine) { frame.getStatusBar().setInfo("Line " + curentLine + ":" + " Error: " + text); } - public void messageEdt(String text, int curentLine) { + public void messageEdt(PlaybackRunner runner, String text, int curentLine) { frame.getStatusBar().setInfo("Line " + curentLine + ": " + text); } @Override - public void codeEdt(String text, int curentLine) { + public void codeEdt(PlaybackRunner runner, String text, int curentLine) { } }, Registry.is("actionSystem.playback.useDirectActionCall"), true); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackContext.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackContext.java index 40ff957581e1..6a34a5f153df 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackContext.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackContext.java @@ -20,15 +20,9 @@ import com.intellij.openapi.application.ApplicationManager; import javax.swing.*; import java.awt.*; import java.io.File; +import java.util.Set; -/** - * Created by IntelliJ IDEA. - * User: kirillk - * Date: 8/4/11 - * Time: 2:37 PM - * To change this template use File | Settings | File Templates. - */ -public class PlaybackContext { +public class PlaybackContext { private PlaybackRunner.StatusCallback myCallback; private int myCurrentLine; @@ -36,14 +30,18 @@ public class PlaybackContext { private boolean myUseDirectActionCall; private PlaybackCommand myCurrentCmd; private File myBaseDir; - - public PlaybackContext(PlaybackRunner.StatusCallback callback, int currentLine, Robot robot, boolean useDriectActionCall, PlaybackCommand currentCmd, File baseDir) { + private Set myCallClasses; + private PlaybackRunner myRunner; + + public PlaybackContext(PlaybackRunner runner, PlaybackRunner.StatusCallback callback, int currentLine, Robot robot, boolean useDriectActionCall, PlaybackCommand currentCmd, File baseDir, Set callClasses) { + myRunner = runner; myCallback = callback; myCurrentLine = currentLine; myRobot = robot; myUseDirectActionCall = useDriectActionCall; myCurrentCmd = currentCmd; myBaseDir = baseDir; + myCallClasses = callClasses; } public PlaybackRunner.StatusCallback getCallback() { @@ -77,7 +75,11 @@ public class PlaybackContext { public void setBaseDir(File dir) { myBaseDir = dir; } - + + public Set getCallClasses() { + return myCallClasses; + } + public void flushAwtAndRun(final Runnable runnable) { if (EventQueue.isDispatchThread()) { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @@ -92,4 +94,16 @@ public class PlaybackContext { runnable.run(); } } + + public void error(String text, int currentLine) { + getCallback().error(myRunner, text, currentLine); + } + + public void message(String text, int currentLine) { + getCallback().message(myRunner, text, currentLine); + } + + public void code(String text, int currentLine) { + getCallback().code(myRunner, text, currentLine); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java index 0e0e4eeb7f7d..29603d92ac71 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java @@ -36,6 +36,8 @@ import java.awt.*; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; public class PlaybackRunner { @@ -54,6 +56,8 @@ public class PlaybackRunner { private boolean myStopOnAppDeactivation; private final ApplicationActivationListener myAppListener; + private HashSet myFacadeClasses = new HashSet(); + private Disposable myOnStop = new Disposable() { @Override public void dispose() { @@ -73,7 +77,7 @@ public class PlaybackRunner { @Override public void applicationDeactivated(IdeFrame ideFrame) { if (myStopOnAppDeactivation) { - myCallback.message("App lost focus, stopping...", 0); + myCallback.message(PlaybackRunner.this, "App lost focus, stopping...", 0); stop(); } } @@ -127,11 +131,11 @@ public class PlaybackRunner { if (cmdIndex < myCommands.size()) { final PlaybackCommand cmd = myCommands.get(cmdIndex); if (myStopRequested) { - myCallback.message("Stopped", cmdIndex); + myCallback.message(this, "Stopped", cmdIndex); myActionCallback.setRejected(); return; } - final PlaybackContext context = new PlaybackContext(myCallback, cmdIndex, myRobot, myUseDirectActionCall, cmd, baseDir); + final PlaybackContext context = new PlaybackContext(this, myCallback, cmdIndex, myRobot, myUseDirectActionCall, cmd, baseDir, (Set)myFacadeClasses.clone()); final ActionCallback cmdCallback = cmd.execute(context); cmdCallback.doWhenDone(new Runnable() { public void run() { @@ -139,18 +143,19 @@ public class PlaybackRunner { executeFrom(cmdIndex + 1, context.getBaseDir()); } else { + myCallback.message(PlaybackRunner.this, "Stopped", cmdIndex); myActionCallback.setDone(); } } }).doWhenRejected(new Runnable() { public void run() { - myCallback.message("Stopped", cmdIndex); + myCallback.message(PlaybackRunner.this, "Stopped", cmdIndex); myActionCallback.setRejected(); } }); } else { - myCallback.message("Finished", myCommands.size() - 1); + myCallback.message(this, "Finished", myCommands.size() - 1); myActionCallback.setDone(); } } @@ -164,8 +169,8 @@ public class PlaybackRunner { while (tokens.hasMoreTokens()) { final String eachLine = tokens.nextToken(); - String cdCmd = AbstractCommand.CMD_PREFIX + "cd"; String includeCmd = AbstractCommand.CMD_PREFIX + "include"; + String importCallCmd = AbstractCommand.CMD_PREFIX + "importCall"; if (eachLine.startsWith(includeCmd)) { File file = new PathMacro().setScriptDir(scriptDir).resolveFile(eachLine.substring(includeCmd.length()).trim(), scriptDir); @@ -182,6 +187,17 @@ public class PlaybackRunner { commandList.add(new ErrorCommand("Error reading file: " + file.getAbsolutePath(), line)); return; } + } else if (eachLine.startsWith(importCallCmd)) { + String className = eachLine.substring(importCallCmd.length()).trim(); + try { + Class facadeClass = Class.forName(className); + myFacadeClasses.add(facadeClass); + myCommands.add(new PrintCommand(eachLine, line++)); + } + catch (ClassNotFoundException e) { + commandList.add(new ErrorCommand("Cannot find class: " + className, line)); + return; + } } else { final PlaybackCommand cmd = createCommand(eachLine, line++, scriptDir); commandList.add(cmd); @@ -240,55 +256,56 @@ public class PlaybackRunner { } public interface StatusCallback { - void error(String text, int currentLine); - void message(String text, int currentLine); + void error(PlaybackRunner runner, String text, int currentLine); - void code(String text, int currentLine); + void message(PlaybackRunner runner, String text, int currentLine); + + void code(PlaybackRunner runner, String text, int currentLine); public abstract static class Edt implements StatusCallback { - public final void error(final String text, final int currentLine) { + public final void error(final PlaybackRunner runner, final String text, final int currentLine) { if (SwingUtilities.isEventDispatchThread()) { - errorEdt(text, currentLine); + errorEdt(runner, text, currentLine); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { - errorEdt(text, currentLine); + errorEdt(runner, text, currentLine); } }); } } - public abstract void errorEdt(String text, int curentLine); + public abstract void errorEdt(PlaybackRunner runner, String text, int curentLine); - public final void message(final String text, final int currentLine) { + public final void message(final PlaybackRunner runner, final String text, final int currentLine) { if (SwingUtilities.isEventDispatchThread()) { - messageEdt(text, currentLine); + messageEdt(runner, text, currentLine); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { - messageEdt(text, currentLine); + messageEdt(runner, text, currentLine); } }); } } - public abstract void messageEdt(String text, int curentLine); + public abstract void messageEdt(PlaybackRunner runner, String text, int curentLine); @Override - public void code(final String text, final int currentLine) { + public void code(final PlaybackRunner runner, final String text, final int currentLine) { if (SwingUtilities.isEventDispatchThread()) { - codeEdt(text, currentLine); + codeEdt(runner, text, currentLine); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { - codeEdt(text, currentLine); + codeEdt(runner, text, currentLine); } }); } } - public abstract void codeEdt(String text, int curentLine); + public abstract void codeEdt(PlaybackRunner runner, String text, int curentLine); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java index 40a7dfa0932a..06dbfd330b37 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java @@ -51,7 +51,7 @@ public abstract class AbstractCommand implements PlaybackCommand { public final ActionCallback execute(final PlaybackContext context) { try { - dumpCommand(context.getCallback()); + dumpCommand(context); final ActionCallback result = new ActionCallback(); if (isAwtThread()) { _execute(context).notify(result); @@ -67,7 +67,7 @@ public abstract class AbstractCommand implements PlaybackCommand { return result; } catch (Exception e) { - context.getCallback().error(e.getMessage(), getLine()); + context.error(e.getMessage(), getLine()); return new ActionCallback.Rejected(); } } @@ -78,12 +78,12 @@ public abstract class AbstractCommand implements PlaybackCommand { protected abstract ActionCallback _execute(PlaybackContext context); - public void dumpCommand(final PlaybackRunner.StatusCallback cb) { - cb.code(getText(), getLine()); + public void dumpCommand(PlaybackContext context) { + context.code(getText(), getLine()); } - public void dumpError(final PlaybackRunner.StatusCallback cb, final String text) { - cb.error(text, getLine()); + public void dumpError(PlaybackContext context, final String text) { + context.error(text, getLine()); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ActionCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ActionCommand.java index 8faa9bb423f4..2ce90b56a234 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ActionCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ActionCommand.java @@ -42,7 +42,7 @@ public class ActionCommand extends TypeCommand { final ActionManager am = ActionManager.getInstance(); final AnAction targetAction = am.getAction(actionName); if (targetAction == null) { - dumpError(context.getCallback(), "Unknown action: " + actionName); + dumpError(context, "Unknown action: " + actionName); return new ActionCallback.Rejected(); } @@ -63,14 +63,19 @@ public class ActionCommand extends TypeCommand { } if (stroke != null) { - final ActionCallback result = new ActionCallback.TimedOut(Registry.intValue("actionSystem.commandProcessingTimeout"), "Timed out calling action id=" + actionName, new Throwable(), true); - context.getCallback().message("Invoking action via shortcut: " + stroke.toString(), getLine()); + final ActionCallback result = new ActionCallback.TimedOut(Registry.intValue("actionSystem.commandProcessingTimeout"), "Timed out calling action id=" + actionName, new Throwable(), true) { + @Override + protected void dumpError() { + context.error(getMessage(), getLine()); + } + }; + context.message("Invoking action via shortcut: " + stroke.toString(), getLine()); final Ref listener = new Ref(); listener.set(new AnActionListener.Adapter() { @Override public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { if (targetAction.equals(action)) { - context.getCallback().message("Performed action: " + actionName, context.getCurrentLine()); + context.message("Performed action: " + actionName, context.getCurrentLine()); am.removeAnActionListener(listener.get()); result.setDone(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AssertFocused.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AssertFocused.java index 8fd5f0c2854c..7993aae5dfa3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AssertFocused.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AssertFocused.java @@ -43,7 +43,7 @@ public class AssertFocused extends AbstractCommand { for (String each : keyValue) { final String[] eachPair = each.split("="); if (eachPair.length != 2) { - context.getCallback().error("Syntax error, must be comma-separated pairs key=value", getLine()); + context.error("Syntax error, must be comma-separated pairs key=value", getLine()); result.setRejected(); return result; } @@ -55,11 +55,11 @@ public class AssertFocused extends AbstractCommand { IdeFocusManager.findInstance().doWhenFocusSettlesDown(new Runnable() { public void run() { try { - doAssert(expected, context.getCallback()); + doAssert(expected, context); result.setDone(); } catch (AssertionError error) { - context.getCallback().error("Assertion failed: " + error.getMessage(), getLine()); + context.error("Assertion failed: " + error.getMessage(), getLine()); result.setRejected(); } } @@ -68,7 +68,7 @@ public class AssertFocused extends AbstractCommand { return result; } - private void doAssert(Map expected, PlaybackRunner.StatusCallback cb) throws AssertionError { + private void doAssert(Map expected, PlaybackContext context) throws AssertionError { final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (owner == null) { @@ -111,7 +111,7 @@ public class AssertFocused extends AbstractCommand { untestedText.append(each).append("=").append(untested.get(each)); } - cb.message("Untested info: " + untestedText.toString(), getLine()); + context.message("Untested info: " + untestedText.toString(), getLine()); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java index 831305de1eeb..69c7b1dae712 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java @@ -15,13 +15,14 @@ */ package com.intellij.openapi.ui.playback.commands; -import com.intellij.openapi.ui.playback.PlaybackCallFacade; import com.intellij.openapi.ui.playback.PlaybackContext; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.AsyncResult; +import com.intellij.openapi.util.Pair; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Set; /** * Created by IntelliJ IDEA. @@ -45,13 +46,13 @@ public class CallCommand extends AbstractCommand { final String cmd = getText().substring(PREFIX.length()).trim(); final int open = cmd.indexOf("("); if (open == -1) { - context.getCallback().error("( expected", getLine()); + context.error("( expected", getLine()); return new ActionCallback.Done(); } final int close = cmd.lastIndexOf(")"); if (close == -1) { - context.getCallback().error(") expected", getLine()); + context.error(") expected", getLine()); return new ActionCallback.Done(); } @@ -67,9 +68,16 @@ public class CallCommand extends AbstractCommand { try { - final Method m = PlaybackCallFacade.class.getMethod(methodName, types); - if (!m.getReturnType().isAssignableFrom(AsyncResult.class)) { - context.getCallback().error("Method " + methodName + " must return AsyncResult object", getLine()); + Pair methodClass = findMethod(context, methodName, types); + if (methodClass == null) { + context.error("No method \"" + methodName + "\" found in facade classes: " + context.getCallClasses(), getLine()); + return new ActionCallback.Rejected(); + } + + Method m = methodClass.getFirst(); + + if (!m.getReturnType().isAssignableFrom(AsyncResult.class)) { + context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object", getLine()); return new ActionCallback.Rejected(); } @@ -82,39 +90,51 @@ public class CallCommand extends AbstractCommand { AsyncResult result = (AsyncResult)m.invoke(null, actualArgs); if (result == null) { - context.getCallback().error("Method " + methodName + " must return AsyncResult object, but was null", getLine()); - return new ActionCallback.Done(); + context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object, but was null", getLine()); + return new ActionCallback.Rejected(); } result.doWhenDone(new AsyncResult.Handler() { @Override public void run(String s) { if (s != null) { - context.getCallback().message(s, getLine()); + context.message(s, getLine()); } cmdResult.setDone(); } }).doWhenRejected(new AsyncResult.Handler() { @Override public void run(String s) { - context.getCallback().error(s, getLine()); + context.error(s, getLine()); cmdResult.setRejected(); } }); } - catch (NoSuchMethodException e) { - context.getCallback().error("No method found in PlaybackCallFacade", getLine()); - } catch (InvocationTargetException e) { - context.getCallback().error("InvocationTargetException while executing command: " + cmd, getLine()); + context.error("InvocationTargetException while executing command: " + cmd, getLine()); } catch (IllegalAccessException e) { - context.getCallback().error("IllegalAccessException while executing command: " + cmd, getLine()); + context.error("IllegalAccessException while executing command: " + cmd, getLine()); } return cmdResult; } + private Pair findMethod(PlaybackContext context, String methodName, Class[] types) { + Set classes = context.getCallClasses(); + for (Class eachClass : classes) { + try { + Method method = eachClass.getMethod(methodName, types); + return new Pair(method, eachClass); + } + catch (NoSuchMethodException e) { + continue; + } + } + + return null; + } + @Override protected boolean isAwtThread() { return true; diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CdCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CdCommand.java index d6bbf71a93fe..7f6e4177982b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CdCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CdCommand.java @@ -42,7 +42,7 @@ public class CdCommand extends AbstractCommand { protected ActionCallback _execute(PlaybackContext context) { File file = context.getPathMacro().resolveFile(myDir, context.getBaseDir()); if (!file.exists()) { - context.getCallback().message("Cannot cd, directory doesn't exist: " + file.getAbsoluteFile(), getLine()); + context.message("Cannot cd, directory doesn't exist: " + file.getAbsoluteFile(), getLine()); return new ActionCallback.Rejected(); } @@ -53,7 +53,7 @@ public class CdCommand extends AbstractCommand { context.setBaseDir(file); } - context.getCallback().message("{base.dir} set to " + context.getBaseDir().getAbsolutePath(), getLine()); + context.message("{base.dir} set to " + context.getBaseDir().getAbsolutePath(), getLine()); return new ActionCallback.Done(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java index 71788151014f..c4689ddef1eb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java @@ -33,7 +33,7 @@ public class DelayCommand extends AbstractCommand { context.getRobot().delay(delay.intValue()); } catch (NumberFormatException e) { - dumpError(context.getCallback(), "Invalid delay value: " + s); + dumpError(context, "Invalid delay value: " + s); return new ActionCallback.Rejected(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ErrorCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ErrorCommand.java index f43df109c08a..93c1ee3292e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ErrorCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ErrorCommand.java @@ -25,7 +25,7 @@ public class ErrorCommand extends AbstractCommand { } public ActionCallback _execute(PlaybackContext context) { - dumpError(context.getCallback(), getText()); + dumpError(context, getText()); return new ActionCallback.Rejected(); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyCodeTypeCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyCodeTypeCommand.java index 05f0d23d6739..eb6063f60a10 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyCodeTypeCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyCodeTypeCommand.java @@ -64,17 +64,17 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand { } }).doWhenRejected(new Runnable() { public void run() { - typeCodes(context.getCallback(), context.getRobot(), codes).notify(result); + typeCodes(context, context.getRobot(), codes).notify(result); } }); } else { - typeCodes(context.getCallback(), context.getRobot(), codes).notify(result); + typeCodes(context, context.getRobot(), codes).notify(result); } return result; } - private ActionCallback typeCodes(PlaybackRunner.StatusCallback cb, Robot robot, String codes) { + private ActionCallback typeCodes(PlaybackContext context, Robot robot, String codes) { String[] pairs = codes.split(CODE_DELIMITER); for (String eachPair : pairs) { try { @@ -84,7 +84,7 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand { type(robot, code.intValue(), modifier.intValue()); } catch (NumberFormatException e) { - dumpError(cb, "Invalid code: " + eachPair); + dumpError(context, "Invalid code: " + eachPair); return new ActionCallback.Rejected(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyShortcutCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyShortcutCommand.java index 1849a8566956..c272125d32c2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyShortcutCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyShortcutCommand.java @@ -30,7 +30,7 @@ public class KeyShortcutCommand extends TypeCommand { public ActionCallback _execute(PlaybackContext context) { final String one = getText().substring(PREFIX.length()); if (!one.endsWith(POSTFIX)) { - dumpError(context.getCallback(), "Expected " + "]"); + dumpError(context, "Expected " + "]"); return new ActionCallback.Rejected(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java index 5577b6157eb1..68cf05a8bbfb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java @@ -36,7 +36,7 @@ public class PrintCommand extends AbstractCommand { @Override protected ActionCallback _execute(PlaybackContext context) { - context.getCallback().code(myText, getLine()); + context.code(myText, getLine()); return new ActionCallback.Done(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/StopCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/StopCommand.java index 093251864700..5e44570ec2ab 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/StopCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/StopCommand.java @@ -27,7 +27,7 @@ public class StopCommand extends AbstractCommand { } protected ActionCallback _execute(PlaybackContext context) { - context.getCallback().message("Stopped", getLine()); + context.message("Stopped", getLine()); return new ActionCallback.Done(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java index f5d097168e42..29688375d5c7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java @@ -54,7 +54,7 @@ public class ToggleActionCommand extends AbstractCommand { String[] args = getText().substring(PREFIX.length()).trim().split(" "); String syntaxText = "Syntax error, expected: " + PREFIX + " " + ON + "|" + OFF + " actionName"; if (args.length != 2) { - context.getCallback().error(syntaxText, getLine()); + context.error(syntaxText, getLine()); return new ActionCallback.Rejected(); } @@ -64,19 +64,19 @@ public class ToggleActionCommand extends AbstractCommand { } else if (OFF.equalsIgnoreCase(args[0])) { on = false; } else { - context.getCallback().error(syntaxText, getLine()); + context.error(syntaxText, getLine()); return new ActionCallback.Rejected(); } String actionId = args[1]; final AnAction action = ActionManager.getInstance().getAction(actionId); if (action == null) { - context.getCallback().error("Unknown action id=" + actionId, getLine()); + context.error("Unknown action id=" + actionId, getLine()); return new ActionCallback.Rejected(); } if (!(action instanceof ToggleAction)) { - context.getCallback().error("Action is not a toggle action id=" + actionId, getLine()); + context.error("Action is not a toggle action id=" + actionId, getLine()); return new ActionCallback.Rejected(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/util/ProjectPlaybackCall.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/util/ProjectPlaybackCall.java new file mode 100644 index 000000000000..02fcf5ec5ac4 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/util/ProjectPlaybackCall.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2011 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 com.intellij.openapi.ui.playback.util; + +import com.intellij.ide.RecentProjectsManagerBase; +import com.intellij.ide.UiActivityMonitor; +import com.intellij.openapi.project.*; +import com.intellij.openapi.startup.StartupManager; +import com.intellij.openapi.ui.Queryable; +import com.intellij.openapi.ui.playback.PlaybackContext; +import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.AsyncResult; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.ui.UIUtil; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.*; + +public class ProjectPlaybackCall { + + public static AsyncResult openProjectClone(final PlaybackContext context, String path) { + try { + File parentDir = FileUtil.createTempDirectory("funcTest", ""); + File sourceDir = context.getPathMacro().resolveFile(path, context.getBaseDir()); + + context.message("Cloning project: " + sourceDir.getAbsolutePath(), context.getCurrentLine()); + FileUtil.copyDir(sourceDir, parentDir); + File projectDir = new File(parentDir, sourceDir.getName()); + return openProject(context, projectDir.getAbsolutePath()); + } + catch (IOException e) { + return new AsyncResult.Rejected("Cannot create temp directory for clone"); + } + } + + public static AsyncResult openLastProject(final PlaybackContext context) { + return openProject(context, RecentProjectsManagerBase.getInstance().getLastProjectPath()); + } + + public static AsyncResult openProject(final PlaybackContext context, final String path) { + final AsyncResult result = new AsyncResult(); + final ProjectManager pm = ProjectManager.getInstance(); + final Ref listener = new Ref(); + listener.set(new ProjectManagerAdapter() { + @Override + public void projectOpened(final Project project) { + StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() { + @Override + public void run() { + pm.removeProjectManagerListener(listener.get()); + DumbService.getInstance(project).runWhenSmart(new Runnable() { + @Override + public void run() { + result.setDone("Opened successfully: " + project.getProjectFilePath()); + } + }); + } + }); + } + }); + pm.addProjectManagerListener(listener.get()); + + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + try { + pm.loadAndOpenProject(path); + } + catch (Exception e) { + context.error(e.getMessage(), context.getCurrentLine()); + result.setRejected(); + } + } + }); + + return result; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/util/WindowSystemPlaybackCall.java similarity index 63% rename from platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java rename to platform/platform-impl/src/com/intellij/openapi/ui/playback/util/WindowSystemPlaybackCall.java index 2472af2ff339..bcb5b606430d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/util/WindowSystemPlaybackCall.java @@ -13,91 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.ui.playback; +package com.intellij.openapi.ui.playback.util; -import com.intellij.ide.RecentProjectsManagerBase; import com.intellij.ide.UiActivityMonitor; -import com.intellij.openapi.project.*; -import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.Queryable; +import com.intellij.openapi.ui.playback.PlaybackContext; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.AsyncResult; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.ui.UIUtil; import java.awt.*; -import java.io.File; -import java.io.IOException; import java.util.*; -/** - * Created by IntelliJ IDEA. - * User: kirillk - * Date: 8/3/11 - * Time: 4:15 PM - * To change this template use File | Settings | File Templates. - */ -public class PlaybackCallFacade { - - - public static AsyncResult openProjectClone(final PlaybackContext context, String path) { - try { - File parentDir = FileUtil.createTempDirectory("funcTest", ""); - File sourceDir = context.getPathMacro().resolveFile(path, context.getBaseDir()); - - context.getCallback().message("Cloning project: " + sourceDir.getAbsolutePath(), context.getCurrentLine()); - FileUtil.copyDir(sourceDir, parentDir); - File projectDir = new File(parentDir, sourceDir.getName()); - return openProject(context, projectDir.getAbsolutePath()); - } - catch (IOException e) { - return new AsyncResult.Rejected("Cannot create temp directory for clone"); - } - } - - public static AsyncResult openLastProject(final PlaybackContext context) { - return openProject(context, RecentProjectsManagerBase.getInstance().getLastProjectPath()); - } - - public static AsyncResult openProject(final PlaybackContext context, final String path) { - final AsyncResult result = new AsyncResult(); - final ProjectManager pm = ProjectManager.getInstance(); - final Ref listener = new Ref(); - listener.set(new ProjectManagerAdapter() { - @Override - public void projectOpened(final Project project) { - StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() { - @Override - public void run() { - pm.removeProjectManagerListener(listener.get()); - DumbService.getInstance(project).runWhenSmart(new Runnable() { - @Override - public void run() { - result.setDone("Opened successfully: " + project.getProjectFilePath()); - } - }); - } - }); - } - }); - pm.addProjectManagerListener(listener.get()); - - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - try { - pm.loadAndOpenProject(path); - } - catch (Exception e) { - context.getCallback().error(e.getMessage(), context.getCurrentLine()); - result.setRejected(); - } - } - }); - - return result; - } +public class WindowSystemPlaybackCall { public static AsyncResult printFocus(final PlaybackContext context) { final AsyncResult result = new AsyncResult(); @@ -207,7 +134,7 @@ public class PlaybackCallFacade { result.setDone(); if (untestedText.length() > 0) { - context.getCallback().message("Untested focus info: " + untestedText.toString(), context.getCurrentLine()); + context.message("Untested focus info: " + untestedText.toString(), context.getCurrentLine()); } } @@ -235,5 +162,4 @@ public class PlaybackCallFacade { getUiReady(context).notify(result); return result; } - } From cd39435a8d18186184a1228bf60c2854f96556eb Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Sun, 4 Sep 2011 16:10:17 +0400 Subject: [PATCH 03/14] Flex build configuration now references real module library --- .../classpath/CreateModuleLibraryChooser.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java index 4c0af1c4ece3..b5898b227893 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.classpath; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.libraries.Library; @@ -38,21 +39,29 @@ import java.util.*; /** * @author nik */ -class CreateModuleLibraryChooser implements ClasspathElementChooser { - private final ClasspathPanel myClasspathPanel; +public class CreateModuleLibraryChooser implements ClasspathElementChooser { + private final JComponent myParentComponent; + private final Module myModule; private final LibraryTable.ModifiableModel myModuleLibrariesModel; private final HashMap myLibraryTypes; private LibraryType myLibraryType; private final DefaultLibraryRootsComponentDescriptor myDefaultDescriptor; private List myChosenRoots; - public CreateModuleLibraryChooser(ClasspathPanel classpathPanel, + public CreateModuleLibraryChooser(ClasspathPanel classpathPanel, LibraryTable.ModifiableModel moduleLibraryModel) { + this(LibraryEditingUtil.getSuitableTypes(classpathPanel), classpathPanel.getComponent(), classpathPanel.getRootModel().getModule(), + moduleLibraryModel); + } + + public CreateModuleLibraryChooser(List libraryTypes, JComponent parentComponent, + Module module, final LibraryTable.ModifiableModel moduleLibrariesModel) { - myClasspathPanel = classpathPanel; + myParentComponent = parentComponent; + myModule = module; myModuleLibrariesModel = moduleLibrariesModel; myLibraryTypes = new HashMap(); myDefaultDescriptor = new DefaultLibraryRootsComponentDescriptor(); - for (LibraryType libraryType : LibraryEditingUtil.getSuitableTypes(classpathPanel)) { + for (LibraryType libraryType : libraryTypes) { LibraryRootsComponentDescriptor descriptor = null; if (libraryType != null) { descriptor = libraryType.createLibraryRootsComponentDescriptor(); @@ -128,7 +137,6 @@ class CreateModuleLibraryChooser implements ClasspathElementChooser { } public void doChoose() { - final JComponent parent = myClasspathPanel.getComponent(); final FileChooserDescriptor chooserDescriptor; final List> descriptors = new ArrayList>(); for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) { @@ -160,9 +168,9 @@ class CreateModuleLibraryChooser implements ClasspathElementChooser { } }; } - chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myClasspathPanel.getRootModel().getModule()); + chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule); - final VirtualFile[] files = FileChooser.chooseFiles(parent, chooserDescriptor); + final VirtualFile[] files = FileChooser.chooseFiles(myParentComponent, chooserDescriptor); List suitableDescriptors = new ArrayList(); for (Pair pair : descriptors) { if (acceptAll(pair.getSecond(), files)) { @@ -179,7 +187,7 @@ class CreateModuleLibraryChooser implements ClasspathElementChooser { rootsComponentDescriptor = myDefaultDescriptor; } myChosenRoots = RootDetectionUtil - .detectRoots(Arrays.asList(files), parent, myClasspathPanel.getProject(), rootsComponentDescriptor.getRootDetectors(), true); + .detectRoots(Arrays.asList(files), myParentComponent, myModule.getProject(), rootsComponentDescriptor.getRootDetectors(), true); } private static boolean acceptAll(FileChooserDescriptor descriptor, VirtualFile[] files) { From 0ea395f185013c4c9ce8933da32b3b0a93d29170 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Sun, 4 Sep 2011 16:29:07 +0400 Subject: [PATCH 04/14] comment assertion out until proper implementation is provided --- .../roots/ui/configuration/HeaderHidingTabbedModuleEditor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java index 15e699986383..721cc77135de 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java @@ -47,7 +47,8 @@ public abstract class HeaderHidingTabbedModuleEditor extends TabbedModuleEditor if (displayName != null) { ModuleConfigurationEditor singleEditor = getSingleEditor(); if (singleEditor != null) { - assert singleEditor.getDisplayName().equals(displayName); + // TODO [ksafonov] commented until IDEA-73889 is implemented + //assert singleEditor.getDisplayName().equals(displayName); } else { super.selectEditor(displayName); From 593c85ffa6768d9f99082e50f9dd44dcd0fb2843 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Mon, 5 Sep 2011 18:48:19 +0400 Subject: [PATCH 05/14] Choose active BC action: don't disable action button when dropdown is shown --- .../actionSystem/ex/ComboBoxAction.java | 12 ++++++++-- .../intellij/openapi/ui/popup/JBPopup.java | 3 +++ .../com/intellij/ui/popup/AbstractPopup.java | 22 ++++++++++++++++++- .../com/intellij/ui/popup/WizardPopup.java | 6 +---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java index 76ca28494769..54411bd80bf6 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java @@ -45,11 +45,15 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent public JComponent createCustomComponent(Presentation presentation) { JPanel panel = new JPanel(new GridBagLayout()); - ComboBoxButton button = new ComboBoxButton(presentation); + ComboBoxButton button = createComboBoxButton(presentation); panel.add(button, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 3, 0, 3), 0, 0)); return panel; } + protected ComboBoxButton createComboBoxButton(Presentation presentation) { + return new ComboBoxButton(presentation); + } + @Override public void update(AnActionEvent e) { super.update(e); @@ -133,7 +137,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent protected ListPopup createPopup(Runnable onDispose) { DefaultActionGroup group = createPopupActionGroup(this); - DataContext context = myDataContext == null ? DataManager.getInstance().getDataContext(this) : myDataContext; + DataContext context = getDataContext(); myDataContext = null; final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( null, group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false, onDispose, getMaxRows()); @@ -141,6 +145,10 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent return popup; } + protected DataContext getDataContext() { + return myDataContext == null ? DataManager.getInstance().getDataContext(this) : myDataContext; + } + @Override public void removeNotify() { if (myButtonSynchronizer != null) { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopup.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopup.java index e2235d9c1989..23d424a71bed 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopup.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopup.java @@ -19,6 +19,7 @@ package com.intellij.openapi.ui.popup; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.ui.awt.RelativePoint; @@ -186,4 +187,6 @@ public interface JBPopup extends Disposable, LightweightWindow { void pack(boolean with, boolean height); void setAdText(String s, int alignment); + + void setDataProvider(@NotNull DataProvider dataProvider); } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index 3b9d20965474..c793d0ec9dd0 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -20,6 +20,7 @@ import com.intellij.ide.IdeEventQueue; import com.intellij.ide.UiActivityMonitor; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.ApplicationManagerEx; @@ -45,6 +46,7 @@ import com.intellij.util.Processor; import com.intellij.util.ui.ChildFocusWatcher; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -1081,9 +1083,10 @@ public class AbstractPopup implements JBPopup { } } - public static class MyContentPanel extends JPanel { + public static class MyContentPanel extends JPanel implements DataProvider { private final boolean myResizable; private final boolean myDrawMacCorner; + @Nullable private DataProvider myDataProvider; public MyContentPanel(final boolean resizable, final PopupBorder border, boolean drawMacCorner) { super(new BorderLayout()); @@ -1114,6 +1117,16 @@ public class AbstractPopup implements JBPopup { } return getPreferredSize(); } + + @Nullable + @Override + public Object getData(@NonNls String dataId) { + return myDataProvider != null ? myDataProvider.getData(dataId) : null; + } + + public void setDataProvider(DataProvider dataProvider) { + myDataProvider = dataProvider; + } } public boolean isCancelOnClickOutside() { @@ -1416,6 +1429,13 @@ public class AbstractPopup implements JBPopup { myOk = ok; } + @Override + public void setDataProvider(@NotNull DataProvider dataProvider) { + if (myContent != null) { + myContent.setDataProvider(dataProvider); + } + } + private class SpeedSearchKeyListener implements KeyListener { public void keyTyped(final KeyEvent e) { mySpeedSearch.process(e); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/WizardPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/WizardPopup.java index 9803697b7e39..8ff596a584ea 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/WizardPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/WizardPopup.java @@ -274,7 +274,7 @@ public abstract class WizardPopup extends AbstractPopup implements ActionListene return new MyContainer(resizable, border, isToDrawMacCorner); } - private static class MyContainer extends MyContentPanel implements DataProvider { + private static class MyContainer extends MyContentPanel { private MyContainer(final boolean resizable, final PopupBorder border, final boolean drawMacCorner) { super(resizable, border, drawMacCorner); @@ -282,10 +282,6 @@ public abstract class WizardPopup extends AbstractPopup implements ActionListene setFocusCycleRoot(true); } - public Object getData(String dataId) { - return null; - } - public Dimension getPreferredSize() { final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); Point p = null; From 5c9b957e81f0ee6955ea225e3e93ec2e2b3ea150 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Mon, 5 Sep 2011 19:08:27 +0400 Subject: [PATCH 06/14] Flex SDK now have Global library underneath --- .../openapi/ui/MasterDetailsComponent.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index ca35b3374c70..f42ee6c2fd80 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -638,17 +638,21 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom LOG.error("createComponent() returned null. configurable=" + configurable); } else { myDetails.setContent(comp); - if (!isInitialized(configurable)) { - configurable.reset(); - initializeConfigurable(configurable); - } - myHistory.pushPlaceForElement(TREE_OBJECT, configurable.getEditableObject()); + ensureInitialized(configurable); + myHistory.pushPlaceForElement(TREE_OBJECT, configurable.getEditableObject()); } } else { setEmpty(); } } + public void ensureInitialized(NamedConfigurable configurable) { + if (!isInitialized(configurable)) { + configurable.reset(); + initializeConfigurable(configurable); + } + } + private void setEmpty() { myDetails.setContent(null); myDetails.setEmptyContentText(getEmptySelectionString()); From e05c9f39538a083123d77fc3c67b71d4d7b02854 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 5 Sep 2011 20:40:34 +0400 Subject: [PATCH 07/14] IDEA-73895 Default Project: Browse SVN repository -> Browse changes -> stays "Loading..." --- .../committed/ChangesBrowserDialog.java | 43 +++++++++++---- .../vcs/impl/AbstractVcsHelperImpl.java | 54 +++++++++++-------- .../svn/history/SvnRepositoryLocation.java | 1 + .../svn/update/SvnSelectRevisionUtil.java | 2 +- 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ChangesBrowserDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ChangesBrowserDialog.java index 906e5adcd732..b06fd4969b66 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ChangesBrowserDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ChangesBrowserDialog.java @@ -23,6 +23,8 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.util.AsynchConsumer; +import com.intellij.util.Consumer; +import com.intellij.util.ui.AdjustComponentWhenShown; import javax.swing.*; import java.awt.*; @@ -37,16 +39,19 @@ public class ChangesBrowserDialog extends DialogWrapper { private Mode myMode; private CommittedChangesBrowser myCommittedChangesBrowser; private AsynchConsumer> myAppender; + private final Consumer myInitRunnable; public enum Mode { Simple, Browse, Choose } - public ChangesBrowserDialog(Project project, CommittedChangesTableModel changes, final Mode mode) { + public ChangesBrowserDialog(Project project, CommittedChangesTableModel changes, final Mode mode, Consumer initRunnable) { super(project, true); + myInitRunnable = initRunnable; initDialog(project, changes, mode); } - public ChangesBrowserDialog(Project project, Component parent, CommittedChangesTableModel changes, final Mode mode) { + public ChangesBrowserDialog(Project project, Component parent, CommittedChangesTableModel changes, final Mode mode, Consumer initRunnable) { super(parent, true); + myInitRunnable = initRunnable; initDialog(project, changes, mode); } @@ -63,27 +68,43 @@ public class ChangesBrowserDialog extends DialogWrapper { myAppender = new AsynchConsumer>() { public void finished() { - new AbstractCalledLater(myProject, ModalityState.stateForComponent(myCommittedChangesBrowser)) { + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - myCommittedChangesBrowser.stopLoading(); + if (ChangesBrowserDialog.this.isShowing()) { + myCommittedChangesBrowser.stopLoading(); + } } - }.callMe(); + }); } public void consume(final List committedChangeLists) { - new AbstractCalledLater(myProject, ModalityState.stateForComponent(myCommittedChangesBrowser)) { + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty()); - myChanges.addRows(committedChangeLists); - if (selectFirst) { - myCommittedChangesBrowser.selectFirstIfAny(); + if (ChangesBrowserDialog.this.isShowing()) { + final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty()); + myChanges.addRows(committedChangeLists); + if (selectFirst) { + myCommittedChangesBrowser.selectFirstIfAny(); + } } } - }.callMe(); + }); } }; init(); + + if (myInitRunnable != null) { + new AdjustComponentWhenShown() { + @Override + protected boolean init() { + myInitRunnable.consume(ChangesBrowserDialog.this); + return true; + } + }.install(myCommittedChangesBrowser); + } } public AsynchConsumer> getAppender() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java index e89ab9aa5554..49ec2d4261f4 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java @@ -33,6 +33,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; @@ -393,13 +394,13 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { } private ChangesBrowserDialog createChangesBrowserDialog(CommittedChangesTableModel changelists, - String title, - boolean showSearchAgain, - @Nullable final Component parent) { + String title, + boolean showSearchAgain, + @Nullable final Component parent, Consumer initRunnable) { final ChangesBrowserDialog.Mode mode = showSearchAgain ? ChangesBrowserDialog.Mode.Browse : ChangesBrowserDialog.Mode.Simple; final ChangesBrowserDialog dlg = parent != null - ? new ChangesBrowserDialog(myProject, parent, changelists, mode) - : new ChangesBrowserDialog(myProject, changelists, mode); + ? new ChangesBrowserDialog(myProject, parent, changelists, mode, initRunnable) + : new ChangesBrowserDialog(myProject, changelists, mode, initRunnable); if (title != null) { dlg.setTitle(title); } @@ -412,8 +413,8 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { @Nullable final Component parent) { final ChangesBrowserDialog.Mode mode = showSearchAgain ? ChangesBrowserDialog.Mode.Browse : ChangesBrowserDialog.Mode.Simple; final ChangesBrowserDialog dlg = parent != null - ? new ChangesBrowserDialog(myProject, parent, changelists, mode) - : new ChangesBrowserDialog(myProject, changelists, mode); + ? new ChangesBrowserDialog(myProject, parent, changelists, mode, null) + : new ChangesBrowserDialog(myProject, changelists, mode, null); if (title != null) { dlg.setTitle(title); } @@ -468,24 +469,31 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { parent = WindowManager.getInstance().suggestParentWindow(myProject); } final CommittedChangesTableModel model = new CommittedChangesTableModel(versions, true); - final ChangesBrowserDialog dlg = createChangesBrowserDialog(model, title, filterUI != null, parent); + final AsynchronousListsLoader[] task = new AsynchronousListsLoader[1]; + final ChangeBrowserSettings finalSettings = settings; + final ChangesBrowserDialog dlg = createChangesBrowserDialog(model, title, filterUI != null, parent, new Consumer() { + @Override + public void consume(ChangesBrowserDialog changesBrowserDialog) { + task[0] = new AsynchronousListsLoader(myProject, provider, location, finalSettings, changesBrowserDialog); + ProgressManager.getInstance().run(task[0]); + } + }); - final AsynchronousListsLoader task = new AsynchronousListsLoader(myProject, provider, location, settings, dlg); - ProgressManager.getInstance().run(task); - dlg.show(); dlg.startLoading(); - task.cancel(); + dlg.show(); + if (task[0] != null) { + task[0].cancel(); + final List exceptions = task[0].getExceptions(); + if (! exceptions.isEmpty()) { + Messages.showErrorDialog(myProject, VcsBundle.message("browse.changes.error.message", exceptions.get(0).getMessage()), + VcsBundle.message("browse.changes.error.title")); + return; + } - final List exceptions = task.getExceptions(); - if (! exceptions.isEmpty()) { - Messages.showErrorDialog(myProject, VcsBundle.message("browse.changes.error.message", exceptions.get(0).getMessage()), - VcsBundle.message("browse.changes.error.title")); - return; - } - - if (! task.isRevisionsReturned()) { - Messages.showInfoMessage(myProject, VcsBundle.message("browse.changes.nothing.found"), - VcsBundle.message("browse.changes.nothing.found.title")); + if (! task[0].isRevisionsReturned()) { + Messages.showInfoMessage(myProject, VcsBundle.message("browse.changes.nothing.found"), + VcsBundle.message("browse.changes.nothing.found.title")); + } } } else { @@ -506,7 +514,7 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { } final ChangesBrowserDialog dlg = new ChangesBrowserDialog(myProject, new CommittedChangesTableModel((List)changes, provider.getColumns(), false), - ChangesBrowserDialog.Mode.Choose); + ChangesBrowserDialog.Mode.Choose, null); dlg.show(); if (dlg.isOK()) { return (T)dlg.getSelectedChangeList(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnRepositoryLocation.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnRepositoryLocation.java index d18aca96c732..3d5bcaf0d92b 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnRepositoryLocation.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnRepositoryLocation.java @@ -61,6 +61,7 @@ public class SvnRepositoryLocation implements RepositoryLocation { @Nullable public static FilePath getLocalPath(final String fullPath, final NotNullFunction detector, final SvnVcs vcs) { + if (vcs.getProject().isDefault()) return null; final RootUrlInfo rootForUrl = vcs.getSvnFileUrlMapping().getWcRootForUrl(fullPath); if (rootForUrl != null) { return LocationDetector.filePathByUrlAndPath(fullPath, rootForUrl.getUrl().toString(), rootForUrl.getIoFile().getAbsolutePath(), detector); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SvnSelectRevisionUtil.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SvnSelectRevisionUtil.java index ad6f257ede94..b86236825981 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SvnSelectRevisionUtil.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SvnSelectRevisionUtil.java @@ -37,7 +37,7 @@ public class SvnSelectRevisionUtil { try { final SvnCommittedChangesTableModel model = new SvnCommittedChangesTableModel(location, project, root, SvnVcs.getInstance(project).getCommittedChangesProvider().getColumns()); - final ChangesBrowserDialog dlg = new ChangesBrowserDialog(project, model, ChangesBrowserDialog.Mode.Choose); + final ChangesBrowserDialog dlg = new ChangesBrowserDialog(project, model, ChangesBrowserDialog.Mode.Choose, null); dlg.show(); if (dlg.isOK()) { return (SvnChangeList) dlg.getSelectedChangeList(); From 2aa2d87bf53be9de9a50fe37cce37a95fb3f0774 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 5 Sep 2011 20:50:37 +0400 Subject: [PATCH 08/14] correct dispose chain for svn repository browser --- .../org/jetbrains/idea/svn/actions/BrowseRepositoryAction.java | 3 ++- .../jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BrowseRepositoryAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BrowseRepositoryAction.java index ae17100b9ba3..b983b6fb9d25 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BrowseRepositoryAction.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BrowseRepositoryAction.java @@ -24,6 +24,7 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; @@ -51,7 +52,7 @@ public class BrowseRepositoryAction extends AnAction implements DumbAware { RepositoryToolWindowPanel component = new RepositoryToolWindowPanel(project); w = manager.registerToolWindow(REPOSITORY_BROWSER_TOOLWINDOW, true, ToolWindowAnchor.BOTTOM, project, true); final Content content = ContentFactory.SERVICE.getInstance().createContent(component, "", false); - content.setDisposer(component); + Disposer.register(content, component); w.getContentManager().addContent(content); } w.show(null); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java index 3cf14e87ae4e..46b01dd3699d 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java @@ -116,6 +116,7 @@ public class RepositoryBrowserDialog extends DialogWrapper { setResizable(true); setOKButtonText(CommonBundle.getCloseButtonText()); getHelpAction().setEnabled(true); + Disposer.register(project, getDisposable()); init(); } From 22b304a65b541604b811b0ce698eaf6aeacb5738 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 5 Sep 2011 19:28:42 +0200 Subject: [PATCH 09/14] pretty-printing --- .../intellij/util/io/PersistentHashMap.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/PersistentHashMap.java b/platform/util/src/com/intellij/util/io/PersistentHashMap.java index e8bdb97c4cc0..ae60e05fa38c 100644 --- a/platform/util/src/com/intellij/util/io/PersistentHashMap.java +++ b/platform/util/src/com/intellij/util/io/PersistentHashMap.java @@ -119,7 +119,9 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< ); updateValueId(id, headerRecord, oldHeaderRecord, key, 0); - if (oldHeaderRecord == HeaderRecord.EMPTY) myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; + if (oldHeaderRecord == HeaderRecord.EMPTY) { + myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; + } myStreamPool.recycle(value); } @@ -262,8 +264,12 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< final int id = enumerate(key); HeaderRecord oldheader = readValueId(id); - if (oldheader != HeaderRecord.EMPTY) myLiveAndGarbageKeysCounter++; - else myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; + if (oldheader != HeaderRecord.EMPTY) { + myLiveAndGarbageKeysCounter++; + } + else { + myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; + } HeaderRecord header = new HeaderRecord(myValueStorage.appendBytes(bytes, 0)); @@ -330,7 +336,9 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< myEnumerator.markDirty(true); updateValueId(id, new HeaderRecord(readResult.first), oldHeader, key, 0); - if (oldHeader != HeaderRecord.EMPTY) myLiveAndGarbageKeysCounter++; + if (oldHeader != HeaderRecord.EMPTY) { + myLiveAndGarbageKeysCounter++; + } } final DataInputStream input = new DataInputStream(new ByteArrayInputStream(readResult.second)); @@ -364,7 +372,9 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< myEnumerator.markDirty(true); final HeaderRecord record = readValueId(id); - if (record != HeaderRecord.EMPTY) myLiveAndGarbageKeysCounter++; + if (record != HeaderRecord.EMPTY) { + myLiveAndGarbageKeysCounter++; + } updateValueId(id, HeaderRecord.EMPTY, record, key, 0); } From 0d5211ba43acea77cf3225bb36ccba407cc6bf31 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 5 Sep 2011 17:03:06 +0200 Subject: [PATCH 10/14] AbstractInplaceIntroduceTest should be a little bit more abstract --- .../refactoring/AbstractJavaInplaceIntroduceTest.java | 4 ++++ .../refactoring/AbstractInplaceIntroduceTest.java | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java b/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java index ce82087c79ad..1305b2f80d90 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java @@ -57,4 +57,8 @@ public abstract class AbstractJavaInplaceIntroduceTest extends AbstractInplaceIn protected Sdk getProjectJDK() { return JavaSdkImpl.getMockJdk17(); } + + protected String getExtension() { + return ".java"; + } } diff --git a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java index f57904cefeaa..11b728e10a22 100644 --- a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java +++ b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java @@ -42,7 +42,7 @@ public abstract class AbstractInplaceIntroduceTest pass) throws Exception { String name = getTestName(true); - configureByFile(getBasePath() + name + ".java"); + configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(LightPlatformTestCase.getProject()); try { @@ -89,7 +91,7 @@ public abstract class AbstractInplaceIntroduceTest Date: Mon, 5 Sep 2011 17:32:41 +0200 Subject: [PATCH 11/14] reduce the amount of 'throws Exception' in tests --- .../SecondSmartTypeCompletionTest.java | 2 +- .../completion/LightCompletionTestCase.java | 2 +- .../AbstractInplaceIntroduceTest.java | 4 ++-- .../LightPlatformCodeInsightTestCase.java | 21 ++++++++++++------- .../intellij/lang/ant/AntCompletionTest.java | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java index 3415ee36487e..1ca4b78816c8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java @@ -153,7 +153,7 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase { checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java"); } - protected void checkResultByFile(@NonNls final String filePath) throws Exception { + protected void checkResultByFile(@NonNls final String filePath) { if (myItems != null) { //System.out.println("items = " + Arrays.asList(myItems)); } diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/LightCompletionTestCase.java b/java/testFramework/src/com/intellij/codeInsight/completion/LightCompletionTestCase.java index 2ea0e76a0a81..c16e9f6a174a 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/LightCompletionTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/completion/LightCompletionTestCase.java @@ -48,7 +48,7 @@ public abstract class LightCompletionTestCase extends LightCodeInsightTestCase { } @Override - protected void configureByFile(String filePath) throws Exception { + protected void configureByFile(String filePath) { super.configureByFile(filePath); complete(); diff --git a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java index 11b728e10a22..ab4d3bda1034 100644 --- a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java +++ b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java @@ -40,7 +40,7 @@ public abstract class AbstractInplaceIntroduceTest createIntroduceHandler(); - protected void doTestEscape() throws Exception { + protected void doTestEscape() { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); @@ -70,7 +70,7 @@ public abstract class AbstractInplaceIntroduceTest pass) throws Exception { + protected void doTest(final Pass pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 3b20d4d5939c..d88cf3bc69b5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -101,14 +101,19 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest * @param filePath - relative path from %IDEA_INSTALLATION_HOME%/testData/ * @throws Exception */ - protected void configureByFile(@TestDataFile @NonNls String filePath) throws Exception { - String fullPath = getTestDataPath() + filePath; + protected void configureByFile(@TestDataFile @NonNls String filePath) { + try { + String fullPath = getTestDataPath() + filePath; - final File ioFile = new File(fullPath); - String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8); - fileText = StringUtil.convertLineSeparators(fileText); + final File ioFile = new File(fullPath); + String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8); + fileText = StringUtil.convertLineSeparators(fileText); - configureFromFileText(ioFile.getName(), fileText); + configureFromFileText(ioFile.getName(), fileText); + } + catch (IOException e) { + throw new RuntimeException(e); + } } @NonNls @@ -249,7 +254,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest * @param filePath - relative path from %IDEA_INSTALLATION_HOME%/testData/ * @throws Exception */ - protected void checkResultByFile(@NonNls String filePath) throws Exception { + protected void checkResultByFile(@NonNls String filePath) { checkResultByFile(null, filePath, false); } @@ -261,7 +266,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing. * @throws Exception */ - protected void checkResultByFile(@Nullable String message, final String filePath, final boolean ignoreTrailingSpaces) throws Exception { + protected void checkResultByFile(@Nullable String message, final String filePath, final boolean ignoreTrailingSpaces) { bringRealEditorBack(); getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java index 3233a7620fd9..d60fc5a334dd 100644 --- a/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java +++ b/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java @@ -37,7 +37,7 @@ public class AntCompletionTest extends LightCodeInsightTestCase { } @Override - protected void configureByFile(@TestDataFile @NonNls String filePath) throws Exception { + protected void configureByFile(@TestDataFile @NonNls String filePath) { super.configureByFile(filePath); AntSupport.markFileAsAntFile(myVFile, myFile.getProject(), true); } From c4ec687c0dffad7f086ea1b1c015793325e137ce Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 5 Sep 2011 17:53:29 +0200 Subject: [PATCH 12/14] push down more Java specific stuff, remove unnecessary generification --- .../AbstractJavaInplaceIntroduceTest.java | 39 ++++++++++++++----- .../InplaceIntroduceConstantTest.java | 2 +- .../InplaceIntroduceFieldTest.java | 2 +- .../InplaceIntroduceParameterTest.java | 2 +- .../AbstractInplaceIntroduceTest.java | 37 +++--------------- 5 files changed, 38 insertions(+), 44 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java b/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java index 1305b2f80d90..ff71ff364e15 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/AbstractJavaInplaceIntroduceTest.java @@ -15,11 +15,16 @@ */ package com.intellij.refactoring; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer; import com.intellij.testFramework.IdeaTestCase; +import com.intellij.testFramework.LightPlatformTestCase; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -33,22 +38,18 @@ public abstract class AbstractJavaInplaceIntroduceTest extends AbstractInplaceIn super.setUp(); } - @Override @Nullable - protected PsiExpression getExpressionFromEditor() { - final PsiExpression expression = - PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class); + protected static PsiExpression getExpressionFromEditor() { + final PsiExpression expression = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class); if (expression instanceof PsiReferenceExpression && expression.getParent() instanceof PsiMethodCallExpression) { return (PsiExpression)expression.getParent(); } return expression; } - - @Override - protected PsiLocalVariable getLocalVariableFromEditor() { - final PsiLocalVariable localVariable = - PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class); + protected static PsiLocalVariable getLocalVariableFromEditor() { + final PsiLocalVariable localVariable = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), + PsiLocalVariable.class); assertNotNull(localVariable); return localVariable; } @@ -61,4 +62,24 @@ public abstract class AbstractJavaInplaceIntroduceTest extends AbstractInplaceIn protected String getExtension() { return ".java"; } + + protected abstract MyIntroduceHandler createIntroduceHandler(); + + protected AbstractInplaceIntroducer invokeRefactoring() { + final MyIntroduceHandler introduceHandler = createIntroduceHandler(); + final PsiExpression expression = getExpressionFromEditor(); + if (expression != null) { + introduceHandler.invokeImpl(LightPlatformTestCase.getProject(), expression, getEditor()); + } else { + final PsiLocalVariable localVariable = getLocalVariableFromEditor(); + introduceHandler.invokeImpl(LightPlatformTestCase.getProject(), localVariable, getEditor()); + } + return introduceHandler.getInplaceIntroducer(); + } + + public interface MyIntroduceHandler { + boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor); + boolean invokeImpl(Project project, PsiLocalVariable localVariable, Editor editor); + AbstractInplaceIntroducer getInplaceIntroducer(); + } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceConstantTest.java index 927100df566e..c1fae0c4bc45 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceConstantTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceConstantTest.java @@ -111,7 +111,7 @@ public class InplaceIntroduceConstantTest extends AbstractJavaInplaceIntroduceTe return new MyIntroduceConstantHandler(); } - public static class MyIntroduceConstantHandler extends IntroduceConstantHandler implements MyIntroduceHandler { + public static class MyIntroduceConstantHandler extends IntroduceConstantHandler implements MyIntroduceHandler { @Override public boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor) { return super.invokeImpl(project, selectedExpr, editor); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java index 83a5203640eb..41464013761a 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java @@ -98,7 +98,7 @@ public class InplaceIntroduceFieldTest extends AbstractJavaInplaceIntroduceTest return new MyIntroduceFieldHandler(); } - public static class MyIntroduceFieldHandler extends IntroduceFieldHandler implements MyIntroduceHandler { + public static class MyIntroduceFieldHandler extends IntroduceFieldHandler implements MyIntroduceHandler { @Override public boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor) { return super.invokeImpl(project, selectedExpr, editor); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java index 482b9e6fa7ae..c1df6573a3f8 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java @@ -93,7 +93,7 @@ public class InplaceIntroduceParameterTest extends AbstractJavaInplaceIntroduceT fail("Conflict expected"); } - private static class MyIntroduceParameterHandler extends IntroduceParameterHandler implements MyIntroduceHandler { + private static class MyIntroduceParameterHandler extends IntroduceParameterHandler implements MyIntroduceHandler { @Override public boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor) { diff --git a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java index ab4d3bda1034..6e4c60594f1c 100644 --- a/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java +++ b/platform/testFramework/src/com/intellij/refactoring/AbstractInplaceIntroduceTest.java @@ -18,27 +18,18 @@ package com.intellij.refactoring; import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pass; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import com.intellij.testFramework.LightPlatformTestCase; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * User: anna * Date: 8/25/11 */ -public abstract class AbstractInplaceIntroduceTest extends LightPlatformCodeInsightTestCase { - @Nullable protected abstract V getLocalVariableFromEditor(); - @Nullable protected abstract E getExpressionFromEditor(); +public abstract class AbstractInplaceIntroduceTest extends LightPlatformCodeInsightTestCase { protected abstract String getBasePath(); - protected abstract MyIntroduceHandler createIntroduceHandler(); protected void doTestEscape() { String name = getTestName(true); @@ -49,14 +40,7 @@ public abstract class AbstractInplaceIntroduceTest { - boolean invokeImpl(Project project, @NotNull EH selectedExpr, Editor editor); - boolean invokeImpl(Project project, VH localVariable, Editor editor); - AbstractInplaceIntroducer getInplaceIntroducer(); - } + protected abstract AbstractInplaceIntroducer invokeRefactoring(); } From d3888b6083f1915920d4bb4c8f39fe8c11305879 Mon Sep 17 00:00:00 2001 From: Alexander Kirillin Date: Mon, 5 Sep 2011 22:46:53 +0400 Subject: [PATCH 13/14] splitting annotator and inspections --- .../daemon/impl/LocalInspectionsPassFactory.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java index 056a56667495..53f040a77f57 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java @@ -40,13 +40,7 @@ import java.util.List; public class LocalInspectionsPassFactory extends AbstractProjectComponent implements MainHighlightingPassFactory { public LocalInspectionsPassFactory(Project project, TextEditorHighlightingPassRegistrar highlightingPassRegistrar) { super(project); - - if ( PlatformUtils.isCidr()) { //TODO rework this hack - highlightingPassRegistrar.registerTextEditorHighlightingPass(this, new int[]{Pass.UPDATE_ALL/*, Pass.POPUP_HINTS*/}, null, true, Pass.LOCAL_INSPECTIONS); - } - else { - highlightingPassRegistrar.registerTextEditorHighlightingPass(this, null, new int[]{Pass.UPDATE_ALL/*, Pass.POPUP_HINTS*/}, true, Pass.LOCAL_INSPECTIONS); - } + highlightingPassRegistrar.registerTextEditorHighlightingPass(this, null, new int[]{Pass.UPDATE_ALL/*, Pass.POPUP_HINTS*/}, true, Pass.LOCAL_INSPECTIONS); } @NonNls From 93e3bebb827b06ada109b18618e912b9d2ab6bb3 Mon Sep 17 00:00:00 2001 From: "andrey.zaytsev" Date: Tue, 6 Sep 2011 03:55:23 +0400 Subject: [PATCH 14/14] ugly temporary hack of classloading to ensure that deploy.jar is included in class-path. Needed for using UnixDomainSocket class in AppCode only so far. --- .../src/com/intellij/ide/ClassloaderUtil.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java index 75590af44917..6c76e6b4907a 100644 --- a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java +++ b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java @@ -23,6 +23,7 @@ import com.intellij.ide.startup.StartupActionScriptManager; import com.intellij.idea.Main; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; @@ -91,6 +92,9 @@ public class ClassloaderUtil { addParentClasspath(classpathElements); addIDEALibraries(classpathElements); addAdditionalClassPath(classpathElements); + if (SystemInfo.isMac) { + addDeployJar(classpathElements); + } } catch (IllegalArgumentException e) { if (Main.isHeadless()) { @@ -148,6 +152,17 @@ public class ClassloaderUtil { return newClassLoader; } + private static void addDeployJar(List classpathElements) { + File deployJar = new File("/System/Library/Java/Support/Deploy.bundle/Contents/Home/lib/deploy.jar"); // todo[zajac] + if (deployJar.exists()) { + try { + classpathElements.add(deployJar.toURI().toURL()); + } + catch (MalformedURLException ignore) { + } + } + } + public static void filterClassPath(final List classpathElements) { final String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH); if (ignoreProperty == null) return;