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

This commit is contained in:
Dmitry Avdeev
2009-11-23 14:41:45 +03:00
12 changed files with 93 additions and 81 deletions
@@ -110,6 +110,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
artifactState.getPropertiesList().add(propertiesState);
}
}
Collections.sort(artifactState.getPropertiesList(), new Comparator<ArtifactPropertiesState>() {
public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) {
return o1.getId().compareTo(o2.getId());
}
});
state.getArtifacts().add(artifactState);
}
return state;
@@ -37,14 +37,14 @@ public class ExtendsListFix implements IntentionAction, LocalQuickFix {
private final boolean myToAdd;
private final PsiClassType myTypeToExtendFrom;
public ExtendsListFix(PsiClass aClass, PsiClassType typeToExtendFrom, boolean toAdd) {
public ExtendsListFix(@NotNull PsiClass aClass, @NotNull PsiClassType typeToExtendFrom, boolean toAdd) {
myClass = aClass;
myClassToExtendFrom = typeToExtendFrom.resolve();
myTypeToExtendFrom = typeToExtendFrom;
myToAdd = toAdd;
}
public ExtendsListFix(PsiClass aClass, PsiClass classToExtendFrom, boolean toAdd) {
public ExtendsListFix(@NotNull PsiClass aClass, @NotNull PsiClass classToExtendFrom, boolean toAdd) {
myClass = aClass;
myClassToExtendFrom = classToExtendFrom;
myTypeToExtendFrom = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(classToExtendFrom);
@@ -126,7 +126,7 @@ public class ExtendsListFix implements IntentionAction, LocalQuickFix {
PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements();
boolean alreadyExtends = false;
for (PsiJavaCodeReferenceElement referenceElement : referenceElements) {
if (referenceElement.resolve() == myClassToExtendFrom) {
if (referenceElement.getManager().areElementsEquivalent(myClassToExtendFrom, referenceElement.resolve())) {
alreadyExtends = true;
if (!add) {
referenceElement.delete();
@@ -22,6 +22,7 @@ package com.intellij.refactoring.move.moveClassesOrPackages;
import com.intellij.codeInsight.ChangeContextUtil;
import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFileHandler;
@@ -35,6 +36,7 @@ import java.util.List;
import java.util.Map;
public class MoveJavaFileHandler extends MoveFileHandler {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.move.moveClassesOrPackages.MoveJavaFileHandler");
@Override
public boolean canProcessElement(PsiFile element) {
return element instanceof PsiJavaFile && !JspPsiUtil.isInJspFile(element) && !CollectHighlightsUtil.isOutsideSourceRootJavaFile(element);
@@ -69,7 +71,11 @@ public class MoveJavaFileHandler extends MoveFileHandler {
final PsiElement newElement = oldToNewMap.get(oldElement);
final PsiReference reference = moveRenameUsage.getReference();
if (reference != null) {
reference.bindToElement(newElement);
try {
reference.bindToElement(newElement);
} catch (IncorrectOperationException ex) {
LOG.error(ex);
}
}
}
}
@@ -28,15 +28,13 @@ import java.util.regex.Pattern;
* @author Konstantin Bulenkov
*/
public class UnscrambleListener extends ApplicationAdapter {
private static final int MAX_STACKTRACE_SIZE = 15*1024; //15Kb
private static final int MAX_STACKTRACE_SIZE = 15 * 1024; //15Kb
private String stacktrace = null;
@Override
public void applicationActivated(IdeFrame ideFrame) {
final String clipboard = getClipboardContents();
if (clipboard != null
&& clipboard.length() < MAX_STACKTRACE_SIZE
&& !clipboard.equals(stacktrace)) {
if (clipboard != null && clipboard.length() < MAX_STACKTRACE_SIZE && !clipboard.equals(stacktrace)) {
stacktrace = clipboard;
if (isStacktrace(stacktrace)) {
new UnscrambleDialog(ideFrame.getProject()).doOKAction();
@@ -51,20 +49,22 @@ public class UnscrambleListener extends ApplicationAdapter {
public static String getClipboardContents() {
String result = "";
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
final Transferable contents = clipboard.getContents(null);
final boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
if (hasTransferableText) {
try {
try {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
final Transferable contents = clipboard.getContents(null);
final boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
if (hasTransferableText) {
result = (String)contents.getTransferData(DataFlavor.stringFlavor);
}
catch (Exception ex){//
}
}
catch (Exception e) {//
}
return result;
}
private static final Pattern STACKTRACE_LINE = Pattern.compile("[\t]*at [[a-zA-Z0-9]+\\.]+[a-zA-Z$0-9]+\\.[a-zA-Z0-9_]+\\([A-Za-z0-9_]+\\.java:[\\d]+\\)");
private static final Pattern STACKTRACE_LINE =
Pattern.compile("[\t]*at [[a-zA-Z0-9]+\\.]+[a-zA-Z$0-9]+\\.[a-zA-Z0-9_]+\\([A-Za-z0-9_]+\\.java:[\\d]+\\)");
public static boolean isStacktrace(String stacktrace) {
int linesCount = 0;
for (String line : stacktrace.split("\n")) {
@@ -74,7 +74,8 @@ public class UnscrambleListener extends ApplicationAdapter {
}
if (STACKTRACE_LINE.matcher(line).matches()) {
linesCount++;
} else {
}
else {
linesCount = 0;
}
if (linesCount > 2) return true;
@@ -17,6 +17,8 @@
package com.intellij.openapi.fileEditor.impl.text;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.ide.IdeView;
import com.intellij.ide.util.EditorHelper;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataConstants;
@@ -30,13 +32,13 @@ import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.ide.IdeView;
import com.intellij.ide.util.EditorHelper;
import org.jetbrains.annotations.Nullable;
public class TextEditorPsiDataProvider implements EditorDataProvider {
@Nullable
public Object getData(final String dataId, final Editor e, final VirtualFile file) {
if (!file.isValid()) return null;
if (dataId.equals(AnActionEvent.injectedId(DataConstants.EDITOR))) {
if (PsiDocumentManager.getInstance(e.getProject()).isUncommited(e.getDocument())) {
return e;
@@ -132,4 +134,4 @@ public class TextEditorPsiDataProvider implements EditorDataProvider {
PsiFile psiFile = PsiManager.getInstance(e.getProject()).findFile(file);
return psiFile != null && psiFile.isValid() ? psiFile : null;
}
}
}
@@ -151,9 +151,9 @@ public class ModuleDefaultVcsRootPolicy extends DefaultVcsRootPolicy {
final VcsRoot[] vcsRoots = plVcsManager.getAllVcsRoots();
for (VcsRoot root : vcsRoots) {
if (! root.path.equals(baseDir)) {
//if (! root.path.equals(baseDir)) {
builder.addDirtyDirRecursively(root);
}
//}
}
}
}
@@ -16,13 +16,11 @@
package com.intellij.openapi.project;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.ui.popup.BalloonHandler;
import com.intellij.openapi.util.NotNullLazyKey;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -57,22 +55,7 @@ public abstract class DumbService {
*/
public abstract void runWhenSmart(Runnable runnable);
public void waitForSmartMode() {
final Application application = ApplicationManager.getApplication();
if (!application.isUnitTestMode()) {
assert !application.isDispatchThread();
assert !application.isReadAccessAllowed();
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
runWhenSmart(new Runnable() {
public void run() {
semaphore.up();
}
});
semaphore.waitFor();
}
public abstract void waitForSmartMode();
/**
* Invoke the runnable later on EventDispatchThread AND when IDEA isn't in dumb mode
@@ -28,6 +28,7 @@ import com.intellij.openapi.ui.popup.BalloonHandler;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.ex.StatusBarEx;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.containers.Queue;
import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.NotNull;
@@ -184,7 +185,25 @@ public class DumbServiceImpl extends DumbService {
}
private static final Ref<CacheUpdateRunner> NULL_ACTION = new Ref<CacheUpdateRunner>(null);
public void waitForSmartMode() {
final Application application = ApplicationManager.getApplication();
if (!application.isUnitTestMode()) {
assert !application.isDispatchThread();
assert !application.isReadAccessAllowed();
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
runWhenSmart(new Runnable() {
public void run() {
semaphore.up();
}
});
semaphore.waitFor();
LOG.assertTrue(!isDumb());
}
private class IndexUpdateRunnable implements Runnable {
private final CacheUpdateRunner myAction;
private double myProcessedItems;
@@ -15,11 +15,12 @@
*/
package com.intellij.openapi.wm.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.impl.commands.FinalizableCommand;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -43,7 +44,7 @@ public final class CommandProcessor implements Runnable {
* commands with BlockFocusEventsCmd - UnbockFocusEventsCmd. It's required to
* prevent focus handling of events which is caused by the commands to be executed.
*/
public final void execute(final List<FinalizableCommand> commandList, Condition expired) {
public final void execute(@NotNull List<FinalizableCommand> commandList, @NotNull Condition expired) {
synchronized (myLock) {
final boolean isBusy = myCommandCount > 0;
@@ -60,32 +61,28 @@ public final class CommandProcessor implements Runnable {
public final void run() {
synchronized (myLock) {
final CommandGroup commandGroup = getNextCommandGroup();
if (commandGroup == null) {
return;
}
if (commandGroup == null || commandGroup.isEmpty()) return;
final Condition conditionForGroup = commandGroup.getExpireCondition();
if (!commandGroup.isEmpty()) {
final FinalizableCommand command = commandGroup.takeNextCommand();
myCommandCount--;
final FinalizableCommand command = commandGroup.takeNextCommand();
myCommandCount--;
final Condition expire = command.getExpireCondition() != null ? command.getExpireCondition() : conditionForGroup;
final Condition expire = command.getExpireCondition() != null ? command.getExpireCondition() : conditionForGroup;
if (LOG.isDebugEnabled()) {
LOG.debug("CommandProcessor.run " + command);
}
// max. I'm not actually quite sure this should have NON_MODAL modality but it should
// definitely have some since runnables in command list may (and do) request some PSI activity
final boolean queueNext = myCommandCount > 0;
ApplicationManager.getApplication().getInvokator().invokeLater(command, ModalityState.NON_MODAL, expire == null ? Condition.FALSE : expire).doWhenDone(new Runnable() {
public void run() {
if (queueNext) {
CommandProcessor.this.run();
}
}
});
if (LOG.isDebugEnabled()) {
LOG.debug("CommandProcessor.run " + command);
}
// max. I'm not actually quite sure this should have NON_MODAL modality but it should
// definitely have some since runnables in command list may (and do) request some PSI activity
final boolean queueNext = myCommandCount > 0;
ApplicationManager.getApplication().getInvokator().invokeLater(command, ModalityState.NON_MODAL, expire == null ? Condition.FALSE : expire).doWhenDone(new Runnable() {
public void run() {
if (queueNext) {
CommandProcessor.this.run();
}
}
});
}
}
@@ -104,9 +101,9 @@ public final class CommandProcessor implements Runnable {
private static class CommandGroup {
private final List<FinalizableCommand> myList;
private final Condition myExpireCondition;
private Condition myExpireCondition;
private CommandGroup(final List<FinalizableCommand> list, final Condition expireCondition) {
private CommandGroup(@NotNull List<FinalizableCommand> list, @NotNull Condition expireCondition) {
myList = list;
myExpireCondition = expireCondition;
}
@@ -120,7 +117,12 @@ public final class CommandProcessor implements Runnable {
}
public FinalizableCommand takeNextCommand() {
return myList.remove(0);
FinalizableCommand command = myList.remove(0);
if (isEmpty()) {
// memory leak otherwise
myExpireCondition = Condition.TRUE;
}
return command;
}
}
}
@@ -17,7 +17,6 @@ package com.intellij.usages;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.*;
import com.intellij.util.containers.ContainerUtil;
@@ -27,18 +26,14 @@ import java.util.List;
* @author max
*/
public class UsageModelTracker implements Disposable {
private final PsiTreeChangeListener myPsiListener;
public interface UsageModelTrackerListener {
void modelChanged(boolean isPropertyChange);
}
private final Project myProject;
private final List<UsageModelTrackerListener> myListeners = ContainerUtil.createEmptyCOWList();
public UsageModelTracker(Project project, Disposable parentDisposable) {
myProject = project;
myPsiListener = new PsiTreeChangeAdapter() {
public UsageModelTracker(Project project) {
final PsiTreeChangeListener myPsiListener = new PsiTreeChangeAdapter() {
public void childAdded(PsiTreeChangeEvent event) {
doFire(event, false);
}
@@ -63,8 +58,7 @@ public class UsageModelTracker implements Disposable {
doFire(event, true);
}
};
PsiManager.getInstance(project).addPsiTreeChangeListener(myPsiListener);
Disposer.register(parentDisposable, this);
PsiManager.getInstance(project).addPsiTreeChangeListener(myPsiListener, this);
}
private void doFire(final PsiTreeChangeEvent event, boolean propertyChange) {
@@ -76,7 +70,6 @@ public class UsageModelTracker implements Disposable {
}
public void dispose() {
PsiManager.getInstance(myProject).removePsiTreeChangeListener(myPsiListener);
}
public void addListener(UsageModelTrackerListener listener) {
@@ -135,7 +135,6 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
@NotNull UsageViewPresentation presentation,
@NotNull UsageTarget[] targets,
Factory<UsageSearcher> usageSearcherFactory) {
myPresentation = presentation;
myTargets = targets;
myUsageSearcherFactory = usageSearcherFactory;
@@ -159,7 +158,8 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
}
};
myRootPanel = new MyPanel(myTree);
myModelTracker = new UsageModelTracker(project, this);
myModelTracker = new UsageModelTracker(project);
Disposer.register(this, myModelTracker);
myModel = new UsageViewTreeModelBuilder(myPresentation, targets);
myRoot = (GroupNode)myModel.getRoot();
@@ -60,10 +60,11 @@ public class CompositeCheckoutListener implements CheckoutProvider.Listener {
result.set(vDir);
if (vDir != null) {
final LocalFileSystem.WatchRequest watchRequest = lfs.addRootToWatch(vDir.getPath(), true);
assert watchRequest != null;
((NewVirtualFile)vDir).markDirtyRecursively();
vDir.refresh(false, true);
lfs.removeWatchedRoot(watchRequest);
if (watchRequest != null) {
lfs.removeWatchedRoot(watchRequest);
}
}
}
});