From a24d665288b4b2b7c4071e53f8f1adecf90a21d0 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 12 Dec 2012 19:18:43 +0400 Subject: [PATCH 01/67] [git] write unsuppressed command output not only to the console, but to the log as well --- plugins/git4idea/src/git4idea/commands/GitHandler.java | 4 ++-- .../git4idea/src/git4idea/commands/GitLineHandler.java | 8 ++++---- .../git4idea/src/git4idea/commands/GitTextHandler.java | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index 5ed74cecf3ed..055a91f2245e 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -58,7 +58,7 @@ public abstract class GitHandler { private final List myErrors = Collections.synchronizedList(new ArrayList()); private final List myLastOutput = Collections.synchronizedList(new ArrayList()); private final int LAST_OUTPUT_SIZE = 5; - private static final Logger LOG = Logger.getInstance(GitHandler.class.getName()); + protected static final Logger LOG = Logger.getInstance(GitHandler.class.getName()); final GeneralCommandLine myCommandLine; @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) Process myProcess; @@ -87,7 +87,7 @@ public abstract class GitHandler { private final EventDispatcher myListeners = EventDispatcher.create(ProcessEventListener.class); @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) - private boolean mySilent; // if true, the command execution is not logged in version control view + protected boolean mySilent; // if true, the command execution is not logged in version control view protected final GitVcs myVcs; private final Map myEnv; diff --git a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java index ecfa17baabec..1a183be3928a 100644 --- a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java @@ -24,9 +24,7 @@ import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; /** * The handler that is based on per-line processing of the text. @@ -151,11 +149,13 @@ public class GitLineHandler extends GitTextHandler { String trimmed = LineHandlerHelper.trimLineSeparator(line); // if line ends with return, then it is a progress line, ignore it if (myVcs != null && !"\r".equals(line.substring(trimmed.length()))) { - if (outputType == ProcessOutputTypes.STDOUT && !isStdoutSuppressed()) { + if (outputType == ProcessOutputTypes.STDOUT && !isStdoutSuppressed() && !mySilent) { myVcs.showMessages(trimmed); + LOG.info(line); } - else if (outputType == ProcessOutputTypes.STDERR && !isStderrSuppressed()) { + else if (outputType == ProcessOutputTypes.STDERR && !isStderrSuppressed() && !mySilent) { myVcs.showErrorMessages(trimmed); + LOG.info(line); } } myLineListeners.getMulticaster().onLineAvailable(trimmed, outputType); diff --git a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java index 9a3f63289471..821a1d32b82c 100644 --- a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java @@ -17,8 +17,10 @@ package git4idea.commands; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; -import com.intellij.execution.process.*; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.execution.process.OSProcessHandler; +import com.intellij.execution.process.ProcessEvent; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.process.ProcessListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; @@ -36,7 +38,6 @@ public abstract class GitTextHandler extends GitHandler { @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) private OSProcessHandler myHandler; private volatile boolean myIsDestroyed; private final Object myProcessStateLock = new Object(); - private static final Logger LOG = Logger.getInstance(GitTextHandler.class.getName()); protected GitTextHandler(@NotNull Project project, @NotNull File directory, @NotNull GitCommand command) { super(project, directory, command); From 2f5e721179f071c1ac80bfb84da7f1e1a309ce23 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 13 Dec 2012 18:28:00 +0400 Subject: [PATCH 02/67] [git] Force refresh repository information before update. --- plugins/git4idea/src/git4idea/update/GitUpdateProcess.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java index d5ccafaaea73..356ab39547af 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java @@ -117,6 +117,10 @@ public class GitUpdateProcess { String oldText = myProgressIndicator.getText(); myProgressIndicator.setText("Updating..."); + for (GitRepository repository : myRepositories) { + repository.update(); + } + // check if update is possible if (checkRebaseInProgress() || isMergeInProgress() || areUnmergedFiles() || !checkTrackedBranchesConfigured()) { return GitUpdateResult.NOT_READY; From 47e66dc67641bb6850c0b764ba430d276aca5406 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 13 Dec 2012 20:25:54 +0400 Subject: [PATCH 03/67] [git] Result class for further general usage. --- plugins/git4idea/src/git4idea/Result.java | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 plugins/git4idea/src/git4idea/Result.java diff --git a/plugins/git4idea/src/git4idea/Result.java b/plugins/git4idea/src/git4idea/Result.java new file mode 100644 index 000000000000..1c13f93a81b3 --- /dev/null +++ b/plugins/git4idea/src/git4idea/Result.java @@ -0,0 +1,49 @@ +/* + * 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 git4idea; + +import org.jetbrains.annotations.Nullable; + +/** + * Result of some operation. + * Encapsulates both information about successfulness of the operation, and error details in the case of failure. + * + * @author Kirill Likhodedov + */ +public class Result { + + public static final Result SUCCESS = new Result(null); + public static final Result CANCEL = new Result("Cancelled by user"); + + @Nullable private final String myErrorDetails; + + public Result(@Nullable String errorDetails) { + myErrorDetails = errorDetails; + } + + public static Result error(String details) { + return new Result(details); + } + + @Nullable + public String getErrorDetails() { + return myErrorDetails; + } + + public boolean isSuccess() { + return this.equals(SUCCESS); + } +} From 98f5fbb18cf10083973f6a53a663b29ef3e15937 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 13 Dec 2012 20:29:31 +0400 Subject: [PATCH 04/67] [git] IDEA-94263 Additional protection against skipping a commit during rebase If "no changes" situation was detected, verify the git status: * if there are local staged changes => the detector somehow detected a false positive => report the error and continue rebase instead of skip. * if there are unstaged changes => probably another case of a false positive => report the error, ADD all files to the index and continue. * if "no changes" is confirmed, execute skip. --- plugins/git4idea/src/git4idea/GitUtil.java | 21 ++++++++- .../src/git4idea/rebase/GitRebaseUtils.java | 5 +++ .../src/git4idea/rebase/GitRebaser.java | 44 ++++++++++++++++--- .../src/git4idea/update/GitMergeUpdater.java | 17 +------ 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index 70f53dc458d5..9ec8058cbe5a 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -34,7 +34,6 @@ import com.intellij.openapi.vcs.changes.FilePathsHelper; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; import com.intellij.util.Function; @@ -925,4 +924,24 @@ public class GitUtil { } } + /** + * git diff --name-only [--cached] + * @return true if there is anything in the unstaged/staging area, false if the unstraed/staging area is empty. + * @param staged if true checks the staging area, if false checks unstaged files. + * @param project + * @param root + */ + public static boolean hasLocalChanges(boolean staged, Project project, VirtualFile root) throws VcsException { + final GitSimpleHandler diff = new GitSimpleHandler(project, root, GitCommand.DIFF); + diff.addParameters("--name-only"); + if (staged) { + diff.addParameters("--cached"); + } + diff.setNoSSH(true); + diff.setStdoutSuppressed(true); + diff.setStderrSuppressed(true); + diff.setSilent(true); + final String output = diff.run(); + return !output.trim().isEmpty(); + } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java index a7065892996c..e159027039b5 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java @@ -162,5 +162,10 @@ public class GitRebaseUtils { this.revision = revision; this.subject = subject; } + + @Override + public String toString() { + return revision.toString(); + } } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java index f72d250447ca..a3c76e83f892 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java @@ -173,6 +173,9 @@ public class GitRebaser { return result.get(); } + /** + * @return true if the failure situation was resolved successfully, false if we failed to resolve the problem. + */ private boolean handleRebaseFailure(final VirtualFile root, final GitLineHandler h, GitRebaseProblemDetector rebaseConflictDetector) { if (rebaseConflictDetector.isMergeConflict()) { LOG.info("handleRebaseFailure merge conflict"); @@ -185,17 +188,48 @@ public class GitRebaser { return continueRebase(root, "--continue"); } }.merge(); - } else if (rebaseConflictDetector.isNoChangeError()) { - LOG.info("handleRebaseFailure no change"); - mySkippedCommits.add(GitRebaseUtils.getCurrentRebaseCommit(root)); - return continueRebase(root, "--skip"); - } else { + } + else if (rebaseConflictDetector.isNoChangeError()) { + LOG.info("handleRebaseFailure no changes error detected"); + try { + if (GitUtil.hasLocalChanges(true, myProject, root)) { + LOG.error("The rebase detector incorrectly detected 'no changes' situation. Attempting to continue rebase."); + return continueRebase(root); + } + else if (GitUtil.hasLocalChanges(false, myProject, root)) { + LOG.warn("No changes from patch were not added to the index. Adding all changes from tracked files."); + stageEverything(root); + return continueRebase(root); + } + else { + GitRebaseUtils.CommitInfo commit = GitRebaseUtils.getCurrentRebaseCommit(root); + LOG.info("no changes confirmed. Skipping commit " + commit); + mySkippedCommits.add(commit); + return continueRebase(root, "--skip"); + } + } + catch (VcsException e) { + LOG.info("Failed to work around 'no changes' error.", e); + String message = "Couldn't proceed with rebase. " + e.getMessage(); + GitUIUtil.notifyImportantError(myProject, "Error rebasing", message); + return false; + } + } + else { LOG.info("handleRebaseFailure error " + h.errors()); GitUIUtil.notifyImportantError(myProject, "Error rebasing", GitUIUtil.stringifyErrors(h.errors())); return false; } } + private void stageEverything(@NotNull VirtualFile root) throws VcsException { + GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.ADD); + handler.setSilent(false); + handler.setNoSSH(true); + handler.addParameters("--update"); + handler.run(); + } + private static GitConflictResolver.Params makeParamsForRebaseConflict() { return new GitConflictResolver.Params(). setReverse(true). diff --git a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java index a1bb5e8753fc..11fd0ff42fac 100644 --- a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java @@ -150,7 +150,7 @@ public class GitMergeUpdater extends GitUpdater { @Override public boolean isSaveNeeded() { try { - if (hasStagedChanges()) { + if (GitUtil.hasLocalChanges(true, myProject, myRoot)) { return true; } } @@ -185,21 +185,6 @@ public class GitMergeUpdater extends GitUpdater { } } - /** - * git diff --name-only --cached - * @return true if there is anything in the staging area, false if the staging area is empty. - */ - private boolean hasStagedChanges() throws VcsException { - final GitSimpleHandler diff = new GitSimpleHandler(myProject, myRoot, GitCommand.DIFF); - diff.addParameters("--name-only", "--cached"); - diff.setNoSSH(true); - diff.setStdoutSuppressed(true); - diff.setStderrSuppressed(true); - diff.setSilent(true); - final String output = diff.run(); - return !output.trim().isEmpty(); - } - private void cancel() { try { GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.RESET); From f6f26e787cab0e3a40a75d348d56f754f6b3a7ef Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 14 Dec 2012 13:37:17 +0400 Subject: [PATCH 05/67] [git] Don't add extra line to the log in the GitHandler output. --- plugins/git4idea/src/git4idea/commands/GitLineHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java index 1a183be3928a..165939de3cad 100644 --- a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java @@ -151,11 +151,11 @@ public class GitLineHandler extends GitTextHandler { if (myVcs != null && !"\r".equals(line.substring(trimmed.length()))) { if (outputType == ProcessOutputTypes.STDOUT && !isStdoutSuppressed() && !mySilent) { myVcs.showMessages(trimmed); - LOG.info(line); + LOG.info(line.trim()); } else if (outputType == ProcessOutputTypes.STDERR && !isStderrSuppressed() && !mySilent) { myVcs.showErrorMessages(trimmed); - LOG.info(line); + LOG.info(line.trim()); } } myLineListeners.getMulticaster().onLineAvailable(trimmed, outputType); From 2342edc400000e14feeb2312e8650e5dc55b8988 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 14 Dec 2012 13:38:25 +0400 Subject: [PATCH 06/67] [git] Print output from GitSimpleHandler as well. Don't print empty line. --- .../src/git4idea/commands/GitLineHandler.java | 5 +++-- .../git4idea/commands/GitSimpleHandler.java | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java index 165939de3cad..506375655fc2 100644 --- a/plugins/git4idea/src/git4idea/commands/GitLineHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitLineHandler.java @@ -18,6 +18,7 @@ package git4idea.commands; import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.LineHandlerHelper; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.EventDispatcher; @@ -149,11 +150,11 @@ public class GitLineHandler extends GitTextHandler { String trimmed = LineHandlerHelper.trimLineSeparator(line); // if line ends with return, then it is a progress line, ignore it if (myVcs != null && !"\r".equals(line.substring(trimmed.length()))) { - if (outputType == ProcessOutputTypes.STDOUT && !isStdoutSuppressed() && !mySilent) { + if (outputType == ProcessOutputTypes.STDOUT && !isStdoutSuppressed() && !mySilent && !StringUtil.isEmptyOrSpaces(line)) { myVcs.showMessages(trimmed); LOG.info(line.trim()); } - else if (outputType == ProcessOutputTypes.STDERR && !isStderrSuppressed() && !mySilent) { + else if (outputType == ProcessOutputTypes.STDERR && !isStderrSuppressed() && !mySilent && !StringUtil.isEmptyOrSpaces(line)) { myVcs.showErrorMessages(trimmed); LOG.info(line.trim()); } diff --git a/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java b/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java index ebcebc81c2a2..d672f4522e5e 100644 --- a/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java @@ -18,6 +18,7 @@ package git4idea.commands; import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.i18n.GitBundle; @@ -79,12 +80,16 @@ public class GitSimpleHandler extends GitTextHandler { */ protected void processTerminated(final int exitCode) { if (myVcs == null) { return; } - if (!isStdoutSuppressed() && myStdoutLine.length() != 0) { - myVcs.showMessages(myStdoutLine.toString()); + String stdout = myStdoutLine.toString(); + String stderr = myStdoutLine.toString(); + if (!isStdoutSuppressed() && !StringUtil.isEmptyOrSpaces(stdout)) { + myVcs.showMessages(stdout); + LOG.info(stdout.trim()); myStdoutLine.setLength(0); } - else if (!isStderrSuppressed() && myStderrLine.length() != 0) { - myVcs.showErrorMessages(myStderrLine.toString()); + else if (!isStderrSuppressed() && !StringUtil.isEmptyOrSpaces(stderr)) { + myVcs.showErrorMessages(stderr); + LOG.info(stderr.trim()); myStderrLine.setLength(0); } } @@ -148,11 +153,13 @@ public class GitSimpleHandler extends GitTextHandler { else { line = text.substring(start, savedPos); } - if (ProcessOutputTypes.STDOUT == outputType) { + if (ProcessOutputTypes.STDOUT == outputType && !StringUtil.isEmptyOrSpaces(line)) { myVcs.showMessages(line); + LOG.info(line.trim()); } - else if (ProcessOutputTypes.STDERR == outputType) { + else if (ProcessOutputTypes.STDERR == outputType && !StringUtil.isEmptyOrSpaces(line)) { myVcs.showErrorMessages(line); + LOG.info(line.trim()); } } start = savedPos; From e1d05354f4a581914bdc6bfc5e2bf92d4520250d Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 14 Dec 2012 17:13:13 +0400 Subject: [PATCH 07/67] [git] Make some commands silent. --- plugins/git4idea/src/git4idea/branch/GitBranchUtil.java | 1 + plugins/git4idea/src/git4idea/history/GitHistoryUtils.java | 2 +- .../src/git4idea/update/GitUpdateLocallyModifiedDialog.java | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java b/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java index 560dbb44cc51..88c5d20c8869 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java +++ b/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java @@ -112,6 +112,7 @@ public class GitBranchUtil { GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.REV_PARSE); handler.addParameters("--abbrev-ref", "HEAD"); handler.setNoSSH(true); + handler.setSilent(true); try { String name = handler.run(); if (!name.equals("HEAD")) { diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index 37fd78431b35..19f49e3048f1 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -836,7 +836,7 @@ public class GitHistoryUtils { GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW); GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, AUTHOR_TIME); h.setNoSSH(true); - h.setStdoutSuppressed(true); + h.setSilent(true); h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8"); h.addParameters(commitsId); diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java b/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java index e597477eeb21..c295a54cda50 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java @@ -136,6 +136,7 @@ public class GitUpdateLocallyModifiedDialog extends DialogWrapper { GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.DIFF); h.addParameters("--name-status"); h.setNoSSH(true); + h.setSilent(true); h.setStdoutSuppressed(true); StringScanner s = new StringScanner(h.run()); while (s.hasMoreData()) { From a591891ed0b2e3fb150ff05bd600c0f8dacd7d55 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 14 Dec 2012 17:18:27 +0400 Subject: [PATCH 08/67] [git] remove unused classes. --- .../git4idea/ui/GitRefspecAddRefsDialog.form | 77 --- .../git4idea/ui/GitRefspecAddRefsDialog.java | 340 --------- .../src/git4idea/ui/GitRefspecPanel.form | 125 ---- .../src/git4idea/ui/GitRefspecPanel.java | 652 ------------------ 4 files changed, 1194 deletions(-) delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form b/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form deleted file mode 100644 index d198315c4e9e..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form +++ /dev/null @@ -1,77 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java b/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java deleted file mode 100644 index 5d1c3a77a341..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright 2000-2009 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 git4idea.ui; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.CheckboxTree; -import com.intellij.ui.CheckedTreeNode; -import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.tree.TreeUtil; -import git4idea.GitBranch; -import git4idea.GitTag; -import git4idea.commands.GitCommand; -import git4idea.commands.GitHandlerUtil; -import git4idea.commands.GitSimpleHandler; -import git4idea.i18n.GitBundle; -import git4idea.util.StringScanner; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashSet; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * This dialog allows adding selected tag and branches are references. - */ -public class GitRefspecAddRefsDialog extends DialogWrapper { - /** - * Get references button - */ - private JButton myGetRefsButton; - /** - * If selected, the branches are fetched by {@link #myGetRefsButton} - */ - private JCheckBox myIncludeBranchesCheckBox; - /** - * If selected, the tags are fetched by {@link #myGetRefsButton} - */ - private JCheckBox myIncludeTagsCheckBox; - /** - * The selector for tags and branches - */ - private CheckboxTree myReferenceChooser; - /** - * The root panel of the dialog - */ - private JPanel myPanel; - /** - * The context project - */ - private final Project myProject; - /** - * Root of the tree - */ - private CheckedTreeNode myTreeRoot; - /** - * The git root of the repository - */ - private final VirtualFile myRoot; - /** - * The name of the remote - */ - private final String myRemote; - /** - * The set of tags - */ - private final SortedSet myTags; - /** - * The set of branches - */ - private final SortedSet myBranches; - /** - * The logger for the class - */ - private static final Logger log = Logger.getInstance(GitRefspecAddRefsDialog.class.getName()); - - /** - * A constructor - * - * @param project the project - * @param root the git repository root - * @param remote the remote name or url of remote repository - * @param tags the set of tags (might be modified if update button is pressed) - * @param branches the set of branches (might be modified if update button is pressed) - */ - protected GitRefspecAddRefsDialog(@NotNull Project project, - @NotNull VirtualFile root, - @NotNull String remote, - @NotNull SortedSet tags, - @NotNull SortedSet branches) { - super(project, true); - setTitle(GitBundle.getString("addrefspec.title")); - setOKButtonText(GitBundle.getString("addrefspec.button")); - myProject = project; - myRoot = root; - myRemote = remote; - myTags = tags; - myBranches = branches; - updateTree(); - setupGetReferences(); - init(); - setOKActionEnabled(false); - } - - - /** - * Set up action listener for {@link #myGetRefsButton} - */ - private void setupGetReferences() { - // setup enabled state - final ActionListener enabledListener = new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myGetRefsButton.setEnabled(myIncludeBranchesCheckBox.isSelected() || myIncludeTagsCheckBox.isSelected()); - } - }; - myIncludeBranchesCheckBox.addActionListener(enabledListener); - myIncludeTagsCheckBox.addActionListener(enabledListener); - // perform update - myGetRefsButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - GitSimpleHandler handler = new GitSimpleHandler(myProject, myRoot, GitCommand.LS_REMOTE); - if (myIncludeBranchesCheckBox.isSelected()) { - handler.addParameters("--heads"); - myBranches.clear(); - } - if (myIncludeTagsCheckBox.isSelected()) { - handler.addParameters("--tags"); - myTags.clear(); - } - handler.addParameters(myRemote); - String result = GitHandlerUtil - .doSynchronously(handler, GitBundle.message("addrefspec.getting.references.title", myRemote), handler.printableCommandLine()); - if (result != null) { - StringScanner s = new StringScanner(result); - while (s.hasMoreData()) { - s.tabToken(); // skip last commit hash - String ref = s.line(); - if (ref.startsWith(GitBranch.REFS_HEADS_PREFIX)) { - myBranches.add(ref); - } - else if (ref.startsWith(GitTag.REFS_TAGS_PREFIX)) { - myTags.add(ref); - } - else { - log.warn("Unknwon reference type from ls-remote \"" + myRemote + "\" :" + ref); - } - } - } - updateTree(); - } - }); - } - - /** - * Update checkbox tree basing on the current state of the tag and branches set. The checkbox state is preserved. New items are created - * in unselected state. - */ - private void updateTree() { - // save the previous selection - HashSet oldTags = new HashSet(); - HashSet oldBranches = new HashSet(); - for (Reference ref : myReferenceChooser.getCheckedNodes(Reference.class, null)) { - (ref.isTag ? oldTags : oldBranches).add(ref.name); - } - // clear the tree - myTreeRoot.removeAllChildren(); - // fill tags and branches - addReferences(false, oldBranches, myBranches, GitBundle.getString("addrefspec.node.branches")); - addReferences(true, oldTags, myTags, GitBundle.getString("addrefspec.node.tags")); - TreeUtil.expandAll(myReferenceChooser); - myReferenceChooser.treeDidChange(); - } - - /** - * Add references to the tree along with category node - * - * @param isTag if true tag nodes are added - * @param old the set of old elements (used to select - * @param current the current set of elements (after update) - * @param name the name of the set - */ - private void addReferences(final boolean isTag, final HashSet old, final SortedSet current, @Nls final String name) { - if (!current.isEmpty()) { - final CheckedTreeNode tagsRoot = new CheckedTreeNode(name); - for (String t : current) { - final CheckedTreeNode node = new CheckedTreeNode(new Reference(isTag, t)); - node.setChecked(old.contains(t)); - tagsRoot.add(node); - } - myTreeRoot.add(tagsRoot); - } - } - - /** - * {@inheritDoc} - */ - @Override - protected String getDimensionServiceKey() { - return GitRefspecAddRefsDialog.class.getName(); - } - - /** - * {@inheritDoc} - */ - protected JComponent createCenterPanel() { - return myPanel; - } - - /** - * Create UI components that require custom creation: {@link #myReferenceChooser} - */ - private void createUIComponents() { - myTreeRoot = new CheckedTreeNode(""); - myReferenceChooser = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer() { - - public void customizeRenderer(final JTree tree, - final Object value, - final boolean selected, - final boolean expanded, - final boolean leaf, - final int row, - final boolean hasFocus) { - if (!(value instanceof CheckedTreeNode)) return; - final CheckedTreeNode node = (CheckedTreeNode)value; - final Object userObject = node.getUserObject(); - String text; - SimpleTextAttributes attributes; - Icon icon; - if (userObject == null) { - // invisible root (do nothing) - //noinspection HardCodedStringLiteral - text = "INVISBLE ROOT"; - attributes = SimpleTextAttributes.ERROR_ATTRIBUTES; - icon = null; - } - else if (userObject instanceof String) { - // category node (render as bold) - text = (String)userObject; - attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; - icon = PlatformIcons.DIRECTORY_CLOSED_ICON; - } - else { - // reference node - text = ((Reference)userObject).name; - attributes = node.isChecked() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES; - icon = null; - } - final ColoredTreeCellRenderer textRenderer = getTextRenderer(); - if (icon != null) { - textRenderer.setIcon(icon); - } - if (text != null) { - textRenderer.append(text, attributes); - } - } - }, myTreeRoot) { - @Override - protected void onNodeStateChanged(final CheckedTreeNode node) { - boolean flag = node.isChecked() || myReferenceChooser.getCheckedNodes(Reference.class, null).length != 0; - setOKActionEnabled(flag); - super.onNodeStateChanged(node); - } - }; - } - - /** - * Get selected elements - * - * @param isTag if true tags are returned, heads otherwise - * @return a collection of selected reference of the specified type - */ - public SortedSet getSelected(final boolean isTag) { - TreeSet rc = new TreeSet(); - final Reference[] checked = myReferenceChooser.getCheckedNodes(Reference.class, new Tree.NodeFilter() { - public boolean accept(final Reference node) { - return node.isTag == isTag; - } - }); - for (Reference r : checked) { - rc.add(r.name); - } - return rc; - } - - /** - * {@inheritDoc} - */ - @Override - protected String getHelpId() { - return "reference.VersionControl.Git.Fetch.AddReference"; - } - - - /** - * A remote reference - */ - static final class Reference { - /** - * If true, the name represents a tag. if false, the name represents the branch name. - */ - final boolean isTag; - /** - * Name of the reference - */ - final String name; - - /** - * A constructor from fields - * - * @param tag the value for {@link #isTag} - * @param name the value for {@link #name} - */ - public Reference(final boolean tag, final String name) { - isTag = tag; - this.name = name; - } - } -} diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form b/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form deleted file mode 100644 index 51c901871e04..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form +++ /dev/null @@ -1,125 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java b/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java deleted file mode 100644 index 52b128b0b3c0..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java +++ /dev/null @@ -1,652 +0,0 @@ -/* - * Copyright 2000-2009 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 git4idea.ui; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.DocumentAdapter; -import com.intellij.util.containers.HashMap; -import git4idea.GitBranch; -import git4idea.GitDeprecatedRemote; -import git4idea.GitTag; -import git4idea.util.GitUIUtil; -import git4idea.util.StringScanner; -import git4idea.i18n.GitBundle; -import git4idea.validators.GitBranchNameValidator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * The component that allows specifying a list of references - */ -public class GitRefspecPanel extends JPanel { - /** - * The logger for the class - */ - private static final Logger log = Logger.getInstance(Logger.class.getName()); - /** - * Named remotes associated with the current git root - */ - private final HashMap myRemotes = new HashMap(); - /** - * The project - */ - private Project myProject; - /** - * The git root for mapping - */ - private VirtualFile myGitRoot; - /** - * Remote heads (for Add... dialog) - */ - private final SortedSet myRemoteHeads = new TreeSet(); - /** - * Remote tags (for Add.. dialog) - */ - private final SortedSet myRemoteTags = new TreeSet(); - /** - * The button that adds all branches button - */ - private JButton myAddAllBranchesButton; - /** - * The button that adds selected references - */ - private JButton myAddButton; - /** - * The button that removes currently selected entries from the table - */ - private JButton myRemoveButton; - /** - * The text that contains remote name - */ - private JTextField myRemoteNameTextField; - /** - * The root panel of the form - */ - private JPanel myPanel; - /** - * The references table - */ - private JTable myReferences; - /** - * The button that adds entry that maps all tags - */ - private JButton myAddAllTagsButton; - /** - * Restore default mapping button - */ - private JButton myDefaultButton; - /** - * The name of the remote - */ - private String myRemote; - /** - * The source of default references - */ - private ReferenceSource myReferenceSource; - /** - * Mapping table model - */ - private final MyMappingTableModel myReferencesModel = new MyMappingTableModel(); - - /** - * A constructor - */ - public GitRefspecPanel() { - super(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - c.weightx = 1; - c.weighty = 1; - c.fill = GridBagConstraints.BOTH; - add(myPanel, c); - setupTable(); - setupButtons(); - } - - - /** - * Validates fields - * - * @return null if there is no error; empty string means that there is no error yet but OK should be disabled; otherwise error text should be used as the current error for dialog - */ - @Nullable - public String validateFields() { - final String remote = getRemoteName(); - if (remote.length() == 0) { - if (myReferencesModel.isRemoteNameUsed()) { - return GitBundle.getString("refspec.validation.remote.is.blank"); - } - } - else { - if (!GitBranchNameValidator.INSTANCE.checkInput(remote)) { - return GitBundle.getString("refspec.validation.remote.invalid"); - } - } - return null; - } - - /** - * Set project for panel - * - * @param project the context project - */ - public void setProject(Project project) { - myProject = project; - } - - /** - * Setup add/remove buttons - */ - private void setupButtons() { - // disable ok button if nothing is selected - myReferences.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - myRemoveButton.setEnabled(myReferences.getSelectedRowCount() != 0); - } - }); - // remove selected mappings - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myReferencesModel.removeSelectedMapping(); - } - }); - // add all tags (mapped to tags directory) - myAddAllTagsButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myReferencesModel.addMapping(false, tagName("*"), tagName("*")); - } - }); - // all heads (mapped to remotes directory) - myAddAllBranchesButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - addAllBranches(); - } - }); - // map selected tags and heads - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - if (myGitRoot == null) { - throw new IllegalStateException("Git root must be already set at this point."); - } - GitRefspecAddRefsDialog d = new GitRefspecAddRefsDialog(myProject, myGitRoot, myRemote, myRemoteTags, myRemoteHeads); - d.show(); - if (!d.isOK()) { - return; - } - for (String tag : d.getSelected(true)) { - myReferencesModel.addMapping(false, tag, tag); - } - for (String head : d.getSelected(false)) { - myReferencesModel.addMapping(true, head, remoteName(head.substring(GitBranch.REFS_HEADS_PREFIX.length()))); - } - } - }); - myDefaultButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - String remote = myRemote; - setRemote(null); - setRemote(remote); - } - }); - } - - /** - * Add mapping for all branches - */ - private void addAllBranches() { - myReferencesModel.addMapping(false, headName("*"), remoteName("*")); - } - - - /** - * Generate tag with remote name - * - * @param remoteName the name of remote in the local system - * @param tagName the name of the tag - * @return the full path to the head - */ - private static String tagRemoteName(final String remoteName, final String tagName) { - return GitTag.REFS_TAGS_PREFIX + remoteName + "/" + tagName; - } - - /** - * Simple tag name - * - * @param tagName the short name of tag - * @return the fully qualified tag reference name - */ - private static String tagName(final String tagName) { - return GitTag.REFS_TAGS_PREFIX + tagName; - } - - /** - * Generate remote head name in local file system, note that as name of remote {@link #getRemoteName()} is used. - * - * @param headName the name head of remote in the local system - * @return the full path to the head - */ - private String remoteName(final String headName) { - return remoteName(getRemoteName(), headName); - } - - /** - * Generate remote name in local file system - * - * @param remote a remote name, if blank a local branch is returned. - * @param headName the name head of remote in the local system - * @return the full path to the head - */ - private static String remoteName(final String remote, final String headName) { - return remote.length() != 0 ? GitBranch.REFS_REMOTES_PREFIX + remote + "/" + headName : headName(headName); - } - - /** - * Generate head name - * - * @param head the head name - * @return the full path to the head - */ - private static String headName(final String head) { - return GitBranch.REFS_HEADS_PREFIX + head; - } - - /** - * @return the current name of the remote - */ - public String getRemoteName() { - return myRemoteNameTextField.getText(); - } - - /** - * Setup table header and table model - */ - private void setupTable() { - // setup model - myReferences.setModel(myReferencesModel); - myReferences.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - myReferences.getColumnModel().getColumn(MyMappingTableModel.FORCE_COLUMN).sizeWidthToFit(); - myRemoteNameTextField.getDocument().addDocumentListener(new DocumentAdapter() { - protected void textChanged(final DocumentEvent e) { - myReferencesModel.remoteUpdated(); - } - }); - } - - /** - * Set git root for reference mapping - * - * @param gitRoot a git root - */ - public void setGitRoot(final VirtualFile gitRoot) { - if (Comparing.equal(gitRoot, myGitRoot)) { - return; - } - myGitRoot = gitRoot; - myRemotes.clear(); - if (myGitRoot != null) { - try { - for (GitDeprecatedRemote r : GitDeprecatedRemote.list(myProject, myGitRoot)) { - myRemotes.put(r.name(), r); - } - } - catch (VcsException e) { - GitUIUtil.showOperationError(myProject, e, "listing remotes"); - } - } - } - - /** - * Set remote or url - * - * @param name a name of remote or URL - */ - public void setRemote(String name) { - if (name != null && name.length() == 0) { - name = null; - } - if (myRemote == null && name == null || myRemote != null && myRemote.equals(name)) { - return; - } - myRemote = name; - myAddButton.setEnabled(myRemote != null && myRemote.length() != 0); - final GitDeprecatedRemote remote = myRemotes.get(name); - if (remote != null) { - myRemoteNameTextField.setText(name); - myRemoteNameTextField.setEditable(false); - myDefaultButton.setEnabled(true); - } - else { - myRemoteNameTextField.setText(""); - myRemoteNameTextField.setEditable(true); - myDefaultButton.setEnabled(false); - } - myRemoteHeads.clear(); - myRemoteTags.clear(); - setDefaultMapping(); - } - - /** - * Set default mapping - */ - private void setDefaultMapping() { - final GitDeprecatedRemote remote = myRemotes.get(myRemote); - myReferencesModel.clear(); - if (remote != null && myReferenceSource == ReferenceSource.FETCH) { - try { - for (String ref : GitDeprecatedRemote.getFetchSpecs(myProject, myGitRoot, remote.name())) { - StringScanner s = new StringScanner(ref); - boolean force = s.tryConsume('+'); - String remotePart = s.boundedToken(':'); - String localPart = s.line(); - myReferencesModel.addMapping(force, remotePart, localPart); - } - } - catch (VcsException e) { - log.error("Failed to get fetch references ", e); - } - } - else { - addAllBranches(); - } - } - - /** - * Add listener that is fired when validation is required - * - * @param l a listener to add - */ - public void addValidationRequiredListener(final ActionListener l) { - myRemoteNameTextField.getDocument().addDocumentListener(new DocumentAdapter() { - protected void textChanged(final DocumentEvent e) { - //noinspection HardCodedStringLiteral - l.actionPerformed(new ActionEvent(myRemoteNameTextField, ActionEvent.ACTION_PERFORMED, "validationRequired")); - } - }); - } - - /** - * Set default reference source for panel. - * - * @param referenceSource a reference source - */ - public void setReferenceSource(final ReferenceSource referenceSource) { - myReferenceSource = referenceSource; - } - - /** - * @return references added to the model - */ - public String[] getReferences() { - return myReferencesModel.getReferences(); - } - - /** - * Mapping table model - */ - private class MyMappingTableModel extends AbstractTableModel { - /** - * Force column in the table - */ - private static final int FORCE_COLUMN = 0; - /** - * Remote reference column in the table - */ - private static final int REMOTE_COLUMN = 1; - /** - * Local reference column in the table - */ - private static final int LOCAL_COLUMN = 2; - /** - * Remote name used for the table update - */ - private String mySavedRemoteName = null; - /** - * The currently constructed mapping - */ - private final ArrayList myMapping = new ArrayList(); - - /** - * {@inheritDoc} - */ - public int getRowCount() { - return myMapping.size(); - } - - /** - * Remove currently selected mappings - */ - public void removeSelectedMapping() { - final int[] rows = myReferences.getSelectedRows(); - Arrays.sort(rows); - for (int i = rows.length - 1; i >= 0; i--) { - myMapping.remove(rows[i]); - } - fireTableDataChanged(); - } - - /** - * {@inheritDoc} - */ - public int getColumnCount() { - return LOCAL_COLUMN + 1; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isCellEditable(final int rowIndex, final int columnIndex) { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) { - RefMapping m = myMapping.get(rowIndex); - switch (columnIndex) { - case FORCE_COLUMN: - m.force = ((Boolean)aValue).booleanValue(); - break; - case LOCAL_COLUMN: - m.local = (String)aValue; - break; - case REMOTE_COLUMN: - m.remote = (String)aValue; - break; - default: - throw new IllegalStateException("Invalid column: " + columnIndex); - } - } - - /** - * {@inheritDoc} - */ - @Override - public String getColumnName(final int column) { - switch (column) { - case FORCE_COLUMN: - return GitBundle.getString("refspec.column.force"); - case LOCAL_COLUMN: - return GitBundle.getString("refspec.column.local"); - case REMOTE_COLUMN: - return GitBundle.getString("refspec.column.remote"); - default: - throw new IllegalStateException("Invalid column: " + column); - } - } - - /** - * {@inheritDoc} - */ - public Object getValueAt(final int rowIndex, final int columnIndex) { - RefMapping m = myMapping.get(rowIndex); - switch (columnIndex) { - case FORCE_COLUMN: - return m.force; - case LOCAL_COLUMN: - return m.local; - case REMOTE_COLUMN: - return m.remote; - default: - throw new IllegalStateException("Invalid column: " + columnIndex); - } - } - - /** - * Add mapping - * - * @param force a force flag - * @param remote a remote reference - * @param local a local reference - */ - public void addMapping(final boolean force, @NonNls final String remote, @NonNls final String local) { - final RefMapping m = new RefMapping(); - m.force = force; - m.remote = remote; - m.local = local; - int row = myMapping.size(); - myMapping.add(m); - fireTableRowsInserted(row, row); - if (mySavedRemoteName == null) { - remoteUpdated(); - } - } - - /** - * This method updates all local heads in the table with remote name - */ - private void remoteUpdated() { - String newText = myRemoteNameTextField.getText(); - if (mySavedRemoteName != null && !newText.equals(mySavedRemoteName)) { - @NonNls String oldTagsPrefix = tagRemoteName(mySavedRemoteName, ""); - @NonNls String newTagsPrefix = tagRemoteName(newText, ""); - @NonNls String oldHeadsPrefix = remoteName(mySavedRemoteName, ""); - @NonNls String newHeadsPrefix = remoteName(newText, ""); - for (RefMapping m : myMapping) { - if (m.local.startsWith(oldTagsPrefix)) { - m.local = newTagsPrefix + m.local.substring(oldTagsPrefix.length()); - } - else if (m.local.startsWith(oldHeadsPrefix)) { - m.local = newHeadsPrefix + m.local.substring(oldHeadsPrefix.length()); - } - } - fireTableDataChanged(); - } - mySavedRemoteName = newText; - } - - @Override - public Class getColumnClass(final int columnIndex) { - if (columnIndex == FORCE_COLUMN) { - return Boolean.class; - } - return super.getColumnClass(columnIndex); - } - - /** - * @return true if remote name is actually used in the entries - */ - boolean isRemoteNameUsed() { - String text = myRemoteNameTextField.getText(); - @NonNls String tagsPrefix = tagRemoteName(text, ""); - for (RefMapping m : myMapping) { - if (m.local.startsWith(tagsPrefix)) { - return true; - } - } - return false; - } - - /** - * Clear the mapping - */ - public void clear() { - myMapping.clear(); - fireTableDataChanged(); - } - - /** - * @return a list of references - */ - public String[] getReferences() { - final int n = myMapping.size(); - String[] rc = new String[n]; - for (int i = 0; i < n; i++) { - rc[i] = myMapping.get(i).toString(); - } - return rc; - } - - /** - * Reference mapping object used in the table model - */ - class RefMapping { - /** - * if true update is forced - */ - boolean force; - /** - * remote reference name - */ - String remote; - /** - * local reference name - */ - String local; - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return (force ? "+" : "") + remote + ":" + local; - } - } - } - - /** - * The source of default references - */ - public enum ReferenceSource { - /** - * The references are pulled from fetch specification - */ - FETCH, - /** - * The references are pulled from push specification - */ - PUSH, } -} From 7662d31115da8601160fbc93a5a7e2dd336451be Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Fri, 14 Dec 2012 17:50:18 +0400 Subject: [PATCH 09/67] Remember files marked as plain text in .idea folder (WI-9630) --- .../EnforcedPlainTextFileTypeManager.java | 91 ++++++++++++++++++- .../ProjectPlainTextFileTypeManager.java | 46 ++++++++++ resources/src/idea/RichPlatformPlugin.xml | 2 + 3 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/openapi/file/exclude/ProjectPlainTextFileTypeManager.java diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java index 44b8a5089ef2..a0fba8f81ffc 100644 --- a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java @@ -26,21 +26,51 @@ import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.project.ProjectManagerListener; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; +import com.intellij.openapi.roots.impl.DirectoryIndex; import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.indexing.FileBasedIndex; +import java.util.*; + /** + * Maintains a list of files marked as plain text in a local environment (configuration). Every time a project is loaded/open, it reads + * files marked as plain text from a project into local environment (configuration). User actions (mark/unmark as plain text) are + * synchronized between local and project configurations. + * * @author Rustam Vishnyakov */ @State(name = "EnforcedPlainTextFileTypeManager", storages = {@Storage( file = StoragePathMacros.APP_CONFIG + "/plainTextFiles.xml")}) -public class EnforcedPlainTextFileTypeManager extends PersistentFileSetManager { - +public class EnforcedPlainTextFileTypeManager extends PersistentFileSetManager implements ProjectManagerListener { + + private Set myProcessedProjects = new HashSet(); + private boolean myNeedsSync = true; + + public EnforcedPlainTextFileTypeManager() { + ProjectManager.getInstance().addProjectManagerListener(this); + } + public boolean isMarkedAsPlainText(VirtualFile file) { + if (myNeedsSync) { + myNeedsSync = !syncWithOpenProject(); + } return containsFile(file); } + public boolean syncWithOpenProject() { + Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); + if (openProjects.length > 0) { + Project firstOpenProject = openProjects[0]; + if (!myProcessedProjects.contains(firstOpenProject)) { + return syncWithProject(firstOpenProject); + } + return true; + } + return false; + } + public static boolean isApplicableFor(VirtualFile file) { if (file.isDirectory()) return false; FileType originalType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()); @@ -53,29 +83,44 @@ public class EnforcedPlainTextFileTypeManager extends PersistentFileSetManager { } public void markAsPlainText(VirtualFile... files) { + List filesToSync = new ArrayList(); for (VirtualFile file : files) { if (addFile(file)) { + filesToSync.add(file); FileBasedIndex.getInstance().requestReindex(file); } } - fireRootsChanged(); + fireRootsChanged(filesToSync, true); } public void unmarkPlainText(VirtualFile... files) { + List filesToSync = new ArrayList(); for (VirtualFile file : files) { if (removeFile(file)) { + filesToSync.add(file); FileBasedIndex.getInstance().requestReindex(file); } } - fireRootsChanged(); + fireRootsChanged(filesToSync, false); } - private static void fireRootsChanged() { + private static void fireRootsChanged(final Collection files, final boolean isAdded) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (Project project : ProjectManager.getInstance().getOpenProjects()) { ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true); + ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project); + for (VirtualFile file : files) { + if (projectPlainTextFileTypeManager.hasProjectContaining(file)) { + if (isAdded) { + projectPlainTextFileTypeManager.addFile(file); + } + else { + projectPlainTextFileTypeManager.removeFile(file); + } + } + } } } }); @@ -89,4 +134,40 @@ public class EnforcedPlainTextFileTypeManager extends PersistentFileSetManager { } return ourInstance; } + + @Override + public void projectOpened(Project project) { + syncWithProject(project); + } + + @Override + public boolean canCloseProject(Project project) { + return true; + } + + @Override + public void projectClosed(Project project) { + if (myProcessedProjects.contains(project)) { + myProcessedProjects.remove(project); + } + } + + @Override + public void projectClosing(Project project) { + } + + private boolean syncWithProject(Project project) { + if (!DirectoryIndex.getInstance(project).isInitialized()) return false; + myProcessedProjects.add(project); + ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project); + for (VirtualFile file : projectPlainTextFileTypeManager.getFiles()) { + addFile(file); + } + for (VirtualFile file : getFiles()) { + if (projectPlainTextFileTypeManager.hasProjectContaining(file)) { + projectPlainTextFileTypeManager.addFile(file); + } + } + return true; + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/ProjectPlainTextFileTypeManager.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/ProjectPlainTextFileTypeManager.java new file mode 100644 index 000000000000..ba74997c8433 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/ProjectPlainTextFileTypeManager.java @@ -0,0 +1,46 @@ +/* + * 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.file.exclude; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.components.StoragePathMacros; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.vfs.VirtualFile; + +/** + * @author Rustam Vishnyakov + */ +@State(name = "ProjectPlainTextFileTypeManager", storages = {@Storage( file = StoragePathMacros.PROJECT_FILE)}) +public class ProjectPlainTextFileTypeManager extends PersistentFileSetManager { + private ProjectFileIndex myIndex; + + public ProjectPlainTextFileTypeManager(Project project) { + myIndex = ProjectRootManager.getInstance(project).getFileIndex(); + } + + public boolean hasProjectContaining(VirtualFile file) { + return myIndex.isInContent(file); + } + + public static ProjectPlainTextFileTypeManager getInstance(Project project) { + return ServiceManager.getService(project, ProjectPlainTextFileTypeManager.class); + } + +} diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index a39cc8a889e2..1abfbfa9a576 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -371,6 +371,8 @@ + From 7af34f3d5d90d2ff7e9d07b6a7df3aaa2fd7c13c Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 12:58:08 +0100 Subject: [PATCH 10/67] check for update: no need to start plugin hosts checking when connectivity problems exist (IDEA-97529) --- .../updateSettings/impl/CheckForUpdateAction.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java index 315706a84900..c7b15139569e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java @@ -52,15 +52,19 @@ public class CheckForUpdateAction extends AnAction implements DumbAware { indicator.setIndeterminate(true); final CheckForUpdateResult result = UpdateChecker.checkForUpdates(instance, true); + if (result.getState() == UpdateStrategy.State.CONNECTION_ERROR) { + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + UpdateChecker.showConnectionErrorDialog(); + } + }); + return; + } + final List updatedPlugins = UpdateChecker.updatePlugins(true, hostsConfigurable, indicator); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { - if (result.getState() == UpdateStrategy.State.CONNECTION_ERROR) { - UpdateChecker.showConnectionErrorDialog(); - return; - } - instance.saveLastCheckedInfo(); UpdateChecker.showUpdateResult(result, updatedPlugins, true, enableLink, true); } From b8c340ff6bbab4c47d4d33c51ff764a3946c335f Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 13:35:08 +0100 Subject: [PATCH 11/67] inplace introduce: do not replace identifier with method expr even when ref names equals (IDEA-97536) --- .../AbstractJavaInplaceIntroducer.java | 2 +- .../paramNameEqMethodName.java | 10 ++++++++++ .../paramNameEqMethodName_after.java | 9 +++++++++ .../refactoring/InplaceIntroduceParameterTest.java | 8 ++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName.java create mode 100644 java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName_after.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java index 5424f7086e51..9e94d3250263 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java @@ -139,7 +139,7 @@ public abstract class AbstractJavaInplaceIntroducer extends AbstractInplaceIntro PsiExpression expression = refVariableElement instanceof PsiKeyword && refVariableElementParent instanceof PsiNewExpression ? (PsiNewExpression)refVariableElementParent : PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class); - if (expression instanceof PsiReferenceExpression) { + if (expression instanceof PsiReferenceExpression && !(expression.getParent() instanceof PsiMethodCallExpression)) { final String referenceName = ((PsiReferenceExpression)expression).getReferenceName(); if (((PsiReferenceExpression)expression).resolve() == psiVariable || Comparing.strEqual(psiVariable.getName(), referenceName) || diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName.java b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName.java new file mode 100644 index 000000000000..8a724c88aa5b --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName.java @@ -0,0 +1,10 @@ +class A { + int f() { + return 0; + } + + void m() { + f(); + f(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName_after.java new file mode 100644 index 000000000000..7216093f6f37 --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/paramNameEqMethodName_after.java @@ -0,0 +1,9 @@ +class A { + int f() { + return 0; + } + + void m(int f) { + f(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java index 97c475910e9e..b5ec296e7bc5 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java @@ -69,6 +69,14 @@ public class InplaceIntroduceParameterTest extends AbstractJavaInplaceIntroduceT }); } + public void testParamNameEqMethodName() throws Exception { + doTest(new Pass() { + @Override + public void pass(AbstractInplaceIntroducer inplaceIntroducePopup) { + } + }); + } + @Override protected String getBasePath() { return BASE_PATH; From c484ce61f06483dcdfb7e265908539b1ae17d174 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 14:44:09 +0100 Subject: [PATCH 12/67] composition of extends/super wildcard should get just its bound (IDEA-96721) --- .../com/intellij/psi/impl/PsiSubstitutorImpl.java | 2 +- .../WildcardsBoundsIntersection.java | 15 +++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java index b21bc6bb3415..5ecdebebed0d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java @@ -159,7 +159,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { if (newBound instanceof PsiCapturedWildcardType) { final PsiWildcardType wildcard = ((PsiCapturedWildcardType)newBound).getWildcard(); if (wildcardType.isExtends() != wildcard.isExtends()) { - return wildcard.isBounded() ? PsiWildcardType.createUnbounded(wildcardType.getManager()) : newBound; + return wildcard.isBounded() ? wildcard.getBound() : newBound; } if (!wildcard.isBounded()) return PsiWildcardType.createUnbounded(wildcardType.getManager()); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java new file mode 100644 index 000000000000..013657a5ea8e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java @@ -0,0 +1,15 @@ +class NodeProperty {} + +class NodeType {} +class NumberExpression extends NodeType {} +class Node { + public ValueT get(NodeProperty prop) { + return null; + } +} + +class Main { + public static void main(NodeProperty nval, Node expr) { + int val = expr.get(nval); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 8bc65e0cb36d..54f69672b856 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -205,6 +205,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testInstanceClassInStaticContextAccess() throws Exception { doTest17Incompatibility(false); } public void testFlattenIntersectionType() throws Exception { doTest17Incompatibility(false); } public void testIDEA97276() throws Exception { doTest17Incompatibility(false); } + public void testWildcardsBoundsIntersection() throws Exception { doTest17Incompatibility(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); From ec78d7bc177cfaf43a9b06e08c78ee8ac40f470e Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 14 Dec 2012 15:37:27 +0100 Subject: [PATCH 13/67] honor per-file encoding (IDEA-97558 External build: Honor file-level encoding during maven resources processing) --- .../jetbrains/jps/maven/compiler/MavenResourcesBuilder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 f653c20fe96a..189d594b0b1a 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 @@ -19,6 +19,8 @@ import org.jetbrains.jps.incremental.messages.CompilerMessage; import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.jetbrains.jps.maven.model.JpsMavenExtensionService; import org.jetbrains.jps.maven.model.impl.*; +import org.jetbrains.jps.model.JpsEncodingConfigurationService; +import org.jetbrains.jps.model.JpsEncodingProjectConfiguration; import java.io.*; import java.text.SimpleDateFormat; @@ -49,7 +51,8 @@ public class MavenResourcesBuilder extends TargetBuilder filteringExcludedExtensions = config.getFilteringExcludedExtensions(); - final String encoding = context.getProjectDescriptor().getEncodingConfiguration().getPreferredModuleEncoding(target.getModule()); + final JpsEncodingProjectConfiguration encodingConfig = + JpsEncodingConfigurationService.getInstance().getEncodingConfiguration(target.getModule().getProject()); final Date timestamp = new Date(); @Nullable @@ -111,6 +114,7 @@ public class MavenResourcesBuilder extends TargetBuilder Date: Fri, 14 Dec 2012 18:51:18 +0400 Subject: [PATCH 14/67] Get java indent options directly from Java settings --- .../psi/formatter/java/AbstractJavaBlock.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java index ef0cf6652e03..82dabf200e99 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java @@ -21,7 +21,6 @@ import com.intellij.formatting.alignment.AlignmentInColumnsHelper; import com.intellij.formatting.alignment.AlignmentStrategy; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -156,7 +155,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo Wrap wrap, @NotNull AlignmentStrategy alignmentStrategy, int startOffset) { - Indent actualIndent = indent == null ? getDefaultSubtreeIndent(child, settings.getRootSettings().getIndentOptions(StdFileTypes.JAVA)) : indent; + Indent actualIndent = indent == null ? getDefaultSubtreeIndent(child, getJavaIndentOptions(settings)) : indent; final IElementType elementType = child.getElementType(); Alignment alignment = alignmentStrategy.getAlignment(elementType); @@ -207,10 +206,17 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo @NotNull public static Block createJavaBlock(@NotNull ASTNode child, @NotNull CommonCodeStyleSettings settings) { - return createJavaBlock(child, settings, getDefaultSubtreeIndent(child, settings.getRootSettings().getIndentOptions(StdFileTypes.JAVA)), + return createJavaBlock(child, settings, getDefaultSubtreeIndent(child, getJavaIndentOptions(settings)), null, AlignmentStrategy.getNullStrategy()); } + @NotNull + private static CommonCodeStyleSettings.IndentOptions getJavaIndentOptions(CommonCodeStyleSettings settings) { + CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(); + assert indentOptions != null : "Java indent options are not initialized"; + return indentOptions; + } + private static boolean isLikeExtendsList(final IElementType elementType) { return elementType == JavaElementType.EXTENDS_LIST || elementType == JavaElementType.IMPLEMENTS_LIST From 04365caf8e1351b2b81d72b6276cb7b426907787 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Fri, 14 Dec 2012 19:13:56 +0400 Subject: [PATCH 15/67] Followed the intention --- .../com/intellij/ide/favoritesTreeView/FavoritesManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java index 1b0bdfec2164..3d7bbb119b79 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesManager.java @@ -206,7 +206,7 @@ public class FavoritesManager implements ProjectComponent, JDOMExternalizable { } private void appendChildNodes(AbstractTreeNode node, TreeItem> treeItem) { - final Collection children = node.getChildren(); + final Collection children = node.getChildren(); for (AbstractTreeNode child : children) { final TreeItem> childTreeItem = new TreeItem>(createPairForNode(child)); treeItem.addChild(childTreeItem); From cbbf5f4aae026328de2c904edaff577a3ae7327d Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 14 Dec 2012 16:15:06 +0100 Subject: [PATCH 16/67] display compiler version info only once per compile session --- .../jps/incremental/java/JavaBuilder.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 73fae619652e..fe34a7db9e2e 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -62,6 +62,7 @@ import java.net.ServerSocket; import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; /** * @author Eugene Zhuravlev @@ -74,6 +75,8 @@ public class JavaBuilder extends ModuleLevelBuilder { public static final boolean USE_EMBEDDED_JAVAC = System.getProperty(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null; private static final Key JAVA_COMPILER_VERSION_KEY = Key.create("_java_compiler_version_"); private static final Key IS_ENABLED = Key.create("_java_compiler_enabled_"); + private static final Key> COMPILER_VERSION_INFO = Key.create("_java_compiler_version_info_"); + private static final Set FILTERED_OPTIONS = new HashSet(Arrays.asList( "-target" )); @@ -130,10 +133,7 @@ public class JavaBuilder extends ModuleLevelBuilder { else if (isEclipse) { messageText = "Using eclipse compiler to compile java sources"; } - if (messageText != null) { - LOG.info(messageText); - context.processMessage(new CompilerMessage("", BuildMessage.Kind.INFO, messageText)); - } + COMPILER_VERSION_INFO.set(context, new AtomicReference(messageText)); } public ExitCode build(final CompileContext context, @@ -221,6 +221,12 @@ public class JavaBuilder extends ModuleLevelBuilder { final OutputFilesSink outputSink = new OutputFilesSink(context, outputConsumer, mappingsCallback, chunk.getName()); try { if (hasSourcesToCompile) { + final AtomicReference ref = COMPILER_VERSION_INFO.get(context); + final String versionInfo = ref.getAndSet(null); // display compiler version info only once per compile session + if (versionInfo != null) { + LOG.info(versionInfo); + context.processMessage(new CompilerMessage("", BuildMessage.Kind.INFO, versionInfo)); + } exitCode = ExitCode.OK; final Set srcPath = new HashSet(); From 3246026fd1cad2eb194674c6546c5e2990dcc88b Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 14 Dec 2012 12:43:28 +0400 Subject: [PATCH 17/67] javadoc --- xml/openapi/src/com/intellij/psi/xml/XmlTag.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xml/openapi/src/com/intellij/psi/xml/XmlTag.java b/xml/openapi/src/com/intellij/psi/xml/XmlTag.java index 2df573fa037d..9e02224195a1 100644 --- a/xml/openapi/src/com/intellij/psi/xml/XmlTag.java +++ b/xml/openapi/src/com/intellij/psi/xml/XmlTag.java @@ -78,7 +78,13 @@ public interface XmlTag extends XmlElement, PsiNamedElement, PsiMetaOwner, XmlTa @NotNull XmlTag[] getSubTags(); @NotNull XmlTag[] findSubTags(@NonNls String qname); - @NotNull XmlTag[] findSubTags(@NonNls String localName, @NonNls String namespace); + + /** + * @param localName non-qualified tag name + * @param namespace if null, tags from all namespaces will be returned + */ + @NotNull XmlTag[] findSubTags(@NonNls String localName, @Nullable String namespace); + @Nullable XmlTag findFirstSubTag(@NonNls String qname); @NotNull @NonNls String getNamespacePrefix(); From 899bf764619dfc0ea032274c1ac9db256e6fb5db Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 14 Dec 2012 12:55:48 +0400 Subject: [PATCH 18/67] javadoc --- xml/openapi/src/com/intellij/psi/xml/XmlTag.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/openapi/src/com/intellij/psi/xml/XmlTag.java b/xml/openapi/src/com/intellij/psi/xml/XmlTag.java index 9e02224195a1..8ca8bb01d5fa 100644 --- a/xml/openapi/src/com/intellij/psi/xml/XmlTag.java +++ b/xml/openapi/src/com/intellij/psi/xml/XmlTag.java @@ -80,8 +80,8 @@ public interface XmlTag extends XmlElement, PsiNamedElement, PsiMetaOwner, XmlTa @NotNull XmlTag[] findSubTags(@NonNls String qname); /** - * @param localName non-qualified tag name - * @param namespace if null, tags from all namespaces will be returned + * @param localName non-qualified tag name. + * @param namespace if null, name treated as qualified name to find. */ @NotNull XmlTag[] findSubTags(@NonNls String localName, @Nullable String namespace); From a9f784ef55bbb7740fd16f92929d8f9ae55f7e28 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 14 Dec 2012 18:06:48 +0400 Subject: [PATCH 19/67] IDEA-96597 Find Usages not working [nik]: fixing ParentStrategy for stubbed custom elements --- .../com/intellij/util/xml/stubs/DomStub.java | 4 +++ .../util/xml/stubs/StubParentStrategy.java | 32 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java index 3285ff4d2b12..9b94200b66c9 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java @@ -132,4 +132,8 @@ public abstract class DomStub extends ObjectStubBase { public void setHandler(DomInvocationHandler handler) { myHandler = handler; } + + public boolean isCustom() { + return false; + } } diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java index 1759fc31799b..392065ef2867 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java @@ -19,6 +19,7 @@ import com.intellij.psi.xml.XmlElement; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.impl.*; +import com.intellij.xml.util.XmlUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,12 +65,33 @@ public class StubParentStrategy implements DomParentStrategy { DomStub parentStub = myStub.getParentStub(); if (parentStub == null) return null; int index = parentStub.getChildIndex(myStub); - DomInvocationHandler handler = parentStub.getHandler(); - XmlTag tag = handler.getXmlTag(); - if (tag == null) return null; - XmlTag[] subTags = tag.findSubTags(myStub.getName()); + if (index < 0) { + return null; + } + XmlTag parentTag = parentStub.getHandler().getXmlTag(); + if (parentTag == null) return null; - return index < 0 || index >= subTags.length ? null : subTags[index]; + // for custom elements, namespace information is lost + // todo: propagate ns info through DomChildDescriptions + XmlTag[] tags = parentTag.getSubTags(); + int i = 0; + String nameToFind = myStub.isCustom() ? XmlUtil.findLocalNameByQualifiedName(myStub.getName()) : myStub.getName(); + assert nameToFind != null; + for (XmlTag xmlTag : tags) { + if (myStub.isCustom()) { + if (nameToFind.equals(xmlTag.getLocalName())) { + if (index == i++) { + return xmlTag; + } + } + } + else if (nameToFind.equals(xmlTag.getName())) { + if (index == i++) { + return xmlTag; + } + } + } + return null; } @NotNull From ad7688b05725982bfc44547595b1e297643c3d0d Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 14 Dec 2012 19:39:20 +0400 Subject: [PATCH 20/67] test fixed --- .../intellij/util/xml/stubs/DomStubBuilderTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubBuilderTest.java b/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubBuilderTest.java index 70d5cbbdf667..faca1b68ff9b 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubBuilderTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubBuilderTest.java @@ -1,6 +1,10 @@ package com.intellij.util.xml.stubs; import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.stubs.ObjectStubTree; +import com.intellij.psi.stubs.StubTreeLoader; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.xml.XmlName; import com.intellij.util.xml.reflect.DomExtender; @@ -50,8 +54,13 @@ public class DomStubBuilderTest extends DomStubTest { } public void testNullTag() throws Exception { - doBuilderTest("nullTag.xml", "File:foo\n" + - " Element:foo\n"); + PsiFile psiFile = myFixture.configureByFile("nullTag.xml"); + + StubTreeLoader loader = StubTreeLoader.getInstance(); + VirtualFile file = psiFile.getVirtualFile(); + assertTrue(loader.canHaveStub(file)); + ObjectStubTree stubTree = loader.readFromVFile(getProject(), file); + assertNull(stubTree); // no stubs for invalid XML } public static class TestExtender extends DomExtender { From ad59c95b7cc5270971ce5a42d106c041661495d3 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 14 Dec 2012 16:53:31 +0100 Subject: [PATCH 21/67] improve "Extended 'for' statement" inspection quickfix --- .../ig/jdk/ForeachStatementInspection.java | 118 +++++++----------- .../BareCollectionLoop.after.java | 14 +++ .../foreach_statement/BareCollectionLoop.java | 12 ++ .../foreach_statement/BoundedTypes.after.java | 13 ++ .../jdk/foreach_statement/BoundedTypes.java | 11 ++ .../foreach_statement/GenericTypes.after.java | 19 +++ .../jdk/foreach_statement/GenericTypes.java | 18 +++ .../foreach_statement/Precedence.after.java | 16 +++ .../jdk/foreach_statement/Precedence.java | 14 +++ .../foreach_statement/Wildcards.after.java | 14 +++ .../jdk/foreach_statement/Wildcards.java | 12 ++ .../ig/fixes/jdk/ForeachStatementFixTest.java | 22 ++++ 12 files changed, 212 insertions(+), 71 deletions(-) create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.java create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/jdk/ForeachStatementFixTest.java diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java index 99db4d68193c..564e93955541 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ package com.siyeh.ig.jdk; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.ParenthesesUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -31,14 +34,12 @@ public class ForeachStatementInspection extends BaseInspection { @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "extended.for.statement.display.name"); + return InspectionGadgetsBundle.message("extended.for.statement.display.name"); } @NotNull public String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "extended.for.statement.problem.descriptor"); + return InspectionGadgetsBundle.message("extended.for.statement.problem.descriptor"); } protected InspectionGadgetsFix buildFix(Object... infos) { @@ -49,85 +50,62 @@ public class ForeachStatementInspection extends BaseInspection { @NotNull public String getName() { - return InspectionGadgetsBundle.message( - "extended.for.statement.replace.quickfix"); + return InspectionGadgetsBundle.message("extended.for.statement.replace.quickfix"); } - public void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { + public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement element = descriptor.getPsiElement(); - final PsiForeachStatement statement = - (PsiForeachStatement)element.getParent(); - final JavaCodeStyleManager codeStyleManager = - JavaCodeStyleManager.getInstance(project); + final PsiForeachStatement statement = (PsiForeachStatement)element.getParent(); + final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); assert statement != null; final PsiExpression iteratedValue = statement.getIteratedValue(); if (iteratedValue == null) { return; } - @NonNls final StringBuffer newStatement = new StringBuffer(); - final PsiParameter iterationParameter = - statement.getIterationParameter(); + @NonNls final StringBuilder newStatement = new StringBuilder(); + final PsiParameter iterationParameter = statement.getIterationParameter(); + final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project); if (iteratedValue.getType() instanceof PsiArrayType) { final PsiType type = iterationParameter.getType(); - final String index = - codeStyleManager.suggestUniqueVariableName("i", - statement, true); - newStatement.append("for(int "); - newStatement.append(index); - newStatement.append(" = 0;"); - newStatement.append(index); - newStatement.append('<'); - newStatement.append(iteratedValue.getText()); - newStatement.append(".length;"); - newStatement.append(index); - newStatement.append("++)"); - newStatement.append("{ "); - newStatement.append(type.getCanonicalText()); - newStatement.append(' '); - newStatement.append(iterationParameter.getName()); - newStatement.append(" = "); - newStatement.append(iteratedValue.getText()); - newStatement.append('['); - newStatement.append(index); - newStatement.append("];"); + final String index = codeStyleManager.suggestUniqueVariableName("i", statement, true); + newStatement.append("for(int ").append(index).append(" = 0;"); + newStatement.append(index).append('<').append(iteratedValue.getText()).append(".length;"); + newStatement.append(index).append("++)").append("{ "); + if (codeStyleSettings.GENERATE_FINAL_LOCALS) { + newStatement.append("final "); + } + newStatement.append(type.getCanonicalText()).append(' ').append(iterationParameter.getName()); + newStatement.append(" = ").append(iteratedValue.getText()).append('[').append(index).append("];"); } else { - final PsiType iteratedType = iteratedValue.getType(); - final PsiType type; - if (iteratedType instanceof PsiClassType) { - final PsiClassType classType = (PsiClassType)iteratedType; - final PsiType[] types = classType.getParameters(); - type = types[0]; + @NonNls final StringBuilder methodCall = new StringBuilder(); + if (ParenthesesUtils.getPrecedence(iteratedValue) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) { + methodCall.append('(').append(iteratedValue.getText()).append(')'); } else { - type = iterationParameter.getType(); + methodCall.append(iteratedValue.getText()); } - final String iterator = - codeStyleManager.suggestUniqueVariableName("it", - statement, true); - final String typeText = type.getCanonicalText(); - newStatement.append("for(java.util.Iterator<"); - newStatement.append(typeText); - newStatement.append("> "); - newStatement.append(iterator); - newStatement.append(" = "); - newStatement.append(iteratedValue.getText()); - newStatement.append(".iterator();"); - newStatement.append(iterator); - newStatement.append(".hasNext();)"); - newStatement.append('{'); - newStatement.append(typeText); - newStatement.append(' '); - newStatement.append(iterationParameter.getName()); - newStatement.append(" = "); - newStatement.append(iterator); - newStatement.append(".next();"); + methodCall.append(".iterator()"); + final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); + final PsiExpression iteratorCall = factory.createExpressionFromText(methodCall.toString(), iteratedValue); + final PsiType variableType = GenericsUtil.getVariableTypeByExpressionType(iteratorCall.getType()); + if (variableType == null) { + return; + } + final PsiType parameterType = iterationParameter.getType(); + final String typeText = parameterType.getCanonicalText(); + newStatement.append("for(").append(variableType.getCanonicalText()).append(' '); + final String iterator = codeStyleManager.suggestUniqueVariableName("iterator", statement, true); + newStatement.append(iterator).append("=").append(iteratorCall.getText()).append(';'); + newStatement.append(iterator).append(".hasNext();){"); + if (codeStyleSettings.GENERATE_FINAL_LOCALS) { + newStatement.append("final "); + } + newStatement.append(typeText).append(' ').append(iterationParameter.getName()).append(" = ").append(iterator).append(".next();"); } final PsiStatement body = statement.getBody(); if (body instanceof PsiBlockStatement) { - final PsiBlockStatement blockStatement = - (PsiBlockStatement)body; + final PsiBlockStatement blockStatement = (PsiBlockStatement)body; final PsiCodeBlock block = blockStatement.getCodeBlock(); final PsiElement[] children = block.getChildren(); for (int i = 1; i < children.length - 1; i++) { @@ -146,7 +124,7 @@ public class ForeachStatementInspection extends BaseInspection { newStatement.append(bodyText); } newStatement.append('}'); - replaceStatement(statement, newStatement.toString()); + replaceStatementAndShortenClassNames(statement, newStatement.toString()); } } @@ -154,12 +132,10 @@ public class ForeachStatementInspection extends BaseInspection { return new ForeachStatementVisitor(); } - private static class ForeachStatementVisitor - extends BaseInspectionVisitor { + private static class ForeachStatementVisitor extends BaseInspectionVisitor { @Override - public void visitForeachStatement( - @NotNull PsiForeachStatement statement) { + public void visitForeachStatement(@NotNull PsiForeachStatement statement) { super.visitForeachStatement(statement); registerStatementError(statement); } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.after.java new file mode 100644 index 000000000000..bbd05ffa135d --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.after.java @@ -0,0 +1,14 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Collection; +import java.util.Iterator; + +class BareCollectionLoop { + + void x(Collection c) { + for (Iterator iterator = c.iterator(); iterator.hasNext(); ) { + Object n = iterator.next(); + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.java new file mode 100644 index 000000000000..7f54c5dbf683 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BareCollectionLoop.java @@ -0,0 +1,12 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Collection; + +class BareCollectionLoop { + + void x(Collection c) { + for (Object n : c) { + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.after.java new file mode 100644 index 000000000000..9486d1d880ae --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.after.java @@ -0,0 +1,13 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Collection; +import java.util.Iterator; + +class BoundedTypes { + void x(Collection c) { + for (Iterator iterator = c.iterator(); iterator.hasNext(); ) { + Number n = iterator.next(); + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.java new file mode 100644 index 000000000000..b844a26c9cd0 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/BoundedTypes.java @@ -0,0 +1,11 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Collection; + +class BoundedTypes { + void x(Collection c) { + for (Number n : c) { + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.after.java new file mode 100644 index 000000000000..858011a5fd72 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.after.java @@ -0,0 +1,19 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Iterator; + +class GenericTypes implements Iterable { + + @Override + public Iterator iterator() { + return null; + } + + public void test() { + final GenericTypes test = new GenericTypes(); + for (Iterator iterator = test.iterator(); iterator.hasNext(); ) { + Integer integer = iterator.next(); + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.java new file mode 100644 index 000000000000..2dac33dc18a0 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/GenericTypes.java @@ -0,0 +1,18 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Iterator; + +class GenericTypes implements Iterable { + + @Override + public Iterator iterator() { + return null; + } + + public void test() { + final GenericTypes test = new GenericTypes(); + for (Integer integer : test) { + + } + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.after.java new file mode 100644 index 000000000000..04b582bd9e32 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.after.java @@ -0,0 +1,16 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +class Precedence { + + void x(Collection c) { + for (Iterator iterator = (c = new ArrayList()).iterator(); iterator.hasNext(); ) { + Object n = iterator.next(); + + } + } + +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.java new file mode 100644 index 000000000000..2d2b2d4295ee --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Precedence.java @@ -0,0 +1,14 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.ArrayList; +import java.util.Collection; + +class Precedence { + + void x(Collection c) { + for (Object n : c = new ArrayList()) { + + } + } + +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.after.java new file mode 100644 index 000000000000..cec460546a2b --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.after.java @@ -0,0 +1,14 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +class Wildcards { + + void renames(Map allRenames) { + for (Iterator> iterator = allRenames.entrySet().iterator(); iterator.hasNext(); ) { + Map.Entry entry = iterator.next(); + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.java new file mode 100644 index 000000000000..bed428093895 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/jdk/foreach_statement/Wildcards.java @@ -0,0 +1,12 @@ +package com.siyeh.igfixes.jdk.foreach_statement; + +import java.util.List; +import java.util.Map; + +class Wildcards { + + void renames(Map allRenames) { + for (Map.Entry entry : allRenames.entrySet()) { + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/jdk/ForeachStatementFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/jdk/ForeachStatementFixTest.java new file mode 100644 index 000000000000..f78a1fb7bf62 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/jdk/ForeachStatementFixTest.java @@ -0,0 +1,22 @@ +package com.siyeh.ig.fixes.jdk; + +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.IGQuickFixesTestCase; +import com.siyeh.ig.jdk.ForeachStatementInspection; + +public class ForeachStatementFixTest extends IGQuickFixesTestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.enableInspections(new ForeachStatementInspection()); + myRelativePath = "jdk/foreach_statement"; + myDefaultHint = InspectionGadgetsBundle.message("extended.for.statement.replace.quickfix"); + } + + public void testBareCollectionLoop() { doTest(); } + public void testBoundedTypes() { doTest(); } + public void testGenericTypes() { doTest(); } + public void testPrecedence() { doTest(); } + public void testWildcards() { doTest(); } +} \ No newline at end of file From 0152a4042ce5034aa0ba1e953fe730348b22ac41 Mon Sep 17 00:00:00 2001 From: "Nadya.Zabrodina" Date: Fri, 14 Dec 2012 20:05:02 +0400 Subject: [PATCH 22/67] IDEA-80632 Mercurial: there's no "Pushed successfully" dialog after changesets are pushed *Change dialog notification type to TOOLWINDOW or STICKY_BALLOON. *Change String HgVcs.NOTIFICATION_GROUP_ID to NotificationGroup *Refactor: HgCommandResultNotifier now only notify about success or error after command execution *Refactor: Now every notifications are called from HgCommandResultNotifier *Class HgErrorUtil is used for error analyzing --- .../src/org/zmlx/hg4idea/HgPusher.java | 20 ++++---- .../hg4idea/src/org/zmlx/hg4idea/HgVcs.java | 8 ++- .../action/HgCommandResultNotifier.java | 49 +++++++++++-------- .../hg4idea/action/HgCreateTagAction.java | 10 ++-- .../src/org/zmlx/hg4idea/action/HgInit.java | 31 ++++++------ .../HgSwitchWorkingDirectoryAction.java | 6 ++- .../zmlx/hg4idea/command/HgInitCommand.java | 6 +-- .../zmlx/hg4idea/command/HgPullCommand.java | 15 +++--- .../command/HgRemoteChangesetsCommand.java | 23 ++++----- .../hg4idea/provider/HgCheckoutProvider.java | 17 +++---- .../org/zmlx/hg4idea/util/HgErrorUtil.java | 4 +- .../src/org/zmlx/hg4idea/util/HgUtil.java | 13 ----- 12 files changed, 101 insertions(+), 101 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java index 60829de0d7fa..94a751a1d8a8 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java @@ -82,14 +82,14 @@ public class HgPusher { push(myProject, pushCommand.get()); } } - }); + }); } public static String getDefaultPushPath(@NotNull Project project, @NotNull VirtualFile repo) { final HgShowConfigCommand configCommand = new HgShowConfigCommand(project); return configCommand.getDefaultPushPath(repo); } - + public static List getBranches(@NotNull Project project, @NotNull VirtualFile root) { final AtomicReference> branchesRef = new AtomicReference>(); new HgTagBranchCommand(project, root).listBranches(new Consumer>() { @@ -111,18 +111,16 @@ public class HgPusher { } int commitsNum = getNumberOfPushedCommits(result); - if (commitsNum > 0 && result.getExitValue() == 0 ) { + if (commitsNum > 0 && result.getExitValue() == 0) { String successTitle = "Pushed successfully"; String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), repo.getPresentableName()); - new HgCommandResultNotifier(project).process(result, successTitle, successDescription); - } - else if (commitsNum == 0) { - new HgCommandResultNotifier(project).process(result, "", "Nothing to push"); - } - else { - new HgCommandResultNotifier(project).process(result, null, null, "Push failed", - "Failed to push to [" + repo.getPresentableName() + "]" ); + new HgCommandResultNotifier(project).notifySuccess(successTitle, successDescription); + } else if (commitsNum == 0) { + new HgCommandResultNotifier(project).notifySuccess("", "Nothing to push"); + } else { + new HgCommandResultNotifier(project).notifyError(result, "Push failed", + "Failed to push to [" + repo.getPresentableName() + "]"); } } }); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java index 4a693563a2bd..d64ad75309d6 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java @@ -12,6 +12,8 @@ // limitations under the License. package org.zmlx.hg4idea; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.diagnostic.Logger; @@ -32,6 +34,7 @@ import com.intellij.openapi.vcs.VcsKey; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.changes.ChangeProvider; import com.intellij.openapi.vcs.changes.CommitExecutor; +import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.diff.DiffProvider; import com.intellij.openapi.vcs.history.VcsHistoryProvider; @@ -74,7 +77,10 @@ public class HgVcs extends AbstractVcs { private static final Logger LOG = Logger.getInstance(HgVcs.class); public static final String VCS_NAME = "hg4idea"; - public static final String NOTIFICATION_GROUP_ID = "Mercurial"; + public static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.toolWindowGroup( + "Mercurial Messages", ChangesViewContentManager.TOOLWINDOW_ID, true); + public static final NotificationGroup IMPORTANT_ERROR_NOTIFICATION = new NotificationGroup( + "Mercurial Important Messages", NotificationDisplayType.STICKY_BALLOON, true); public static final String HG_EXECUTABLE_FILE_NAME = (SystemInfo.isWindows ? "hg.exe" : "hg"); private final static VcsKey ourKey = createKey(VCS_NAME); private static final int MAX_CONSOLE_OUTPUT_SIZE = 10000; diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommandResultNotifier.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommandResultNotifier.java index b1568f5ce8d2..1c8dcccd1065 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommandResultNotifier.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommandResultNotifier.java @@ -12,48 +12,55 @@ // limitations under the License. package org.zmlx.hg4idea.action; -import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.vcsUtil.VcsImplUtil; -import com.intellij.vcsUtil.VcsUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.execution.HgCommandResult; -import org.zmlx.hg4idea.util.HgErrorUtil; import java.util.List; public final class HgCommandResultNotifier { private final Project myProject; + private static final Logger LOG = Logger.getInstance(HgCommandResultNotifier.class); public HgCommandResultNotifier(Project project) { myProject = project; } - public void process(HgCommandResult result, @Nullable String successTitle, @Nullable String successDescription) { - process(result, successTitle, successDescription, null, null ); + public void notifySuccess(@NotNull String title, @NotNull String successDescription) { + HgVcs.NOTIFICATION_GROUP.createNotification(title, successDescription, NotificationType.INFORMATION, null).notify(myProject); } - public void process( HgCommandResult result, - @Nullable String successTitle, @Nullable String successDescription, - @Nullable String failureTitle, @Nullable String failureDescription ){ - List out = result.getOutputLines(); + public void notifyError(HgCommandResult result, @NotNull String failureTitle, @NotNull String failureDescription) { + notifyError(result, failureTitle, failureDescription, null); + } + + public void notifyError(@NotNull HgCommandResult result, + @NotNull String failureTitle, + @NotNull String failureDescription, + @Nullable NotificationListener listener) { List err = result.getErrorLines(); - if (!out.isEmpty()) { - VcsUtil.showStatusMessage(myProject, out.get(out.size() - 1)); + String errorMessage; + if (StringUtil.isEmptyOrSpaces(failureDescription)) { + failureDescription = failureTitle; } - if (HgErrorUtil.isAbort(result)) { - VcsImplUtil.showErrorMessage( - myProject, "" + StringUtil.join(err, "
") + "", "Error" - ); - } else if ( result.getExitValue() != 0 && failureTitle != null && failureDescription != null ){ - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, failureTitle, failureDescription, NotificationType.ERROR), myProject); - } else if (successTitle != null && successDescription != null) { - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, successTitle, successDescription, NotificationType.INFORMATION), myProject); + if (err.isEmpty()) { + LOG.assertTrue(!StringUtil.isEmptyOrSpaces(failureDescription), + "Failure title, failure description and errors log can not be empty at the same time"); + errorMessage = failureDescription; + } else if (failureDescription.isEmpty()) { + errorMessage = "" + StringUtil.join(err, "
") + ""; + } else { + errorMessage = "" + failureDescription + "
" + StringUtil.join(err, "
") + ""; } + HgVcs.IMPORTANT_ERROR_NOTIFICATION + .createNotification(failureTitle, errorMessage, NotificationType.ERROR, listener) + .notify(myProject); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java index ef97b082d720..1c442b1d837f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java @@ -12,14 +12,15 @@ // limitations under the License. package org.zmlx.hg4idea.action; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.command.HgTagCreateCommand; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.execution.HgCommandResultHandler; import org.zmlx.hg4idea.ui.HgTagDialog; +import org.zmlx.hg4idea.util.HgErrorUtil; import java.util.Collection; @@ -39,7 +40,7 @@ public class HgCreateTagAction extends HgAbstractGlobalAction { }; } - private HgGlobalCommand buildCommand(final HgTagDialog dialog, final Project project) { + private static HgGlobalCommand buildCommand(final HgTagDialog dialog, final Project project) { return new HgGlobalCommand() { public VirtualFile getRepo() { return dialog.getRepository(); @@ -49,11 +50,12 @@ public class HgCreateTagAction extends HgAbstractGlobalAction { new HgTagCreateCommand(project, dialog.getRepository(), dialog.getTagName()).execute(new HgCommandResultHandler() { @Override public void process(@Nullable HgCommandResult result) { - new HgCommandResultNotifier(project).process(result, null, null); + if (HgErrorUtil.hasErrorsInCommandExecution(result)) { + new HgCommandResultNotifier(project).notifyError(result, "Creation failed", "Tag creation [" + dialog.getTagName() + "] failed"); + } } }); } }; } - } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java index 8ab3aaa6c7e1..7734f444436a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java @@ -1,8 +1,5 @@ package org.zmlx.hg4idea.action; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.DumbAwareAction; @@ -12,13 +9,16 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; -import org.zmlx.hg4idea.util.HgUtil; +import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.command.HgInitCommand; +import org.zmlx.hg4idea.execution.HgCommandResult; +import org.zmlx.hg4idea.execution.HgCommandResultHandler; import org.zmlx.hg4idea.ui.HgInitAlreadyUnderHgDialog; import org.zmlx.hg4idea.ui.HgInitDialog; +import org.zmlx.hg4idea.util.HgErrorUtil; +import org.zmlx.hg4idea.util.HgUtil; import java.util.ArrayList; import java.util.List; @@ -110,21 +110,18 @@ public class HgInit extends DumbAwareAction { } private void createRepository(final VirtualFile selectedRoot, final VirtualFile mapRoot) { - new HgInitCommand(myProject).execute(selectedRoot, new Consumer() { + new HgInitCommand(myProject).execute(selectedRoot, new HgCommandResultHandler() { @Override - public void consume(Boolean succeeded) { - if (succeeded) { + public void process(@Nullable HgCommandResult result) { + if (!HgErrorUtil.hasErrorsInCommandExecution(result)) { updateDirectoryMappings(mapRoot); + new HgCommandResultNotifier(myProject.isDefault() ? null : myProject) + .notifySuccess("hg4idea.init.created.notification.title", "hg4idea.init.created.notification.description"); + } else { + new HgCommandResultNotifier(myProject.isDefault() ? null : myProject) + .notifyError(result, "hg4idea.init.error.title", HgVcsMessages.message("hg4idea.init.error.description", + selectedRoot.getPresentableUrl())); } - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, - HgVcsMessages.message( - succeeded ? "hg4idea.init.created.notification.title" : "hg4idea.init.error.title"), - HgVcsMessages.message(succeeded - ? "hg4idea.init.created.notification.description" - : "hg4idea.init.error.description", - selectedRoot.getPresentableUrl()), - succeeded ? NotificationType.INFORMATION : NotificationType.ERROR), - myProject.isDefault() ? null : myProject); } }); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgSwitchWorkingDirectoryAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgSwitchWorkingDirectoryAction.java index e7d186a3d323..a75f5f74cc65 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgSwitchWorkingDirectoryAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgSwitchWorkingDirectoryAction.java @@ -20,6 +20,7 @@ import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.command.HgUpdateCommand; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.ui.HgSwitchDialog; +import org.zmlx.hg4idea.util.HgErrorUtil; import java.util.Collection; @@ -62,12 +63,13 @@ public class HgSwitchWorkingDirectoryAction extends HgAbstractGlobalAction { @Override public void run() { HgCommandResult result = command.execute(); - new HgCommandResultNotifier(project).process(result, null, null); + if (HgErrorUtil.hasErrorsInCommandExecution(result)) { + new HgCommandResultNotifier(project).notifyError(result, "", "Update failed"); + } project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project, null); } }); } }; } - } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java index 67c8a6180429..4c78dba985fc 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java @@ -2,10 +2,8 @@ package org.zmlx.hg4idea.command; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.zmlx.hg4idea.util.HgErrorUtil; import org.zmlx.hg4idea.execution.HgCommandExecutor; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.execution.HgCommandResultHandler; @@ -24,7 +22,7 @@ public class HgInitCommand { myProject = project; } - public void execute(@NotNull VirtualFile repositoryRoot, @NotNull final Consumer booleanResultHandler) { + public void execute(@NotNull VirtualFile repositoryRoot,final HgCommandResultHandler resultHandler) { final List args = new ArrayList(1); args.add(repositoryRoot.getPath()); final HgCommandExecutor executor = new HgCommandExecutor(myProject); @@ -32,7 +30,7 @@ public class HgInitCommand { executor.execute(null, "init", args, new HgCommandResultHandler() { @Override public void process(@Nullable HgCommandResult result) { - booleanResultHandler.consume(result != null && !HgErrorUtil.isAbort(result)); + resultHandler.process(result); } }); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java index f27724ed4a33..8f275f9ef392 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java @@ -22,7 +22,6 @@ import org.zmlx.hg4idea.action.HgCommandResultNotifier; import org.zmlx.hg4idea.execution.HgCommandExecutor; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.util.HgErrorUtil; -import org.zmlx.hg4idea.util.HgUtil; import java.util.LinkedList; import java.util.List; @@ -37,7 +36,7 @@ public class HgPullCommand { private boolean update = true; private boolean rebase = !update; private static final Logger LOG = Logger.getInstance(HgPullCommand.class); - + public HgPullCommand(Project project, @NotNull VirtualFile repo) { this.project = project; this.repo = repo; @@ -60,6 +59,10 @@ public class HgPullCommand { } public boolean execute() { + return execute(false); + } + + public boolean execute(boolean forceAuthorization) { List arguments = new LinkedList(); if (update) { arguments.add("--update"); @@ -78,15 +81,15 @@ public class HgPullCommand { executor.setShowOutput(true); final HgCommandResult result = executor.executeInCurrentThread(repo, "pull", arguments); if (HgErrorUtil.isAuthorizationError(result)) { - HgUtil.notifyError(project, "Authorization required", "http authorization required for " + source + ""); + new HgCommandResultNotifier(project) + .notifyError(result, "Authorization required", "http authorization required for " + source + ""); return false; - } else if (HgErrorUtil.isAbort(result)) { - new HgCommandResultNotifier(project).process(result, null, null); + } else if (HgErrorUtil.hasErrorsInCommandExecution(result)) { + new HgCommandResultNotifier(project).notifyError(result, "", "Pull failed"); return false; } else { project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project, null); return true; } } - } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoteChangesetsCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoteChangesetsCommand.java index d0e8b770c5b1..e3d3e3f3eb95 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoteChangesetsCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoteChangesetsCommand.java @@ -17,8 +17,6 @@ package org.zmlx.hg4idea.command; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; @@ -26,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.zmlx.hg4idea.HgProjectSettings; import org.zmlx.hg4idea.HgVcs; +import org.zmlx.hg4idea.action.HgCommandResultNotifier; import org.zmlx.hg4idea.execution.HgCommandExecutor; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.util.HgErrorUtil; @@ -72,15 +71,17 @@ public abstract class HgRemoteChangesetsCommand extends HgChangesetsCommand { if (vcs == null) { return result; } - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, "Checking for incoming/outgoing changes disabled", - "Authentication is required to check incoming/outgoing changes in " + repositoryURL + - "
You may enable checking for changes in the Settings." - , NotificationType.ERROR, new NotificationListener() { - @Override - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - ShowSettingsUtil.getInstance().showSettingsDialog(project, vcs.getConfigurable().getDisplayName()); - } - }), project); + new HgCommandResultNotifier(project).notifyError(result, "Checking for incoming/outgoing changes disabled", + "Authentication is required to check incoming/outgoing changes in " + repositoryURL + + "
You may enable checking for changes in the Settings.", + new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, + @NotNull HyperlinkEvent event) { + ShowSettingsUtil.getInstance() + .showSettingsDialog(project, vcs.getConfigurable().getDisplayName()); + } + }); final HgProjectSettings projectSettings = vcs.getProjectSettings(); projectSettings.setCheckIncomingOutgoing(false); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgCheckoutProvider.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgCheckoutProvider.java index 38882ce0ae8f..74a48a3d3cde 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgCheckoutProvider.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgCheckoutProvider.java @@ -15,9 +15,6 @@ */ package org.zmlx.hg4idea.provider; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -31,9 +28,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.HgVcsMessages; +import org.zmlx.hg4idea.action.HgCommandResultNotifier; import org.zmlx.hg4idea.command.HgCloneCommand; import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.ui.HgCloneDialog; +import org.zmlx.hg4idea.util.HgErrorUtil; import java.io.File; @@ -73,9 +72,11 @@ public class HgCheckoutProvider implements CheckoutProvider { // handle result final HgCommandResult myCloneResult = clone.execute(); if (myCloneResult == null) { - notifyError("Clone failed", "Clone failed due to unknown error", project); - } else if (myCloneResult.getExitValue() != 0) { - notifyError("Clone failed", "Clone from " + sourceRepositoryURL + " failed.

" + myCloneResult.getRawError(), project); + new HgCommandResultNotifier(project).notifyError(myCloneResult, "Clone failed", "Clone failed due to unknown error"); + } else if (HgErrorUtil.hasErrorsInCommandExecution(myCloneResult)) { + new HgCommandResultNotifier(project).notifyError(myCloneResult, "Clone failed", "Clone from " + + sourceRepositoryURL + + " failed."); } else { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override @@ -92,10 +93,6 @@ public class HgCheckoutProvider implements CheckoutProvider { } - private static void notifyError(String title, String description, Project project) { - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, title, description, NotificationType.ERROR), project); - } - /** * {@inheritDoc} */ diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java index add5e19feae9..b272862af45e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java @@ -53,5 +53,7 @@ public final class HgErrorUtil { return errorLines.get(errorLines.size() - 1); } - + public static boolean hasErrorsInCommandExecution(HgCommandResult result) { + return isAbort(result) || result.getExitValue() != 0; + } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java index 55ea7e7ff330..ec4313f63ebc 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java @@ -12,15 +12,11 @@ // limitations under the License. package org.zmlx.hg4idea.util; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.history.FileHistoryPanelImpl; @@ -284,15 +280,6 @@ public abstract class HgUtil { return map; } - /** - * Displays an error notification. - */ - public static void notifyError(Project project, String title, String description) { - if (StringUtil.isEmptyOrSpaces(description)) { - description = title; - } - Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, title, description, NotificationType.ERROR), project); - } public static HgFile getFileNameInTargetRevision(Project project, HgRevisionNumber vcsRevisionNumber, HgFile localHgFile) { HgStatusCommand statCommand = new HgStatusCommand(project); From dc9ddba2e0ee348aa49d986072e3b97893a296d8 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Fri, 14 Dec 2012 21:01:21 +0400 Subject: [PATCH 23/67] IDEA-94168 error message if launching debug on real device with "debuggable" attribute set to false --- .../android/run/AndroidRunConfigurationBase.java | 11 ++++++++++- .../jetbrains/android/run/AndroidRunningState.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationBase.java b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationBase.java index 368d997b67a4..7bf4f34bf843 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationBase.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationBase.java @@ -46,6 +46,7 @@ import com.intellij.util.PsiNavigateUtil; import com.intellij.util.containers.HashMap; import com.intellij.util.xml.GenericAttributeValue; import org.jdom.Element; +import org.jetbrains.android.dom.manifest.Application; import org.jetbrains.android.dom.manifest.Manifest; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.facet.AndroidFacetConfiguration; @@ -196,7 +197,15 @@ public abstract class AndroidRunConfigurationBase extends ModuleBasedConfigurati } boolean debug = DefaultDebugExecutor.EXECUTOR_ID.equals(executor.getId()); + boolean nonDebuggableOnDevice = false; + if (debug) { + final Manifest manifest = facet.getManifest(); + final Application application = manifest != null ? manifest.getApplication() : null; + + nonDebuggableOnDevice = application != null && Boolean.FALSE.toString(). + equals(application.getDebuggable().getStringValue()); + if (!AndroidSdkUtils.activateDdmsIfNecessary(facet.getModule().getProject(), new Computable() { @Nullable @Override @@ -236,7 +245,7 @@ public abstract class AndroidRunConfigurationBase extends ModuleBasedConfigurati if (applicationLauncher != null) { final boolean supportMultipleDevices = supportMultipleDevices() && executor.getId().equals(DefaultRunExecutor.EXECUTOR_ID); return new AndroidRunningState(env, facet, targetChooser, computeCommandLine(), aPackage, applicationLauncher, - depModule2PackageName, supportMultipleDevices, CLEAR_LOGCAT, this); + depModule2PackageName, supportMultipleDevices, CLEAR_LOGCAT, this, nonDebuggableOnDevice); } return null; } diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java index 44650110a63a..4db66b154f17 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java @@ -134,6 +134,7 @@ public class AndroidRunningState implements RunProfileState, AndroidDebugBridge. private final boolean mySupportMultipleDevices; private final boolean myClearLogcatBeforeStart; private final List myListeners = new ArrayList(); + private final boolean myNonDebuggableOnDevice; public void setDebugMode(boolean debugMode) { myDebugMode = debugMode; @@ -305,7 +306,8 @@ public class AndroidRunningState implements RunProfileState, AndroidDebugBridge. Map additionalFacet2PackageName, boolean supportMultipleDevices, boolean clearLogcatBeforeStart, - @NotNull AndroidRunConfigurationBase configuration) throws ExecutionException { + @NotNull AndroidRunConfigurationBase configuration, + boolean nonDebuggableOnDevice) throws ExecutionException { myFacet = facet; myCommandLine = commandLine; myConfiguration = configuration; @@ -323,6 +325,7 @@ public class AndroidRunningState implements RunProfileState, AndroidDebugBridge. myTargetPackageName = packageName; myAdditionalFacet2PackageName = additionalFacet2PackageName; myClearLogcatBeforeStart = clearLogcatBeforeStart; + myNonDebuggableOnDevice = nonDebuggableOnDevice; } public void setDeploy(boolean deploy) { @@ -633,6 +636,12 @@ public class AndroidRunningState implements RunProfileState, AndroidDebugBridge. } private boolean prepareAndStartApp(IDevice device) { + if (myDebugMode && myNonDebuggableOnDevice && !device.isEmulator()) { + message("Cannot debug the application " + myPackageName + " on device '" + device.getName() + "',\n" + + "because 'debuggable' attribute is set to 'false' in AndroidManifest.xml.\nYou may remove the attribute " + + "and the IDE will automatically assign it during debug and release builds.", STDERR); + return false; + } if (!doPrepareAndStart(device)) { fireExecutionFailed(); return false; From d29e6b8b99d62079625e0793d4326ac90cd42d9d Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 18:22:40 +0100 Subject: [PATCH 24/67] composition of extends/super wildcard reworked (IDEA-96721) --- .../src/com/intellij/psi/impl/PsiSubstitutorImpl.java | 8 +++++++- .../genericsHighlighting/WildcardsBoundsIntersection.java | 2 +- .../com/intellij/psi/resolve/TypeInferenceTest.java | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java index 5ecdebebed0d..013ed3cd366d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java @@ -159,7 +159,13 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { if (newBound instanceof PsiCapturedWildcardType) { final PsiWildcardType wildcard = ((PsiCapturedWildcardType)newBound).getWildcard(); if (wildcardType.isExtends() != wildcard.isExtends()) { - return wildcard.isBounded() ? wildcard.getBound() : newBound; + if (wildcard.isBounded()) { + return wildcardType.isExtends() ? PsiWildcardType.createExtends(wildcardType.getManager(), newBound) + : PsiWildcardType.createSuper(wildcardType.getManager(), newBound); + } + else { + return newBound; + } } if (!wildcard.isBounded()) return PsiWildcardType.createUnbounded(wildcardType.getManager()); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java index 013657a5ea8e..c84c5890e8c5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardsBoundsIntersection.java @@ -10,6 +10,6 @@ class Node { class Main { public static void main(NodeProperty nval, Node expr) { - int val = expr.get(nval); + int val = expr.get(nval); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/psi/resolve/TypeInferenceTest.java b/java/java-tests/testSrc/com/intellij/psi/resolve/TypeInferenceTest.java index cfa1c9348144..58e71599b153 100644 --- a/java/java-tests/testSrc/com/intellij/psi/resolve/TypeInferenceTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/resolve/TypeInferenceTest.java @@ -152,6 +152,6 @@ public class TypeInferenceTest extends Resolve15TestCase { } public void testBoundComposition() throws Exception { - checkResolvesTo("java.lang.Class"); + checkResolvesTo("java.lang.Class"); } } From 5aa6fe3572800e2d30d4352668be9612bae4ea5b Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 18:31:56 +0100 Subject: [PATCH 25/67] check overriding in correct order (IDEA-97506) --- .../intellij/psi/impl/PsiSuperMethodImplUtil.java | 6 +++--- .../OverrideWithMoreSpecificReturn.java | 15 +++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java index 61d7d54c077b..70f80b470158 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java @@ -215,15 +215,15 @@ public class PsiSuperMethodImplUtil { LOG.assertTrue(copy.getMethod().isValid()); map.put(signature, copy); } + else if (isSuperMethod(aClass, existing, hierarchicalMethodSignature)) { + mergeSupers(existing, hierarchicalMethodSignature); + } else if (isReturnTypeIsMoreSpecificThan(hierarchicalMethodSignature, existing) && isSuperMethod(aClass, hierarchicalMethodSignature, existing)) { HierarchicalMethodSignatureImpl newSuper = copy(hierarchicalMethodSignature); mergeSupers(newSuper, existing); LOG.assertTrue(newSuper.getMethod().isValid()); map.put(signature, newSuper); } - else if (isSuperMethod(aClass, existing, hierarchicalMethodSignature)) { - mergeSupers(existing, hierarchicalMethodSignature); - } // just drop an invalid method declaration there - to highlight accordingly else if (!result.containsKey(signature)) { LOG.assertTrue(hierarchicalMethodSignature.getMethod().isValid()); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java new file mode 100644 index 000000000000..c2f68775cbfb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideWithMoreSpecificReturn.java @@ -0,0 +1,15 @@ +import java.util.List; + +interface ExampleInterface { + public List exampleMethod(); +} + +class ExampleSuperClass { + public List exampleMethod() { + return null; + } +} + + +public class ExampleSubClass extends ExampleSuperClass implements ExampleInterface { +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 54f69672b856..efd46470ee23 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -206,6 +206,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testFlattenIntersectionType() throws Exception { doTest17Incompatibility(false); } public void testIDEA97276() throws Exception { doTest17Incompatibility(false); } public void testWildcardsBoundsIntersection() throws Exception { doTest17Incompatibility(false); } + public void testOverrideWithMoreSpecificReturn() throws Exception { doTest17Incompatibility(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); From 2c5e21bc4048951f97f79142afcac16eda5c10a7 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 14 Dec 2012 19:24:53 +0100 Subject: [PATCH 26/67] [r=nik] automatically exclude from compilation annotation processors output --- ...ilders.java.ExcludedJavaSourceRootProvider | 1 + .../src/org/jetbrains/jps/ProjectPaths.java | 20 +++----- .../java/ExcludedJavaSourceRootProvider.java | 1 + .../jps/incremental/CompileContext.java | 10 ---- .../jps/incremental/CompileContextImpl.java | 42 ---------------- .../jps/incremental/ModuleBuildTarget.java | 7 ++- .../jps/incremental/ResourcesTarget.java | 27 ---------- .../ClassProcessingBuilder.java | 6 +-- .../instrumentation/RmiStubsGenerator.java | 3 +- ...tationsExcludedJavaSourceRootProvider.java | 49 +++++++++++++++++++ .../jps/incremental/java/JavaBuilder.java | 17 ++++--- .../jps/builders/ModuleClasspathTest.groovy | 10 ++-- .../JpsJavaCompilerConfiguration.java | 16 +++++- .../JpsJavaCompilerConfigurationImpl.java | 32 +++++++++++- ...psJavaCompilerConfigurationSerializer.java | 2 +- .../JpsCompilerConfigurationTest.java | 2 +- .../AndroidLibraryPackagingBuilder.java | 3 +- .../jps/android/AndroidPackagingBuilder.java | 3 +- .../builder/AndroidPackagingBuildTarget.java | 3 +- .../jps/incremental/groovy/GroovyBuilder.java | 3 +- .../compiler/FormsInstrumenter.java | 5 +- 21 files changed, 134 insertions(+), 128 deletions(-) create mode 100644 jps/jps-builders/src/META-INF/services/org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider create mode 100644 jps/jps-builders/src/org/jetbrains/jps/incremental/java/AnnotationsExcludedJavaSourceRootProvider.java diff --git a/jps/jps-builders/src/META-INF/services/org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider b/jps/jps-builders/src/META-INF/services/org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider new file mode 100644 index 000000000000..e398bfd69f5c --- /dev/null +++ b/jps/jps-builders/src/META-INF/services/org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider @@ -0,0 +1 @@ +org.jetbrains.jps.incremental.java.AnnotationsExcludedJavaSourceRootProvider \ No newline at end of file diff --git a/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java b/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java index 156d9240ba6e..caa7e58a4338 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java +++ b/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java @@ -21,7 +21,6 @@ import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.JpsDummyElement; -import org.jetbrains.jps.model.JpsProject; import org.jetbrains.jps.model.JpsSimpleElement; import org.jetbrains.jps.model.java.*; import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; @@ -41,30 +40,25 @@ import java.util.*; * Date: 9/30/11 */ public class ProjectPaths { - @NotNull - private final JpsProject myProject; - //private final Map>> myCachedClasspath = new HashMap>>(); - - public ProjectPaths(@NotNull JpsProject project) { - myProject = project; + private ProjectPaths() { } - public Collection getCompilationClasspathFiles(ModuleChunk chunk, + public static Collection getCompilationClasspathFiles(ModuleChunk chunk, boolean includeTests, final boolean excludeMainModuleOutput, final boolean exportedOnly) { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(includeTests), excludeMainModuleOutput, ClasspathPart.WHOLE, exportedOnly); } - public Collection getPlatformCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { + public static Collection getPlatformCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(chunk.containsTests()), excludeMainModuleOutput, ClasspathPart.BEFORE_JDK, true); } - public Collection getCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { + public static Collection getCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(chunk.containsTests()), excludeMainModuleOutput, ClasspathPart.AFTER_JDK, true); } - private Collection getClasspathFiles(ModuleChunk chunk, + private static Collection getClasspathFiles(ModuleChunk chunk, JpsJavaClasspathKind kind, final boolean excludeMainModuleOutput, ClasspathPart classpathPart, final boolean exportedOnly) { @@ -159,12 +153,12 @@ public class ProjectPaths { } @Nullable - public File getModuleOutputDir(JpsModule module, boolean forTests) { + public static File getModuleOutputDir(JpsModule module, boolean forTests) { return JpsJavaExtensionService.getInstance().getOutputDirectory(module, forTests); } @Nullable - public File getAnnotationProcessorGeneratedSourcesOutputDir(JpsModule module, final boolean forTests, ProcessorConfigProfile profile) { + public static File getAnnotationProcessorGeneratedSourcesOutputDir(JpsModule module, final boolean forTests, ProcessorConfigProfile profile) { final String sourceDirName = profile.getGeneratedSourcesDirectoryName(forTests); if (profile.isOutputRelativeToContentRoot()) { List roots = module.getContentRootsList().getUrls(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/ExcludedJavaSourceRootProvider.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/ExcludedJavaSourceRootProvider.java index 64dbd190e72e..18b1a52a9ffb 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/ExcludedJavaSourceRootProvider.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/ExcludedJavaSourceRootProvider.java @@ -20,6 +20,7 @@ import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleSourceRoot; /** + * * @author nik */ public abstract class ExcludedJavaSourceRootProvider { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java index 23d081c336d7..b878c75b3180 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java @@ -16,15 +16,11 @@ package org.jetbrains.jps.incremental; import com.intellij.openapi.util.UserDataHolder; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.ModuleChunk; -import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.logging.BuildLoggingManager; import org.jetbrains.jps.cmdline.ProjectDescriptor; -import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; -import org.jetbrains.jps.model.module.JpsModule; /** * @author Eugene Zhuravlev @@ -33,8 +29,6 @@ import org.jetbrains.jps.model.module.JpsModule; public interface CompileContext extends UserDataHolder, MessageHandler { ProjectDescriptor getProjectDescriptor(); - ProjectPaths getProjectPaths(); - CompileScope getScope(); boolean isMake(); @@ -48,10 +42,6 @@ public interface CompileContext extends UserDataHolder, MessageHandler { void removeBuildListener(BuildListener listener); - @NotNull - ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module); - - boolean shouldDifferentiate(ModuleChunk chunk); CanceledStatus getCancelStatus(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java index 8b1ae2062ed7..5ccf72e73312 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java @@ -18,10 +18,8 @@ package org.jetbrains.jps.incremental; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.util.EventDispatcher; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.ModuleChunk; -import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.jps.builders.logging.BuildLoggingManager; @@ -30,10 +28,6 @@ import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.FileDeletedEvent; import org.jetbrains.jps.incremental.messages.FileGeneratedEvent; import org.jetbrains.jps.incremental.messages.ProgressMessage; -import org.jetbrains.jps.model.java.JpsJavaExtensionService; -import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration; -import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; -import org.jetbrains.jps.model.module.JpsModule; import java.util.*; @@ -49,14 +43,12 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon private final MessageHandler myDelegateMessageHandler; private final Set myNonIncrementalModules = new HashSet(); - private final ProjectPaths myProjectPaths; private volatile long myCompilationStartStamp; private final ProjectDescriptor myProjectDescriptor; private final Map myBuilderParams; private final CanceledStatus myCancelStatus; private volatile float myDone = -1.0f; private EventDispatcher myListeners = EventDispatcher.create(BuildListener.class); - private Map myAnnotationProcessingProfileMap; public CompileContextImpl(CompileScope scope, ProjectDescriptor pd, boolean isMake, @@ -72,7 +64,6 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon myIsProjectRebuild = isProjectRebuild; myIsMake = !isProjectRebuild && isMake; myDelegateMessageHandler = delegateMessageHandler; - myProjectPaths = new ProjectPaths(pd.getProject()); } @Override @@ -85,11 +76,6 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon myCompilationStartStamp = System.currentTimeMillis(); } - @Override - public ProjectPaths getProjectPaths() { - return myProjectPaths; - } - @Override public boolean isMake() { return myIsMake; @@ -121,34 +107,6 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon myListeners.removeListener(listener); } - @Override - @NotNull - public ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module) { - final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( - getProjectDescriptor().getProject()); - Map map = myAnnotationProcessingProfileMap; - if (map == null) { - map = new HashMap(); - final Map namesMap = new HashMap(); - for (JpsModule m : getProjectDescriptor().getProject().getModules()) { - namesMap.put(m.getName(), m); - } - if (!namesMap.isEmpty()) { - for (ProcessorConfigProfile profile : compilerConfig.getAnnotationProcessingConfigurations()) { - for (String name : profile.getModuleNames()) { - final JpsModule mod = namesMap.get(name); - if (mod != null) { - map.put(mod, profile); - } - } - } - } - myAnnotationProcessingProfileMap = map; - } - final ProcessorConfigProfile profile = map.get(module); - return profile != null? profile : compilerConfig.getDefaultAnnotationProcessingConfiguration(); - } - @Override public void markNonIncremental(ModuleBuildTarget target) { if (!target.isTests()) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java index 42be4576b4dd..e27534b98d40 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java @@ -21,6 +21,7 @@ import com.intellij.util.SmartList; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.builders.*; import org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; @@ -69,9 +70,11 @@ public final class ModuleBuildTarget extends JVMModuleBuildTarget allProfiles = - JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(model.getProject()).getAnnotationProcessingConfigurations(); - ProcessorConfigProfile profile = null; - final String moduleName = getModule().getName(); - for (ProcessorConfigProfile p : allProfiles) { - if (p.getModuleNames().contains(moduleName)) { - if (p.isEnabled()) { - profile = p; - } - break; - } - } - return profile; - } - @NotNull @Override public String getPresentableName() { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/ClassProcessingBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/ClassProcessingBuilder.java index 475be1ed2564..8131cfd62739 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/ClassProcessingBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/ClassProcessingBuilder.java @@ -79,11 +79,9 @@ public abstract class ClassProcessingBuilder extends ModuleLevelBuilder { try { InstrumentationClassFinder finder = CLASS_FINDER.get(context); // try using shared finder if (finder == null) { - final ProjectPaths paths = context.getProjectPaths(); - final Collection platformCp = paths.getPlatformCompilationClasspath(chunk, false); - + final Collection platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false); final Collection classpath = new ArrayList(); - classpath.addAll(paths.getCompilationClasspath(chunk, false)); + classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false)); classpath.addAll(ProjectPaths.getSourceRootsWithDependents(chunk).keySet()); finder = createInstrumentationClassFinder(platformCp, classpath, outputConsumer); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java index f4322364aca1..02c5cc1c1c30 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java @@ -30,6 +30,7 @@ import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.ModuleChunk; +import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.incremental.*; import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.CompilerMessage; @@ -118,7 +119,7 @@ public class RmiStubsGenerator extends ClassProcessingBuilder { OutputConsumer outputConsumer) { ExitCode exitCode = ExitCode.NOTHING_DONE; - final Collection classpath = context.getProjectPaths().getCompilationClasspath(chunk, false); + final Collection classpath = ProjectPaths.getCompilationClasspath(chunk, false); final StringBuilder buf = new StringBuilder(); for (File file : classpath) { if (buf.length() > 0) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/AnnotationsExcludedJavaSourceRootProvider.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/AnnotationsExcludedJavaSourceRootProvider.java new file mode 100644 index 000000000000..4634be644d28 --- /dev/null +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/AnnotationsExcludedJavaSourceRootProvider.java @@ -0,0 +1,49 @@ +/* + * 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.jetbrains.jps.incremental.java; + +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.ProjectPaths; +import org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider; +import org.jetbrains.jps.model.java.JavaSourceRootType; +import org.jetbrains.jps.model.java.JpsJavaExtensionService; +import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration; +import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; +import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.module.JpsModuleSourceRoot; + +import java.io.File; + +/** + * @author Eugene Zhuravlev + * Date: 12/14/12 + */ +public class AnnotationsExcludedJavaSourceRootProvider extends ExcludedJavaSourceRootProvider{ + @Override + public boolean isExcludedFromCompilation(@NotNull JpsModule module, @NotNull JpsModuleSourceRoot root) { + final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject()); + final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(module); + if (!profile.isEnabled()) { + return false; + } + + final File outputDir = + ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(module, JavaSourceRootType.TEST_SOURCE == root.getRootType(), profile); + + return outputDir != null && FileUtil.filesEqual(outputDir, root.getFile()); + } +} diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index fe34a7db9e2e..aa6202ce1b05 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -207,12 +207,11 @@ public class JavaBuilder extends ModuleLevelBuilder { return exitCode; } - final ProjectPaths paths = context.getProjectPaths(); final ProjectDescriptor pd = context.getProjectDescriptor(); JavaBuilderUtil.ensureModuleHasJdk(chunk.representativeTarget().getModule(), context, BUILDER_NAME); - final Collection classpath = paths.getCompilationClasspath(chunk, false/*context.isProjectRebuild()*/); - final Collection platformCp = paths.getPlatformCompilationClasspath(chunk, false/*context.isProjectRebuild()*/); + final Collection classpath = ProjectPaths.getCompilationClasspath(chunk, false/*context.isProjectRebuild()*/); + final Collection platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false/*context.isProjectRebuild()*/); // begin compilation round final DiagnosticSink diagnosticSink = new DiagnosticSink(context); @@ -297,14 +296,18 @@ public class JavaBuilder extends ModuleLevelBuilder { final TasksCounter counter = new TasksCounter(); COUNTER_KEY.set(context, counter); + final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance(); + final JpsJavaCompilerConfiguration compilerConfig = javaExt.getCompilerConfiguration(context.getProjectDescriptor().getProject()); + assert compilerConfig != null; + final Set modules = chunk.getModules(); ProcessorConfigProfile profile = null; if (modules.size() == 1) { - profile = context.getAnnotationProcessingProfile(modules.iterator().next()); + final JpsModule module = modules.iterator().next(); + profile = compilerConfig.getAnnotationProcessingProfile(module); } else { // perform cycle-related validations - final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance(); Pair pair = null; for (JpsModule module : modules) { final LanguageLevel moduleLevel = javaExt.getLanguageLevel(module); @@ -322,7 +325,7 @@ public class JavaBuilder extends ModuleLevelBuilder { // check that all chunk modules are excluded from annotation processing for (JpsModule module : modules) { - final ProcessorConfigProfile prof = context.getAnnotationProcessingProfile(module); + final ProcessorConfigProfile prof = compilerConfig.getAnnotationProcessingProfile(module); if (prof.isEnabled()) { final String message = "Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [" + chunk.getName() + "] are excluded from annotation processing"; diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, message)); @@ -596,7 +599,7 @@ public class JavaBuilder extends ModuleLevelBuilder { options.add("-A" + optionEntry.getKey() + "=" + optionEntry.getValue()); } - final File srcOutput = context.getProjectPaths().getAnnotationProcessorGeneratedSourcesOutputDir( + final File srcOutput = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir( chunk.getModules().iterator().next(), chunk.containsTests(), profile ); if (srcOutput != null) { diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy index 55f8a86d4170..6c33c437cfd7 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy @@ -59,18 +59,14 @@ public class ModuleClasspathTest extends JpsRebuildTestCase { public void testCompilationClasspath() { ModuleChunk chunk = createChunk('main') assertClasspath(["util/lib/exported.jar", "out/production/util", "/jdk.jar"], - getPathsList(getProjectPaths().getPlatformCompilationClasspath(chunk, true))) + getPathsList(ProjectPaths.getPlatformCompilationClasspath(chunk, true))) assertClasspath(["main/lib/service.jar"], - getPathsList(getProjectPaths().getCompilationClasspath(chunk, true))) - } - - private ProjectPaths getProjectPaths() { - return new ProjectPaths(myProject) + getPathsList(ProjectPaths.getCompilationClasspath(chunk, true))) } private def assertClasspath(String moduleName, boolean includeTests, List expected) { ModuleChunk chunk = createChunk(moduleName) - final List classpath = getPathsList(new ProjectPaths(myProject).getCompilationClasspathFiles(chunk, includeTests, true, true)) + final List classpath = getPathsList(new ProjectPaths().getCompilationClasspathFiles(chunk, includeTests, true, true)) assertClasspath(expected, toSystemIndependentPaths(classpath)) } diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/compiler/JpsJavaCompilerConfiguration.java b/jps/model-api/src/org/jetbrains/jps/model/java/compiler/JpsJavaCompilerConfiguration.java index 04c15923e086..8aaf77b1687d 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/java/compiler/JpsJavaCompilerConfiguration.java +++ b/jps/model-api/src/org/jetbrains/jps/model/java/compiler/JpsJavaCompilerConfiguration.java @@ -18,6 +18,7 @@ package org.jetbrains.jps.model.java.compiler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.module.JpsModule; import java.util.Collection; import java.util.List; @@ -36,10 +37,21 @@ public interface JpsJavaCompilerConfiguration extends JpsElement { JpsCompilerExcludes getCompilerExcludes(); @NotNull - ProcessorConfigProfile getDefaultAnnotationProcessingConfiguration(); + ProcessorConfigProfile getDefaultAnnotationProcessingProfile(); ProcessorConfigProfile addAnnotationProcessingProfile(); + + /** + * @return a list of currently configured profiles excluding default one + */ @NotNull - Collection getAnnotationProcessingConfigurations(); + Collection getAnnotationProcessingProfiles(); + + /** + * @param module + * @return annotation profile with which the given module is associated + */ + @NotNull + ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module); void addResourcePattern(String pattern); List getResourcePatterns(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/JpsJavaCompilerConfigurationImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/JpsJavaCompilerConfigurationImpl.java index 65851a20a549..12d01689ea0a 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/JpsJavaCompilerConfigurationImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/JpsJavaCompilerConfigurationImpl.java @@ -24,6 +24,7 @@ import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes; import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration; import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions; import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; +import org.jetbrains.jps.model.module.JpsModule; import java.util.*; @@ -42,6 +43,7 @@ public class JpsJavaCompilerConfigurationImpl extends JpsCompositeElementBase myModulesByteCodeTargetLevels = new HashMap(); private Map myCompilerOptions = new HashMap(); private String myJavaCompilerId = "Javac"; + private Map myAnnotationProcessingProfileMap; public JpsJavaCompilerConfigurationImpl() { } @@ -84,13 +86,13 @@ public class JpsJavaCompilerConfigurationImpl extends JpsCompositeElementBase getAnnotationProcessingConfigurations() { + public Collection getAnnotationProcessingProfiles() { return myAnnotationProcessingProfiles; } @@ -163,4 +165,30 @@ public class JpsJavaCompilerConfigurationImpl extends JpsCompositeElementBase map = myAnnotationProcessingProfileMap; + if (map == null) { + map = new HashMap(); + final Map namesMap = new HashMap(); + for (JpsModule m : module.getProject().getModules()) { + namesMap.put(m.getName(), m); + } + if (!namesMap.isEmpty()) { + for (ProcessorConfigProfile profile : getAnnotationProcessingProfiles()) { + for (String name : profile.getModuleNames()) { + final JpsModule mod = namesMap.get(name); + if (mod != null) { + map.put(mod, profile); + } + } + } + } + myAnnotationProcessingProfileMap = map; + } + final ProcessorConfigProfile profile = map.get(module); + return profile != null? profile : getDefaultAnnotationProcessingProfile(); + } } diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java index 253f9434225f..b5cefb3b8b06 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java @@ -80,7 +80,7 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS for (Element profileTag : profiles) { boolean isDefault = Boolean.parseBoolean(profileTag.getAttributeValue("default")); if (isDefault) { - AnnotationProcessorProfileSerializer.readExternal(configuration.getDefaultAnnotationProcessingConfiguration(), profileTag); + AnnotationProcessorProfileSerializer.readExternal(configuration.getDefaultAnnotationProcessingProfile(), profileTag); } else { AnnotationProcessorProfileSerializer.readExternal(configuration.addAnnotationProcessingProfile(), profileTag); diff --git a/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsCompilerConfigurationTest.java b/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsCompilerConfigurationTest.java index b39b76f536c2..654f349a96a2 100644 --- a/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsCompilerConfigurationTest.java +++ b/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsCompilerConfigurationTest.java @@ -38,7 +38,7 @@ public class JpsCompilerConfigurationTest extends JpsSerializationTestCase { assertNotNull(configuration); assertFalse(configuration.isClearOutputDirectoryOnRebuild()); assertFalse(configuration.isAddNotNullAssertions()); - ProcessorConfigProfile defaultProfile = configuration.getDefaultAnnotationProcessingConfiguration(); + ProcessorConfigProfile defaultProfile = configuration.getDefaultAnnotationProcessingProfile(); assertTrue(defaultProfile.isEnabled()); assertFalse(defaultProfile.isObtainProcessorsFromClasspath()); assertEquals(FileUtil.toSystemDependentName(JpsPathUtil.urlToPath(getUrl("src"))), defaultProfile.getProcessorPath()); diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java index 231b21a57767..2d46ef40efb4 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java @@ -60,7 +60,6 @@ public class AndroidLibraryPackagingBuilder extends ModuleLevelBuilder { continue; } - final ProjectPaths projectPaths = context.getProjectPaths(); File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME); if (outputDir == null) { @@ -68,7 +67,7 @@ public class AndroidLibraryPackagingBuilder extends ModuleLevelBuilder { continue; } - final File classesDir = projectPaths.getModuleOutputDir(module, false); + final File classesDir = ProjectPaths.getModuleOutputDir(module, false); if (classesDir == null || !classesDir.isDirectory()) { continue; } diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java index 45118d7e21d3..b417740b769d 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java @@ -370,11 +370,10 @@ public class AndroidPackagingBuilder extends TargetBuilder getOutputRoots(CompileContext context) { - final File moduleOutputDir = context.getProjectPaths().getModuleOutputDir(myModule, false); + final File moduleOutputDir = ProjectPaths.getModuleOutputDir(myModule, false); final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule); if (moduleOutputDir == null || extension == null) { diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java index 99060e81c62a..0ac63d6ee5b7 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.ClassReader; import org.jetbrains.jps.ModuleChunk; +import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.FileProcessor; @@ -372,7 +373,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { // IMPORTANT! must be the first in classpath cp.add(getGroovyRtRoot().getPath()); - for (File file : context.getProjectPaths().getCompilationClasspathFiles(chunk, chunk.containsTests(), false, false)) { + for (File file : ProjectPaths.getCompilationClasspathFiles(chunk, chunk.containsTests(), false, false)) { cp.add(FileUtil.toCanonicalPath(file.getPath())); } diff --git a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsInstrumenter.java b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsInstrumenter.java index 62063da6e95e..614c4e3a7491 100644 --- a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsInstrumenter.java +++ b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsInstrumenter.java @@ -85,11 +85,10 @@ public class FormsInstrumenter extends FormsBuilder { } try { - final ProjectPaths paths = context.getProjectPaths(); - final Collection platformCp = paths.getPlatformCompilationClasspath(chunk, false); + final Collection platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false); final List classpath = new ArrayList(); - classpath.addAll(paths.getCompilationClasspath(chunk, false)); + classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false)); classpath.add(getResourcePath(GridConstraints.class)); // forms_rt.jar final Map chunkSourcePath = ProjectPaths.getSourceRootsWithDependents(chunk); classpath.addAll(chunkSourcePath.keySet()); // sourcepath for loading forms resources From 7d33e875b0bab051348771d2d87d7f333daf1b65 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Fri, 14 Dec 2012 22:46:26 +0400 Subject: [PATCH 27/67] IDEA-95977 Strange GUI behavior with Favorites and Structure --- .../src/com/intellij/openapi/ui/Splitter.java | 99 ++++++++-------- .../com/intellij/openapi/ui/SplitterTest.java | 106 ++++++++---------- 2 files changed, 92 insertions(+), 113 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/ui/Splitter.java b/platform/util/src/com/intellij/openapi/ui/Splitter.java index b8969d36d8f7..a26628f1fe5c 100644 --- a/platform/util/src/com/intellij/openapi/ui/Splitter.java +++ b/platform/util/src/com/intellij/openapi/ui/Splitter.java @@ -54,7 +54,7 @@ public class Splitter extends JPanel { private final float myMaxProp; - protected float myProportion; + protected float myProportion;// first size divided by total size private final Divider myDivider; private JComponent mySecondComponent; @@ -177,7 +177,7 @@ public class Splitter extends JPanel { if (myFirstComponent != null && myFirstComponent.isVisible() && mySecondComponent != null && mySecondComponent.isVisible()) { final Dimension firstMinSize = myFirstComponent.getMinimumSize(); final Dimension secondMinSize = mySecondComponent.getMinimumSize(); - return getOrientation() + return isVertical() ? new Dimension(Math.max(firstMinSize.width, secondMinSize.width), firstMinSize.height + dividerWidth + secondMinSize.height) : new Dimension(firstMinSize.width + dividerWidth + secondMinSize.width, Math.max(firstMinSize.height, secondMinSize.height)); } @@ -199,7 +199,7 @@ public class Splitter extends JPanel { if (myFirstComponent != null && myFirstComponent.isVisible() && mySecondComponent != null && mySecondComponent.isVisible()) { final Dimension firstPrefSize = myFirstComponent.getPreferredSize(); final Dimension secondPrefSize = mySecondComponent.getPreferredSize(); - return getOrientation() + return isVertical() ? new Dimension(Math.max(firstPrefSize.width, secondPrefSize.width), firstPrefSize.height + dividerWidth + secondPrefSize.height) : new Dimension(firstPrefSize.width + dividerWidth + secondPrefSize.width, @@ -225,11 +225,11 @@ public class Splitter extends JPanel { mySkipNextLayouting = false; return; } - final double width = getWidth(); - final double height = getHeight(); + int width = getWidth(); + int height = getHeight(); - final double componentSize = getOrientation() ? height : width; - if (componentSize <= 0) return; + int total = isVertical() ? height : width; + if (total <= 0) return; if (!isNull(myFirstComponent) && myFirstComponent.isVisible() && !isNull(mySecondComponent) && mySecondComponent.isVisible()) { // both first and second components are visible @@ -237,64 +237,52 @@ public class Splitter extends JPanel { Rectangle dividerRect = new Rectangle(); Rectangle secondRect = new Rectangle(); - double dividerWidth = getDividerWidth(); - double firstComponentSize; - double secondComponentSize; + int d = getDividerWidth(); + double size1; - if (componentSize <= dividerWidth) { - firstComponentSize = 0; - secondComponentSize = 0; - dividerWidth = componentSize; + if (total <= d) { + size1 = 0; + d = total; } else { - firstComponentSize = myProportion * (float)(componentSize - dividerWidth); - secondComponentSize = getOrientation() ? height - firstComponentSize - dividerWidth : width - firstComponentSize - dividerWidth; + size1 = myProportion * total; + double size2 = total - size1 - d; if (isHonorMinimumSize()) { - final double firstMinSize = - getOrientation() ? myFirstComponent.getMinimumSize().getHeight() : myFirstComponent.getMinimumSize().getWidth(); - final double secondMinSize = - getOrientation() ? mySecondComponent.getMinimumSize().getHeight() : mySecondComponent.getMinimumSize().getWidth(); + double mSize1 = isVertical() ? myFirstComponent.getMinimumSize().getHeight() : myFirstComponent.getMinimumSize().getWidth(); + double mSize2 = isVertical() ? mySecondComponent.getMinimumSize().getHeight() : mySecondComponent.getMinimumSize().getWidth(); - if (firstComponentSize + secondComponentSize < firstMinSize + secondMinSize) { - double proportion = firstMinSize / (firstMinSize + secondMinSize); - firstComponentSize = (int)(proportion * (float)(componentSize - dividerWidth)); - secondComponentSize = getOrientation() ? height - firstComponentSize - dividerWidth : width - firstComponentSize - dividerWidth; + if (size1 + size2 < mSize1 + mSize2) { + double proportion = mSize1 / (mSize1 + mSize2); + size1 = proportion * total; } else { - if (firstComponentSize < firstMinSize) { - secondComponentSize -= firstMinSize - firstComponentSize; - firstComponentSize = firstMinSize; + if (size1 < mSize1) { + size1 = mSize1; } - else if (secondComponentSize < secondMinSize) { - firstComponentSize -= secondMinSize - secondComponentSize; - secondComponentSize = secondMinSize; + else if (size2 < mSize2) { + size2 = mSize2; + size1 = total - size2 - d; } } } } - myProportion = (float)(firstComponentSize / (firstComponentSize + secondComponentSize)); + myProportion = (float)(size1 / total); - firstComponentSize = Math.floor(firstComponentSize); - secondComponentSize = Math.floor(secondComponentSize); + int iSize1 = (int)Math.round(Math.floor(size1)); + int iSize2 = (int)Math.round(total - size1 - d); - if (getOrientation()) { - // fix flooring - secondComponentSize += (int)(height - firstComponentSize - secondComponentSize - dividerWidth); - - firstRect.setBounds(0, 0, (int)width, (int)firstComponentSize); - dividerRect.setBounds(0, (int)firstComponentSize, (int)width, (int)dividerWidth); - secondRect.setBounds(0, (int)(firstComponentSize + dividerWidth), (int)width, (int)secondComponentSize); + if (isVertical()) { + firstRect.setBounds(0, 0, width, iSize1); + dividerRect.setBounds(0, iSize1, width, d); + secondRect.setBounds(0, iSize1 + d, width, iSize2); } else { - // fix flooring - secondComponentSize += (int)(width - firstComponentSize - secondComponentSize - dividerWidth); - - firstRect.setBounds(0, 0, (int)firstComponentSize, (int)height); - dividerRect.setBounds((int)firstComponentSize, 0, (int)dividerWidth, (int)height); - secondRect.setBounds((int)(firstComponentSize + dividerWidth), 0, (int)secondComponentSize, (int)height); + firstRect.setBounds(0, 0, iSize1, height); + dividerRect.setBounds(iSize1, 0, d, height); + secondRect.setBounds((iSize1 + d), 0, iSize2, height); } myDivider.setVisible(true); myFirstComponent.setBounds(firstRect); @@ -306,13 +294,13 @@ public class Splitter extends JPanel { else if (!isNull(myFirstComponent) && myFirstComponent.isVisible()) { // only first component is visible hideNull(mySecondComponent); myDivider.setVisible(false); - myFirstComponent.setBounds(0, 0, (int)width, (int)height); + myFirstComponent.setBounds(0, 0, width, height); myFirstComponent.revalidate(); } else if (!isNull(mySecondComponent) && mySecondComponent.isVisible()) { // only second component is visible hideNull(myFirstComponent); myDivider.setVisible(false); - mySecondComponent.setBounds(0, 0, (int)width, (int)height); + mySecondComponent.setBounds(0, 0, width, height); mySecondComponent.revalidate(); } else { // both components are null or invisible @@ -401,6 +389,13 @@ public class Splitter extends JPanel { return myVerticalSplit; } + /** + * @return true if |-| + */ + public boolean isVertical() { + return myVerticalSplit; + } + /** * @param verticalSplit true means that splitter will have vertical split */ @@ -486,7 +481,7 @@ public class Splitter extends JPanel { private void setOrientation(boolean isVerticalSplit) { removeAll(); - setCursor(getOrientation() ? + setCursor(isVertical() ? Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); @@ -570,7 +565,7 @@ public class Splitter extends JPanel { if (MouseEvent.MOUSE_DRAGGED == e.getID()) { myPoint = SwingUtilities.convertPoint(this, e.getPoint(), Splitter.this); float proportion; - if (getOrientation()) { + if (isVertical()) { if (getHeight() > 0) { proportion = Math.min(1.0f, Math.max(.0f, Math .min(Math.max(getMinProportion(myFirstComponent), (float)myPoint.y / (float)Splitter.this.getHeight()), @@ -593,7 +588,7 @@ public class Splitter extends JPanel { if (isHonorMinimumSize()) { if (component != null && myFirstComponent != null && myFirstComponent.isVisible() && mySecondComponent != null && mySecondComponent.isVisible()) { - if (getOrientation()) { + if (isVertical()) { return (float)component.getMinimumSize().height / (float)(Splitter.this.getHeight() - getDividerWidth()); } else { @@ -623,7 +618,7 @@ public class Splitter extends JPanel { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { - setCursor(getOrientation() ? + setCursor(isVertical() ? Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); } diff --git a/platform/util/testSrc/com/intellij/openapi/ui/SplitterTest.java b/platform/util/testSrc/com/intellij/openapi/ui/SplitterTest.java index c6faea578df2..c801e704622f 100644 --- a/platform/util/testSrc/com/intellij/openapi/ui/SplitterTest.java +++ b/platform/util/testSrc/com/intellij/openapi/ui/SplitterTest.java @@ -20,10 +20,7 @@ import junit.framework.TestCase; import javax.swing.*; import java.awt.*; -import com.intellij.util.concurrency.Semaphore; - public class SplitterTest extends TestCase{ - private static final int RATHER_LATER_INVOKES = 10; public void testResizeVert() { resizeTest(new Splitter(true)); @@ -43,44 +40,51 @@ public class SplitterTest extends TestCase{ splitter.setHonorComponentsMinimumSize(true); - // disabled since honoring min size is rather confusing, reasonable min size is hardcoded instead - //splitter.setSize(new Dimension(500, 500)); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setSize(new Dimension(300, 300)); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setProportion(.1f); - //splitter.doLayout(); - //checkBounds(splitter); - // - ////assertTrue(Math.abs(splitter.getProportion() - jPanel1.getMinimumSize().height / (splitter.getSize().height - splitter.getDividerWidth())) < .00001); - // - //splitter.setProportion(.9f); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setSize(new Dimension(100, 100)); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setProportion(.1f); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setSize(new Dimension(10, 10)); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setSize(new Dimension(100, 100)); - //splitter.doLayout(); - //checkBounds(splitter); - // - //splitter.setSize(new Dimension(150, 150)); - //splitter.doLayout(); - //checkBounds(splitter); + splitter.setSize(new Dimension(500, 500)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(new Dimension(300, 300)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setProportion(.1f); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setProportion(.9f); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(new Dimension(100, 100)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setProportion(.1f); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(new Dimension(10, 10)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(new Dimension(100, 100)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(new Dimension(150, 150)); + splitter.doLayout(); + checkBounds(splitter); + + splitter.setSize(splitter.isVertical() ? new Dimension(150, 1000) : new Dimension(1000, 150)); + for (float f = .01F; f < 1F; f+=.01F) { + splitter.setProportion(f); + splitter.doLayout(); + float proportion = splitter.getProportion(); + assertTrue (proportion>=.1 && proportion<=9); + if (f>=.1 && f<=.89) + assertEquals(f, proportion, 1e-4); + } } @@ -107,24 +111,4 @@ public class SplitterTest extends TestCase{ assertTrue(firstSize.height < firstMinimum.height == secondSize.height < secondMinimum.height); } } - - private void invokeRatherLater(final Runnable runnable) { - invokeRatherLater(runnable, RATHER_LATER_INVOKES); - } - - private void invokeRatherLater(final Runnable runnable, final int n) { - if(n == 0) { - runnable.run(); - } - else { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - invokeRatherLater(runnable, n - 1); - } - }); - } - } - - } From 75c3b867b01409c60c85d47131cfc7ea13ba9f8a Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 20:27:31 +0100 Subject: [PATCH 28/67] remember "create final" option for extract field between restarts, use one from dialog in inplace mode (IDEA-97583) --- .../introduceField/IntroduceFieldCentralPanel.java | 5 ++++- .../refactoring/introduceField/IntroduceFieldPopupPanel.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java index cc07e950aa43..68d5e99cc536 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java @@ -15,6 +15,7 @@ */ package com.intellij.refactoring.introduceField; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; @@ -37,7 +38,8 @@ import java.awt.event.ItemListener; public abstract class IntroduceFieldCentralPanel { protected static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.introduceField.IntroduceFieldDialog"); - public static boolean ourLastCbFinalState = false; + private static final String INTRODUCE_FIELD_FINAL_CHECKBOX = "introduce.final.checkbox"; + public static boolean ourLastCbFinalState = PropertiesComponent.getInstance().getBoolean(INTRODUCE_FIELD_FINAL_CHECKBOX, true); protected final PsiClass myParentClass; protected final PsiExpression myInitializerExpression; @@ -273,6 +275,7 @@ public abstract class IntroduceFieldCentralPanel { public void saveFinalState() { if (myCbFinal != null && myCbFinal.isEnabled()) { ourLastCbFinalState = myCbFinal.isSelected(); + PropertiesComponent.getInstance().setValue(INTRODUCE_FIELD_FINAL_CHECKBOX, String.valueOf(ourLastCbFinalState)); } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index 41a16ece2667..e0e26cbaf4dd 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -92,7 +92,7 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { @Override public boolean isDeclareFinal() { - return allowFinal(); + return ourLastCbFinalState && allowFinal(); } private void selectInCurrentMethod() { From 471f42e0d12fb5ac6efe846e2109e27509cb6cf2 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 21:45:01 +0100 Subject: [PATCH 29/67] simplify b == true -> b != null && b in case of boxed type (IDEA-97560) --- .../PointlessBooleanExpressionInspection.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java index 3757d075af2f..b522c2f1e176 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java @@ -188,8 +188,12 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { private void buildSimplifiedExpression(List expressions, String token, boolean negate, StringBuilder out) { if (expressions.size() == 1) { final PsiExpression expression = expressions.get(0); + final String expressionText = expression.getText(); + if (isBoxedTypeComparison(token, expression)) { + out.append(expressionText).append(" != null && "); + } if (!negate) { - out.append(expression.getText()); + out.append(expressionText); return; } if (ComparisonUtils.isComparison(expression)) { @@ -202,10 +206,10 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { } else { if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.PREFIX_PRECEDENCE) { - out.append("!(").append(expression.getText()).append(')'); + out.append("!(").append(expressionText).append(')'); } else { - out.append('!').append(expression.getText()); + out.append('!').append(expressionText); } } } @@ -229,6 +233,10 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { } } + private static boolean isBoxedTypeComparison(String token, PsiExpression expression) { + return ("==".equals(token) || "!=".equals(token)) && expression instanceof PsiReferenceExpression && expression.getType() instanceof PsiClassType; + } + private void buildSimplifiedPrefixExpression(PsiPrefixExpression expression, StringBuilder out) { final PsiJavaToken sign = expression.getOperationSign(); final IElementType tokenType = sign.getTokenType(); From fc4bdff28acf1285ce39be86d0e9baa1983ecdb2 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 14 Dec 2012 20:51:15 +0100 Subject: [PATCH 30/67] Cleanup --- .../ui/impl/DialogWrapperPeerImpl.java | 144 ++++++++---------- .../util/src/com/intellij/ui/JBColor.java | 2 +- 2 files changed, 63 insertions(+), 83 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java index 31aeaf50fdab..b6f9d07ed1f7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -45,7 +45,6 @@ import com.intellij.ui.*; import com.intellij.ui.mac.foundation.Foundation; import com.intellij.ui.mac.foundation.ID; import com.intellij.ui.mac.foundation.MacUtil; -import com.intellij.ui.popup.StackingPopupDispatcherImpl; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -67,11 +66,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra private DialogWrapper myWrapper; private AbstractDialog myDialog; private boolean myCanBeParent = true; - /* - * Default dialog's actions. - */ private WindowManagerEx myWindowManager; - private final java.util.List myDisposeActions = new ArrayList(); + private final List myDisposeActions = new ArrayList(); private Project myProject; private final ActionCallback myWindowFocusedCallback = new ActionCallback("DialogFocusedCallback"); @@ -89,7 +85,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra */ protected DialogWrapperPeerImpl(DialogWrapper wrapper, @Nullable Project project, boolean canBeParent) { myWrapper = wrapper; - myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : (ActionCallback)null; + myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : null; myWindowManager = null; Application application = ApplicationManager.getApplication(); if (application != null && application.hasComponent(WindowManager.class)) { @@ -100,6 +96,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra if (myWindowManager != null) { if (project == null) { + //noinspection deprecation project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); } @@ -150,7 +147,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } /** - * @param parent parent component whicg is used to canculate heavy weight window ancestor. + * @param parent parent component which is used to calculate heavy weight window ancestor. * parent cannot be null and must be showing. */ protected DialogWrapperPeerImpl(DialogWrapper wrapper, @NotNull Component parent, boolean canBeParent) { @@ -211,18 +208,11 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra return; } - if (owner instanceof Frame) { - myDialog = new MyDialog((Frame)owner, myWrapper, myProject, myWindowFocusedCallback, myTypeAheadDone, myTypeAheadCallback); - } - else { - myDialog = new MyDialog((Dialog)owner, myWrapper, myProject, myWindowFocusedCallback, myTypeAheadDone, myTypeAheadCallback); - } + myDialog = new MyDialog(owner, myWrapper, myProject, myWindowFocusedCallback, myTypeAheadDone, myTypeAheadCallback); myDialog.setModal(true); myCanBeParent = canBeParent; - } - public void toFront() { myDialog.toFront(); } @@ -231,6 +221,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra myDialog.toBack(); } + @SuppressWarnings("SSBasedInspection") protected void dispose() { LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only"); for (Runnable runnable : myDisposeActions) { @@ -243,14 +234,6 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra public void run() { myDialog.dispose(); myProject = null; - /* - if (myWindowManager == null) { - myDialog.dispose(); - } - else { - myWindowManager.hideDialog(myDialog, myProject); - } - */ SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -403,14 +386,6 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra final boolean appStarted = commandProcessor != null; if (myDialog.isModal() && !isProgressDialog()) { - /* - if (ApplicationManager.getApplication() != null) { - if (ApplicationManager.getApplication().getCurrentWriteAction(null) != null) { - LOG.warn( - "Showing of a modal dialog inside write-action may be dangerous and resulting in unpredictable behavior! Current modalityState=" + ModalityState.current(), new Exception()); - } - } - */ if (appStarted) { commandProcessor.enterModal(); LaterInvocator.enterModal(myDialog); @@ -438,16 +413,14 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra return result; } -//[kirillk] for now it only deals with the TaskWindow under Mac OS X: modal dialogs are shown behind JBPopup - //hopefully this whole code will go away private void hidePopupsIfNeeded() { if (!SystemInfo.isMac) return; - StackingPopupDispatcherImpl.getInstance().hidePersistentPopups(); + StackingPopupDispatcher.getInstance().hidePersistentPopups(); myDisposeActions.add(new Runnable() { public void run() { - StackingPopupDispatcherImpl.getInstance().restorePersistentPopups(); + StackingPopupDispatcher.getInstance().restorePersistentPopups(); } }); } @@ -488,6 +461,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra private static class MyDialog extends JDialog implements DialogWrapperDialog, DataProvider, FocusTrackback.Provider, Queryable, AbstractDialog { private final WeakReference myDialogWrapper; + /** * Initial size of the dialog. When the dialog is being closed and * current size of the dialog is not equals to the initial size then the @@ -507,16 +481,12 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra private ActionCallback myTypeAheadCallback; private MyComponentListener myComponentListener; - public MyDialog(Dialog owner, DialogWrapper dialogWrapper, Project project, ActionCallback focused, ActionCallback typeAheadDone, ActionCallback typeAheadCallback) { - super(owner); - myDialogWrapper = new WeakReference(dialogWrapper); - myProject = project != null ? new WeakReference(project) : null; - initDialog(focused, typeAheadDone, typeAheadCallback); - } - - - - public MyDialog(Frame owner, DialogWrapper dialogWrapper, Project project, ActionCallback focused, ActionCallback typeAheadDone, ActionCallback typeAheadCallback) { + public MyDialog(Window owner, + DialogWrapper dialogWrapper, + Project project, + ActionCallback focused, + ActionCallback typeAheadDone, + ActionCallback typeAheadCallback) { super(owner); myDialogWrapper = new WeakReference(dialogWrapper); myProject = project != null ? new WeakReference(project) : null; @@ -605,6 +575,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra return new DialogRootPane(); } + @SuppressWarnings("deprecation") public void show() { myFocusTrackback = new FocusTrackback(getDialogWrapper(), getParent(), true); @@ -628,7 +599,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra location = DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess); Dimension size = DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess); if (size != null) { - myInitialSize = (Dimension)size.clone(); + myInitialSize = new Dimension(size); _setSizeForLocation(myInitialSize.width, myInitialSize.height, location); } } @@ -653,7 +624,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra setBounds(bounds); addWindowListener(new WindowAdapter() { - public void windowActivated(final WindowEvent e) { + @Override + public void windowActivated(WindowEvent e) { final DialogWrapper wrapper = getDialogWrapper(); if (wrapper != null && myFocusTrackback != null) { myFocusTrackback.cleanParentWindow(); @@ -665,10 +637,12 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } - public void windowDeactivated(final WindowEvent e) { + @Override + public void windowDeactivated(WindowEvent e) { if (!isModal()) { final Ref focusManager = new Ref(null); - if (myProject != null && myProject.get() != null && !myProject.get().isDisposed()) { + Project project = getProject(); + if (project != null && !project.isDisposed()) { focusManager.set(getFocusManager()); focusManager.get().doWhenFocusSettlesDown(new Runnable() { public void run() { @@ -681,6 +655,20 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } } + + @Override + public void windowOpened(WindowEvent e) { + if (!SystemInfo.isMacOSLion) return; + Window window = e.getWindow(); + if (window instanceof Dialog) { + ID _native = MacUtil.findWindowForTitle(((Dialog)window).getTitle()); + if (_native != null && _native.intValue() > 0) { + // see MacMainFrameDecorator + // NSCollectionBehaviorFullScreenAuxiliary = 1 << 8 + Foundation.invoke(_native, "setCollectionBehavior:", 1 << 8); + } + } + } }); if (Registry.is("actionSystem.fixLostTyping")) { @@ -697,40 +685,28 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } - if (SystemInfo.isMacOSLion) { - final WindowAdapter macFullScreenPatchListener = new WindowAdapter() { - @Override - public void windowOpened(WindowEvent e) { - Window window = e.getWindow(); - if (window instanceof Dialog) { - ID _native = MacUtil.findWindowForTitle(((Dialog)window).getTitle()); - if (_native != null && _native.intValue() > 0) { - // see MacMainFrameDecorator - // NSCollectionBehaviorFullScreenAuxiliary = 1 << 8 - Foundation.invoke(_native, "setCollectionBehavior:", 1 << 8); - } - } - } - }; - - addWindowListener(macFullScreenPatchListener); - } if (SystemInfo.isMac && myProject != null && Registry.is("ide.mac.fix.dialog.showing") && !dialogWrapper.isModalProgress()) { final IdeFrame frame = WindowManager.getInstance().getIdeFrame(myProject.get()); AppIcon.getInstance().requestFocus(frame); } - setBackground(UIUtil.getPanelBackground()); - superShow(); - } - private void superShow() { + setBackground(UIUtil.getPanelBackground()); + super.show(); } + @Nullable + private Project getProject() { + return myProject != null ? myProject.get() : null; + } + + @Override public IdeFocusManager getFocusManager() { - if (myProject != null && myProject.get() != null && !myProject.get().isDisposed()) { - return IdeFocusManager.getInstance(myProject.get()); - } else { + Project project = getProject(); + if (project != null && !project.isDisposed()) { + return IdeFocusManager.getInstance(project); + } + else { return IdeFocusManager.findInstance(); } } @@ -758,7 +734,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } - @Deprecated + @Override + @SuppressWarnings("deprecation") public void hide() { super.hide(); if (myFocusTrackback != null && !(myFocusTrackback.isSheduledForRestore() || myFocusTrackback.isWillBeSheduledForRestore())) { @@ -774,6 +751,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } + @Override public void dispose() { if (isShowing()) { hide(); @@ -858,6 +836,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra super.paint(g); } + @SuppressWarnings("SSBasedInspection") private class MyWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { DialogWrapper dialogWrapper = getDialogWrapper(); @@ -866,6 +845,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } + @Override public void windowClosed(WindowEvent e) { saveSize(); } @@ -888,7 +868,6 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } - @Override public void windowOpened(WindowEvent e) { SwingUtilities.invokeLater(new Runnable() { @@ -904,6 +883,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra }); } + @Override public void windowActivated(final WindowEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -979,8 +959,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra Robot robot = new Robot(); robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2); } - catch (AWTException exc) { - exc.printStackTrace(); + catch (AWTException e) { + LOG.warn(e); } } } @@ -1016,7 +996,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra public Object getData(@NonNls String dataId) { final DialogWrapper wrapper = myDialogWrapper.get(); - return PlatformDataKeys.UI_DISPOSABLE.is(dataId) ? wrapper.getDisposable() : null; + return wrapper != null && PlatformDataKeys.UI_DISPOSABLE.is(dataId) ? wrapper.getDisposable() : null; } } @@ -1057,7 +1037,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra myEvents.addAll(context.getQueue()); context.getQueue().clear(); - if (isToDipatchToDialogNow(e)) { + if (isToDispatchToDialogNow(e)) { return false; } else { myEvents.add(e); @@ -1065,7 +1045,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra } } - private boolean isToDipatchToDialogNow(KeyEvent e) { + private boolean isToDispatchToDialogNow(KeyEvent e) { return e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_TAB; } diff --git a/platform/util/src/com/intellij/ui/JBColor.java b/platform/util/src/com/intellij/ui/JBColor.java index 4a27f4f8f133..3366a40e88bd 100644 --- a/platform/util/src/com/intellij/ui/JBColor.java +++ b/platform/util/src/com/intellij/ui/JBColor.java @@ -22,7 +22,7 @@ import java.awt.*; /** * @author Konstantin Bulenkov */ -@SuppressWarnings("InspectionUsingJBColors") +@SuppressWarnings("UseJBColor") public class JBColor extends Color { public JBColor(int rgb, int darkRGB) { super(isDark() ? darkRGB : rgb); From 1c7b52b483de0228784d870f85114b0b96449ae0 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 14 Dec 2012 21:47:19 +0100 Subject: [PATCH 31/67] Cleanup --- .../openapi/util/io/FileSystemUtil.java | 2 +- .../util/io/FileAttributesNio2ReadingTest.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java index 4d25175c655d..2b6f845bfb34 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java @@ -43,7 +43,7 @@ import static com.intellij.util.BitUtil.notSet; * @version 11.1 */ public class FileSystemUtil { - public static final String FORCE_USE_NIO2_KEY = "idea.io.use.nio2"; + private static final String FORCE_USE_NIO2_KEY = "idea.io.use.nio2"; private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.io.FileSystemUtil"); diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java index d1d2c395ef53..a97b4b736f9b 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java @@ -19,22 +19,36 @@ import com.intellij.openapi.util.SystemInfo; import org.junit.AfterClass; import org.junit.BeforeClass; +import java.lang.reflect.Field; + import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeTrue; public class FileAttributesNio2ReadingTest extends FileAttributesReadingTest { + private static final String FORCE_USE_NIO_2_KEY; + static { + try { + Field field = FileSystemUtil.class.getDeclaredField("FORCE_USE_NIO2_KEY"); + field.setAccessible(true); + FORCE_USE_NIO_2_KEY = (String)field.get(null); + } + catch (Exception e) { + throw new AssertionError("Please keep constants in sync", e); + } + } + @BeforeClass public static void setUpClass() throws Exception { assumeTrue(SystemInfo.isJavaVersionAtLeast("1.7")); - System.setProperty(FileSystemUtil.FORCE_USE_NIO2_KEY, "true"); + System.setProperty(FORCE_USE_NIO_2_KEY, "true"); FileSystemUtil.resetMediator(); assertEquals("NIO2", FileSystemUtil.getMediatorName()); } @AfterClass public static void tearDownClass() throws Exception { - System.setProperty(FileSystemUtil.FORCE_USE_NIO2_KEY, ""); + System.setProperty(FORCE_USE_NIO_2_KEY, ""); FileSystemUtil.resetMediator(); } } From 0644bd671999a2bb6ee6766f9b24609028ea5cb3 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 14 Dec 2012 21:52:31 +0100 Subject: [PATCH 32/67] compilation fix --- .../intellij/openapi/util/io/FileAttributesNio2ReadingTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java index a97b4b736f9b..a732c3408060 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java @@ -33,7 +33,7 @@ public class FileAttributesNio2ReadingTest extends FileAttributesReadingTest { FORCE_USE_NIO_2_KEY = (String)field.get(null); } catch (Exception e) { - throw new AssertionError("Please keep constants in sync", e); + throw new AssertionError("Please keep constants in sync: " + e.getMessage()); } } From ad00470f1733524cd14d0adab87983b6353d5e77 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 14 Dec 2012 21:57:58 +0100 Subject: [PATCH 33/67] Fix API level inspection settings --- .idea/inspectionProfiles/idea_default.xml | 4 +--- .idea/inspectionProfiles/idea_default_no_spellchecker.xml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index 95664e3124f2..cb79a6725114 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -504,9 +504,7 @@ - - - +