Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Alexey Pegov
2011-09-06 09:55:59 +04:00
47 changed files with 515 additions and 304 deletions
@@ -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);
@@ -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<Library> {
private final ClasspathPanel myClasspathPanel;
public class CreateModuleLibraryChooser implements ClasspathElementChooser<Library> {
private final JComponent myParentComponent;
private final Module myModule;
private final LibraryTable.ModifiableModel myModuleLibrariesModel;
private final HashMap<LibraryRootsComponentDescriptor,LibraryType> myLibraryTypes;
private LibraryType myLibraryType;
private final DefaultLibraryRootsComponentDescriptor myDefaultDescriptor;
private List<OrderRoot> 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<? extends LibraryType> libraryTypes, JComponent parentComponent,
Module module,
final LibraryTable.ModifiableModel moduleLibrariesModel) {
myClasspathPanel = classpathPanel;
myParentComponent = parentComponent;
myModule = module;
myModuleLibrariesModel = moduleLibrariesModel;
myLibraryTypes = new HashMap<LibraryRootsComponentDescriptor, LibraryType>();
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<Library> {
}
public void doChoose() {
final JComponent parent = myClasspathPanel.getComponent();
final FileChooserDescriptor chooserDescriptor;
final List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>>();
for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) {
@@ -160,9 +168,9 @@ class CreateModuleLibraryChooser implements ClasspathElementChooser<Library> {
}
};
}
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<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<LibraryRootsComponentDescriptor>();
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (acceptAll(pair.getSecond(), files)) {
@@ -179,7 +187,7 @@ class CreateModuleLibraryChooser implements ClasspathElementChooser<Library> {
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) {
@@ -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));
}
@@ -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;
}
@@ -57,4 +58,28 @@ public abstract class AbstractJavaInplaceIntroduceTest extends AbstractInplaceIn
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
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();
}
}
@@ -111,7 +111,7 @@ public class InplaceIntroduceConstantTest extends AbstractJavaInplaceIntroduceTe
return new MyIntroduceConstantHandler();
}
public static class MyIntroduceConstantHandler extends IntroduceConstantHandler implements MyIntroduceHandler<PsiExpression, PsiLocalVariable> {
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);
@@ -98,7 +98,7 @@ public class InplaceIntroduceFieldTest extends AbstractJavaInplaceIntroduceTest
return new MyIntroduceFieldHandler();
}
public static class MyIntroduceFieldHandler extends IntroduceFieldHandler implements MyIntroduceHandler<PsiExpression, PsiLocalVariable> {
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);
@@ -93,7 +93,7 @@ public class InplaceIntroduceParameterTest extends AbstractJavaInplaceIntroduceT
fail("Conflict expected");
}
private static class MyIntroduceParameterHandler extends IntroduceParameterHandler implements MyIntroduceHandler<PsiExpression, PsiLocalVariable> {
private static class MyIntroduceParameterHandler extends IntroduceParameterHandler implements MyIntroduceHandler {
@Override
public boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor) {
@@ -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();
@@ -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<URL> 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<URL> classpathElements) {
final String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH);
if (ignoreProperty == null) return;
@@ -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();
@@ -1 +1,4 @@
%cd {script.dir}/../../../..
%importCall com.intellij.openapi.ui.playback.util.WindowSystemPlaybackCall
%importCall com.intellij.openapi.ui.playback.util.ProjectPlaybackCall
%cd {script.dir}/../../../..
@@ -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
@@ -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();
}
@@ -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);
@@ -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) {
@@ -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());
@@ -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);
}
@@ -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();
}
@@ -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);
@@ -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<Class> myCallClasses;
private PlaybackRunner myRunner;
public PlaybackContext(PlaybackRunner runner, PlaybackRunner.StatusCallback callback, int currentLine, Robot robot, boolean useDriectActionCall, PlaybackCommand currentCmd, File baseDir, Set<Class> 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<Class> 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);
}
}
@@ -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<Class> myFacadeClasses = new HashSet<Class>();
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<Class>)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);
}
}
@@ -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
@@ -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<AnActionListener> listener = new Ref<AnActionListener>();
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();
}
@@ -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<String, String> expected, PlaybackRunner.StatusCallback cb) throws AssertionError {
private void doAssert(Map<String, String> 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());
}
}
@@ -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<Method, Class> 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<String>)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<String>() {
@Override
public void run(String s) {
if (s != null) {
context.getCallback().message(s, getLine());
context.message(s, getLine());
}
cmdResult.setDone();
}
}).doWhenRejected(new AsyncResult.Handler<String>() {
@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<Method, Class> findMethod(PlaybackContext context, String methodName, Class[] types) {
Set<Class> classes = context.getCallClasses();
for (Class eachClass : classes) {
try {
Method method = eachClass.getMethod(methodName, types);
return new Pair<Method, Class>(method, eachClass);
}
catch (NoSuchMethodException e) {
continue;
}
}
return null;
}
@Override
protected boolean isAwtThread() {
return true;
@@ -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();
}
}
@@ -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();
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
@@ -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();
}
}
@@ -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();
}
@@ -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();
}
@@ -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<String> 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<String>("Cannot create temp directory for clone");
}
}
public static AsyncResult<String> openLastProject(final PlaybackContext context) {
return openProject(context, RecentProjectsManagerBase.getInstance().getLastProjectPath());
}
public static AsyncResult<String> openProject(final PlaybackContext context, final String path) {
final AsyncResult<String> result = new AsyncResult<String>();
final ProjectManager pm = ProjectManager.getInstance();
final Ref<ProjectManagerListener> listener = new Ref<ProjectManagerListener>();
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;
}
}
@@ -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<String> 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<String>("Cannot create temp directory for clone");
}
}
public static AsyncResult<String> openLastProject(final PlaybackContext context) {
return openProject(context, RecentProjectsManagerBase.getInstance().getLastProjectPath());
}
public static AsyncResult<String> openProject(final PlaybackContext context, final String path) {
final AsyncResult<String> result = new AsyncResult<String>();
final ProjectManager pm = ProjectManager.getInstance();
final Ref<ProjectManagerListener> listener = new Ref<ProjectManagerListener>();
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<String> printFocus(final PlaybackContext context) {
final AsyncResult result = new AsyncResult<String>();
@@ -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;
}
}
@@ -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);
@@ -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;
@@ -18,49 +18,33 @@ 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<E extends PsiElement, V extends PsiNameIdentifierOwner> 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<E, V> createIntroduceHandler();
protected void doTestEscape() throws Exception {
protected void doTestEscape() {
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 {
templateManager.setTemplateTesting(true);
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
final MyIntroduceHandler introduceFieldHandler = createIntroduceHandler();
final E expression = getExpressionFromEditor();
if (expression != null) {
introduceFieldHandler.invokeImpl(LightPlatformTestCase.getProject(), expression, getEditor());
} else {
final V localVariable = getLocalVariableFromEditor();
introduceFieldHandler.invokeImpl(LightPlatformTestCase.getProject(), localVariable, getEditor());
}
invokeRefactoring();
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
state.gotoEnd(true);
checkResultByFile(getBasePath() + name + "_after.java");
checkResultByFile(getBasePath() + name + "_after" + getExtension());
}
finally {
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
@@ -68,28 +52,23 @@ public abstract class AbstractInplaceIntroduceTest<E extends PsiElement, V exten
}
}
protected void doTest(final Pass<AbstractInplaceIntroducer> pass) throws Exception {
protected abstract String getExtension();
protected void doTest(final Pass<AbstractInplaceIntroducer> pass) {
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 {
templateManager.setTemplateTesting(true);
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
final MyIntroduceHandler introduceFieldHandler = createIntroduceHandler();
final E expression = getExpressionFromEditor();
if (expression != null) {
introduceFieldHandler.invokeImpl(LightPlatformTestCase.getProject(), expression, getEditor());
} else {
final V localVariable = getLocalVariableFromEditor();
introduceFieldHandler.invokeImpl(LightPlatformTestCase.getProject(), localVariable, getEditor());
}
pass.pass(introduceFieldHandler.getInplaceIntroducer());
final AbstractInplaceIntroducer introducer = invokeRefactoring();
pass.pass(introducer);
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
state.gotoEnd(false);
checkResultByFile(getBasePath() + name + "_after.java");
checkResultByFile(getBasePath() + name + "_after" + getExtension());
}
finally {
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
@@ -97,9 +76,5 @@ public abstract class AbstractInplaceIntroduceTest<E extends PsiElement, V exten
}
}
public interface MyIntroduceHandler<EH extends PsiElement, VH extends PsiNameIdentifierOwner> {
boolean invokeImpl(Project project, @NotNull EH selectedExpr, Editor editor);
boolean invokeImpl(Project project, VH localVariable, Editor editor);
AbstractInplaceIntroducer getInplaceIntroducer();
}
protected abstract AbstractInplaceIntroducer invokeRefactoring();
}
@@ -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();
@@ -119,7 +119,9 @@ public class PersistentHashMap<Key, Value> 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<Key, Value> 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<Key, Value> 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<Key, Value> 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);
}
@@ -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<List<CommittedChangeList>> myAppender;
private final Consumer<ChangesBrowserDialog> 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<ChangesBrowserDialog> 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<ChangesBrowserDialog> initRunnable) {
super(parent, true);
myInitRunnable = initRunnable;
initDialog(project, changes, mode);
}
@@ -63,27 +68,43 @@ public class ChangesBrowserDialog extends DialogWrapper {
myAppender = new AsynchConsumer<List<CommittedChangeList>>() {
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<CommittedChangeList> 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<List<CommittedChangeList>> getAppender() {
@@ -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<ChangesBrowserDialog> 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<ChangesBrowserDialog>() {
@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<VcsException> 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<VcsException> 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<CommittedChangeList>)changes,
provider.getColumns(), false),
ChangesBrowserDialog.Mode.Choose);
ChangesBrowserDialog.Mode.Choose, null);
dlg.show();
if (dlg.isOK()) {
return (T)dlg.getSelectedChangeList();
@@ -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);
}
@@ -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);
@@ -116,6 +116,7 @@ public class RepositoryBrowserDialog extends DialogWrapper {
setResizable(true);
setOKButtonText(CommonBundle.getCloseButtonText());
getHelpAction().setEnabled(true);
Disposer.register(project, getDisposable());
init();
}
@@ -61,6 +61,7 @@ public class SvnRepositoryLocation implements RepositoryLocation {
@Nullable
public static FilePath getLocalPath(final String fullPath, final NotNullFunction<File, Boolean> 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);
@@ -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();