diff --git a/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java b/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java index a1f4ce122e1a..b859be9299ac 100644 --- a/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java @@ -24,7 +24,6 @@ import com.intellij.psi.search.searches.MethodReferencesSearch; import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.refactoring.BaseRefactoringProcessor; -import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.rename.RenameProcessor; import com.intellij.refactoring.rename.RenameUtil; import com.intellij.refactoring.util.MoveRenameUsageInfo; @@ -62,11 +61,13 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { mySmartPointerManager = SmartPointerManager.getInstance(project); } + @Override @NotNull protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) { return new InvertBooleanUsageViewDescriptor(myElement); } + @Override protected boolean preprocessUsages(Ref refUsages) { if (myRenameProcessor.preprocessUsages(refUsages)) { prepareSuccessful(); @@ -75,6 +76,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { return false; } + @Override @NotNull protected UsageInfo[] findUsages() { final List toInvert = new ArrayList(); @@ -175,7 +177,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { for (PsiReference ref : refs) { final PsiElement element = ref.getElement(); if (element instanceof PsiReferenceExpression) { - final PsiReferenceExpression refExpr = ((PsiReferenceExpression)element); + final PsiReferenceExpression refExpr = (PsiReferenceExpression)element; PsiElement parent = refExpr.getParent(); if (parent instanceof PsiAssignmentExpression && refExpr.equals(((PsiAssignmentExpression)parent).getLExpression())) { toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(((PsiAssignmentExpression)parent).getRExpression())); @@ -203,9 +205,10 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { } } + @Override protected void refreshElements(PsiElement[] elements) { LOG.assertTrue(elements.length == 1 && elements[0] instanceof PsiMethod); - myElement = ((PsiMethod)elements[0]); + myElement = (PsiMethod)elements[0]; } private static UsageInfo[] extractUsagesForElement(PsiElement element, UsageInfo[] usages) { @@ -222,17 +225,11 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { } + @Override protected void performRefactoring(UsageInfo[] usages) { - for (final PsiElement element : myRenameProcessor.getElements()) { try { - RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, new RefactoringElementListener() { - public void elementMoved(@NotNull PsiElement newElement) { - } - - public void elementRenamed(@NotNull PsiElement newElement) { - } - }); + RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, null); } catch (final IncorrectOperationException e) { RenameUtil.showErrorMessage(e, element, myProject); @@ -263,6 +260,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { } } + @Override protected String getCommandName() { return InvertBooleanHandler.REFACTORING_NAME; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java index 8278a85557ac..8f8b7770beba 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java @@ -61,7 +61,8 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor { public void renameElement(final PsiElement element, final String newName, - final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException { + final UsageInfo[] usages, + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { PsiClass aClass = (PsiClass) element; ArrayList postponedCollisions = new ArrayList(); List hidesOut = new ArrayList(); @@ -111,7 +112,9 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor { }*/ - listener.elementRenamed(aClass); + if (listener != null) { + listener.elementRenamed(aClass); + } } @Nullable diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java index 43d08e304970..24a17f8e7238 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java @@ -59,7 +59,8 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor { public void renameElement(final PsiElement psiElement, final String newName, - final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException { + final UsageInfo[] usages, + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { PsiMethod method = (PsiMethod) psiElement; Set methodAndOverriders = new HashSet(); Set containingClasses = new HashSet(); @@ -115,7 +116,9 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor { ((PsiMethod)element).setName(newName); } } - listener.elementRenamed(method); + if (listener != null) { + listener.elementRenamed(method); + } for (PsiElement element: renamedReferences) { fixNameCollisionsWithInnerClassMethod(element, newName, methodAndOverriders, containingClasses, diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java index 072f8283bd0e..1573362df95e 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java @@ -57,7 +57,8 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor { public void renameElement(final PsiElement psiElement, final String newName, - final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException { + final UsageInfo[] usages, + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { PsiVariable variable = (PsiVariable) psiElement; List outerHides = new ArrayList(); List staticImportHides = new ArrayList(); @@ -104,7 +105,9 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor { } // do actual rename variable.setName(newName); - listener.elementRenamed(variable); + if (listener != null) { + listener.elementRenamed(variable); + } if (variable instanceof PsiField) { for (PsiElement occurrence : occurrencesToCheckForConflict) { diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java index 48ca3de9a253..1b28e46a7ee7 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java @@ -56,7 +56,8 @@ public class RenamePsiDirectoryProcessor extends RenamePsiElementProcessor { public void renameElement(final PsiElement element, final String newName, - final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException { + final UsageInfo[] usages, + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { PsiDirectory aDirectory = (PsiDirectory) element; // rename all non-package statement references for (UsageInfo usage : usages) { @@ -71,7 +72,9 @@ public class RenamePsiDirectoryProcessor extends RenamePsiElementProcessor { } aDirectory.setName(newName); - listener.elementRenamed(aDirectory); + if (listener != null) { + listener.elementRenamed(aDirectory); + } } public String getQualifiedNameAfterRename(final PsiElement element, final String newName, final boolean nonJava) { diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java index 55bc7706e5d5..1e9296f046e1 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java @@ -44,7 +44,8 @@ public class RenamePsiPackageProcessor extends RenamePsiElementProcessor { public void renameElement(final PsiElement element, final String newName, - final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException { + final UsageInfo[] usages, + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { final PsiPackage psiPackage = (PsiPackage)element; psiPackage.handleQualifiedNameChange(PsiUtilCore.getQualifiedNameAfterRename(psiPackage.getQualifiedName(), newName)); RenameUtil.doRenameGenericNamedElement(element, newName, usages, listener); diff --git a/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java b/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java index 7d897b1fe243..2284de42ff49 100644 --- a/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java +++ b/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java @@ -34,7 +34,6 @@ import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.ThreeState; import com.intellij.util.containers.ConcurrentSoftHashMap; import com.intellij.util.containers.ConcurrentSoftValueHashMap; -import com.intellij.util.containers.ConcurrentWeakHashMap; import com.intellij.util.containers.MultiMap; import gnu.trove.THashMap; import org.jdom.Document; @@ -139,7 +138,7 @@ public class BaseExternalAnnotationsManager extends ExternalAnnotationsManager { return result.isEmpty() ? null : result.values().toArray(new PsiAnnotation[result.size()]); } - private final ConcurrentMap> cache = new ConcurrentWeakHashMap>(); + private final ConcurrentMap> cache = new ConcurrentSoftHashMap>(); @NotNull private Map collectExternalAnnotations(@NotNull final PsiModifierListOwner listOwner) { if (!hasAnyAnnotationsRoots()) return Collections.emptyMap(); diff --git a/java/java-tests/testSrc/com/intellij/psi/TreeIsCorrectAfterDiffReparseTest.java b/java/java-tests/testSrc/com/intellij/psi/TreeIsCorrectAfterDiffReparseTest.java index b5e1712fbbd6..ef874519d512 100644 --- a/java/java-tests/testSrc/com/intellij/psi/TreeIsCorrectAfterDiffReparseTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/TreeIsCorrectAfterDiffReparseTest.java @@ -6,11 +6,12 @@ package com.intellij.psi; import com.intellij.openapi.editor.Document; import com.intellij.psi.impl.DebugUtil; import com.intellij.testFramework.LightCodeInsightTestCase; +import org.jetbrains.annotations.NonNls; public class TreeIsCorrectAfterDiffReparseTest extends LightCodeInsightTestCase { public void testIDEADEV41862() throws Exception { - String part1 = "package com.test;\n" + + @NonNls String part1 = "package com.test;\n" + "\n" + "\n" + "//------------------------------------------------------------------\n" + @@ -952,7 +953,7 @@ public class TreeIsCorrectAfterDiffReparseTest extends LightCodeInsightTestCase "\n" + " "; - String part2 = "\n" + + @NonNls String part2 = "\n" + " private TransactionStatus getHighestPriorityError(TransactionStatus existingStatus, Message newError) {\n" + " if(existingStatus == null) {\n" + " return newError;\n" + diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/JavaCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/JavaCodeInsightFixtureTestCase.java index 4fc029dcd86c..d811f49e3358 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/JavaCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/JavaCodeInsightFixtureTestCase.java @@ -55,6 +55,14 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase{ myModule = moduleFixtureBuilder.getFixture().getModule(); } + @Override + protected void tearDown() throws Exception { + myModule = null; + myFixture.tearDown(); + myFixture = null; + super.tearDown(); + } + /** * Return relative path to the test data. Path is relative to the * {@link com.intellij.openapi.application.PathManager#getHomePath()} @@ -78,13 +86,6 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase{ protected void tuneFixture(final JavaModuleFixtureBuilder moduleBuilder) throws Exception {} - @Override - protected void tearDown() throws Exception { - myModule = null; - myFixture.tearDown(); - myFixture = null; - super.tearDown(); - } protected Project getProject() { return myFixture.getProject(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScope.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScope.java index daed44103c40..cedaaeb811f9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScope.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScope.java @@ -12,8 +12,6 @@ import java.io.File; public abstract class CompileScope { public abstract boolean isAffected(BuildTarget target, @NotNull File file); - public abstract void expandScope(BuildTarget target, @NotNull File file); - public abstract boolean isAffected(@NotNull BuildTarget target); public abstract boolean isRecompilationForced(@NotNull BuildTarget target); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java index 43e2473d93c8..958187a852ae 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java @@ -1,8 +1,5 @@ package org.jetbrains.jps.incremental; -import com.intellij.openapi.util.io.FileUtil; -import gnu.trove.THashMap; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.BuildTargetType; @@ -12,7 +9,6 @@ import org.jetbrains.jps.model.module.JpsModule; import java.io.File; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Set; @@ -24,7 +20,6 @@ public class CompileScopeImpl extends CompileScope { private final Collection> myTypes; private final Collection> myTargets; private final Map, Set> myFiles; - private final Map, Set> myAppendedFiles = Collections.synchronizedMap(new THashMap, Set>()); public CompileScopeImpl(boolean forcedCompilation, Collection> types, Collection> targets, Map, Set> files) { @@ -46,32 +41,14 @@ public class CompileScopeImpl extends CompileScope { @Override public boolean isAffected(BuildTarget target, @NotNull File file) { - if (myFiles.isEmpty() && myAppendedFiles.isEmpty()) {//optimization + if (myFiles.isEmpty()) {//optimization return true; } if (myTypes.contains(target.getTargetType()) || myTargets.contains(target) || isAffectedByAssociatedModule(target)) { return true; } final Set files = myFiles.get(target); - if (files != null && files.contains(file)) { - return true; - } - synchronized (myAppendedFiles) { - final Set appended = myAppendedFiles.get(target); - return appended != null && appended.contains(file); - } - } - - @Override - public void expandScope(BuildTarget target, @NotNull File file) { - synchronized (myAppendedFiles) { - Set files = myAppendedFiles.get(target); - if (files == null) { - files = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - myAppendedFiles.put(target, files); - } - files.add(file); - } + return files != null && files.contains(file); } private boolean isAffectedByAssociatedModule(BuildTarget target) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java index 71ec950098f1..a3c1a5887c88 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java @@ -112,7 +112,7 @@ public class ResourcesBuilder extends TargetBuilder extends RedBla // returns true if all markers are valid public boolean checkMax(boolean assertInvalid) { - if (!VERIFY) return false; + return VERIFY && doCheckMax(assertInvalid); + } + protected boolean doCheckMax(boolean assertInvalid) { try { l.readLock().lock(); diff --git a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationFactory.java b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationFactory.java index 47b7e35715d5..cc62714454cd 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationFactory.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationFactory.java @@ -77,6 +77,10 @@ public abstract class ConfigurationFactory { public void configureBeforeRunTaskDefaults(Key providerID, BeforeRunTask task) { } + public boolean isConfigurationSingletonByDefault() { + return false; + } + public boolean canConfigurationBeSingleton() { return true; // Configuration may be marked as singleton by default } diff --git a/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java b/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java index 5e9ca0638703..1f40130f1a57 100644 --- a/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java +++ b/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java @@ -59,15 +59,20 @@ public class CommonRefactoringUtil { } } - public static void showErrorHint(Project project, @Nullable Editor editor, String message, String title, @Nullable @NonNls String helpId) { + public static void showErrorHint(final Project project, @Nullable final Editor editor, final String message, final String title, @Nullable @NonNls final String helpId) { if (ApplicationManager.getApplication().isUnitTestMode()) throw new RefactoringErrorHintException(message); - if (editor == null) { - showErrorMessage(title, message, helpId, project); - } - else { - HintManager.getInstance().showErrorHint(editor, message); - } + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + if (editor == null) { + showErrorMessage(title, message, helpId, project); + } + else { + HintManager.getInstance().showErrorHint(editor, message); + } + } + }); } @NonNls diff --git a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java index 03f405e93515..41f65d385060 100644 --- a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java +++ b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java @@ -167,7 +167,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L if (myActions != null) return myActions; DefaultActionGroup group = new DefaultActionGroup(); - final AnAction[] actions = getConsole().createConsoleActions(); + final AnAction[] actions = getConsoleNotNull().createConsoleActions(); for (AnAction action : actions) { group.add(action); } @@ -203,7 +203,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L public JComponent getComponent() { if (!myWasInitialized) { myWasInitialized = true; - add(getConsole().getComponent(), BorderLayout.CENTER); + add(getConsoleNotNull().getComponent(), BorderLayout.CENTER); add(createToolbar(), BorderLayout.NORTH); } return this; @@ -285,7 +285,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L protected synchronized void addMessage(final String text) { if (text == null) return; if (myContentPreprocessor != null) { - final java.util.List fragments = myContentPreprocessor.parseLogLine(text + "\n"); + final List fragments = myContentPreprocessor.parseLogLine(text + "\n"); myOriginalDocument = getOriginalDocument(); for (LogFragment fragment : fragments) { myProcessHandler.notifyTextAvailable(fragment.getText(), fragment.getOutputType()); @@ -391,7 +391,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L } private synchronized void doFilter() { - final ConsoleView console = getConsole(); + final ConsoleView console = getConsoleNotNull(); console.clear(); myModel.processingStarted(); @@ -424,7 +424,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L } private int printMessageToConsole(String line) { - final ConsoleView console = getConsole(); + final ConsoleView console = getConsoleNotNull(); if (myContentPreprocessor != null) { List fragments = myContentPreprocessor.parseLogLine(line + '\n'); for (LogFragment fragment : fragments) { @@ -455,11 +455,24 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L } } - @NotNull + @Nullable public synchronized ConsoleView getConsole() { return myConsole; } + /** + * A shortcut for "getConsole()+assert console != null" + * Use this method when you are sure that console must not be null. + * If we get the assertion then it is a time to revisit logic of caller ;) + */ + + @NotNull + private synchronized ConsoleView getConsoleNotNull() { + final ConsoleView console = getConsole(); + assert console != null: "it looks like console has been disposed"; + return console; + } + public ActionGroup getToolbarActions() { return getOrCreateActions(); } @@ -468,12 +481,14 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L return ActionPlaces.UNKNOWN; } + @Nullable public JComponent getToolbarContextComponent() { - return getConsole().getComponent(); + final ConsoleView console = getConsole(); + return console == null ? null : console.getComponent(); } public JComponent getPreferredFocusableComponent() { - return getConsole().getPreferredFocusableComponent(); + return getConsoleNotNull().getPreferredFocusableComponent(); } public String getTitle() { @@ -481,7 +496,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L } public synchronized void clear() { - getConsole().clear(); + getConsoleNotNull().clear(); myOriginalDocument = null; } @@ -508,8 +523,10 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L private void resetLogFilter() { for (LogFilter filter : myFilters) { if (myModel.isFilterSelected(filter)) { - myLogFilterCombo.setSelectedItem(filter); - break; + if (myLogFilterCombo.getSelectedItem() != filter) { + myLogFilterCombo.setSelectedItem(filter); + break; + } } } } diff --git a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java index d1ffbf31d23d..0524c9b37c29 100644 --- a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java +++ b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java @@ -78,6 +78,7 @@ public abstract class RunManagerEx extends RunManager { public abstract Icon getConfigurationIcon(@NotNull RunnerAndConfigurationSettings settings); public abstract void invalidateConfigurationIcon(@NotNull RunnerAndConfigurationSettings settings); + @NotNull public abstract Collection getSortedConfigurations(); public abstract void removeConfiguration(@Nullable RunnerAndConfigurationSettings settings); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java index ab84ddb00e36..e8bc7bc90252 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java @@ -183,7 +183,7 @@ class RunConfigurable extends BaseConfigurable { snapshot = settings.getSettings(); configuration = settings.getConfiguration(); name = settings.getNameText(); - shared = runManager.isConfigurationShared(snapshot); + shared = settings.isStoreProjectConfiguration(); setIcon(ProgramRunnerUtil.getConfigurationIcon(snapshot, !settings.isValid(), runManager.isTemporary(configuration))); } else if (userObject instanceof RunnerAndConfigurationSettingsImpl) { @@ -459,6 +459,14 @@ class RunConfigurable extends BaseConfigurable { update(); } }); + + info.addSharedListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + changed[0] = true; + update(); + } + }); } private void drawPressAddButtonMessage(final ConfigurationType configurationType) { @@ -669,7 +677,7 @@ class RunConfigurable extends BaseConfigurable { RunnerAndConfigurationSettings settings = null; if (userObject instanceof SingleConfigurationConfigurable) { final SingleConfigurationConfigurable configurable = (SingleConfigurationConfigurable)userObject; - settings = (RunnerAndConfigurationSettings)configurable.getSettings(); + settings = (RunnerAndConfigurationSettings)configurable.getSettings(); if (manager.isTemporary(settings)) { applyConfiguration(typeNode, configurable); } @@ -925,6 +933,11 @@ class RunConfigurable extends BaseConfigurable { return null; } + @NotNull + private DefaultMutableTreeNode getNode(int row) { + return (DefaultMutableTreeNode)myTree.getPathForRow(row).getLastPathComponent(); + } + @Nullable Trinity getAvailableDropPosition(int direction) { int[] rows = myTree.getSelectionRows(); @@ -944,6 +957,20 @@ class RunConfigurable extends BaseConfigurable { INTO : direction > 0 ? BELOW : ABOVE; if (myTreeModel.canDrop(oldIndex, newIndex, position)) { + DefaultMutableTreeNode oldNode = getNode(oldIndex); + DefaultMutableTreeNode newNode = getNode(newIndex); + if (oldNode.getParent() != newNode.getParent() && getKind(newNode) != FOLDER) { + RowsDnDSupport.RefinedDropSupport.Position copy = position; + if (position == BELOW) { + copy = ABOVE; + } + else if (position == ABOVE) { + copy = BELOW; + } + if (myTreeModel.canDrop(oldIndex, newIndex, copy)) { + return Trinity.create(oldIndex, newIndex, copy); + } + } return Trinity.create(oldIndex, newIndex, position); } if (position == BELOW && newIndex < myTree.getRowCount() - 1 && myTreeModel.canDrop(oldIndex, newIndex + 1, ABOVE)) { @@ -996,7 +1023,7 @@ class RunConfigurable extends BaseConfigurable { private SingleConfigurationConfigurable createNewConfiguration(final RunnerAndConfigurationSettings settings, final DefaultMutableTreeNode node) { final SingleConfigurationConfigurable configurationConfigurable = - SingleConfigurationConfigurable.editSettings(settings, null); + SingleConfigurationConfigurable.editSettings(settings, null); installUpdateListeners(configurationConfigurable); DefaultMutableTreeNode nodeToAdd = new DefaultMutableTreeNode(configurationConfigurable); myTreeModel.insertNodeInto(nodeToAdd, node, node.getChildCount()); @@ -1057,76 +1084,76 @@ class RunConfigurable extends BaseConfigurable { } }); final ListPopup popup = - popupFactory.createListPopup(new BaseListPopupStep( - ExecutionBundle.message("add.new.run.configuration.acrtion.name"), configurationTypes) { + popupFactory.createListPopup(new BaseListPopupStep( + ExecutionBundle.message("add.new.run.configuration.acrtion.name"), configurationTypes) { - @NotNull - public String getTextFor(final ConfigurationType type) { - return type.getDisplayName(); + @NotNull + public String getTextFor(final ConfigurationType type) { + return type.getDisplayName(); + } + + @Override + public boolean isSpeedSearchEnabled() { + return true; + } + + @Override + public boolean canBeHidden(ConfigurationType value) { + return true; + } + + public Icon getIconFor(final ConfigurationType type) { + return type.getIcon(); + } + + public PopupStep onChosen(final ConfigurationType type, final boolean finalChoice) { + if (hasSubstep(type)) { + return getSupStep(type); } - - @Override - public boolean isSpeedSearchEnabled() { - return true; + final ConfigurationFactory[] factories = type.getConfigurationFactories(); + if (factories.length > 0) { + createNewConfiguration(factories[0]); } + return FINAL_CHOICE; + } - @Override - public boolean canBeHidden(ConfigurationType value) { - return true; - } + public int getDefaultOptionIndex() { + ConfigurationType type = getSelectedConfigurationType(); + return type != null ? ArrayUtilRt.find(configurationTypes, type) : super.getDefaultOptionIndex(); + } - public Icon getIconFor(final ConfigurationType type) { - return type.getIcon(); - } - - public PopupStep onChosen(final ConfigurationType type, final boolean finalChoice) { - if (hasSubstep(type)) { - return getSupStep(type); + private ListPopupStep getSupStep(final ConfigurationType type) { + final ConfigurationFactory[] factories = type.getConfigurationFactories(); + Arrays.sort(factories, new Comparator() { + public int compare(final ConfigurationFactory factory1, final ConfigurationFactory factory2) { + return factory1.getName().compareTo(factory2.getName()); } - final ConfigurationFactory[] factories = type.getConfigurationFactories(); - if (factories.length > 0) { - createNewConfiguration(factories[0]); + }); + return new BaseListPopupStep( + ExecutionBundle.message("add.new.run.configuration.action.name", type.getDisplayName()), factories) { + + @NotNull + public String getTextFor(final ConfigurationFactory value) { + return value.getName(); } - return FINAL_CHOICE; - } - public int getDefaultOptionIndex() { - ConfigurationType type = getSelectedConfigurationType(); - return type != null ? ArrayUtilRt.find(configurationTypes, type) : super.getDefaultOptionIndex(); - } + public Icon getIconFor(final ConfigurationFactory factory) { + return factory.getIcon(); + } - private ListPopupStep getSupStep(final ConfigurationType type) { - final ConfigurationFactory[] factories = type.getConfigurationFactories(); - Arrays.sort(factories, new Comparator() { - public int compare(final ConfigurationFactory factory1, final ConfigurationFactory factory2) { - return factory1.getName().compareTo(factory2.getName()); - } - }); - return new BaseListPopupStep( - ExecutionBundle.message("add.new.run.configuration.action.name", type.getDisplayName()), factories) { + public PopupStep onChosen(final ConfigurationFactory factory, final boolean finalChoice) { + createNewConfiguration(factory); + return FINAL_CHOICE; + } - @NotNull - public String getTextFor(final ConfigurationFactory value) { - return value.getName(); - } + }; + } - public Icon getIconFor(final ConfigurationFactory factory) { - return factory.getIcon(); - } + public boolean hasSubstep(final ConfigurationType type) { + return type.getConfigurationFactories().length > 1; + } - public PopupStep onChosen(final ConfigurationFactory factory, final boolean finalChoice) { - createNewConfiguration(factory); - return FINAL_CHOICE; - } - - }; - } - - public boolean hasSubstep(final ConfigurationType type) { - return type.getConfigurationFactories().length > 1; - } - - }); + }); //new TreeSpeedSearch(myTree); popup.showUnderneathOf(myToolbarDecorator.getActionsPanel()); } @@ -1800,7 +1827,7 @@ class RunConfigurable extends BaseConfigurable { } else { index = newParent.getIndex(newNode); if (position == BELOW) - index++; + index++; } insertNodeInto(oldNode, newParent, index); } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java index f86d2f052dde..3402d75309c9 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java @@ -104,8 +104,17 @@ extends BeforeRunTaskProvider configurations = + RunManagerImpl.getInstanceImpl(runConfiguration.getProject()).getSortedConfigurations(); + if (configurations.isEmpty() + || (configurations.size() == 1 && configurations.iterator().next().getConfiguration() == runConfiguration)) { + return null; + } + } + return new RunConfigurableBeforeRunTask(); } @Override diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java index b9850e395679..23439b768766 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java @@ -273,6 +273,7 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable, RunnerAndConfigurationSettings template = myTemplateConfigurationsMap.get(factory.getType().getId() + "." + factory.getName()); if (template == null) { template = new RunnerAndConfigurationSettingsImpl(this, factory.createTemplateConfiguration(myProject, this), true); + template.setSingleton(factory.isConfigurationSingletonByDefault()); if (template.getConfiguration() instanceof UnknownRunConfiguration) { ((UnknownRunConfiguration)template.getConfiguration()).setDoNotStore(true); } @@ -410,6 +411,7 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable, } @Override + @NotNull public Collection getSortedConfigurations() { if (!myOrdered) { //compatibility List> order diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java index 8ab7df16d222..2522de239c5b 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java @@ -172,17 +172,21 @@ public class RunnerAndConfigurationSettingsImpl implements JDOMExternalizable, C myIsTemplate = Boolean.valueOf(element.getAttributeValue(TEMPLATE_FLAG_ATTRIBUTE)).booleanValue(); myTemporary = Boolean.valueOf(element.getAttributeValue(TEMPORARY_ATTRIBUTE)).booleanValue() || TEMP_CONFIGURATION.equals(element.getName()); myEditBeforeRun = Boolean.valueOf(element.getAttributeValue(EDIT_BEFORE_RUN)).booleanValue(); - mySingleton = Boolean.valueOf(element.getAttributeValue(SINGLETON)).booleanValue(); myFolderName = element.getAttributeValue(FOLDER_NAME); + // singleton is not configurable by user for template + if (!myIsTemplate) { + mySingleton = Boolean.valueOf(element.getAttributeValue(SINGLETON)).booleanValue(); + } final ConfigurationFactory factory = getFactory(element); if (factory == null) return; if (myIsTemplate) { + mySingleton = factory.isConfigurationSingletonByDefault(); myConfiguration = myManager.getConfigurationTemplate(factory).getConfiguration(); } else { final String name = element.getAttributeValue(NAME_ATTR); - // souldn't call createConfiguration since it calls StepBeforeRunProviders that + // shouldn't call createConfiguration since it calls StepBeforeRunProviders that // may not be loaded yet. This creates initialization order issue. myConfiguration = myManager.doCreateConfiguration(name, factory, false); } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java index 2b07c5619a22..4e78acd33773 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; @@ -187,6 +188,10 @@ public final class SingleConfigurationConfigurable downloadThreadFuture = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { try { - HttpConfigurable.getInstance().prepareURL(url); - final URL requestUrl = new URL(url + "?build=" + ApplicationInfo.getInstance().getBuild().asString()); + URL requestUrl = new URL(url); + if (!StandardFileSystems.FILE_PROTOCOL.equals(requestUrl.getProtocol())) { + HttpConfigurable.getInstance().prepareURL(url); + requestUrl = new URL(url + "?build=" + ApplicationInfo.getInstance().getBuild().asString()); + } inputStreams[0] = requestUrl.openStream(); } catch (IOException e) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index 4a38c34f6124..c4ddb41a944a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -139,7 +139,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap } @TestOnly - public void cleanupForNextTest(Set survivors) throws IOException { + public void cleanupForNextTest(@NotNull Set survivors) throws IOException { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java b/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java index 74e6014da327..c29de88f5fc5 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java @@ -154,6 +154,7 @@ public class MacMainFrameDecorator implements UISettingsListener, Disposable { @Override public void windowEnteredFullScreen(AppEvent.FullScreenEvent event) { myInFullScreen = true; + frame.storeFullScreenStateIfNeeded(true); JRootPane rootPane = frame.getRootPane(); if (rootPane != null) rootPane.putClientProperty(FULL_SCREEN, Boolean.TRUE); diff --git a/platform/platform-impl/src/org/jetbrains/io/WebServer.java b/platform/platform-impl/src/org/jetbrains/io/WebServer.java index 24f518db0d21..7faec0ffd883 100644 --- a/platform/platform-impl/src/org/jetbrains/io/WebServer.java +++ b/platform/platform-impl/src/org/jetbrains/io/WebServer.java @@ -14,8 +14,8 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.*; import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; import org.jboss.netty.handler.codec.http.*; import org.jboss.netty.util.CharsetUtil; import org.jetbrains.annotations.NonNls; @@ -52,7 +52,7 @@ public class WebServer { application.executeOnPooledThread(command); } }; - private final NioServerSocketChannelFactory channelFactory = new NioServerSocketChannelFactory(pooledThreadExecutor, pooledThreadExecutor, 2); + private final NioServerSocketChannelFactory channelFactory = new NioServerSocketChannelFactory(pooledThreadExecutor, pooledThreadExecutor, 1); public boolean isRunning() { return !openChannels.isEmpty(); @@ -82,11 +82,12 @@ public class WebServer { } private boolean checkPort(final InetSocketAddress remoteAddress) { - ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(pooledThreadExecutor, pooledThreadExecutor, 1)); + final ClientBootstrap bootstrap = new ClientBootstrap(new OioClientSocketChannelFactory(pooledThreadExecutor)); bootstrap.setOption("child.tcpNoDelay", true); - final AtomicBoolean result = new AtomicBoolean(); + final AtomicBoolean result = new AtomicBoolean(false); final Semaphore semaphore = new Semaphore(); + semaphore.down(); // must call to down() here to ensure that down was called _before_ up() bootstrap.setPipeline( pipeline(new HttpResponseDecoder(), new HttpChunkAggregator(1048576), new HttpRequestEncoder(), new SimpleChannelUpstreamHandler() { @Override @@ -117,13 +118,12 @@ public class WebServer { } })); - ChannelFuture connectFuture = bootstrap.connect(remoteAddress); + ChannelFuture connectFuture = null; + try { + connectFuture = bootstrap.connect(remoteAddress); if (!waitComplete(connectFuture, "connect")) { return false; } - - try { - semaphore.down(); ChannelFuture writeFuture = connectFuture.getChannel().write(new DefaultHttpRequest(HTTP_1_1, HttpMethod.GET, START_TIME_PATH)); if (!waitComplete(writeFuture, "write")) { return false; @@ -141,7 +141,9 @@ public class WebServer { } } finally { - connectFuture.getChannel().close(); + if (connectFuture != null) { + connectFuture.getChannel().close().awaitUninterruptibly(); + } bootstrap.releaseExternalResources(); } return result.get(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/AbstractEditorProcessingOnDocumentModificationTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/AbstractEditorProcessingOnDocumentModificationTest.java index 59b39a0f53c1..c49532ca9315 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/AbstractEditorProcessingOnDocumentModificationTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/AbstractEditorProcessingOnDocumentModificationTest.java @@ -25,6 +25,7 @@ import com.intellij.openapi.util.Trinity; import com.intellij.openapi.util.text.StringUtil; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import com.intellij.testFramework.TestFileType; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -44,7 +45,7 @@ import java.util.regex.Pattern; * @since 11/18/10 7:43 PM */ public abstract class AbstractEditorProcessingOnDocumentModificationTest extends LightPlatformCodeInsightTestCase { - protected void init(@NotNull String fileText, @NotNull TestFileType type) throws IOException { + protected void init(@NotNull @NonNls String fileText, @NotNull TestFileType type) throws IOException { configureFromFileText(getFileName(type), fileText); } @@ -52,18 +53,21 @@ public abstract class AbstractEditorProcessingOnDocumentModificationTest extends return getTestName(false) + type.getExtension(); } - protected static void addFoldRegion(final int startOffset, final int endOffset, final String placeholder) { + protected static FoldRegion addFoldRegion(final int startOffset, final int endOffset, final String placeholder) { + final FoldRegion[] result = new FoldRegion[1]; myEditor.getFoldingModel().runBatchFoldingOperation(new Runnable() { @Override public void run() { - myEditor.getFoldingModel().addFoldRegion(startOffset, endOffset, placeholder); + result[0] = myEditor.getFoldingModel().addFoldRegion(startOffset, endOffset, placeholder); } }); + return result[0]; } - protected static void addCollapsedFoldRegion(final int startOffset, final int endOffset, final String placeholder) { - addFoldRegion(startOffset, endOffset, placeholder); + protected static FoldRegion addCollapsedFoldRegion(final int startOffset, final int endOffset, final String placeholder) { + FoldRegion region = addFoldRegion(startOffset, endOffset, placeholder); toggleFoldRegionState(getFoldRegion(startOffset), false); + return region; } protected static void toggleFoldRegionState(final FoldRegion foldRegion, final boolean expanded) { @@ -200,10 +204,4 @@ public abstract class AbstractEditorProcessingOnDocumentModificationTest extends mapper.rawAdd(visualLine, startOffset, endOffset, startLogicalLine, startLogicalColumn, endLogicalLine, endLogicalColumn, endVisualColumn, foldRegions, tabData); } } - - public static void main(String[] args) { - setupFolding( - "FoldRegion +(0:600), FoldRegion +(640:1573), FoldRegion +(8130:8233), FoldRegion +(10189:10257), FoldRegion +(13582:13686), FoldRegion +(22805:22829), FoldRegion +(24069:24147), FoldRegion +(25024:25214), FoldRegion +(28313:28362), FoldRegion -(-1:-1)(invalid), FoldRegion -(-1:-1)(invalid), FoldRegion -(-1:-1)(invalid), FoldRegion -(-1:-1)(invalid)" - ); - } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java new file mode 100644 index 000000000000..59538325b4cc --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VirtualFileListenerTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2012 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.vfs; + +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.util.Ref; +import com.intellij.testFramework.PlatformLangTestCase; + +import java.io.IOException; + +/** + * @author nik + */ +public class VirtualFileListenerTest extends PlatformLangTestCase { + public void testFireEvent() throws IOException { + final VirtualFile dir = getVirtualFile(createTempDir("vDir")); + assertNotNull(dir); + dir.getChildren(); + final Ref eventFired = Ref.create(false); + VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() { + @Override + public void fileCreated(VirtualFileEvent event) { + eventFired.set(true); + } + }, myTestRootDisposable); + new WriteAction() { + protected void run(final Result result) { + try { + dir.createChildData(this, "x.txt"); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + }.execute(); + + assertTrue(eventFired.get()); + } +} diff --git a/platform/testFramework/src/com/intellij/mock/MockRunManager.java b/platform/testFramework/src/com/intellij/mock/MockRunManager.java index c248d888b1bf..19c4784e679c 100644 --- a/platform/testFramework/src/com/intellij/mock/MockRunManager.java +++ b/platform/testFramework/src/com/intellij/mock/MockRunManager.java @@ -157,8 +157,9 @@ public class MockRunManager extends RunManagerEx { } @Override + @NotNull public Collection getSortedConfigurations() { - return null; + return Collections.emptyList(); } @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 4966c5aca1c7..d2265d4254c4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -595,7 +595,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest new CommentByLineCommentHandler().invoke(getProject(), getEditor(), getFile()); } - protected static void executeAction(@NotNull final String actionId) { + protected static void executeAction(@NonNls @NotNull final String actionId) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { diff --git a/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java b/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java index 45bfee429047..0b0c8ddddb1e 100644 --- a/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java +++ b/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java @@ -86,7 +86,7 @@ public class ContainerUtilRt { } @NotNull - public static LinkedList newLinkedList(T... elements) { + public static LinkedList newLinkedList(@NotNull T... elements) { final LinkedList list = newLinkedList(); Collections.addAll(list, elements); return list; @@ -103,7 +103,7 @@ public class ContainerUtilRt { } @NotNull - public static ArrayList newArrayList(T... elements) { + public static ArrayList newArrayList(@NotNull T... elements) { ArrayList list = newArrayListWithCapacity(elements.length); Collections.addAll(list, elements); return list; @@ -132,7 +132,8 @@ public class ContainerUtilRt { return 5 + size + size / 5; } - private static > C copy(C collection, @NotNull Iterable elements) { + @NotNull + private static > C copy(@NotNull C collection, @NotNull Iterable elements) { for (T element : elements) { collection.add(element); } @@ -145,7 +146,7 @@ public class ContainerUtilRt { } @NotNull - public static HashSet newHashSet(T... elements) { + public static HashSet newHashSet(@NotNull T... elements) { return new com.intellij.util.containers.HashSet(Arrays.asList(elements)); } @@ -171,7 +172,7 @@ public class ContainerUtilRt { } @NotNull - public static LinkedHashSet newLinkedHashSet(T... elements) { + public static LinkedHashSet newLinkedHashSet(@NotNull T... elements) { return newLinkedHashSet(Arrays.asList(elements)); } @@ -190,7 +191,7 @@ public class ContainerUtilRt { } @NotNull - public static TreeSet newTreeSet(T... elements) { + public static TreeSet newTreeSet(@NotNull T... elements) { TreeSet set = newTreeSet(); Collections.addAll(set, elements); return set; @@ -212,48 +213,62 @@ public class ContainerUtilRt { } @NotNull - public static Stack newStack(Collection elements) { + public static Stack newStack(@NotNull Collection elements) { return new Stack(elements); } @NotNull - public static Stack newStack(T... initial) { + public static Stack newStack(@NotNull T... initial) { return new Stack(Arrays.asList(initial)); } /** * Optimized toArray() as opposed to the {@link java.util.Collections#emptyList()}. */ - private static class EmptyList extends AbstractList implements RandomAccess { + private static class EmptyList extends AbstractList implements RandomAccess { private static final EmptyList INSTANCE = new EmptyList(); + @Override public int size() { return 0; } + @Override public boolean contains(Object obj) { return false; } - public Object get(int index) { + @Override + public T get(int index) { throw new IndexOutOfBoundsException("Index: " + index); } + @NotNull @Override public Object[] toArray() { return ArrayUtilRt.EMPTY_OBJECT_ARRAY; } + @NotNull @Override - public T[] toArray(T[] a) { + public T[] toArray(@NotNull T[] a) { + if (a.length != 0) { + a[0] = null; + } return a; } + + @NotNull + @Override + public Iterator iterator() { + return EmptyIterator.getInstance(); + } } @NotNull public static List emptyList() { - @SuppressWarnings({"unchecked"}) final List list = (List)EmptyList.INSTANCE; - return list; + //noinspection unchecked + return (List)EmptyList.INSTANCE; } @NotNull diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index 03fd44e0fbea..030124122e9f 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -42,7 +42,7 @@ public class ContainerUtil extends ContainerUtilRt { private static final int INSERTION_SORT_THRESHOLD = 10; @NotNull - public static T[] ar(T... elements) { + public static T[] ar(@NotNull T... elements) { return elements; } @@ -97,7 +97,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static LinkedList newLinkedList(T... elements) { + public static LinkedList newLinkedList(@NotNull T... elements) { return ContainerUtilRt.newLinkedList(elements); } @@ -112,7 +112,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static ArrayList newArrayList(E... array) { + public static ArrayList newArrayList(@NotNull E... array) { return ContainerUtilRt.newArrayList(array); } @@ -159,7 +159,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static HashSet newHashSet(T... elements) { + public static HashSet newHashSet(@NotNull T... elements) { return ContainerUtilRt.newHashSet(elements); } @@ -184,7 +184,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static LinkedHashSet newLinkedHashSet(T... elements) { + public static LinkedHashSet newLinkedHashSet(@NotNull T... elements) { return ContainerUtilRt.newLinkedHashSet(elements); } @@ -199,7 +199,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static THashSet newTroveSet(T... elements) { + public static THashSet newTroveSet(@NotNull T... elements) { return newTroveSet(Arrays.asList(elements)); } @@ -236,7 +236,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static TreeSet newTreeSet(T... elements) { + public static TreeSet newTreeSet(@NotNull T... elements) { return ContainerUtilRt.newTreeSet(elements); } @@ -250,7 +250,8 @@ public class ContainerUtil extends ContainerUtilRt { return new ConcurrentHashMap(); } - public static List reverse(final List elements) { + @NotNull + public static List reverse(@NotNull final List elements) { return new AbstractList() { @Override public E get(int index) { @@ -264,6 +265,7 @@ public class ContainerUtil extends ContainerUtilRt { }; } + @NotNull public static Map union(@NotNull Map map, @NotNull Map map2) { THashMap result = new THashMap(map.size() + map2.size()); result.putAll(map); @@ -271,6 +273,7 @@ public class ContainerUtil extends ContainerUtilRt { return result; } + @NotNull public static Set union(@NotNull Set set, @NotNull Set set2) { THashSet result = new THashSet(set.size() + set2.size()); result.addAll(set); @@ -278,24 +281,28 @@ public class ContainerUtil extends ContainerUtilRt { return result; } - public static Set immutableSet(final E ... elements) { + @NotNull + public static Set immutableSet(@NotNull E ... elements) { return Collections.unmodifiableSet(new THashSet(Arrays.asList(elements))); } - public static ImmutableList immutableList(E ... array) { + @NotNull + public static ImmutableList immutableList(@NotNull E ... array) { return new ImmutableListBackedByArray(array); } - public static ImmutableList immutableList(List list) { + @NotNull + public static ImmutableList immutableList(@NotNull List list) { return new ImmutableListBackedByList(list); } + @NotNull public static ImmutableMapBuilder immutableMapBuilder() { return new ImmutableMapBuilder(); } public static class ImmutableMapBuilder { - private THashMap myMap = new THashMap(); + private final Map myMap = new THashMap(); public ImmutableMapBuilder put(K key, V value) { myMap.put(key, value); @@ -310,7 +317,7 @@ public class ContainerUtil extends ContainerUtilRt { private static class ImmutableListBackedByList extends ImmutableList { private final List myStore; - private ImmutableListBackedByList(List list) { + private ImmutableListBackedByList(@NotNull List list) { myStore = list; } @@ -328,7 +335,7 @@ public class ContainerUtil extends ContainerUtilRt { private static class ImmutableListBackedByArray extends ImmutableList { private final E[] myStore; - private ImmutableListBackedByArray(E[] array) { + private ImmutableListBackedByArray(@NotNull E[] array) { myStore = array; } @@ -343,7 +350,8 @@ public class ContainerUtil extends ContainerUtilRt { } } - public static Map intersection(Map map1, Map map2) { + @NotNull + public static Map intersection(@NotNull Map map1, @NotNull Map map2) { final Map res = newHashMap(); final Set keys = newHashSet(); keys.addAll(map1.keySet()); @@ -351,14 +359,15 @@ public class ContainerUtil extends ContainerUtilRt { for (K k : keys) { V v1 = map1.get(k); V v2 = map2.get(k); - if (v1 == v2 || (v1 != null && v1.equals(v2))) { + if (v1 == v2 || v1 != null && v1.equals(v2)) { res.put(k, v1); } } return res; } - public static Map> diff(Map map1, Map map2) { + @NotNull + public static Map> diff(@NotNull Map map1, @NotNull Map map2) { final Map> res = newHashMap(); final Set keys = newHashSet(); keys.addAll(map1.keySet()); @@ -366,53 +375,70 @@ public class ContainerUtil extends ContainerUtilRt { for (K k : keys) { V v1 = map1.get(k); V v2 = map2.get(k); - if (!(v1 == v2 || (v1 != null && v1.equals(v2)))) { + if (!(v1 == v2 || v1 != null && v1.equals(v2))) { res.put(k, Pair.create(v1, v2)); } } return res; } - @NotNull - public static List mergeSortedLists(@NotNull List list1, @NotNull List list2, @NotNull Comparator comparator, boolean mergeEqualItems){ - List result = new ArrayList(list1.size() + list2.size()); - + public static boolean processSortedListsInOrder(@NotNull List list1, + @NotNull List list2, + @NotNull Comparator comparator, + boolean mergeEqualItems, + @NotNull Processor processor) { int index1 = 0; int index2 = 0; while (index1 < list1.size() || index2 < list2.size()) { + T e; if (index1 >= list1.size()) { - result.add(list2.get(index2++)); + e = list2.get(index2++); } else if (index2 >= list2.size()) { - result.add(list1.get(index1++)); + e = list1.get(index1++); } else { T element1 = list1.get(index1); T element2 = list2.get(index2); int c = comparator.compare(element1, element2); - if (c < 0) { - result.add(element1); + if (c <= 0) { + e = element1; index1++; } - else if (c > 0) { - result.add(element2); - index2++; - } else { - result.add(element1); - if (!mergeEqualItems) { - result.add(element2); - } - index1++; + e = element2; index2++; } + if (c == 0 && !mergeEqualItems) { + if (!processor.process(e)) return false; + index2++; + e = element2; + } } + if (!processor.process(e)) return false; } + return true; + } + + @NotNull + public static List mergeSortedLists(@NotNull List list1, + @NotNull List list2, + @NotNull Comparator comparator, + boolean mergeEqualItems) { + final List result = new ArrayList(list1.size() + list2.size()); + processSortedListsInOrder(list1, list2, comparator, mergeEqualItems, new Processor() { + @Override + public boolean process(T t) { + result.add(t); + return true; + } + }); return result; } + @NotNull - public static List mergeSortedArrays(@NotNull T[] list1, @NotNull T[] list2, @NotNull Comparator comparator, boolean mergeEqualItems, @Nullable Processor filter){ + public static List mergeSortedArrays(@NotNull T[] list1, @NotNull T[] list2, @NotNull Comparator comparator, boolean mergeEqualItems, @Nullable Processor filter) { int index1 = 0; int index2 = 0; List result = new ArrayList(list1.length + list2.length); @@ -462,7 +488,8 @@ public class ContainerUtil extends ContainerUtilRt { return result; } - public static List subList(List list, int from) { + @NotNull + public static List subList(@NotNull List list, int from) { return list.subList(from, list.size()); } @@ -624,6 +651,7 @@ public class ContainerUtil extends ContainerUtilRt { @Nullable public static T find(@NotNull Iterable iterable, final T equalTo) { return find(iterable, new Condition() { + @Override public boolean value(final T object) { return equalTo == object || equalTo.equals(object); } @@ -764,6 +792,7 @@ public class ContainerUtil extends ContainerUtilRt { } } + @NotNull public static Map stringMap(@NotNull final String... keyValues) { final Map result = newHashMap(); for (int i = 0; i < keyValues.length - 1; i+=2) { @@ -781,14 +810,17 @@ public class ContainerUtil extends ContainerUtilRt { @NotNull public static Iterator iterate(@NotNull final Enumeration enumeration) { return new Iterator() { + @Override public boolean hasNext() { return enumeration.hasMoreElements(); } + @Override public T next() { return enumeration.nextElement(); } + @Override public void remove() { throw new UnsupportedOperationException(); } @@ -804,15 +836,18 @@ public class ContainerUtil extends ContainerUtilRt { public static Iterable iterate(@NotNull final Collection collection, @NotNull final Condition condition) { if (collection.isEmpty()) return emptyIterable(); return new Iterable() { + @Override public Iterator iterator() { return new Iterator() { Iterator impl = collection.iterator(); T next = findNext(); + @Override public boolean hasNext() { return next != null; } + @Override public T next() { T result = next; next = findNext(); @@ -830,6 +865,7 @@ public class ContainerUtil extends ContainerUtilRt { return null; } + @Override public void remove() { throw new UnsupportedOperationException(); } @@ -841,18 +877,22 @@ public class ContainerUtil extends ContainerUtilRt { @NotNull public static Iterable iterateBackward(@NotNull final List list) { return new Iterable() { + @Override public Iterator iterator() { return new Iterator() { ListIterator it = list.listIterator(list.size()); + @Override public boolean hasNext() { return it.hasPrevious(); } + @Override public T next() { return it.previous(); } + @Override public void remove() { it.remove(); } @@ -880,6 +920,7 @@ public class ContainerUtil extends ContainerUtilRt { } } + @NotNull public static > C addAll(@NotNull C collection, @NotNull A... elements) { //noinspection ManualArrayToCollectionCopy for (T element : elements) { @@ -891,6 +932,7 @@ public class ContainerUtil extends ContainerUtilRt { /** * Adds all not-null elements from the {@code elements}, ignoring nulls */ + @NotNull public static > C addAllNotNull(@NotNull C collection, @NotNull A... elements) { //noinspection ManualArrayToCollectionCopy for (T element : elements) { @@ -936,6 +978,7 @@ public class ContainerUtil extends ContainerUtilRt { final int size = size1 + list2.size(); return new AbstractList() { + @Override public T get(int index) { if (index < size1) { return list1.get(index); @@ -944,6 +987,7 @@ public class ContainerUtil extends ContainerUtilRt { return list2.get(index - size1); } + @Override public int size() { return size; } @@ -953,6 +997,7 @@ public class ContainerUtil extends ContainerUtilRt { @NotNull public static Iterable concat(@NotNull final Iterable... iterables) { return new Iterable() { + @Override public Iterator iterator() { Iterator[] iterators = new Iterator[iterables.length]; for (int i = 0, iterablesLength = iterables.length; i < iterablesLength; i++) { @@ -966,6 +1011,7 @@ public class ContainerUtil extends ContainerUtilRt { @NotNull public static Iterable concat(@NotNull final T[]... iterables) { return new Iterable() { + @Override public Iterator iterator() { Iterator[] iterators = new Iterator[iterables.length]; for (int i = 0, iterablesLength = iterables.length; i < iterablesLength; i++) { @@ -985,6 +1031,7 @@ public class ContainerUtil extends ContainerUtilRt { } final int finalSize = size; return new AbstractList() { + @Override public T get(final int index) { if (index >= 0 && index < finalSize) { int from = 0; @@ -996,6 +1043,7 @@ public class ContainerUtil extends ContainerUtilRt { throw new IndexOutOfBoundsException("index: " + index + "size: " + size()); } + @Override public int size() { return finalSize; } @@ -1039,7 +1087,7 @@ public class ContainerUtil extends ContainerUtilRt { } @Nullable - public static T getFirstItem(final Collection items) { + public static T getFirstItem(@Nullable Collection items) { return getFirstItem(items, null); } @@ -1065,14 +1113,17 @@ public class ContainerUtil extends ContainerUtilRt { return set; } + @NotNull public static T[] toArray(@Nullable Collection c, @NotNull ArrayFactory factory) { return c != null ? c.toArray(factory.create(c.size())) : factory.create(0); } + @NotNull public static T[] toArray(@NotNull Collection c1, @NotNull Collection c2, @NotNull ArrayFactory factory) { return ArrayUtil.mergeCollections(c1, c2, factory); } + @NotNull public static T[] mergeCollectionsToArray(@NotNull Collection c1, @NotNull Collection c2, @NotNull ArrayFactory factory) { return ArrayUtil.mergeCollections(c1, c2, factory); } @@ -1219,9 +1270,11 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static List mapNotNull(@NotNull T[] array, Function mapping) { + public static List mapNotNull(@NotNull T[] array, @NotNull Function mapping) { return mapNotNull(Arrays.asList(array), mapping); } + + @NotNull public static V[] mapNotNull(@NotNull T[] arr, @NotNull Function mapping, @NotNull V[] emptyArray) { List result = new ArrayList(arr.length); for (T t : arr) { @@ -1234,7 +1287,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static List mapNotNull(Iterable iterable, Function mapping) { + public static List mapNotNull(@NotNull Iterable iterable, @NotNull Function mapping) { List result = new ArrayList(); for (T t : iterable) { final V o = mapping.fun(t); @@ -1244,8 +1297,9 @@ public class ContainerUtil extends ContainerUtilRt { } return result; } + @NotNull - public static List mapNotNull(Collection iterable, Function mapping) { + public static List mapNotNull(@NotNull Collection iterable, @NotNull Function mapping) { List result = new ArrayList(iterable.size()); for (T t : iterable) { final V o = mapping.fun(t); @@ -1284,7 +1338,7 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static Set set(T ... items) { + public static Set set(@NotNull T ... items) { return addAll(newHashSet(items)); } @@ -1297,6 +1351,7 @@ public class ContainerUtil extends ContainerUtilRt { public static void add(final T element, @NotNull final Collection result, @NotNull final Disposable parentDisposable) { if (result.add(element)) { Disposer.register(parentDisposable, new Disposable() { + @Override public void dispose() { result.remove(element); } @@ -1361,6 +1416,7 @@ public class ContainerUtil extends ContainerUtilRt { return false; } + @NotNull public static List unfold(@Nullable T t, @NotNull NullableFunction next) { if (t == null) return Collections.emptyList(); @@ -1473,10 +1529,10 @@ public class ContainerUtil extends ContainerUtilRt { * Merge sorted points, which are sorted by x and with equal x by y. * Result is put to x1 y1. */ - public static void mergeSortedArrays(TIntArrayList x1, - TIntArrayList y1, - TIntArrayList x2, - TIntArrayList y2) { + public static void mergeSortedArrays(@NotNull TIntArrayList x1, + @NotNull TIntArrayList y1, + @NotNull TIntArrayList x2, + @NotNull TIntArrayList y2) { TIntArrayList newX = new TIntArrayList(); TIntArrayList newY = new TIntArrayList(); @@ -1484,12 +1540,12 @@ public class ContainerUtil extends ContainerUtilRt { int j = 0; while (i < x1.size() && j < x2.size()) { - if (x1.get(i) < x2.get(j) || (x1.get(i) == x2.get(j) && y1.get(i) < y2.get(j))) { + if (x1.get(i) < x2.get(j) || x1.get(i) == x2.get(j) && y1.get(i) < y2.get(j)) { newX.add(x1.get(i)); newY.add(y1.get(i)); i++; } - else if (x1.get(i) > x2.get(j) || (x1.get(i) == x2.get(j) && y1.get(i) > y2.get(j))) { + else if (x1.get(i) > x2.get(j) || x1.get(i) == x2.get(j) && y1.get(i) > y2.get(j)) { newX.add(x2.get(j)); newY.add(y2.get(j)); j++; @@ -1523,72 +1579,91 @@ public class ContainerUtil extends ContainerUtilRt { @NotNull public static Set singleton(final T o, @NotNull final TObjectHashingStrategy strategy) { return new Set() { + @Override public int size() { return 1; } + @Override public boolean isEmpty() { return false; } + @Override public boolean contains(Object elem) { return strategy.equals(o, (T)elem); } + @NotNull + @Override public Iterator iterator() { return new Iterator() { boolean atEnd; + @Override public boolean hasNext() { return !atEnd; } + @Override public T next() { if (atEnd) throw new NoSuchElementException(); atEnd = true; return o; } + @Override public void remove() { throw new IncorrectOperationException(); } }; } + @NotNull + @Override public Object[] toArray() { return new Object[]{o}; } + @NotNull + @Override public T[] toArray(T[] a) { assert a.length == 1; a[0] = (T)o; return a; } + @Override public boolean add(T t) { throw new IncorrectOperationException(); } + @Override public boolean remove(Object o) { throw new IncorrectOperationException(); } + @Override public boolean containsAll(Collection c) { return false; } + @Override public boolean addAll(Collection c) { throw new IncorrectOperationException(); } + @Override public boolean retainAll(Collection c) { throw new IncorrectOperationException(); } + @Override public boolean removeAll(Collection c) { throw new IncorrectOperationException(); } + @Override public void clear() { throw new IncorrectOperationException(); } @@ -1599,6 +1674,7 @@ public class ContainerUtil extends ContainerUtilRt { public static List flatten(@NotNull Collection[] collections) { return flatten(Arrays.asList(collections)); } + @NotNull public static List flatten(@NotNull Iterable> collections) { List result = new ArrayList(); @@ -1609,7 +1685,8 @@ public class ContainerUtil extends ContainerUtilRt { return result; } - public static V[] convert(K[] from, V[] to, Function fun) { + @NotNull + public static V[] convert(@NotNull K[] from, @NotNull V[] to, @NotNull Function fun) { if (to.length < from.length) { to = (V[])Array.newInstance(to.getClass().getComponentType(), from.length); } @@ -1619,7 +1696,7 @@ public class ContainerUtil extends ContainerUtilRt { return to; } - public static boolean containsIdentity(Iterable list, T element) { + public static boolean containsIdentity(@NotNull Iterable list, T element) { for (T t : list) { if (t == element) { return true; @@ -1628,7 +1705,7 @@ public class ContainerUtil extends ContainerUtilRt { return false; } - public static int indexOfIdentity(List list, T element) { + public static int indexOfIdentity(@NotNull List list, T element) { for (int i = 0, listSize = list.size(); i < listSize; i++) { if (list.get(i) == element) { return i; @@ -1638,7 +1715,7 @@ public class ContainerUtil extends ContainerUtilRt { } - public static boolean equalsIdentity(List list1, List list2) { + public static boolean equalsIdentity(@NotNull List list1, @NotNull List list2) { int listSize = list1.size(); if (list2.size() != listSize) { return false; @@ -1653,7 +1730,7 @@ public class ContainerUtil extends ContainerUtilRt { } - public static int indexOf(List list, Condition condition) { + public static int indexOf(@NotNull List list, @NotNull Condition condition) { for (int i = 0, listSize = list.size(); i < listSize; i++) { T t = list.get(i); if (condition.value(t)) { @@ -1663,7 +1740,8 @@ public class ContainerUtil extends ContainerUtilRt { return -1; } - public static Map reverseMap(Map map) { + @NotNull + public static Map reverseMap(@NotNull Map map) { final Map result = newHashMap(); for (A a : map.keySet()) { result.put(map.get(a), a); @@ -1671,7 +1749,7 @@ public class ContainerUtil extends ContainerUtilRt { return result; } - public static boolean processRecursively(final T root, final PairProcessor> processor) { + public static boolean processRecursively(final T root, @NotNull PairProcessor> processor) { final LinkedList list = new LinkedList(); list.add(root); while (!list.isEmpty()) { @@ -1699,12 +1777,12 @@ public class ContainerUtil extends ContainerUtilRt { } @NotNull - public static Stack newStack(Collection initial) { + public static Stack newStack(@NotNull Collection initial) { return ContainerUtilRt.newStack(initial); } @NotNull - public static Stack newStack(T... initial) { + public static Stack newStack(@NotNull T... initial) { return ContainerUtilRt.newStack(initial); } @@ -1718,6 +1796,10 @@ public class ContainerUtil extends ContainerUtilRt { return ContainerUtilRt.createEmptyCOWList(); } + public static List createLockFreeCopyOnWriteList(@NotNull Collection c) { + return new CopyOnWriteArrayList(c); + } + public static void addIfNotNull(@Nullable T element, @NotNull Collection result) { ContainerUtilRt.addIfNotNull(element, result); } diff --git a/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java b/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java index 57d8ed8fc2a9..cca415694f6e 100644 --- a/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java +++ b/platform/util/src/com/intellij/util/containers/UnsafeWeakList.java @@ -41,10 +41,12 @@ public class UnsafeWeakList extends AbstractList { myArray = array; } + @Override public T get(int index) { return myArray.get(index); } + @Override public boolean add(T element) { tryReduceCapacity(-1); myArray.add(element); @@ -63,24 +65,33 @@ public class UnsafeWeakList extends AbstractList { return true; } + @Override public void add(int index, T element) { tryReduceCapacity(-1); myArray.add(index, element); } + @Override public T remove(int index) { tryReduceCapacity(-1); return myArray.remove(index); } + @NotNull + @Override public Iterator iterator() { return new MyIterator(); } + @Override public int size() { return myArray.size(); } + public void clear(int index) { + myArray.removeReference(index); + } + public List toStrongList() { List result = new ArrayList(myArray.size()); myArray.toStrongCollection(result); @@ -134,10 +145,12 @@ public class UnsafeWeakList extends AbstractList { } } + @Override public boolean hasNext() { return myNextElement != null; } + @Override public T next() { if (modCount != myModCount) throw new ConcurrentModificationException(); if (myNextElement == null) throw new NoSuchElementException(); @@ -147,6 +160,7 @@ public class UnsafeWeakList extends AbstractList { return element; } + @Override public void remove() { if (myCurrentIndex == -1) throw new IllegalStateException(); myArray.remove(myCurrentIndex); diff --git a/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java b/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java index 98930829879c..6e860e8ca54d 100644 --- a/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java +++ b/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java @@ -64,6 +64,7 @@ public class ReadWriteDirectBufferWrapper extends DirectBufferWrapper { channel.position(myPosition); buffer.rewind(); channel.write(buffer); + myDirty = false; } finally { channel.close(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java index 5154916f3f18..c14c170ca84a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java @@ -35,6 +35,9 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +/** + * @author Bas Leijdekkers + */ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { @Override @@ -46,15 +49,13 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { @NotNull @Override public String getDisplayName() { - return InspectionGadgetsBundle.message( - "try.finally.can.be.try.with.resources.display.name"); + return InspectionGadgetsBundle.message("try.finally.can.be.try.with.resources.display.name"); } @NotNull @Override protected String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "try.finally.can.be.try.with.resources.problem.descriptor"); + return InspectionGadgetsBundle.message("try.finally.can.be.try.with.resources.problem.descriptor"); } @Override @@ -62,16 +63,13 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return new TryFinallyCanBeTryWithResourcesFix(); } - private static class TryFinallyCanBeTryWithResourcesFix - extends InspectionGadgetsFix { + private static class TryFinallyCanBeTryWithResourcesFix extends InspectionGadgetsFix { - public TryFinallyCanBeTryWithResourcesFix() { - } + public TryFinallyCanBeTryWithResourcesFix() {} @NotNull public String getName() { - return InspectionGadgetsBundle.message( - "try.finally.can.be.try.with.resources.quickfix"); + return InspectionGadgetsBundle.message("try.finally.can.be.try.with.resources.quickfix"); } @Override @@ -89,7 +87,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { final PsiElement[] tryBlockChildren = tryBlock.getChildren(); final Set variables = new HashSet(); for (PsiLocalVariable variable : collectVariables(tryStatement)) { - if (!isVariableUsedOutsideContext(variable, tryStatement)) { + if (!isVariableUsedOutsideContext(variable, tryBlock)) { variables.add(variable); } } @@ -110,10 +108,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (separator) { newTryStatementText.append(';'); } - newTryStatementText.append(variable.getTypeElement().getText()); - newTryStatementText.append(' '); - newTryStatementText.append(variable.getName()); - newTryStatementText.append('='); + newTryStatementText.append(variable.getTypeElement().getText()).append(' ').append(variable.getName()).append('='); if (hasInitializer) { newTryStatementText.append(initializer.getText()); } @@ -200,31 +195,24 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { tryStatement.replace(newTryStatement); } - private static boolean isCloseStatement( - PsiElement element, Set variables) { + private static boolean isCloseStatement(PsiElement element, Set variables) { if (element instanceof PsiExpressionStatement) { - final PsiExpressionStatement expressionStatement = - (PsiExpressionStatement)element; - final PsiExpression expression = - expressionStatement.getExpression(); + final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)element; + final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiMethodCallExpression)) { return false; } - final PsiMethodCallExpression methodCallExpression = - (PsiMethodCallExpression)expression; - final PsiReferenceExpression methodExpression = - methodCallExpression.getMethodExpression(); + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression; + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final String methodName = methodExpression.getReferenceName(); if (!HardcodedMethodConstants.CLOSE.equals(methodName)) { return false; } - final PsiExpression qualifier = - methodExpression.getQualifierExpression(); + final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (!(qualifier instanceof PsiReferenceExpression)) { return false; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)qualifier; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier; final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiLocalVariable)) { return false; @@ -241,10 +229,8 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(condition instanceof PsiBinaryExpression)) { return false; } - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)condition; - final IElementType tokenType = - binaryExpression.getOperationTokenType(); + final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition; + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!JavaTokenType.NE.equals(tokenType)) { return false; } @@ -258,8 +244,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(lhs instanceof PsiReferenceExpression)) { return false; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)lhs; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lhs; variable = referenceExpression.resolve(); if (!(variable instanceof PsiLocalVariable)) { return false; @@ -269,8 +254,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(rhs instanceof PsiReferenceExpression)) { return false; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)rhs; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)rhs; variable = referenceExpression.resolve(); if (!(variable instanceof PsiLocalVariable)) { return false; @@ -284,13 +268,10 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return isCloseStatement(thenBranch, variables); } else if (thenBranch instanceof PsiBlockStatement) { - final PsiBlockStatement blockStatement = - (PsiBlockStatement)thenBranch; - final PsiCodeBlock codeBlock = - blockStatement.getCodeBlock(); + final PsiBlockStatement blockStatement = (PsiBlockStatement)thenBranch; + final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiStatement[] statements = codeBlock.getStatements(); - return statements.length == 1 && - isCloseStatement(statements[0], variables); + return statements.length == 1 && isCloseStatement(statements[0], variables); } else { return false; @@ -307,8 +288,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return new TryFinallyCanBeTryWithResourcesVisitor(); } - private static class TryFinallyCanBeTryWithResourcesVisitor - extends BaseInspectionVisitor { + private static class TryFinallyCanBeTryWithResourcesVisitor extends BaseInspectionVisitor { @Override public void visitTryStatement(PsiTryStatement tryStatement) { @@ -320,15 +300,14 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (resourceList != null) { return; } - final List variables = - collectVariables(tryStatement); - if (variables.isEmpty()) { - return; - } final PsiCodeBlock tryBlock = tryStatement.getTryBlock(); if (tryBlock == null) { return; } + final List variables = collectVariables(tryStatement); + if (variables.isEmpty()) { + return; + } final PsiStatement[] tryBlockStatements = tryBlock.getStatements(); boolean found = false; for (PsiVariable variable : variables) { @@ -341,10 +320,9 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { final PsiType type = initializer.getType(); hasInitializer = !PsiType.NULL.equals(type); } - final int index = findInitialization(tryBlockStatements, - variable, hasInitializer); + final int index = findInitialization(tryBlockStatements, variable, hasInitializer); if (index >= 0 ^ hasInitializer) { - if (isVariableUsedOutsideContext(variable, tryStatement)) { + if (isVariableUsedOutsideContext(variable, tryBlock)) { continue; } found = true; @@ -358,14 +336,9 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { } } - static boolean isVariableUsedOutsideContext( - PsiVariable variable, PsiElement context) { - final VariableUsedOutsideContextVisitor visitor = - new VariableUsedOutsideContextVisitor(variable, - context); - final PsiElement declarationScope = - PsiTreeUtil.getParentOfType(variable, - PsiCodeBlock.class); + static boolean isVariableUsedOutsideContext(PsiVariable variable, PsiElement context) { + final VariableUsedOutsideContextVisitor visitor = new VariableUsedOutsideContextVisitor(variable, context); + final PsiElement declarationScope = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class); if (declarationScope == null) { return true; } @@ -373,8 +346,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return visitor.variableIsUsed(); } - static List collectVariables( - PsiTryStatement tryStatement) { + static List collectVariables(PsiTryStatement tryStatement) { final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock(); if (finallyBlock == null) { return Collections.EMPTY_LIST; @@ -385,8 +357,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { } final List variables = new ArrayList(); for (PsiStatement statement : statements) { - final PsiLocalVariable variable = - findAutoCloseableVariable(statement); + final PsiLocalVariable variable = findAutoCloseableVariable(statement); if (variable != null) { variables.add(variable); } @@ -395,8 +366,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { } @Nullable - static PsiLocalVariable findAutoCloseableVariable( - PsiStatement statement) { + static PsiLocalVariable findAutoCloseableVariable(PsiStatement statement) { if (statement instanceof PsiIfStatement) { final PsiIfStatement ifStatement = (PsiIfStatement)statement; if (ifStatement.getElseBranch() != null) { @@ -406,10 +376,8 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(condition instanceof PsiBinaryExpression)) { return null; } - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)condition; - final IElementType tokenType = - binaryExpression.getOperationTokenType(); + final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition; + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!JavaTokenType.NE.equals(tokenType)) { return null; } @@ -423,8 +391,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(lhs instanceof PsiReferenceExpression)) { return null; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)lhs; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lhs; variable = referenceExpression.resolve(); if (!(variable instanceof PsiLocalVariable)) { return null; @@ -434,8 +401,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(rhs instanceof PsiReferenceExpression)) { return null; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)rhs; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)rhs; variable = referenceExpression.resolve(); if (!(variable instanceof PsiLocalVariable)) { return null; @@ -450,10 +416,8 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { resourceVariable = findAutoCloseableVariable(thenBranch); } else if (thenBranch instanceof PsiBlockStatement) { - final PsiBlockStatement blockStatement = - (PsiBlockStatement)thenBranch; - final PsiCodeBlock codeBlock = - blockStatement.getCodeBlock(); + final PsiBlockStatement blockStatement = (PsiBlockStatement)thenBranch; + final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiStatement[] statements = codeBlock.getStatements(); if (statements.length != 1) { return null; @@ -468,33 +432,24 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { } } else if (statement instanceof PsiExpressionStatement) { - final PsiExpressionStatement expressionStatement = - (PsiExpressionStatement)statement; - final PsiExpression expression = - expressionStatement.getExpression(); + final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)statement; + final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiMethodCallExpression)) { return null; } - final PsiMethodCallExpression methodCallExpression = - (PsiMethodCallExpression)expression; - final PsiReferenceExpression methodExpression = - methodCallExpression.getMethodExpression(); + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression; + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final String methodName = methodExpression.getReferenceName(); if (!HardcodedMethodConstants.CLOSE.equals(methodName)) { return null; } - final PsiExpression qualifier = - methodExpression.getQualifierExpression(); + final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (!(qualifier instanceof PsiReferenceExpression)) { return null; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)qualifier; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier; final PsiElement target = referenceExpression.resolve(); - if (!(target instanceof PsiLocalVariable)) { - return null; - } - if (target instanceof PsiResourceVariable) { + if (!(target instanceof PsiLocalVariable) || target instanceof PsiResourceVariable) { return null; } final PsiLocalVariable variable = (PsiLocalVariable)target; @@ -516,8 +471,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return aClass != null && InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE); } - static int findInitialization( - PsiElement[] elements, PsiVariable variable, + static int findInitialization(PsiElement[] elements, PsiVariable variable, boolean hasInitializer) { int result = -1; final int statementsLength = elements.length; @@ -526,21 +480,17 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (!(element instanceof PsiExpressionStatement)) { continue; } - final PsiExpressionStatement expressionStatement = - (PsiExpressionStatement)element; - final PsiExpression expression = - expressionStatement.getExpression(); + final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)element; + final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiAssignmentExpression)) { continue; } - final PsiAssignmentExpression assignmentExpression = - (PsiAssignmentExpression)expression; + final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression; final PsiExpression lhs = assignmentExpression.getLExpression(); if (!(lhs instanceof PsiReferenceExpression)) { continue; } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)lhs; + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lhs; final PsiElement target = referenceExpression.resolve(); if (variable.equals(target)) { if (result >= 0 && !hasInitializer) { @@ -552,15 +502,13 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { return result; } - static class VariableUsedOutsideContextVisitor - extends JavaRecursiveElementVisitor { + static class VariableUsedOutsideContextVisitor extends JavaRecursiveElementVisitor { private boolean used = false; @NotNull private final PsiVariable variable; private final PsiElement skipContext; - public VariableUsedOutsideContextVisitor(@NotNull PsiVariable variable, - PsiElement skipContext) { + public VariableUsedOutsideContextVisitor(@NotNull PsiVariable variable, PsiElement skipContext) { this.variable = variable; this.skipContext = skipContext; } @@ -577,8 +525,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { } @Override - public void visitReferenceExpression( - @NotNull PsiReferenceExpression referenceExpression) { + public void visitReferenceExpression(@NotNull PsiReferenceExpression referenceExpression) { if (used) { return; } @@ -587,11 +534,25 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection { if (target == null) { return; } - if (target.equals(variable)) { + if (target.equals(variable) && !isCloseMethodCalled(referenceExpression)) { used = true; } } + private static boolean isCloseMethodCalled(PsiReferenceExpression referenceExpression) { + final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(referenceExpression, PsiMethodCallExpression.class); + if (methodCallExpression == null) { + return false; + } + final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); + if (argumentList.getExpressions().length != 0) { + return false; + } + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); + final String name = methodExpression.getReferenceName(); + return HardcodedMethodConstants.CLOSE.equals(name); + } + public boolean variableIsUsed() { return used; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java index d47d4032892b..74535a305bb8 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java @@ -446,7 +446,8 @@ public class ParenthesesUtils { public static boolean areParenthesesNeeded(PsiExpression expression, PsiExpression parentExpression, boolean ignoreClarifyingParentheses) { - if (parentExpression instanceof PsiParenthesizedExpression) { + if (parentExpression instanceof PsiParenthesizedExpression || parentExpression instanceof PsiArrayAccessExpression || + parentExpression instanceof PsiArrayInitializerExpression) { return false; } final int parentPrecedence = getPrecedence(parentExpression); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/TryFinallyCanBeTryWithResources.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/TryFinallyCanBeTryWithResources.java new file mode 100644 index 000000000000..ede5211f4e0d --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/TryFinallyCanBeTryWithResources.java @@ -0,0 +1,37 @@ +package com.siyeh.igtest.migration.try_finally_can_be_try_with_resources; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +class TryFinallyCanBeTryWithResources { + + public void read1() throws IOException { + final InputStream stream = new InputStream() { + @Override + public int read() throws IOException { + return 0; + } + }; + try { + stream.read(); + } finally { + stream.close(); + } + } + + public void write2() throws IOException { + final InputStream stream = new InputStream() { + @Override + public int read() throws IOException { + return 0; + } + }; + try { + stream.read(); + } finally { + System.out.println(stream); + stream.close(); + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/expected.xml new file mode 100644 index 000000000000..81af53304a06 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/try_finally_can_be_try_with_resources/expected.xml @@ -0,0 +1,9 @@ + + + + TryFinallyCanBeTryWithResources.java + 16 + 'try finally' replaceable with 'try' with resources + <code>try</code> can use automatic resource management #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspectionTest.java new file mode 100644 index 000000000000..b0f661376983 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspectionTest.java @@ -0,0 +1,20 @@ +package com.siyeh.ig.migration; + +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.siyeh.ig.IGInspectionTestCase; + +public class TryFinallyCanBeTryWithResourcesInspectionTest extends IGInspectionTestCase { + + @Override + protected Sdk getTestProjectSdk() { + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); + return JavaSdkImpl.getMockJdk17(); + } + + public void test() throws Exception { + doTest("com/siyeh/igtest/migration/try_finally_can_be_try_with_resources", new TryFinallyCanBeTryWithResourcesInspection()); + } +} diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadFragment.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadFragment.java index 578cac120bd1..3418fe002d65 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadFragment.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadFragment.java @@ -36,16 +36,21 @@ import java.util.List; */ public class RadFragment extends RadViewComponent implements IConfigurableComponent { private static final Property NAME_PROPERTY = - new FragmentProperty("name", new ResourceEditor(null, Collections.emptySet(), null) { - @Override - protected void showDialog() { - String fragment = chooseFragment(myRootComponent); + new FragmentProperty("name", + new MyResourceEditor(), + JavadocParser.build("name", "Supply the name of the fragment class to instantiate.")); + + private static final Property CLASS_PROPERTY = new FragmentProperty("class", + new MyResourceEditor(), + JavadocParser.build("class", + "Supply the name of the fragment class to instantiate.")) { + @Nullable + @Override + protected String getNamespace() { + return null; + } + }; - if (fragment != null) { - setValue(fragment); - } - } - }, JavadocParser.build("name", "Supply the name of the fragment class to instantiate.")); private static final Property TAG_PROPERTY = new FragmentProperty("tag", new TextEditorWrapper(), JavadocParser.build( "tag", @@ -56,6 +61,7 @@ public class RadFragment extends RadViewComponent implements IConfigurableCompon " {@link android.app.admin.DeviceAdminReceiver#DEVICE_ADMIN_META_DATA}\n" + " meta-data entry. Described here are the attributes that can be\n" + " included in that tag.")); + private static final String NAME_KEY = "fragment.name"; @Override @@ -97,9 +103,25 @@ public class RadFragment extends RadViewComponent implements IConfigurableCompon if (!properties.isEmpty()) { properties = new ArrayList(properties); properties.add(NAME_PROPERTY); + properties.add(CLASS_PROPERTY); properties.add(IdProperty.INSTANCE); properties.add(TAG_PROPERTY); } super.setProperties(properties); } + + private static final class MyResourceEditor extends ResourceEditor { + public MyResourceEditor() { + super(null, Collections.emptySet(), null); + } + + @Override + protected void showDialog() { + String fragment = chooseFragment(myRootComponent); + + if (fragment != null) { + setValue(fragment); + } + } + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml index 12eb4955c621..e40cc68befd2 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml +++ b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml @@ -520,6 +520,8 @@ class="android.widget.ImageView" tag="ImageView"> + + @@ -542,6 +544,8 @@ class="android.widget.ImageButton" tag="ImageButton"> + + diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java index 7e2775a62735..cc637ff24ec6 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java @@ -16,7 +16,6 @@ package com.intellij.android.designer.propertyTable; import com.android.SdkConstants; -import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.model.PropertiesContainer; import com.intellij.designer.model.Property; @@ -55,7 +54,7 @@ public class FragmentProperty extends Property implements IXml @Override public Object getValue(@NotNull RadViewComponent component) throws Exception { - String value = component.getTag().getAttributeValue(myAttribute, SdkConstants.NS_RESOURCES); + String value = component.getTag().getAttributeValue(myAttribute, getNamespace()); return value == null ? "" : value; } @@ -65,10 +64,13 @@ public class FragmentProperty extends Property implements IXml @Override public void run() { if (StringUtil.isEmpty((String)value)) { - ModelParser.deleteAttribute(component, myAttribute); + XmlAttribute attribute = component.getTag().getAttribute(myAttribute, getNamespace()); + if (attribute != null) { + attribute.delete(); + } } else { - component.getTag().setAttribute(myAttribute, SdkConstants.NS_RESOURCES, (String)value); + component.getTag().setAttribute(myAttribute, getNamespace(), (String)value); } } }); @@ -76,12 +78,12 @@ public class FragmentProperty extends Property implements IXml @Override public boolean isDefaultValue(@NotNull RadViewComponent component) throws Exception { - return component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) == null; + return component.getTag().getAttribute(myAttribute, getNamespace()) == null; } @Override public void setDefaultValue(@NotNull RadViewComponent component) throws Exception { - if (component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) != null) { + if (component.getTag().getAttribute(myAttribute, getNamespace()) != null) { setValue(component, null); } } @@ -109,6 +111,11 @@ public class FragmentProperty extends Property implements IXml @Override public boolean checkAttribute(RadViewComponent component, XmlAttribute attribute) { - return component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) == attribute; + return component.getTag().getAttribute(myAttribute, getNamespace()) == attribute; + } + + @Nullable + protected String getNamespace() { + return SdkConstants.NS_RESOURCES; } } \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java index e72c176796e5..c71605775e88 100644 --- a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java +++ b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java @@ -251,7 +251,7 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor { } @Override - public void renameElement(PsiElement element, final String newName, UsageInfo[] usages, RefactoringElementListener listener) + public void renameElement(PsiElement element, final String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException { if (element instanceof PsiField) { new RenameJavaVariableProcessor().renameElement(element, newName, usages, listener); diff --git a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowFactory.java b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowFactory.java index ee848abf001e..56a8f94f6d42 100644 --- a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowFactory.java +++ b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowFactory.java @@ -178,6 +178,7 @@ public class AndroidLogcatToolWindowFactory implements ToolWindowFactory { private static void checkFacetAndSdk(Project project, AndroidLogcatView view) { final List facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID); final ConsoleView console = view.getLogConsole().getConsole(); + assert console != null; if (facets.size() == 0) { console.clear(); diff --git a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java index 881ee81dc5a8..a0bfc70d7d37 100644 --- a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java +++ b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java @@ -21,6 +21,7 @@ import com.android.ddmlib.Log; import com.intellij.CommonBundle; import com.intellij.diagnostic.logging.LogConsoleBase; import com.intellij.diagnostic.logging.LogConsoleListener; +import com.intellij.execution.ui.ConsoleView; import com.intellij.facet.ProjectFacetManager; import com.intellij.icons.AllIcons; import com.intellij.openapi.Disposable; @@ -392,7 +393,10 @@ public abstract class AndroidLogcatView implements Disposable { } } if (device != null) { - myLogConsole.getConsole().clear(); + final ConsoleView console = myLogConsole.getConsole(); + if (console != null) { + console.clear(); + } final Pair pair = AndroidLogcatUtil.startLoggingThread(myProject, device, false, myLogConsole); if (pair != null) { myCurrentReader = pair.first; diff --git a/plugins/git4idea/src/git4idea/GitRevisionNumber.java b/plugins/git4idea/src/git4idea/GitRevisionNumber.java index ba6abd45826f..3bf47f01fb81 100644 --- a/plugins/git4idea/src/git4idea/GitRevisionNumber.java +++ b/plugins/git4idea/src/git4idea/GitRevisionNumber.java @@ -217,6 +217,7 @@ public class GitRevisionNumber implements ShortVcsRevisionNumber { @NotNull public static GitRevisionNumber parseRevlistOutputAsRevisionNumber(@NotNull GitSimpleHandler h, @NotNull String output) { StringTokenizer tokenizer = new StringTokenizer(output, "\n\r \t", false); + assert tokenizer.hasMoreTokens() : "No required tokens in the output: \n" + output; Date timestamp = GitUtil.parseTimestampWithNFEReport(tokenizer.nextToken(), h, output); return new GitRevisionNumber(tokenizer.nextToken(), timestamp); } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java index 0d1236621278..da1f15ab787b 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java @@ -18,13 +18,9 @@ package git4idea.repo; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.VcsRoot; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import git4idea.GitPlatformFacade; @@ -39,7 +35,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; /** * @author Kirill Likhodedov */ -public class GitRepositoryManagerImpl extends AbstractProjectComponent implements Disposable, GitRepositoryManager { +public class GitRepositoryManagerImpl extends AbstractProjectComponent implements Disposable, GitRepositoryManager, VcsListener { private static final Logger LOG = Logger.getInstance(GitRepositoryManager.class); @@ -61,12 +57,8 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement @Override public void initComponent() { Disposer.register(myProject, this); - GitRootScanner rootScanner = new GitRootScanner(myProject, new DumbAwareRunnable() { - @Override - public void run() { - updateRepositoriesCollection(); - } - }); + myProject.getMessageBus().connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this); + GitRootScanner rootScanner = new GitRootScanner(myProject); Disposer.register(this, rootScanner); } @@ -81,6 +73,11 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement } } + @Override + public void directoryMappingChanged() { + updateRepositoriesCollection(); + } + @Override @Nullable public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) { diff --git a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java b/plugins/git4idea/src/git4idea/roots/GitRootScanner.java index b67491e2cd40..6628a2c1f928 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootScanner.java @@ -40,7 +40,6 @@ import java.util.concurrent.TimeUnit; */ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Disposable, VcsListener { - @NotNull private final Runnable myExecuteAfterScan; @NotNull private final GitRootProblemNotifier myRootProblemNotifier; private volatile boolean myProjectIsInitialized; @@ -49,8 +48,7 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Dis @NotNull private final Alarm myAlarm; private static final long WAIT_BEFORE_SCAN = TimeUnit.SECONDS.toMillis(1); - public GitRootScanner(@NotNull Project project, @NotNull Runnable executeAfterScan) { - myExecuteAfterScan = executeAfterScan; + public GitRootScanner(@NotNull Project project) { myRootProblemNotifier = GitRootProblemNotifier.getInstance(project); StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() { @@ -118,7 +116,6 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Dis @Override public void run() { myRootProblemNotifier.rescanAndNotifyIfNeeded(); - myExecuteAfterScan.run(); } }, WAIT_BEFORE_SCAN); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesDetector.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesDetector.java index 4ccaa93552d0..9f5966bc70a6 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesDetector.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesDetector.java @@ -12,11 +12,15 @@ import com.intellij.util.Alarm; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.diff.GradleProjectStructureChange; import org.jetbrains.plugins.gradle.manage.GradleProjectEntityChangeListener; +import org.jetbrains.plugins.gradle.model.gradle.GradleProject; import org.jetbrains.plugins.gradle.task.GradleTaskManager; import org.jetbrains.plugins.gradle.task.GradleTaskType; import org.jetbrains.plugins.gradle.util.GradleUtil; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -26,21 +30,26 @@ import java.util.concurrent.atomic.AtomicLong; * @author Denis Zhdanov * @since 11/3/11 3:57 PM */ -public class GradleProjectStructureChangesDetector extends AbstractProjectComponent { - +public class GradleProjectStructureChangesDetector extends AbstractProjectComponent implements GradleProjectStructureChangeListener { + private static final int REFRESH_DELAY_MILLIS = (int)500; - private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); - private final AtomicLong myStartRefreshTime = new AtomicLong(); - private final RefreshRequest myRequest = new RefreshRequest(); - private final AtomicInteger myImportCounter = new AtomicInteger(); - - public GradleProjectStructureChangesDetector(@NotNull Project project) { + private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); + private final AtomicLong myStartRefreshTime = new AtomicLong(); + private final RefreshRequest myRequest = new RefreshRequest(); + private final AtomicInteger myImportCounter = new AtomicInteger(); + private final AtomicBoolean myNewChangesDetected = new AtomicBoolean(); + + @NotNull private final GradleProjectStructureChangesModel myChangesModel; + + public GradleProjectStructureChangesDetector(@NotNull Project project, @NotNull GradleProjectStructureChangesModel model) { super(project); + myChangesModel = model; + myChangesModel.addListener(this); subscribeToGradleImport(project); subscribeToRootChanges(project); } - + private void subscribeToGradleImport(@NotNull Project project) { MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(GradleProjectEntityChangeListener.TOPIC, new GradleProjectEntityChangeListener() { @@ -77,11 +86,34 @@ public class GradleProjectStructureChangesDetector extends AbstractProjectCompon treeModel.rebuild(); } } - + + @Override + public void onChanges(@NotNull Collection oldChanges, + @NotNull Collection currentChanges) + { + myNewChangesDetected.set(true); + } + private void scheduleUpdate() { if (ApplicationManager.getApplication().isUnitTestMode()) { return; } + + // We experienced a situation when project root change event has been fired but no actual project structure change has + // occurred (e.g. compile output directory was modified externally). That's why we perform additional check here in order + // to ensure that project structure has really been changed. + // + // The idea is to check are there any new project structure changes comparing to the gradle project structure used last time. + // We don't do anything in case no new changes have been detected. + GradleProject project = myChangesModel.getGradleProject(); + if (project != null) { + myNewChangesDetected.set(false); + myChangesModel.update(project); + if (!myNewChangesDetected.get()) { + return; + } + } + myStartRefreshTime.set(System.currentTimeMillis() + REFRESH_DELAY_MILLIS); myAlarm.cancelAllRequests(); myAlarm.addRequest(myRequest, REFRESH_DELAY_MILLIS); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java index 4b57a047c411..7d4a65ef4315 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java @@ -70,7 +70,7 @@ public class RenameAliasImportedMethodProcessor extends RenameJavaMethodProcesso public void renameElement(PsiElement psiElement, String newName, UsageInfo[] usages, - RefactoringElementListener listener) throws IncorrectOperationException { + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { boolean isGetter = isSimplePropertyGetter((PsiMethod)psiElement); boolean isSetter = isSimplePropertySetter((PsiMethod)psiElement); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrAccessorProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrAccessorProcessor.java index 050f61cd91f8..fbeb0cb4e4d9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrAccessorProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrAccessorProcessor.java @@ -24,6 +24,7 @@ import com.intellij.refactoring.rename.RenameJavaMethodProcessor; import com.intellij.usageView.UsageInfo; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; @@ -46,7 +47,7 @@ public class RenameGrAccessorProcessor extends RenameJavaMethodProcessor { public void renameElement(PsiElement psiElement, String newName, UsageInfo[] usages, - RefactoringElementListener listener) throws IncorrectOperationException { + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrFieldProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrFieldProcessor.java index 618cec44e1e6..68c1149037ed 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrFieldProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrFieldProcessor.java @@ -33,6 +33,7 @@ import com.intellij.util.containers.MultiMap; import com.intellij.util.containers.hash.HashMap; import com.intellij.util.containers.hash.LinkedHashMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; @@ -84,7 +85,7 @@ public class RenameGrFieldProcessor extends RenameJavaVariableProcessor { public void renameElement(final PsiElement psiElement, String newName, final UsageInfo[] usages, - final RefactoringElementListener listener) throws IncorrectOperationException { + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { final GrField field = (GrField)psiElement; String fieldName = field.getName(); Map renames = new HashMap(); @@ -164,7 +165,9 @@ public class RenameGrFieldProcessor extends RenameJavaVariableProcessor { rename(element, info, newName, true, manager); } } - listener.elementRenamed(field); + if (listener != null) { + listener.elementRenamed(field); + } } private static void rename(PsiNamedElement element, diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java index b9600b86fe9c..228bb57490b8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java @@ -23,6 +23,7 @@ import com.intellij.refactoring.rename.RenamePsiElementProcessor; import com.intellij.usageView.UsageInfo; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; @@ -57,7 +58,7 @@ public class RenameGroovyPropertyProcessor extends RenamePsiElementProcessor { } @Override - public void renameElement(PsiElement element, String newName, UsageInfo[] usages, RefactoringElementListener listener) + public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException { //do nothing diff --git a/plugins/hg4idea/src/META-INF/plugin.xml b/plugins/hg4idea/src/META-INF/plugin.xml index baa2474bfdfc..ea85d1e3bedd 100644 --- a/plugins/hg4idea/src/META-INF/plugin.xml +++ b/plugins/hg4idea/src/META-INF/plugin.xml @@ -19,6 +19,8 @@ serviceImplementation="org.zmlx.hg4idea.HgProjectSettings"/> + diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java index e36054b13728..60829de0d7fa 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java @@ -19,7 +19,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; @@ -64,16 +63,16 @@ public class HgPusher { VcsBalloonProblemNotifier.showOverChangesView(myProject, "No Mercurial repositories in the project", MessageType.ERROR); } VirtualFile firstRepo = repositories.get(0); - final String defaultPushPath = getDefaultPushPath(myProject, firstRepo); final List branches = getBranches(myProject, firstRepo); final AtomicReference pushCommand = new AtomicReference(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - final HgPushDialog dialog = new HgPushDialog(myProject, repositories, defaultPushPath, branches); + final HgPushDialog dialog = new HgPushDialog(myProject, repositories, branches); dialog.show(); if (dialog.isOK()) { + dialog.rememberSettings(); pushCommand.set(preparePushCommand(myProject, dialog)); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgRememberedInputs.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgRememberedInputs.java new file mode 100644 index 000000000000..f269403f5fb1 --- /dev/null +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgRememberedInputs.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2012 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 org.zmlx.hg4idea; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Nadya Zabrodina + */ +@State( + name = "HgRememberedInputs", + storages = @Storage(file = StoragePathMacros.WORKSPACE_FILE) +) +public class HgRememberedInputs implements PersistentStateComponent { + private State myState = new State(); + + public static class State { + public List repositoryUrls = new ArrayList(); + } + + + public static HgRememberedInputs getInstance(@NotNull Project project) { + return ServiceManager.getService(project, HgRememberedInputs.class); + } + + @Override + public State getState() { + return myState; + } + + @Override + public void loadState(State state) { + myState = state; + } + + public void addRepositoryUrl(@NotNull String url) { + if (!myState.repositoryUrls.contains(url)) { // don't add multiple entries for a single path + myState.repositoryUrls.add(url); + } + } + + @NotNull + public List getRepositoryUrls() { + return myState.repositoryUrls; + } +} diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java index 9d53d02e0279..1aad8baedf7f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java @@ -35,6 +35,7 @@ public class HgPullAction extends HgAbstractGlobalAction { dialog.setRoots(repos); dialog.show(); if (dialog.isOK()) { + dialog.rememberSettings(); return buildCommand(dialog, project); } return null; @@ -42,7 +43,7 @@ public class HgPullAction extends HgAbstractGlobalAction { }; } - private HgGlobalCommand buildCommand(final HgPullDialog dialog, final Project project) { + private static HgGlobalCommand buildCommand(final HgPullDialog dialog, final Project project) { return new HgGlobalCommand() { public VirtualFile getRepo() { return dialog.getRepository(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.form index 8c27a5b411d9..f20b151cdab4 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.form +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.form @@ -39,11 +39,15 @@ - + - + + + - + + + diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java index 9b1ba82bcbcb..93e4911b24b0 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java @@ -13,16 +13,19 @@ package org.zmlx.hg4idea.ui; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.event.DocumentAdapter; +import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.EditorComboBox; +import com.intellij.util.ArrayUtil; import com.intellij.util.ui.UIUtil; +import org.zmlx.hg4idea.HgRememberedInputs; import org.zmlx.hg4idea.command.HgShowConfigCommand; import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Collection; @@ -31,8 +34,8 @@ public class HgPullDialog extends DialogWrapper { private final Project project; private HgRepositorySelectorComponent hgRepositorySelector; - private JTextField sourceTxt; private JPanel mainPanel; + private EditorComboBox myRepositoryURL; public HgPullDialog(Project project) { super(project, false); @@ -43,31 +46,36 @@ public class HgPullDialog extends DialogWrapper { onChangeRepository(); } }); - DocumentListener documentListener = new DocumentListener() { - public void insertUpdate(DocumentEvent e) { - onChangePullSource(); - } - public void removeUpdate(DocumentEvent e) { - onChangePullSource(); - } - - public void changedUpdate(DocumentEvent e) { - onChangePullSource(); - } - }; - sourceTxt.getDocument().addDocumentListener(documentListener); setTitle("Pull"); setOKButtonText("Pull"); init(); } + public void createUIComponents() { + myRepositoryURL = new EditorComboBox(""); + final HgRememberedInputs rememberedInputs = HgRememberedInputs.getInstance(project); + myRepositoryURL.setHistory(ArrayUtil.toObjectArray(rememberedInputs.getRepositoryUrls(), String.class)); + myRepositoryURL.addDocumentListener(new DocumentAdapter() { + @Override + public void documentChanged(DocumentEvent e) { + onChangePullSource(); + } + }); + } + + public void rememberSettings() { + final HgRememberedInputs rememberedInputs = HgRememberedInputs.getInstance(project); + rememberedInputs.addRepositoryUrl(getSource()); + } + + public VirtualFile getRepository() { return hgRepositorySelector.getRepository(); } public String getSource() { - return sourceTxt.getText(); + return myRepositoryURL.getText(); } public void setRoots(Collection repos) { @@ -94,7 +102,7 @@ public class HgPullDialog extends DialogWrapper { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - sourceTxt.setText(defaultPath); + myRepositoryURL.setText(defaultPath); } }); @@ -104,7 +112,7 @@ public class HgPullDialog extends DialogWrapper { } private void onChangePullSource() { - setOKActionEnabled(!StringUtil.isEmptyOrSpaces(sourceTxt.getText())); + setOKActionEnabled(!StringUtil.isEmptyOrSpaces(myRepositoryURL.getText())); } @Override diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form index dbd7e813891b..546b3c2d8ef0 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form @@ -21,12 +21,6 @@ - - - - - - @@ -98,10 +92,19 @@ - + + + + + + + + + + diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java index ccddabefb439..e69c7fafd760 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java @@ -14,13 +14,17 @@ package org.zmlx.hg4idea.ui; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.EditorComboBox; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgPusher; +import org.zmlx.hg4idea.HgRememberedInputs; import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.command.HgTagBranch; @@ -39,22 +43,18 @@ public class HgPushDialog extends DialogWrapper { private final Project myProject; private JPanel contentPanel; - private JTextField repositoryTxt; private JCheckBox revisionCbx; private JTextField revisionTxt; private HgRepositorySelectorComponent hgRepositorySelectorComponent; private JCheckBox forceCheckBox; private JCheckBox branchCheckBox; private JComboBox branchComboBox; + private EditorComboBox myRepositoryURL; - public HgPushDialog(Project project, Collection repos, String defaultPushPath, List branches) { + public HgPushDialog(Project project, Collection repos, List branches) { super(project, false); myProject = project; - hgRepositorySelectorComponent.setRoots(repos); - updateBranchComboBox(branches); - updateRepositoryUrlText(defaultPushPath); - hgRepositorySelectorComponent.setTitle("Select repository to push from"); hgRepositorySelectorComponent.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -65,12 +65,27 @@ public class HgPushDialog extends DialogWrapper { final UpdatingListener updatingListener = new UpdatingListener(); revisionCbx.addChangeListener(updatingListener); branchCheckBox.addChangeListener(updatingListener); - repositoryTxt.getDocument().addDocumentListener(updatingListener); revisionTxt.getDocument().addDocumentListener(updatingListener); setTitle(HgVcsMessages.message("hg4idea.push.dialog.title")); setOKButtonText("Push"); init(); + + hgRepositorySelectorComponent.setRoots(repos); + updateBranchComboBox(branches); + updateRepository(); + } + + public void createUIComponents() { + myRepositoryURL = new EditorComboBox(""); + final HgRememberedInputs rememberedInputs = HgRememberedInputs.getInstance(myProject); + myRepositoryURL.setHistory(ArrayUtil.toObjectArray(rememberedInputs.getRepositoryUrls(), String.class)); + myRepositoryURL.addDocumentListener(new DocumentAdapter() { + @Override + public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) { + setOKActionEnabled(!StringUtil.isEmptyOrSpaces(myRepositoryURL.getText())); + } + }); } public VirtualFile getRepository() { @@ -78,7 +93,7 @@ public class HgPushDialog extends DialogWrapper { } public String getTarget() { - return repositoryTxt.getText(); + return myRepositoryURL.getText(); } @Nullable @@ -123,7 +138,7 @@ public class HgPushDialog extends DialogWrapper { } private void updateRepositoryUrlText(String defaultPath) { - repositoryTxt.setText(defaultPath); + myRepositoryURL.setText(defaultPath); update(); } @@ -138,7 +153,7 @@ public class HgPushDialog extends DialogWrapper { } private boolean validateOptions() { - return !StringUtil.isEmptyOrSpaces(repositoryTxt.getText()) + return !StringUtil.isEmptyOrSpaces(myRepositoryURL.getText()) && !(revisionCbx.isSelected() && StringUtil.isEmptyOrSpaces(revisionTxt.getText())) && !(branchCheckBox.isSelected() && (branchComboBox.getSelectedItem() == null)); } @@ -148,6 +163,11 @@ public class HgPushDialog extends DialogWrapper { return HgPushDialog.class.getName(); } + public void rememberSettings() { + final HgRememberedInputs rememberedInputs = HgRememberedInputs.getInstance(myProject); + rememberedInputs.addRepositoryUrl(myRepositoryURL.getText()); + } + /** * Updates the form on every change. */ diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenResourcesBuilder.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenResourcesBuilder.java index 7033c9219997..f653c20fe96a 100644 --- a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenResourcesBuilder.java +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenResourcesBuilder.java @@ -172,7 +172,7 @@ public class MavenResourcesBuilder extends TargetBuildertest" + - "project" + - "1" + - "" + - " " + - " " + - " maven-compiler-plugin" + - " " + - " " + - " " + - " compile" + - " unknownGoal" + - " " + - " " + - " " + - " " + - " " + - " unresolved-plugin" + - " " + - " " + - " " + - " compile" + - " unknownGoal" + - " " + - " " + - " " + - " " + - " " + + @Bombed(day = 10, month = Calendar.DECEMBER, year = 2012) + public void testDontHighlightGoalsForUnresolvedPlugin() throws Throwable { + createProjectPom("test\n" + + "project\n" + + "1\n" + + + "\n" + + " \n" + + " \n" + + " maven-compiler-plugin\n" + + " \n" + + " \n" + + " \n" + + " compile\n" + + " unknownGoal\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " unresolved-plugin\n" + + " \n" + + " \n" + + " \n" + + " compile\n" + + " unknownGoal\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + ""); checkHighlighting(); diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/IgnoredFilesTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/IgnoredFilesTest.java index 2e83c50c715a..270e6d49c607 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/IgnoredFilesTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/IgnoredFilesTest.java @@ -75,9 +75,7 @@ public class IgnoredFilesTest extends Svn17TestCase { myVcsManager.registerVcs(myVcs); myVcsManager.setDirectoryMapping(myWorkingCopyDir.getPath(), myVcs.getName()); - ((ProjectComponent)myChangeListManager).projectOpened(); myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); - ((ProjectComponent)myVcsDirtyScopeManager).projectOpened(); myLocalFileSystem = LocalFileSystem.getInstance(); } catch (Exception e) { diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/IgnoredFilesTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/IgnoredFilesTest.java index 1c1252dcbc91..2370f5183e9e 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/IgnoredFilesTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/IgnoredFilesTest.java @@ -74,9 +74,7 @@ public class IgnoredFilesTest extends Svn16TestCase { myVcsManager.registerVcs(myVcs); myVcsManager.setDirectoryMapping(myWorkingCopyDir.getPath(), myVcs.getName()); - ((ProjectComponent)myChangeListManager).projectOpened(); myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); - ((ProjectComponent)myVcsDirtyScopeManager).projectOpened(); myLocalFileSystem = LocalFileSystem.getInstance(); } catch (Exception e) { diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/GotoTaskAction.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/GotoTaskAction.java index 53d05b60e071..089e85ffe70b 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/GotoTaskAction.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/GotoTaskAction.java @@ -48,7 +48,6 @@ public class GotoTaskAction extends GotoActionBase { } void perform(final Project project) { - myInAction = getClass(); final Ref shiftPressed = Ref.create(false); final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, new GotoTaskPopupModel(project), new ChooseByNameItemProvider() { @@ -134,8 +133,12 @@ public class GotoTaskAction extends GotoActionBase { }); final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); + actionToolbar.updateActionsImmediately(); + actionToolbar.getComponent().setFocusable(false); + actionToolbar.getComponent().setBorder(null); popup.setToolArea(actionToolbar.getComponent()); popup.setMaximumListSizeLimit(10); + popup.setListSizeIncreasing(10); showNavigationPopup(new GotoActionCallback() { @Override @@ -205,8 +208,7 @@ public class GotoTaskAction extends GotoActionBase { @Override public String getCheckBoxName() { - return null; - //return "Include closed tasks"; + return "Include closed tasks"; } @Override diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java index 49a3b01b0797..30ec06962558 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java @@ -39,6 +39,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.Collections; @@ -54,16 +55,18 @@ public class SwitchTaskAction extends BaseTaskAction { DataContext dataContext = e.getDataContext(); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); assert project != null; - final ListPopupImpl popup = createPopup(dataContext, null, true); + ListPopupImpl popup = createPopup(dataContext, null, true); popup.showCenteredInCurrentWindow(project); } - public static ListPopupImpl createPopup(final DataContext dataContext, @Nullable final Runnable onDispose, boolean withTitle) { + public static ListPopupImpl createPopup(final DataContext dataContext, + @Nullable final Runnable onDispose, + boolean withTitle) { final Project project = PlatformDataKeys.PROJECT.getData(dataContext); final Ref shiftPressed = Ref.create(false); final Ref componentRef = Ref.create(); List items = project == null ? Collections.emptyList() : - createPopupActionGroup(project, shiftPressed, dataContext); + createPopupActionGroup(project, shiftPressed, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext)); final String title = withTitle ? "Switch to Task" : null; ListPopupStep step = new MultiSelectionListPopupStep(title, items) { @Override @@ -73,7 +76,8 @@ public class SwitchTaskAction extends BaseTaskAction { return FINAL_CHOICE; } ActionGroup group = createActionsStep(selectedValues, project, shiftPressed); - return JBPopupFactory.getInstance().createActionsStep(group, DataManager.getInstance().getDataContext(componentRef.get()), false, false, null, null, true); + return JBPopupFactory.getInstance() + .createActionsStep(group, DataManager.getInstance().getDataContext(componentRef.get()), false, false, null, null, true); } @Override @@ -165,7 +169,7 @@ public class SwitchTaskAction extends BaseTaskAction { @NotNull private static List createPopupActionGroup(@NotNull final Project project, final Ref shiftPressed, - final DataContext dataContext) { + final Component contextComponent) { List group = new ArrayList(); final AnAction action = ActionManager.getInstance().getAction(GotoTaskAction.ID); @@ -176,8 +180,7 @@ public class SwitchTaskAction extends BaseTaskAction { @Override void select() { ActionManager.getInstance().tryToExecute(gotoTaskAction, ActionCommand.getInputEvent(GotoTaskAction.ID), - PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext), ActionPlaces.UNKNOWN, true); - gotoTaskAction.perform(project); + contextComponent, ActionPlaces.UNKNOWN, false); } }); @@ -232,12 +235,13 @@ public class SwitchTaskAction extends BaseTaskAction { }); boolean removeIt = true; - l: for (LocalChangeList list : lists) { + l: + for (LocalChangeList list : lists) { if (!list.getChanges().isEmpty()) { int result = Messages.showYesNoCancelDialog(project, - "Changelist associated with '" + task.getSummary() + "' is not empty.\n" + - "Do you want to remove it and move the changes to the active changelist?", - "Changelist Not Empty", Messages.getWarningIcon()); + "Changelist associated with '" + task.getSummary() + "' is not empty.\n" + + "Do you want to remove it and move the changes to the active changelist?", + "Changelist Not Empty", Messages.getWarningIcon()); switch (result) { case 0: break l; @@ -257,5 +261,4 @@ public class SwitchTaskAction extends BaseTaskAction { manager.removeTask(task); } } - } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepository.java index ade2fa43fe1a..8a5b0cffa152 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepository.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepository.java @@ -13,6 +13,7 @@ import com.intellij.tasks.mantis.model.*; import com.intellij.util.Function; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.text.VersionComparatorUtil; import com.intellij.util.xmlb.annotations.Tag; import org.apache.axis.utils.StringUtils; import org.jetbrains.annotations.NotNull; @@ -22,6 +23,7 @@ import javax.xml.rpc.ServiceException; import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; +import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -141,7 +143,8 @@ public class MantisRepository extends BaseRepositoryImpl { if (id == null) return null; String summary = data.getSummary(); if (summary == null) return null; - return new MantisTask(id, summary, myProject, this, data.getLast_updated().getTime()) { + final boolean closed = data.getStatus().getId().intValue() >= 90; + return new MantisTask(id, summary, myProject, this, data.getLast_updated().getTime(), closed) { @Override public String getDescription() { return data.getDescription(); @@ -190,7 +193,8 @@ public class MantisRepository extends BaseRepositoryImpl { if (id == null) return null; String summary = data.getSummary(); if (summary == null) return null; - return new MantisTask(id, summary, myProject, this, data.getLast_updated().getTime()); + final boolean closed = data.getStatus().intValue() >= 90; + return new MantisTask(id, summary, myProject, this, data.getLast_updated().getTime(), closed); } public List getProjects() throws Exception { @@ -217,14 +221,13 @@ public class MantisRepository extends BaseRepositoryImpl { return new MantisProject(data.getId().intValue(), data.getName()); } }); - projects.add(0, MantisProject.ALL_PROJECTS); - String version = soap.mc_version(); + if (allProjectsAvailable(soap)){ + projects.add(0, MantisProject.ALL_PROJECTS); + } for (MantisProject project : projects) { FilterData[] filterDatas = soap.mc_filter_get(getUsername(), getPassword(), BigInteger.valueOf(project.getId())); List filters = new ArrayList(); - if (!MantisProject.ALL_PROJECTS.equals(project) || !version.startsWith("1.1")) { - filters.add(MantisFilter.LAST_TASKS); - } + filters.add(MantisFilter.LAST_TASKS); filters.addAll(ContainerUtil.map(filterDatas, new Function() { @Override public MantisFilter fun(final FilterData data) { @@ -238,6 +241,11 @@ public class MantisRepository extends BaseRepositoryImpl { } + private static boolean allProjectsAvailable(final MantisConnectPortType soap) throws RemoteException { + String version = soap.mc_version(); + return VersionComparatorUtil.compare(version, "1.2.9") >= 0; + } + private synchronized MantisConnectPortType createSoap() throws ServiceException, MalformedURLException { return new MantisConnectLocator().getMantisConnectPort(new URL(getUrl() + SOAP_API_LOCATION)); } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisTask.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisTask.java index 06d6c6a182de..ddad988e2a9e 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisTask.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisTask.java @@ -14,14 +14,21 @@ import java.util.Date; public class MantisTask extends Task { private final String myId; private final String mySummary; - private final Date myTime; + private final Date myUpdated; + private final boolean myClosed; private String myProjectName; private MantisRepository myRepository; - public MantisTask(final String id, final String summary, MantisProject project, MantisRepository repository, final Date time) { + public MantisTask(final String id, + final String summary, + MantisProject project, + MantisRepository repository, + final Date updated, + final boolean closed) { myId = id; mySummary = summary; - myTime = time; + myUpdated = updated; + myClosed = closed; myProjectName = !MantisProject.ALL_PROJECTS.equals(project) ? project.getName() : null; myRepository = repository; } @@ -65,7 +72,7 @@ public class MantisTask extends Task { @Nullable @Override public Date getUpdated() { - return myTime; + return myUpdated; } @Nullable @@ -76,7 +83,7 @@ public class MantisTask extends Task { @Override public boolean isClosed() { - return false; + return myClosed; } @Override diff --git a/plugins/tasks/tasks-time-tracking/tasks-time-tracking.iml b/plugins/tasks/tasks-time-tracking/tasks-time-tracking.iml index a4c5ad9414ee..ecee65315829 100644 --- a/plugins/tasks/tasks-time-tracking/tasks-time-tracking.iml +++ b/plugins/tasks/tasks-time-tracking/tasks-time-tracking.iml @@ -5,7 +5,7 @@ - + diff --git a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java index fd0045b61f1d..649eb2adc92d 100644 --- a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java +++ b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java @@ -132,7 +132,6 @@ public class FormsBindingManager extends FormsBuilder { addBinding(boundSource, form, srcToForms); FSOperations.markDirty(context, boundSource); filesToCompile.put(boundSource, target); - context.getScope().expandScope(target, boundSource); exitCode = ExitCode.OK; } } @@ -150,7 +149,6 @@ public class FormsBindingManager extends FormsBuilder { addBinding(srcFile, formFile, srcToForms); FSOperations.markDirty(context, formFile); formsToCompile.put(formFile, target); - context.getScope().expandScope(target, formFile); exitCode = ExitCode.OK; } } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InplaceEditingLayer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InplaceEditingLayer.java index 1f8f59ebfd88..06dbad60f37a 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InplaceEditingLayer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InplaceEditingLayer.java @@ -228,6 +228,7 @@ public final class InplaceEditingLayer extends JComponent{ } private void adjustEditorComponentSize(){ + if (myInplaceEditorComponent == null) return; final Dimension preferredSize = myInplaceEditorComponent.getPreferredSize(); int width = Math.max(preferredSize.width, myPreferredBounds.width); // Editor component should not be extended to invisible area diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java index a1222bae18c5..ef5c16bd6e20 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java @@ -353,6 +353,10 @@ public class XPath2Parser extends XPathParser { builder.advanceLexer(); } mark.done(XPath2ElementTypes.SINGLE_TYPE); + + if (builder.getTokenType() == XPathTokenTypes.STAR) { + builder.remapCurrentToken(XPathTokenTypes.MULT); + } } private boolean parseSequenceType(PsiBuilder builder) { @@ -369,6 +373,9 @@ public class XPath2Parser extends XPathParser { mark.done(XPath2ElementTypes.SEQUENCE_TYPE); return true; } else if (parseNodeType(builder) || parseQName(builder)) { + if (builder.getTokenType() == XPathTokenTypes.MULT) { + builder.remapCurrentToken(XPathTokenTypes.STAR); + } if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) { makeToken(builder); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java index aef01e64fc11..b1b068b090cd 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java @@ -279,7 +279,7 @@ public class XPathParser implements PsiParser { if (builder.getTokenType() == XPathTokenTypes.MINUS) { final PsiBuilder.Marker expr = builder.mark(); builder.advanceLexer(); - if (!parsePathExpression(builder)) { + if (!parseUnionExpression(builder)) { builder.error("Expression expected"); } expr.done(XPathElementTypes.PREFIX_EXPRESSION); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AddAssociationAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AddAssociationAction.java index 3b867e7cecec..654331795794 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AddAssociationAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AddAssociationAction.java @@ -18,17 +18,15 @@ package org.intellij.lang.xpath.xslt.associations.impl; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.util.IconUtil; import org.intellij.lang.xpath.xslt.associations.FileAssociationsManager; class AddAssociationAction extends AnAction { - private final FileAssociationsManager myManager; + private final FileAssociationsManager myManager; public AddAssociationAction(FileAssociationsManager manager) { super("Add...", "Add File Association", IconUtil.getAddIcon()); @@ -38,16 +36,12 @@ class AddAssociationAction extends AnAction { public void actionPerformed(AnActionEvent e) { final PsiFile psiFile = AssociationsGroup.getPsiFile(e); if (psiFile == null) return; - final Project project = LangDataKeys.PROJECT.getData(e.getDataContext()); - if (project == null) return; - addAssociation(e, psiFile); - DaemonCodeAnalyzer.getInstance(project).restart(); + addAssociation(psiFile); + DaemonCodeAnalyzer.getInstance(psiFile.getProject()).restart(psiFile); } - protected void addAssociation(AnActionEvent e, PsiFile psiFile) { - final Project project = AssociationsGroup.getEventProject(e); - if (project == null) return; + protected void addAssociation(final PsiFile psiFile) { final VirtualFile virtualFile = psiFile.getVirtualFile(); assert virtualFile != null; @@ -58,7 +52,7 @@ class AddAssociationAction extends AnAction { } }; - final VirtualFile[] virtualFiles = FileChooser.chooseFiles(descriptor, project, psiFile.getVirtualFile()); + final VirtualFile[] virtualFiles = FileChooser.chooseFiles(descriptor, psiFile.getProject(), psiFile.getVirtualFile()); if (virtualFiles.length == 0) return; // cancel for (VirtualFile file : virtualFiles) { @@ -66,5 +60,4 @@ class AddAssociationAction extends AnAction { myManager.addAssociation(psiFile, file); } } - } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AssociationsEditor.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AssociationsEditor.java index ff9d4e2eda89..ed0af7f62b17 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AssociationsEditor.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/AssociationsEditor.java @@ -213,7 +213,7 @@ class AssociationsEditor { public void actionPerformed(AnActionEvent e) { final PsiFile selection = (PsiFile)getTreeSelection(myTree); - addAssociation(e, selection); + addAssociation(selection); myListModel.update(selection); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ConfigureAssociationsAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ConfigureAssociationsAction.java index dc19b795b599..9fa937262c7c 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ConfigureAssociationsAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ConfigureAssociationsAction.java @@ -18,6 +18,7 @@ package org.intellij.lang.xpath.xslt.associations.impl; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; @@ -27,7 +28,7 @@ class ConfigureAssociationsAction extends AnAction { } public void actionPerformed(final AnActionEvent e) { - final Project project = LangDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext()); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/FileAssociationsManagerImpl.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/FileAssociationsManagerImpl.java index 1cb823f49258..7b339e17378d 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/FileAssociationsManagerImpl.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/FileAssociationsManagerImpl.java @@ -15,6 +15,7 @@ */ package org.intellij.lang.xpath.xslt.associations.impl; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.util.PsiUtilCore; import org.intellij.lang.xpath.xslt.associations.FileAssociationsManager; @@ -40,6 +41,8 @@ import org.jdom.Element; import java.util.*; class FileAssociationsManagerImpl extends FileAssociationsManager implements ProjectComponent, JDOMExternalizable, ModificationTracker { + private static final Logger LOG = Logger.getInstance(FileAssociationsManagerImpl.class); + private final Project myProject; private final VirtualFilePointerManager myFilePointerManager; private final Map myAssociations; @@ -178,13 +181,19 @@ class FileAssociationsManagerImpl extends FileAssociationsManager implements Pro public void addAssociation(PsiFile file, PsiFile assoc) { final VirtualFile virtualFile = assoc.getVirtualFile(); - if (virtualFile == null) return; + if (virtualFile == null) { + LOG.warn("No VirtualFile for " + file.getName()); + return; + } addAssociation(file, virtualFile); } public void addAssociation(PsiFile file, VirtualFile assoc) { final VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) return; + if (virtualFile == null) { + LOG.warn("No VirtualFile for " + file.getName()); + return; + } for (VirtualFilePointer pointer : myAssociations.keySet()) { if (pointer.getUrl().equals(virtualFile.getUrl())) { diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ToggleAssociationAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ToggleAssociationAction.java index 7a7691498919..50db1a54b3e6 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ToggleAssociationAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/associations/impl/ToggleAssociationAction.java @@ -16,6 +16,7 @@ package org.intellij.lang.xpath.xslt.associations.impl; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.module.Module; @@ -69,6 +70,6 @@ class ToggleAssociationAction extends ToggleAction { public void setSelected(AnActionEvent e, boolean state) { assert !state; myFileAssociationsManager.removeAssociation(myPsiFile, myAssoc); - DaemonCodeAnalyzer.getInstance(AssociationsGroup.getEventProject(e)).restart(); + DaemonCodeAnalyzer.getInstance(AnAction.getEventProject(e)).restart(); } } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java index 9c43f4262e7f..5a9e4b61ba1c 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java @@ -97,6 +97,21 @@ public class XPath2ParsingTest extends TestBase { doXPathHighlighting(); } + // IDEA-70681 + public void testCastWithMultiplication() throws Throwable { + doXPathHighlighting(); + } + + // IDEA-70688 + public void testKindTestWithStar() throws Throwable { + doXPathHighlighting(); + } + + public void testUnionSubExpression() throws Throwable { + doXPathHighlighting(); + } + + // IDEA-67413 private void doXPathHighlighting() throws Throwable { final String name = getTestFileName(); myFixture.testHighlighting(false, false, false, name + ".xpath2"); diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java index 4d4d366b0350..80c2ced6e569 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java @@ -85,6 +85,11 @@ public class XPathHighlightingTest extends TestBase { doXPathHighlighting(); } + // IDEA-67413 + public void testUnionSubExpression() throws Throwable { + doXPathHighlighting(); + } + private void doXPathHighlighting(String... moreFiles) throws Throwable { final String name = getTestFileName(); myFixture.testHighlighting(true, false, false, ArrayUtil.append(moreFiles, name + ".xpath")); diff --git a/plugins/xpath/xpath-lang/testData/xpath/highlighting/unionSubExpression.xpath b/plugins/xpath/xpath-lang/testData/xpath/highlighting/unionSubExpression.xpath new file mode 100644 index 000000000000..1f1c9e20a5c9 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath/highlighting/unionSubExpression.xpath @@ -0,0 +1 @@ +-.|. \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/parsing/castWithMultiplication.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/parsing/castWithMultiplication.xpath2 new file mode 100644 index 000000000000..6c9920d25881 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/parsing/castWithMultiplication.xpath2 @@ -0,0 +1 @@ +4 cast as xs:integer * 5 \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/parsing/kindTestWithStar.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/parsing/kindTestWithStar.xpath2 new file mode 100644 index 000000000000..556be09e0a75 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/parsing/kindTestWithStar.xpath2 @@ -0,0 +1 @@ +. treat as document-node()* \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/parsing/unionSubExpression.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/parsing/unionSubExpression.xpath2 new file mode 100644 index 000000000000..5689d148612c --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/parsing/unionSubExpression.xpath2 @@ -0,0 +1 @@ +-.|. \ No newline at end of file diff --git a/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java b/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java index 1b8c15d59d58..1f7885b4d913 100644 --- a/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java +++ b/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java @@ -30,6 +30,7 @@ import com.intellij.usageView.UsageInfo; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.Queue; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameXmlAttributeProcessor"); @@ -41,7 +42,7 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { public void renameElement(final PsiElement element, final String newName, final UsageInfo[] usages, - final RefactoringElementListener listener) throws IncorrectOperationException { + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { if (element instanceof XmlAttribute) { doRenameXmlAttribute((XmlAttribute)element, newName, listener); } @@ -52,10 +53,12 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { private static void doRenameXmlAttribute(XmlAttribute attribute, String newName, - RefactoringElementListener listener) { + @Nullable RefactoringElementListener listener) { try { final PsiElement element = attribute.setName(newName); - listener.elementRenamed(element); + if (listener != null) { + listener.elementRenamed(element); + } } catch (IncorrectOperationException e) { LOG.error(e); @@ -65,7 +68,7 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { private static void doRenameXmlAttributeValue(@NotNull XmlAttributeValue value, String newName, UsageInfo[] infos, - RefactoringElementListener listener) + @Nullable RefactoringElementListener listener) throws IncorrectOperationException { LOG.assertTrue(value.isValid()); @@ -75,7 +78,9 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { LOG.assertTrue(psiManager != null); XmlFile file = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText("dummy.xml", ""); final PsiElement element = value.replace(file.getDocument().getRootTag().getAttributes()[0].getValueElement()); - listener.elementRenamed(element); + if (listener != null) { + listener.elementRenamed(element); + } } private static void renameAll(PsiElement originalElement, UsageInfo[] infos, String newName,