From 833b3494b9a73947b61b2a29410ae3a8484dc391 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 23 Jun 2011 20:48:50 +0400 Subject: [PATCH 01/45] IDEA-70152 close piped writer before closing reader [rev=andrey.zaytsev] --- .../diagnostic/logging/LogConsoleBase.java | 17 +++++++++ .../logging/LogConsoleListener.java | 23 ++++++++++++ .../logcat/AndroidLogcatToolWindowView.java | 36 ++++++++++++++++++- .../android/logcat/AndroidLogcatUtil.java | 10 +++--- .../android/run/AndroidDebugRunner.java | 35 +++++++++++++++++- 5 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleListener.java diff --git a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java index 7afb1c3dceb2..020a6448325e 100644 --- a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java +++ b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java @@ -50,6 +50,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.*; +import java.util.ArrayList; import java.util.List; /** @@ -74,6 +75,8 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L private final boolean myBuildInActions; private LogFilterModel myModel; + private final List myListeners = new ArrayList(); + private FilterComponent myFilter = new FilterComponent("LOG_FILTER_HISTORY", 5) { public void filter() { final Task.Backgroundable task = new Task.Backgroundable(myProject, APPLYING_FILTER_TITLE) { @@ -285,6 +288,10 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L } private void stopRunning(boolean checkActive) { + if (!checkActive) { + fireLoggingWillBeStopped(); + } + if (myReaderThread != null && myReaderThread.myReader != null) { if (!checkActive) { myReaderThread.stopRunning(); @@ -480,6 +487,16 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L myProcessHandler.notifyTextAvailable(text, outputType); } + public void addListener(LogConsoleListener listener) { + myListeners.add(listener); + } + + private void fireLoggingWillBeStopped() { + for (LogConsoleListener listener : myListeners) { + listener.loggingWillBeStopped(); + } + } + private static class LightProcessHandler extends ProcessHandler { protected void destroyProcessImpl() { throw new UnsupportedOperationException(); diff --git a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleListener.java b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleListener.java new file mode 100644 index 000000000000..e7770b516de1 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleListener.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.diagnostic.logging; + +/** + * @author Eugene.Kudelevsky + */ +public interface LogConsoleListener { + void loggingWillBeStopped(); +} diff --git a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowView.java b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowView.java index b583bee0f3d6..6fcc445d2a31 100644 --- a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowView.java +++ b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatToolWindowView.java @@ -19,6 +19,7 @@ import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.intellij.diagnostic.logging.LogConsoleBase; +import com.intellij.diagnostic.logging.LogConsoleListener; import com.intellij.diagnostic.logging.LogFilterModel; import com.intellij.facet.ProjectFacetManager; import com.intellij.openapi.Disposable; @@ -27,6 +28,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Pair; import org.jetbrains.android.actions.AndroidEnableDdmsAction; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.sdk.AndroidPlatform; @@ -41,6 +43,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.io.Reader; +import java.io.Writer; import java.util.List; /** @@ -58,7 +61,9 @@ public abstract class AndroidLogcatToolWindowView implements Disposable { private volatile IDevice myDevice; private final Object myLock = new Object(); private final LogConsoleBase myLogConsole; + private volatile Reader myCurrentReader; + private volatile Writer myCurrentWriter; private final AndroidDebugBridge.IDeviceChangeListener myDeviceChangeListener = new AndroidDebugBridge.IDeviceChangeListener() { public void deviceConnected(IDevice device) { @@ -142,6 +147,19 @@ public abstract class AndroidLogcatToolWindowView implements Disposable { return AndroidLogcatToolWindowView.this.isActive(); } }; + myLogConsole.addListener(new LogConsoleListener() { + @Override + public void loggingWillBeStopped() { + if (myCurrentWriter != null) { + try { + myCurrentWriter.close(); + } + catch (IOException e) { + LOG.error(e); + } + } + } + }); mySearchComponentWrapper.add(myLogConsole.getSearchComponent()); JComponent consoleComponent = myLogConsole.getComponent(); DefaultActionGroup group = new DefaultActionGroup(); @@ -184,6 +202,14 @@ public abstract class AndroidLogcatToolWindowView implements Disposable { if (myDevice != device) { synchronized (myLock) { myDevice = device; + if (myCurrentWriter != null) { + try { + myCurrentWriter.close(); + } + catch (IOException e) { + LOG.error(e); + } + } if (myCurrentReader != null) { try { myCurrentReader.close(); @@ -193,7 +219,15 @@ public abstract class AndroidLogcatToolWindowView implements Disposable { } } if (device != null) { - myCurrentReader = AndroidLogcatUtil.startLoggingThread(myProject, device, false, myLogConsole); + final Pair pair = AndroidLogcatUtil.startLoggingThread(myProject, device, false, myLogConsole); + if (pair != null) { + myCurrentReader = pair.first; + myCurrentWriter = pair.second; + } + else { + myCurrentReader = null; + myCurrentWriter = null; + } } } } diff --git a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatUtil.java b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatUtil.java index d9aabcfd248d..5d38f73b56e1 100644 --- a/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatUtil.java +++ b/plugins/android/src/org/jetbrains/android/logcat/AndroidLogcatUtil.java @@ -23,6 +23,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Pair; import com.intellij.util.ui.UIUtil; import org.jetbrains.android.run.LoggingReceiver; import org.jetbrains.android.util.AndroidBundle; @@ -31,10 +32,7 @@ import org.jetbrains.android.util.AndroidUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.io.PipedReader; -import java.io.PipedWriter; -import java.io.Reader; +import java.io.*; import java.util.HashMap; import java.util.Map; @@ -99,7 +97,7 @@ public class AndroidLogcatUtil { } @Nullable - public static Reader startLoggingThread(final Project project, + public static Pair startLoggingThread(final Project project, final IDevice device, final boolean clearLogcat, @NotNull final LogConsoleBase console) { @@ -155,6 +153,6 @@ public class AndroidLogcatUtil { }); } }); - return logReader; + return new Pair(logReader, logWriter); } } diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java b/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java index 6d21ae5749be..4dc384827c67 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java @@ -20,6 +20,7 @@ import com.intellij.debugger.engine.RemoteDebugProcessHandler; import com.intellij.debugger.ui.DebuggerPanelsManager; import com.intellij.debugger.ui.DebuggerSessionTab; import com.intellij.diagnostic.logging.LogConsoleBase; +import com.intellij.diagnostic.logging.LogConsoleListener; import com.intellij.execution.*; import com.intellij.execution.configurations.*; import com.intellij.execution.executors.DefaultDebugExecutor; @@ -34,8 +35,10 @@ import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.RunContentManager; import com.intellij.execution.ui.layout.LayoutViewOptions; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiClass; import org.jetbrains.android.dom.manifest.Instrumentation; import org.jetbrains.android.dom.manifest.Manifest; @@ -47,7 +50,9 @@ import org.jetbrains.android.util.AndroidUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.io.Reader; +import java.io.Writer; import static com.intellij.execution.process.ProcessOutputTypes.STDERR; @@ -55,6 +60,8 @@ import static com.intellij.execution.process.ProcessOutputTypes.STDERR; * @author coyote */ public class AndroidDebugRunner extends DefaultProgramRunner { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.run.AndroidDebugRunner"); + private static final Key ANDROID_PROCESS_HANDLER = new Key("ANDROID_PROCESS_HANDLER"); private static final Object myReaderLock = new Object(); @@ -236,7 +243,9 @@ public class AndroidDebugRunner extends DefaultProgramRunner { RunProfile profile = myEnvironment.getRunProfile(); assert profile instanceof AndroidRunConfigurationBase; final Reader[] readerWrapper = new Reader[1]; + final Writer[] writerWrapper = new Writer[1]; String logcatTabTitle = AndroidBundle.message("android.logcat.tab.title"); + LogConsoleBase console = sessionTab.addLogConsole(logcatTabTitle, new AndroidLoggingReader() { @NotNull protected Object getLock() { @@ -247,9 +256,33 @@ public class AndroidDebugRunner extends DefaultProgramRunner { return readerWrapper[0]; } }, 0, AndroidUtils.ANDROID_ICON); + + console.addListener(new LogConsoleListener() { + @Override + public void loggingWillBeStopped() { + final Writer writer = writerWrapper[0]; + if (writer != null) { + try { + writer.close(); + } + catch (IOException e) { + LOG.error(e); + } + } + } + }); + synchronized (myReaderLock) { - readerWrapper[0] = + final Pair pair = AndroidLogcatUtil.startLoggingThread(myProject, device, ((AndroidRunConfigurationBase)profile).CLEAR_LOGCAT, console); + if (pair != null) { + readerWrapper[0] = pair.first; + writerWrapper[0] = pair.second; + } + else { + readerWrapper[0] = null; + writerWrapper[0] = null; + } } if (!(profile instanceof AndroidTestRunConfiguration)) { String logcatContentId = DebuggerSessionTab.getLogContentId(logcatTabTitle); From e9b3994feab4c532d82fe303673fe7664c1a3ca6 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 23 Jun 2011 20:02:00 +0400 Subject: [PATCH 02/45] avoid up/down when rb is not visible (IDEA-71352) --- .../MoveClassesOrPackagesHandlerBase.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java index b77a7c33c909..9457fad65513 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java @@ -317,7 +317,7 @@ public class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate { moveDirectoryDescription = "Move everything from " + myDirectories[0].getVirtualFile().getPresentableUrl() + " to another directory"; } myRbMoveDirectory = new JRadioButton(); - myRbMoveDirectory.setMnemonic('d'); + myRbMoveDirectory.setMnemonic('e'); myRbMoveDirectory.setText(moveDirectoryDescription); ButtonGroup gr = new ButtonGroup(); @@ -325,7 +325,11 @@ public class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate { gr.add(myRbRearrangePackage); gr.add(myRbMoveDirectory); - new RadioUpDownListener(myRbMovePackage, myRbRearrangePackage, myRbMoveDirectory); + if (myRearrangePackagesEnabled) { + new RadioUpDownListener(myRbMovePackage, myRbRearrangePackage, myRbMoveDirectory); + } else { + new RadioUpDownListener(myRbMovePackage, myRbMoveDirectory); + } Box box = Box.createVerticalBox(); box.add(Box.createVerticalStrut(5)); From 144e5fa172a37383c9ebaf0fb8f1f1878744a7c8 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 24 Jun 2011 10:14:07 +0200 Subject: [PATCH 03/45] IDEA-71354 XSLT debug: error in xslt.transformer.type value: RE at XsltDebuggerRunner$1.start() and no user-friendly message --- .../org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java index f683c03a5acc..d61e904f0646 100644 --- a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java +++ b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java @@ -67,13 +67,11 @@ public class XsltDebuggerRunner extends JavaPatchableProgramRunner { final XDebugSession debugSession = XDebuggerManager.getInstance(project).startSession(this, executionEnvironment, contentToReuse, new XDebugProcessStarter() { @NotNull - public XDebugProcess start(@NotNull final XDebugSession session) { + public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException { ACTIVE.set(Boolean.TRUE); try { final ExecutionResult result = runProfileState.execute(executor, XsltDebuggerRunner.this); return new XsltDebugProcess(session, result); - } catch (ExecutionException e) { - throw new RuntimeException(e); } finally { ACTIVE.remove(); } From bb787a865663ff7613ccf99540aaa48e8a3c3ce8 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 12:21:08 +0400 Subject: [PATCH 04/45] EA-28513 (NPE fixed) --- .../daemon/impl/analysis/HighlightControlFlowUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java index 94f379eb94f7..0c4ac7193054 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -687,7 +687,7 @@ public class HighlightControlFlowUtil { else { scope = new PsiElement[]{variable.getParent()}; } - if (scope.length < 1 || scope[0].getContainingFile() != context.getContainingFile()) return null; + if (scope.length < 1 || scope[0] == null || scope[0].getContainingFile() != context.getContainingFile()) return null; PsiElement parent = context.getParent(); PsiElement prevParent = context; From 8138c37581bcf74c6d769cd15022ff6b687187b9 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 24 Jun 2011 12:26:21 +0400 Subject: [PATCH 05/45] redundant casts: avoid false positives with dbl cast through raw type --- .../intellij/psi/util/RedundantCastUtil.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java b/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java index 8cb12c23b818..236e16beea13 100644 --- a/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java @@ -330,7 +330,14 @@ public class RedundantCastUtil { PsiTypeElement typeElement = ((PsiTypeCastExpression)expr).getCastType(); if (typeElement == null) return; PsiType castType = typeElement.getType(); + final PsiExpression innerOperand = ((PsiTypeCastExpression)expr).getOperand(); + final PsiType operandType = innerOperand != null ? innerOperand.getType() : null; + final PsiType topCastType = typeCast.getType(); if (!(castType instanceof PsiPrimitiveType)) { + if (operandType != null && topCastType != null && TypeConversionUtil.areTypesConvertible(operandType, topCastType)) { + addToResults((PsiTypeCastExpression)expr); + } + } else if (PsiPrimitiveType.getUnboxedType(operandType) == topCastType) { addToResults((PsiTypeCastExpression)expr); } } @@ -341,17 +348,6 @@ public class RedundantCastUtil { //branches need to be of the same type if (!Comparing.equal(operand.getType(), ((PsiConditionalExpression)parent).getType())) return; } - } else if (parent instanceof PsiTypeCastExpression) { - PsiTypeElement typeElement = ((PsiTypeCastExpression)parent).getCastType(); - if (typeElement != null) { - PsiType castType = typeElement.getType(); - if (castType instanceof PsiPrimitiveType) { - final PsiType operandType = operand.getType(); - if (!(operandType instanceof PsiPrimitiveType) && PsiPrimitiveType.getUnboxedType(operandType) != castType) { - return; - } - } - } } processAlreadyHasTypeCast(typeCast); } @@ -362,6 +358,8 @@ public class RedundantCastUtil { PsiElement parent = typeCast.getParent(); while(parent instanceof PsiParenthesizedExpression) parent = parent.getParent(); if (parent instanceof PsiExpressionList) return; // do not replace in arg lists - should be handled by parent + if (parent instanceof PsiReturnStatement) return; + if (parent instanceof PsiTypeCastExpression) return; if (isTypeCastSemantical(typeCast)) return; From 4b63b882ac49b633b614a02f369694cad3a7f894 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 22 Jun 2011 18:07:09 +0200 Subject: [PATCH 06/45] tolerate empty build numbers in plugin.xml --- .../openapi/updateSettings/impl/PluginDownloader.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java index e66ac0fd00b8..7b46296af291 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java @@ -142,11 +142,13 @@ public class PluginDownloader { return false; //was not updated } final BuildNumber currentBuildNumber = ApplicationInfo.getInstance().getBuild(); - final BuildNumber sinceBuild = BuildNumber.fromString(descriptor.getSinceBuild(), descriptor.getName()); + String sinceBuildString = descriptor.getSinceBuild(); + final BuildNumber sinceBuild = StringUtil.isEmptyOrSpaces(sinceBuildString) ? null : BuildNumber.fromString(sinceBuildString, descriptor.getName()); if (sinceBuild != null && sinceBuild.compareTo(currentBuildNumber) > 0) { return false; } - final BuildNumber untilBuild = BuildNumber.fromString(descriptor.getUntilBuild(), descriptor.getName()); + String untilBuildString = descriptor.getUntilBuild(); + final BuildNumber untilBuild = StringUtil.isEmptyOrSpaces(untilBuildString) ? null : BuildNumber.fromString(untilBuildString, descriptor.getName()); if (untilBuild != null && untilBuild.compareTo(currentBuildNumber) < 0) { return false; } From c60bdcdfc651c3589817177dc016db29fe994b41 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Jun 2011 11:13:33 +0200 Subject: [PATCH 07/45] don't highlight license text as typos --- .../spellchecker/src/com/intellij/spellchecker/jetbrains.dic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index c38b96077a3f..551473de03c1 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -225,6 +225,7 @@ nomaxvalue nominvalue nomonitoring nonatomic +noninfingement nonschema noorder noparallel @@ -343,6 +344,7 @@ stdarg stdlib stmt stylesheet +sublicense subpackage subpartition subpartitions From 2b80f1d4e17afd75db50106a395dd1b18089e007 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Jun 2011 12:11:53 +0200 Subject: [PATCH 08/45] one more licensey word --- plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index 551473de03c1..5ffc7bc0b5bd 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -285,6 +285,7 @@ pycharm readonly readwrite rect +redistributions refactor refactored refactoring From 547acb79ead82c8345660999eb9f664dafad4723 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Jun 2011 13:01:30 +0200 Subject: [PATCH 09/45] double-click on .ui file opens it in Qt Designer --- .../src/com/intellij/psi/impl/ElementBase.java | 2 +- .../openapi/fileEditor/OpenFileDescriptor.java | 3 +-- .../intellij/openapi/fileTypes/INativeFileType.java | 5 +++++ .../intellij/openapi/fileTypes/NativeFileType.java | 11 +++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/impl/ElementBase.java b/platform/lang-api/src/com/intellij/psi/impl/ElementBase.java index 5ea69fde9f2c..c9666cc88204 100644 --- a/platform/lang-api/src/com/intellij/psi/impl/ElementBase.java +++ b/platform/lang-api/src/com/intellij/psi/impl/ElementBase.java @@ -135,7 +135,7 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable } public static boolean isNativeFileType(FileType fileType) { - return fileType instanceof INativeFileType || fileType instanceof UnknownFileType; + return (fileType instanceof INativeFileType && ((INativeFileType) fileType).useNativeIcon()) || fileType instanceof UnknownFileType; } protected Icon getAdjustedBaseIcon(Icon icon, int flags) { diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java index ef687bdfd753..3faeb8198840 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java @@ -23,7 +23,6 @@ import com.intellij.openapi.editor.*; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.INativeFileType; -import com.intellij.openapi.fileTypes.NativeFileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; @@ -123,7 +122,7 @@ public class OpenFileDescriptor implements Navigatable { if (type == null || !myFile.isValid()) return false; if (type instanceof INativeFileType) { - return NativeFileType.openAssociatedApplication(myFile); + return ((INativeFileType) type).openFileInAssociatedApplication(project, myFile); } return navigateInRequestedEditor() || navigateInAnyFileEditor(project, focusEditor); diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/INativeFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/INativeFileType.java index 842b009da270..3bc6bf4f8ff4 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/INativeFileType.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/INativeFileType.java @@ -1,4 +1,9 @@ package com.intellij.openapi.fileTypes; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; + public interface INativeFileType extends FileType { + boolean openFileInAssociatedApplication(Project project, VirtualFile file); + boolean useNativeIcon(); } diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/NativeFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/NativeFileType.java index 57a2c754d9f9..cf28c47f6a79 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/NativeFileType.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/NativeFileType.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.fileTypes; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.VirtualFile; @@ -66,6 +67,16 @@ public class NativeFileType implements INativeFileType { return null; } + @Override + public boolean openFileInAssociatedApplication(Project project, VirtualFile file) { + return openAssociatedApplication(file); + } + + @Override + public boolean useNativeIcon() { + return true; + } + public static boolean openAssociatedApplication(VirtualFile file) { List commands = new ArrayList(); if (SystemInfo.isWindows) { From 3e90ecbbead4791fe6d92f8361b591fde4bf5e33 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Jun 2011 18:14:31 +0200 Subject: [PATCH 10/45] refactor to extract common code for running a process and showing the output in a Run toolwindow tab --- .../execution/RunContentExecutor.java | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 platform/lang-impl/src/com/intellij/execution/RunContentExecutor.java diff --git a/platform/lang-impl/src/com/intellij/execution/RunContentExecutor.java b/platform/lang-impl/src/com/intellij/execution/RunContentExecutor.java new file mode 100644 index 000000000000..f0943def7629 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/RunContentExecutor.java @@ -0,0 +1,136 @@ +package com.intellij.execution; + +import com.intellij.execution.executors.DefaultRunExecutor; +import com.intellij.execution.filters.Filter; +import com.intellij.execution.filters.TextConsoleBuilder; +import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.process.ProcessAdapter; +import com.intellij.execution.process.ProcessEvent; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.execution.ui.RunContentDescriptor; +import com.intellij.execution.ui.actions.CloseAction; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.openapi.wm.ToolWindowManager; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Runs a process and prints the output in a content tab within the Run toolwindow. + * + * @author yole + */ +public class RunContentExecutor { + private final Project myProject; + private final ProcessHandler myProcess; + private final List myFilterList = new ArrayList(); + private Runnable myRerun; + private Runnable myAfterCompletion; + private String myTitle = "Output"; + + public RunContentExecutor(Project project, ProcessHandler process) { + myProject = project; + myProcess = process; + } + + public RunContentExecutor withFilter(Filter filter) { + myFilterList.add(filter); + return this; + } + + public RunContentExecutor withTitle(String title) { + myTitle = title; + return this; + } + + public RunContentExecutor withRerun(Runnable rerun) { + myRerun = rerun; + return this; + } + + public RunContentExecutor withAfterCompletion(Runnable afterCompletion) { + myAfterCompletion = afterCompletion; + return this; + } + + private ConsoleView createConsole(Project project, ProcessHandler processHandler) { + TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(project); + for (Filter filter : myFilterList) { + consoleBuilder.addFilter(filter); + } + ConsoleView console = consoleBuilder.getConsole(); + console.attachToProcess(processHandler); + return console; + } + + public void run() { + FileDocumentManager.getInstance().saveAllDocuments(); + + ConsoleView view = createConsole(myProject, myProcess); + Executor executor = ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); + DefaultActionGroup actions = new DefaultActionGroup(); + + final JComponent consolePanel = createConsolePanel(view, actions); + RunContentDescriptor descriptor = new RunContentDescriptor(view, myProcess, consolePanel, myTitle); + + actions.add(new RerunAction(consolePanel)); + actions.add(new CloseAction(executor, descriptor, myProject)); + + ExecutionManager.getInstance(myProject).getContentManager().showRunContent(executor, descriptor); + + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.RUN).activate(null); + } + }); + + if (myAfterCompletion != null) { + myProcess.addProcessListener(new ProcessAdapter() { + public void processTerminated(ProcessEvent event) { + SwingUtilities.invokeLater(myAfterCompletion); + } + }); + } + + myProcess.startNotify(); + } + + private static JComponent createConsolePanel(ConsoleView view, ActionGroup actions) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(view.getComponent(), BorderLayout.CENTER); + panel.add(createToolbar(actions), BorderLayout.WEST); + return panel; + } + + private static JComponent createToolbar(ActionGroup actions) { + ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, false); + return actionToolbar.getComponent(); + } + + private class RerunAction extends AnAction implements DumbAware { + public RerunAction(JComponent consolePanel) { + super("Rerun", "Rerun", + IconLoader.getIcon("/actions/refreshUsages.png")); + registerCustomShortcutSet(CommonShortcuts.getRerun(), consolePanel); + } + + public void actionPerformed(AnActionEvent e) { + myRerun.run(); + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setVisible(myRerun != null); + } + } +} From 655c371db7a8d78aa577be9fa3f028867d2be155 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 12:39:10 +0400 Subject: [PATCH 11/45] EA-28491 (more logging) --- .../com/intellij/psi/JavaStubBuilderTest.java | 9 +++++---- .../com/intellij/psi/stubs/LightStubBuilder.java | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java index 1f9a689f212d..45a08cbf7b46 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,20 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.io.FileUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.impl.DebugUtil; -import com.intellij.psi.impl.source.JavaFileStubBuilder; import com.intellij.psi.impl.source.JavaLightStubBuilder; import com.intellij.psi.stubs.StubElement; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.ThrowableRunnable; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.security.SecureRandom; public class JavaStubBuilderTest extends LightIdeaTestCase { - private static final StubBuilder OLD_BUILDER = new JavaFileStubBuilder(); + @SuppressWarnings("deprecation") + private static final StubBuilder OLD_BUILDER = new com.intellij.psi.impl.source.JavaFileStubBuilder(); private static final StubBuilder NEW_BUILDER = new JavaLightStubBuilder(); private static final int SOE_TEST_DEPTH = 20000; @@ -364,7 +365,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { }).cpuBound().assertTiming(); } - private static void doTest(final String source, final String tree) { + private static void doTest(final String source, @Nullable final String tree) { final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", source); final FileASTNode fileNode = file.getNode(); assertNotNull(fileNode); diff --git a/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java b/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java index 89d0b0356e40..85bf4e34627a 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java +++ b/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.psi.stubs; import com.intellij.lang.*; +import com.intellij.openapi.diagnostic.LogUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; @@ -139,7 +140,7 @@ public class LightStubBuilder implements StubBuilder { } } else { - LOG.error("Element is not of ILighterStubElementType: " + elementType + ", " + element); + LOG.error("Element is not of ILightStubElementType: " + LogUtil.objectAndClass(elementType) + ", " + element); } } @@ -259,6 +260,11 @@ public class LightStubBuilder implements StubBuilder { public int hashCode() { return myNode.hashCode(); } + + @Override + public String toString() { + return "node wrapper[" + myNode + "]"; + } } private static class TokenNodeWrapper extends NodeWrapper implements LighterASTTokenNode { @@ -270,6 +276,11 @@ public class LightStubBuilder implements StubBuilder { public CharSequence getText() { return myNode.getText(); } + + @Override + public String toString() { + return "token wrapper[" + myNode + "]"; + } } } } \ No newline at end of file From 99a1c5098a120c0de71fa2d6f1f53d3e1964d349 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 24 Jun 2011 10:31:39 +0200 Subject: [PATCH 12/45] IDEA-71362 XSLT debug: NPE at RemoteBreakpointImpl.setEnabled() on setting a breakpoint with running debug session --- .../rt/engine/remote/RemoteBreakpointImpl.java | 9 +++++++-- .../rt/engine/remote/RemoteBreakpointManagerImpl.java | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointImpl.java b/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointImpl.java index 08724c146e98..d059f745604d 100644 --- a/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointImpl.java +++ b/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointImpl.java @@ -31,7 +31,8 @@ import java.util.List; class RemoteBreakpointImpl extends PortableRemoteObject implements RemoteBreakpoint { private final Breakpoint myBreakpoint; - public RemoteBreakpointImpl(Breakpoint breakpoint) throws RemoteException { + private RemoteBreakpointImpl(Breakpoint breakpoint) throws RemoteException { + assert breakpoint != null; myBreakpoint = breakpoint; } @@ -86,8 +87,12 @@ class RemoteBreakpointImpl extends PortableRemoteObject implements RemoteBreakpo public static List convert(List list) throws RemoteException { final ArrayList breakpoints = new ArrayList(list.size()); for (Breakpoint breakpoint : list) { - breakpoints.add(new RemoteBreakpointImpl(breakpoint)); + breakpoints.add(create(breakpoint)); } return breakpoints; } + + public static RemoteBreakpointImpl create(Breakpoint breakpoint) throws RemoteException { + return breakpoint != null ? new RemoteBreakpointImpl(breakpoint) : null; + } } diff --git a/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointManagerImpl.java b/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointManagerImpl.java index 15255be03195..a732b9cbf2d9 100644 --- a/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointManagerImpl.java +++ b/plugins/xslt-debugger/engine/src/org/intellij/plugins/xsltDebugger/rt/engine/remote/RemoteBreakpointManagerImpl.java @@ -37,11 +37,11 @@ class RemoteBreakpointManagerImpl extends PortableRemoteObject implements Remote } public RemoteBreakpoint setBreakpoint(File file, int line) throws RemoteException { - return new RemoteBreakpointImpl(myManager.setBreakpoint(file, line)); + return RemoteBreakpointImpl.create(myManager.setBreakpoint(file, line)); } public RemoteBreakpoint setBreakpoint(String uri, int line) throws RemoteException { - return new RemoteBreakpointImpl(myManager.setBreakpoint(uri, line)); + return RemoteBreakpointImpl.create(myManager.setBreakpoint(uri, line)); } public void removeBreakpoint(String uri, int line) { @@ -53,6 +53,6 @@ class RemoteBreakpointManagerImpl extends PortableRemoteObject implements Remote } public RemoteBreakpoint getBreakpoint(String uri, int lineNumber) throws RemoteException { - return new RemoteBreakpointImpl(myManager.getBreakpoint(uri, lineNumber)); + return RemoteBreakpointImpl.create(myManager.getBreakpoint(uri, lineNumber)); } } From 238cea492792f6e50dcf8cbbd416cb3011d18dbd Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 24 Jun 2011 10:38:02 +0200 Subject: [PATCH 13/45] IDEA-71356 XSLT debug: breakpoint on closing XML tag causes AE at BreakpointManagerImpl.setBreakpoint() --- .../plugins/xsltDebugger/impl/XsltBreakpointHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/impl/XsltBreakpointHandler.java b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/impl/XsltBreakpointHandler.java index 7f6a02d84c6b..2bdd6b6cec44 100644 --- a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/impl/XsltBreakpointHandler.java +++ b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/impl/XsltBreakpointHandler.java @@ -45,6 +45,12 @@ public class XsltBreakpointHandler extends XBreakpointHandler Date: Fri, 24 Jun 2011 13:00:56 +0400 Subject: [PATCH 14/45] Couple of tests --- .../daemon/quickFix/LightQuickFixTestCase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java index 636a174fbbc6..f874f78c26c2 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -158,6 +158,13 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase doAction(text, actionShouldBeAvailable, testFullPath, testName, myWrapper); } + protected void doAction(final String actionName) { + final List available = getAvailableActions(); + final IntentionAction action = findActionWithText(available, actionName); + assertNotNull("Action '" + actionName + "' not found among " + available.toString(), action); + invoke(action); + } + protected static void invoke(IntentionAction action) throws IncorrectOperationException { ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText()); } From 73c804ed74d5bb68712c34ff2ec3ad807fa34e9f Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Fri, 24 Jun 2011 13:27:29 +0400 Subject: [PATCH 15/45] IDEA-71304 Editor: Correct brace highlighting for the active debugger line 1. Returned bounding line highlighter to the first non-white space offset with the comment that explains the rationale; 2. Corrected highlighting processing in order to make more respect to the 'lines in range' highlight target area; --- .../openapi/editor/impl/IterationState.java | 57 ++++++++++++++++++- .../openapi/editor/impl/MarkupModelImpl.java | 6 +- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index 2c7ee78c7ad2..47c0c10bb383 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -118,10 +118,10 @@ public final class IterationState { private class HighlighterSweep { private RangeHighlighterEx myNextHighlighter = null; - private Iterator myIterator; + private PushBackIterator myIterator; private void init(@NotNull MarkupModelEx markupModel, int start, int end) { - myIterator = markupModel.overlappingIterator(start, end); + myIterator = new PushBackIterator(markupModel.overlappingIterator(start, end)); int skipped = 0; while (myIterator.hasNext()) { RangeHighlighterEx highlighter = myIterator.next(); @@ -143,6 +143,20 @@ public final class IterationState { myCurrentHighlighters.add(myNextHighlighter); myNextHighlighter = null; } + + // There is a possible case that there are two highlighters mapped to offset of the first non-white space symbol + // on a line. The second one may have HighlighterTargetArea.LINES_IN_RANGE area, so, we should use it for indent + // background processing (that is the case for the active debugger line that starts with highlighted brace/bracket). + // So, we check if it's worth to use next highlighter here. + else if (myIterator.hasNext()) { + final RangeHighlighterEx lookAhead = myIterator.next(); + if (lookAhead.getAffectedAreaStartOffset() <= myStartOffset) { + myCurrentHighlighters.add(lookAhead); + } + else { + myIterator.pushBack(lookAhead); + } + } } while (myNextHighlighter == null && myIterator.hasNext()) { @@ -475,4 +489,43 @@ public final class IterationState { return o1Length - o2Length; } } + + private static class PushBackIterator implements Iterator { + + private final Iterator myDelegate; + private T myPushedBack; + + PushBackIterator(Iterator delegate) { + myDelegate = delegate; + } + + @Override + public boolean hasNext() { + return myPushedBack != null || myDelegate.hasNext(); + } + + @Override + public T next() { + if (myPushedBack != null) { + T result = myPushedBack; + myPushedBack = null; + return result; + } + return myDelegate.next(); + } + + @Override + public void remove() { + if (myPushedBack == null) { + myDelegate.remove(); + } + else { + myPushedBack = null; + } + } + + public void pushBack(T element) { + myPushedBack = element; + } + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java index 7a6dcfc033b5..e74abb1f77bd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java @@ -69,8 +69,10 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx throw new IndexOutOfBoundsException("lineNumber:" + lineNumber + ". Must be in [0, " + (getDocument().getLineCount() - 1) + "]"); } - int offset = getDocument().getLineStartOffset(lineNumber); - //int offset = getFirstNonspaceCharOffset(getDocument(), lineNumber); + // The rationale why we don't bind to the line start offset here is that following: suppose particular breakpoint is hit + // during debugging. We may want to type at the active line indent and highlighted string will be moved one line + // down as well then. + int offset = getFirstNonspaceCharOffset(getDocument(), lineNumber); return addRangeHighlighter(offset, offset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); } From 4a27f20f1c756e222c4962738666b271fb0290f3 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 24 Jun 2011 14:00:07 +0400 Subject: [PATCH 16/45] exception --- .../codeInsight/highlighting/BraceHighlightingHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java index 90ff3154c7d1..468ba53943ba 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java @@ -180,7 +180,7 @@ public class BraceHighlightingHandler { } public void updateBraces() { - if (myPsiFile == null) return; + if (myPsiFile == null || !myPsiFile.isValid()) return; clearBraceHighlighters(); From cf24e13eeb7241a0cbeff5376c2fbae87f10e711 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Fri, 24 Jun 2011 14:52:24 +0400 Subject: [PATCH 17/45] IDEA-71224 Paste multiple items from clipboard history --- .../editor/actions/ContentChooser.java | 49 ++++++++++++++++--- .../editor/actions/MultiplePasteAction.java | 18 +++++-- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actions/ContentChooser.java b/platform/platform-api/src/com/intellij/openapi/editor/actions/ContentChooser.java index 32de0990bfe4..28c8d329d2f5 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actions/ContentChooser.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actions/ContentChooser.java @@ -30,6 +30,7 @@ import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.components.JBList; import com.intellij.util.ArrayUtil; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -54,11 +55,17 @@ public abstract class ContentChooser extends DialogWrapper { private Splitter mySplitter; private final Project myProject; + private final boolean myAllowMultipleSelections; public ContentChooser(Project project, String title, boolean useIdeaEditor) { + this(project, title, useIdeaEditor, false); + } + + public ContentChooser(Project project, String title, boolean useIdeaEditor, boolean allowMultipleSelections) { super(project, true); myProject = project; myUseIdeaEditor = useIdeaEditor; + myAllowMultipleSelections = allowMultipleSelections; setOKButtonText(CommonBundle.getOkButtonText()); setTitle(title); @@ -72,7 +79,9 @@ public abstract class ContentChooser extends DialogWrapper { protected JComponent createCenterPanel() { myList = new JBList(); - myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION + : ListSelectionModel.SINGLE_SELECTION; + myList.setSelectionMode(selectionMode); rebuildListContent(); @@ -92,15 +101,21 @@ public abstract class ContentChooser extends DialogWrapper { myList.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { - int selectedIndex = getSelectedIndex(); - int size = myAllContents.size(); - removeContentAt(myAllContents.get(selectedIndex)); + int newSelectionIndex = -1; + for (int i : getSelectedIndices()) { + removeContentAt(myAllContents.get(i)); + if (newSelectionIndex < 0) { + newSelectionIndex = i; + } + } + rebuildListContent(); - if (size == 1) { + if (myAllContents.size() <= 0) { close(CANCEL_EXIT_CODE); return; } - myList.setSelectedIndex(Math.min(selectedIndex, myAllContents.size() - 1)); + newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1); + myList.setSelectedIndex(newSelectionIndex); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { close(OK_EXIT_CODE); @@ -141,8 +156,11 @@ public abstract class ContentChooser extends DialogWrapper { private void updateViewerForSelection() { if (myAllContents.size() == 0) return; - String fullString = getStringRepresentationFor(myAllContents.get(getSelectedIndex())); - fullString = StringUtil.convertLineSeparators(fullString); + String fullString = ""; + for (int i : getSelectedIndices()) { + String s = getStringRepresentationFor(myAllContents.get(i)); + fullString += StringUtil.convertLineSeparators(s); + } if (myViewer != null) { EditorFactory.getInstance().releaseEditor(myViewer); @@ -219,11 +237,26 @@ public abstract class ContentChooser extends DialogWrapper { if (myList.getSelectedIndex() == -1) return 0; return myList.getSelectedIndex(); } + + @NotNull + public int[] getSelectedIndices() { + return myList.getSelectedIndices(); + } public List getAllContents() { return myAllContents; } + @NotNull + public String getSelectedText() { + String result = ""; + for (int i : getSelectedIndices()) { + String s = getStringRepresentationFor(myAllContents.get(i)); + result += StringUtil.convertLineSeparators(s); + } + return result; + } + private static class MyListCellRenderer extends ColoredListCellRenderer { protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { // Fix GTK background diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java index 4846893c0429..8fc0d2190460 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java @@ -23,12 +23,14 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.UIBundle; import javax.swing.*; import javax.swing.text.DefaultEditorKit; import java.awt.*; import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; @@ -52,8 +54,9 @@ public class MultiplePasteAction extends AnAction implements DumbAware { if (!(focusedComponent instanceof JComponent)) return; + final CopyPasteManagerEx copyPasteManager = (CopyPasteManagerEx)CopyPasteManager.getInstance(); final ContentChooser chooser = new ContentChooser(project, UIBundle.message( - "choose.content.to.paste.dialog.title"), true){ + "choose.content.to.paste.dialog.title"), true, true){ protected String getStringRepresentationFor(final Transferable content) { try { return (String)content.getTransferData(DataFlavor.stringFlavor); @@ -71,7 +74,7 @@ public class MultiplePasteAction extends AnAction implements DumbAware { } protected void removeContentAt(final Transferable content) { - ((CopyPasteManagerEx)CopyPasteManager.getInstance()).removeContent(content); + copyPasteManager.removeContent(content); } }; @@ -79,12 +82,17 @@ public class MultiplePasteAction extends AnAction implements DumbAware { chooser.show(); } else { - chooser.close(ContentChooser.CANCEL_EXIT_CODE); + chooser.close(DialogWrapper.CANCEL_EXIT_CODE); } if (chooser.isOK()) { - final int selectedIndex = chooser.getSelectedIndex(); - ((CopyPasteManagerEx)CopyPasteManager.getInstance()).moveContentTopStackTop(chooser.getAllContents().get(selectedIndex)); + final int[] selectedIndices = chooser.getSelectedIndices(); + if (selectedIndices.length == 1) { + copyPasteManager.moveContentTopStackTop(chooser.getAllContents().get(selectedIndices[0])); + } + else { + copyPasteManager.setContents(new StringSelection(chooser.getSelectedText())); + } if (editor != null) { if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){ From 6a9c7314e386c53e3989c9bacb08ee0b4e5a40ec Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 15:09:24 +0400 Subject: [PATCH 18/45] EA-26394 java.util.ConcurrentModificationException at java.util.TreeMap$NavigableSubMap$SubMapIterator.nextEntry(TreeMap.java:1572) at java.util.TreeMap$NavigableSubMap$SubMapKeyIterator.next(TreeMap.java:1633) at com.intellij.openapi.vcs.changes.RecursiveFileHolder.containsFile(RecursiveFileHolder.java:67) --- .../openapi/vcs/changes/IgnoredFilesCompositeHolder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesCompositeHolder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesCompositeHolder.java index 8360723f824f..899a2db689fc 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesCompositeHolder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesCompositeHolder.java @@ -61,7 +61,9 @@ public class IgnoredFilesCompositeHolder implements IgnoredFilesHolder { @Override public FileHolder copy() { final IgnoredFilesCompositeHolder result = new IgnoredFilesCompositeHolder(myProject); - result.myHolderMap.putAll(new HashMap(myHolderMap)); + for (Map.Entry entry : myHolderMap.entrySet()) { + result.myHolderMap.put(entry.getKey(), (IgnoredFilesHolder) entry.getValue().copy()); + } return result; } From b5df7559da81cdb560a81963d552576f0c46bc17 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 15:16:43 +0400 Subject: [PATCH 19/45] EA-28306 java.lang.NullPointerException at javax.swing.SwingUtilities.convertPointToScreen(SwingUtilities.java:376) at org.jetbrains.idea.svn.SvnAuthenticationNotifier.showAlreadyChecking(SvnAuthenticationNotifier.java:122) at org.jetbrains.idea.svn.SvnAuthenticationNotifier.ask(SvnAuthenticationNotifier.java:92) --- .../org/jetbrains/idea/svn/SvnAuthenticationNotifier.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java index 27d391de5ac9..5c391997ef7c 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java @@ -118,7 +118,10 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl Date: Fri, 24 Jun 2011 15:13:58 +0400 Subject: [PATCH 20/45] redundant cast: move test data; ignore casts to invoke @NotNull methods; ignore suspicious collections method calls --- .../GenericsInspectionToolBase.java | 2 + ...ciousCollectionsMethodCallsInspection.java | 178 ++++++++++-------- .../RedundantCastInspection.java | 62 ++++++ .../redundantCast/AmbigousParm1/expected.xml | 9 + .../AmbigousParm1/src/AmbigousParm1.java | 13 ++ .../redundantCast/AmbigousParm2/expected.xml | 14 ++ .../AmbigousParm2/src/.AmbigousParm2.java.swp | Bin 0 -> 12288 bytes .../AmbigousParm2/src/AmbigousParm2.java | 17 ++ .../redundantCast/AmbigousParm3/expected.xml | 9 + .../AmbigousParm3/src/AmbigousParm3.java | 15 ++ .../redundantCast/AmbigousParm4/expected.xml | 3 + .../AmbigousParm4/src/AmbigousParm4.java | 8 + .../redundantCast/AmbigousParm5/expected.xml | 3 + .../AmbigousParm5/src/AmbigousParm5.java | 8 + .../redundantCast/AnyOfTwo/expected.xml | 3 + .../redundantCast/AnyOfTwo/src/AnyOfTwo.java | 11 ++ .../redundantCast/Assignment1/expected.xml | 9 + .../Assignment1/src/Assignment1.java | 6 + .../ComparingToNull/expected.xml | 9 + .../ComparingToNull/src/Test.java | 6 + .../DifferentFields/expected.xml | 3 + .../DifferentFields/src/Test.java | 12 ++ .../redundantCast/DoubleCast1/expected.xml | 9 + .../DoubleCast1/src/DoubleCast1.java | 9 + .../redundantCast/DoubleCast2/expected.xml | 9 + .../DoubleCast2/src/DoubleCast2.java | 9 + .../redundantCast/DoubleCast3/expected.xml | 14 ++ .../DoubleCast3/src/DoubleCast3.java | 6 + .../redundantCast/DoubleCast4/expected.xml | 14 ++ .../DoubleCast4/src/DoubleCast4.java | 6 + .../redundantCast/DoubleCast5/expected.xml | 3 + .../DoubleCast5/src/DoubleCast5.java | 5 + .../redundantCast/IDEADEV15170/expected.xml | 2 + .../redundantCast/IDEADEV15170/src/Test.java | 16 ++ .../redundantCast/IDEADEV25675/expected.xml | 9 + .../redundantCast/IDEADEV25675/src/A.java | 9 + .../redundantCast/IDEADEV6818/expected.xml | 9 + .../redundantCast/IDEADEV6818/src/A.java | 15 ++ .../redundantCast/InConditional/expected.xml | 9 + .../redundantCast/InConditional/src/A.java | 5 + .../redundantCast/Inaccessible/expected.xml | 3 + .../redundantCast/Inaccessible/src/Test.java | 12 ++ .../redundantCast/Initializer1/expected.xml | 9 + .../Initializer1/src/Initializer1.java | 5 + .../redundantCast/IntToDouble/expected.xml | 3 + .../redundantCast/IntToDouble/src/Test.java | 5 + .../redundantCast/NestedCast/expected.xml | 9 + .../NestedCast/src/CastTest.java | 9 + .../redundantCast/NestedThings/expected.xml | 9 + .../NestedThings/src/NestedThings.java | 26 +++ .../redundantCast/New1/expected.xml | 9 + .../redundantCast/New1/src/New1.java | 7 + .../redundantCast/OneOfTwo/expected.xml | 9 + .../redundantCast/OneOfTwo/src/OneOfTwo.java | 10 + .../redundantCast/SCR11555/expected.xml | 3 + .../redundantCast/SCR11555/src/Test.java | 9 + .../redundantCast/SCR13397/expected.xml | 3 + .../redundantCast/SCR13397/src/Test.java | 21 +++ .../redundantCast/SCR14502/expected.xml | 9 + .../redundantCast/SCR14502/src/Test.java | 5 + .../redundantCast/SCR14559/expected.xml | 3 + .../redundantCast/SCR14559/src/Test.java | 15 ++ .../redundantCast/SCR15236/expected.xml | 8 + .../redundantCast/SCR15236/src/Test.java | 5 + .../redundantCast/SCR6907/expected.xml | 9 + .../redundantCast/SCR6907/src/Test.java | 9 + .../redundantCast/ShortToShort/expected.xml | 9 + .../redundantCast/ShortToShort/src/Test.java | 7 + .../redundantCast/ShortVsInt/expected.xml | 3 + .../ShortVsInt/src/ShortVsInt.java | 8 + .../redundantCast/Truncation/expected.xml | 3 + .../redundantCast/Truncation/src/Test.java | 5 + .../redundantCast/VirtualMethod1/expected.xml | 9 + .../VirtualMethod1/src/VirtualMethod1.java | 14 ++ .../redundantCast/VirtualMethod2/expected.xml | 3 + .../VirtualMethod2/src/VirtualMethod2.java | 14 ++ .../redundantCast/VirtualMethod3/expected.xml | 9 + .../VirtualMethod3/src/VirtualMethod3.java | 6 + .../generics/BoxingInRef/expected.xml | 3 + .../generics/BoxingInRef/src/Test.java | 7 + .../generics/EnumConstant/expected.xml | 9 + .../generics/EnumConstant/src/Test.java | 7 + .../generics/Ignore/expected.xml | 14 ++ .../generics/Ignore/scr/Suspicious.java | 12 ++ .../generics/Ignore/scr/Test.java | 21 +++ .../generics/Inference1/expected.xml | 3 + .../generics/Inference1/src/Test.java | 20 ++ .../generics/Inference2/expected.xml | 3 + .../generics/Inference2/src/Test.java | 32 ++++ .../generics/Inference3/expected.xml | 13 ++ .../generics/Inference3/src/Test.java | 32 ++++ .../NullInVarargsParameter/expected.xml | 13 ++ .../NullInVarargsParameter/src/Test.java | 11 ++ .../generics/RawCast/expected.xml | 2 + .../generics/RawCast/src/Test.java | 11 ++ .../expected.xml | 2 + .../src/CastCast.java | 13 ++ .../src/ReturnValue.java | 16 ++ .../WrapperToPrimitiveCast/expected.xml | 48 +++++ .../src/WrapperToPrimitiveCast.java | 26 +++ .../codeInspection/RedundantCast15Test.java | 47 +++++ .../codeInspection/RedundantCastTest.java | 93 +++++++++ 102 files changed, 1248 insertions(+), 82 deletions(-) create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm1/src/AmbigousParm1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm2/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/.AmbigousParm2.java.swp create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/AmbigousParm2.java create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm3/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm3/src/AmbigousParm3.java create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm4/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm4/src/AmbigousParm4.java create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm5/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AmbigousParm5/src/AmbigousParm5.java create mode 100644 java/java-tests/testData/inspection/redundantCast/AnyOfTwo/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/AnyOfTwo/src/AnyOfTwo.java create mode 100644 java/java-tests/testData/inspection/redundantCast/Assignment1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/Assignment1/src/Assignment1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/ComparingToNull/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/ComparingToNull/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DifferentFields/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DifferentFields/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast1/src/DoubleCast1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast2/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast2/src/DoubleCast2.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast3/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast3/src/DoubleCast3.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast4/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast4/src/DoubleCast4.java create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast5/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/DoubleCast5/src/DoubleCast5.java create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV15170/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV15170/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV25675/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV25675/src/A.java create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV6818/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/IDEADEV6818/src/A.java create mode 100644 java/java-tests/testData/inspection/redundantCast/InConditional/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/InConditional/src/A.java create mode 100644 java/java-tests/testData/inspection/redundantCast/Inaccessible/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/Inaccessible/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/Initializer1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/Initializer1/src/Initializer1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/IntToDouble/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/IntToDouble/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/NestedCast/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/NestedCast/src/CastTest.java create mode 100644 java/java-tests/testData/inspection/redundantCast/NestedThings/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/NestedThings/src/NestedThings.java create mode 100644 java/java-tests/testData/inspection/redundantCast/New1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/New1/src/New1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/OneOfTwo/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/OneOfTwo/src/OneOfTwo.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR11555/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR11555/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR13397/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR13397/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR14502/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR14502/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR14559/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR14559/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR15236/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR15236/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR6907/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/SCR6907/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/ShortToShort/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/ShortToShort/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/ShortVsInt/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/ShortVsInt/src/ShortVsInt.java create mode 100644 java/java-tests/testData/inspection/redundantCast/Truncation/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/Truncation/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod1/src/VirtualMethod1.java create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod2/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod2/src/VirtualMethod2.java create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod3/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/VirtualMethod3/src/VirtualMethod3.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Ignore/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Suspicious.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference1/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference1/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference2/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference2/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference3/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/Inference3/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/RawCast/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/RawCast/src/Test.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/CastCast.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/ReturnValue.java create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/src/WrapperToPrimitiveCast.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInspection/RedundantCastTest.java diff --git a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/GenericsInspectionToolBase.java b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/GenericsInspectionToolBase.java index ff4361e0d331..f29f8c4cafc5 100644 --- a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/GenericsInspectionToolBase.java +++ b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/GenericsInspectionToolBase.java @@ -21,6 +21,7 @@ import com.intellij.codeInspection.ex.BaseLocalInspectionTool; import com.intellij.psi.*; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -62,5 +63,6 @@ public abstract class GenericsInspectionToolBase extends BaseLocalInspectionTool return null; } + @Nullable public abstract ProblemDescriptor[] getDescriptions(PsiElement place, InspectionManager manager, boolean isOnTheFly); } diff --git a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/SuspiciousCollectionsMethodCallsInspection.java b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/SuspiciousCollectionsMethodCallsInspection.java index 2a83d9140083..ec648e2894af 100644 --- a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/SuspiciousCollectionsMethodCallsInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/SuspiciousCollectionsMethodCallsInspection.java @@ -29,8 +29,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; @@ -105,88 +103,12 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect @Override public void visitMethodCallExpression(PsiMethodCallExpression methodCall) { super.visitMethodCallExpression(methodCall); - final PsiReferenceExpression methodExpression = methodCall.getMethodExpression(); - final PsiExpression qualifier = methodExpression.getQualifierExpression(); - if (qualifier == null || qualifier instanceof PsiThisExpression || qualifier instanceof PsiSuperExpression) return; - final PsiExpression[] args = methodCall.getArgumentList().getExpressions(); - if (args.length != 1) return; - PsiType argType = args[0].getType(); - if (argType instanceof PsiPrimitiveType) { - argType = ((PsiPrimitiveType)argType).getBoxedType(methodCall); - } - - if (!(argType instanceof PsiClassType)) return; - - final JavaResolveResult resolveResult = methodExpression.advancedResolve(false); - PsiMethod calleeMethod = (PsiMethod)resolveResult.getElement(); - if (calleeMethod == null) return; - PsiMethod contextMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); - - synchronized (patternMethods) { - if (patternMethods.isEmpty()) { - setupPatternMethods(methodCall.getManager(), methodCall.getResolveScope(), patternMethods, indices); - } - } - - for (int i = 0; i < patternMethods.size(); i++) { - PsiMethod patternMethod = patternMethods.get(i); - if (!patternMethod.getName().equals(methodExpression.getReferenceName())) continue; - int index = indices.get(i); - - //we are in collections method implementation - if (contextMethod != null && isInheritorOrSelf(contextMethod, patternMethod)) return; - - final PsiClass calleeClass = calleeMethod.getContainingClass(); - PsiSubstitutor substitutor = resolveResult.getSubstitutor(); - final PsiClass patternClass = patternMethod.getContainingClass(); - substitutor = TypeConversionUtil.getClassSubstitutor(patternClass, calleeClass, substitutor); - if (substitutor == null) continue; - - if (!patternMethod.getSignature(substitutor).equals(calleeMethod.getSignature(PsiSubstitutor.EMPTY))) continue; - - PsiTypeParameter[] typeParameters = patternClass.getTypeParameters(); - if (typeParameters.length <= index) return; - final PsiTypeParameter typeParameter = typeParameters[index]; - PsiType typeParamMapping = substitutor.substitute(typeParameter); - if (typeParamMapping == null) return; - String message = null; - if (typeParamMapping instanceof PsiCapturedWildcardType) { - typeParamMapping = ((PsiCapturedWildcardType)typeParamMapping).getWildcard(); - } - if (!typeParamMapping.isAssignableFrom(argType)) { - if (typeParamMapping.isConvertibleFrom(argType)) { - if (REPORT_CONVERTIBLE_METHOD_CALLS) { - message = InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor1", - PsiFormatUtil.formatMethod(calleeMethod, substitutor, - PsiFormatUtil.SHOW_NAME | PsiFormatUtil - .SHOW_CONTAINING_CLASS, PsiFormatUtil.SHOW_TYPE)); - } - } - else { - PsiType qualifierType = qualifier.getType(); - LOG.assertTrue(qualifierType != null); - - message = InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor", - PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY), - PsiFormatUtil.formatType(argType, 0, PsiSubstitutor.EMPTY)); - } - } - if (message != null) { - holder.registerProblem(args[0], message); - } - return; + final String message = getSuspiciousMethodCallMessage(methodCall, REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, indices + ); + if (message != null) { + holder.registerProblem(methodCall.getArgumentList().getExpressions()[0], message); } } - - private boolean isInheritorOrSelf(PsiMethod inheritorCandidate, PsiMethod base) { - PsiClass aClass = inheritorCandidate.getContainingClass(); - PsiClass bClass = base.getContainingClass(); - if (aClass == null || bClass == null) return false; - PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(bClass, aClass, PsiSubstitutor.EMPTY); - return substitutor != null && - MethodSignatureUtil.findMethodBySignature(bClass, inheritorCandidate.getSignature(substitutor), false) == base; - } - }; } @@ -204,4 +126,96 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect public String getShortName() { return "SuspiciousMethodCalls"; } + + @Nullable + private static String getSuspiciousMethodCallMessage(final PsiMethodCallExpression methodCall, + final boolean reportConvertibleMethodCalls, final List patternMethods, + final IntArrayList indices) { + final PsiExpression[] args = methodCall.getArgumentList().getExpressions(); + if (args.length != 1) return null; + PsiType argType = args[0].getType(); + return getSuspiciousMethodCallMessage(methodCall, argType, reportConvertibleMethodCalls, patternMethods, indices); + } + + @Nullable + public static String getSuspiciousMethodCallMessage(PsiMethodCallExpression methodCall, + PsiType argType, boolean reportConvertibleMethodCalls, List patternMethods, + IntArrayList indices) { + final PsiReferenceExpression methodExpression = methodCall.getMethodExpression(); + final PsiExpression qualifier = methodExpression.getQualifierExpression(); + if (qualifier == null || qualifier instanceof PsiThisExpression || qualifier instanceof PsiSuperExpression) return null; + if (argType instanceof PsiPrimitiveType) { + argType = ((PsiPrimitiveType)argType).getBoxedType(methodCall); + } + + if (!(argType instanceof PsiClassType)) return null; + + final JavaResolveResult resolveResult = methodExpression.advancedResolve(false); + PsiMethod calleeMethod = (PsiMethod)resolveResult.getElement(); + if (calleeMethod == null) return null; + PsiMethod contextMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); + + synchronized (patternMethods) { + if (patternMethods.isEmpty()) { + setupPatternMethods(methodCall.getManager(), methodCall.getResolveScope(), patternMethods, indices); + } + } + + for (int i = 0; i < patternMethods.size(); i++) { + PsiMethod patternMethod = patternMethods.get(i); + if (!patternMethod.getName().equals(methodExpression.getReferenceName())) continue; + int index = indices.get(i); + + //we are in collections method implementation + if (contextMethod != null && isInheritorOrSelf(contextMethod, patternMethod)) return null; + + final PsiClass calleeClass = calleeMethod.getContainingClass(); + PsiSubstitutor substitutor = resolveResult.getSubstitutor(); + final PsiClass patternClass = patternMethod.getContainingClass(); + substitutor = TypeConversionUtil.getClassSubstitutor(patternClass, calleeClass, substitutor); + if (substitutor == null) continue; + + if (!patternMethod.getSignature(substitutor).equals(calleeMethod.getSignature(PsiSubstitutor.EMPTY))) continue; + + PsiTypeParameter[] typeParameters = patternClass.getTypeParameters(); + if (typeParameters.length <= index) return null; + final PsiTypeParameter typeParameter = typeParameters[index]; + PsiType typeParamMapping = substitutor.substitute(typeParameter); + if (typeParamMapping == null) return null; + String message = null; + if (typeParamMapping instanceof PsiCapturedWildcardType) { + typeParamMapping = ((PsiCapturedWildcardType)typeParamMapping).getWildcard(); + } + if (!typeParamMapping.isAssignableFrom(argType)) { + if (typeParamMapping.isConvertibleFrom(argType)) { + if (reportConvertibleMethodCalls) { + message = InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor1", + PsiFormatUtil.formatMethod(calleeMethod, substitutor, + PsiFormatUtilBase.SHOW_NAME | + PsiFormatUtilBase.SHOW_CONTAINING_CLASS, + PsiFormatUtilBase.SHOW_TYPE)); + } + } + else { + PsiType qualifierType = qualifier.getType(); + LOG.assertTrue(qualifierType != null); + + message = InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor", + PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY), + PsiFormatUtil.formatType(argType, 0, PsiSubstitutor.EMPTY)); + } + } + return message; + } + return null; + } + + private static boolean isInheritorOrSelf(PsiMethod inheritorCandidate, PsiMethod base) { + PsiClass aClass = inheritorCandidate.getContainingClass(); + PsiClass bClass = base.getContainingClass(); + if (aClass == null || bClass == null) return false; + PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(bClass, aClass, PsiSubstitutor.EMPTY); + return substitutor != null && + MethodSignatureUtil.findMethodBySignature(bClass, inheritorCandidate.getSignature(substitutor), false) == base; + } } diff --git a/java/java-impl/src/com/intellij/codeInspection/redundantCast/RedundantCastInspection.java b/java/java-impl/src/com/intellij/codeInspection/redundantCast/RedundantCastInspection.java index e6a3878700b9..75558796a915 100644 --- a/java/java-impl/src/com/intellij/codeInspection/redundantCast/RedundantCastInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/redundantCast/RedundantCastInspection.java @@ -15,18 +15,29 @@ */ package com.intellij.codeInspection.redundantCast; +import com.intellij.codeInsight.AnnotationUtil; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.GroupNames; import com.intellij.codeInspection.*; import com.intellij.codeInspection.miscGenerics.GenericsInspectionToolBase; +import com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspection; +import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.*; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.searches.OverridingMethodsSearch; +import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.RedundantCastUtil; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.containers.IntArrayList; +import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import javax.swing.*; import java.util.ArrayList; import java.util.List; @@ -40,10 +51,15 @@ public class RedundantCastInspection extends GenericsInspectionToolBase { private static final String DISPLAY_NAME = InspectionsBundle.message("inspection.redundant.cast.display.name"); @NonNls private static final String SHORT_NAME = "RedundantCast"; + public boolean IGNORE_ANNOTATED_METHODS = false; + public boolean IGNORE_SUSPICIOUS_METHOD_CALLS = false; + + public RedundantCastInspection() { myQuickFixAction = new AcceptSuggested(); } + @Nullable public ProblemDescriptor[] getDescriptions(PsiElement where, InspectionManager manager, boolean isOnTheFly) { List redundantCasts = RedundantCastUtil.getRedundantCastsInside(where); if (redundantCasts.isEmpty()) return null; @@ -58,10 +74,56 @@ public class RedundantCastInspection extends GenericsInspectionToolBase { return descriptions.toArray(new ProblemDescriptor[descriptions.size()]); } + @Override + public void writeSettings(Element node) throws WriteExternalException { + if (IGNORE_ANNOTATED_METHODS || IGNORE_SUSPICIOUS_METHOD_CALLS) { + super.writeSettings(node); + } + } + + @Override + public JComponent createOptionsPanel() { + final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); + optionsPanel.addCheckbox("Ignore casts appeared in suspicious collections method calls", "IGNORE_SUSPICIOUS_METHOD_CALLS"); + optionsPanel.addCheckbox("Ignore casts to invoke @NotNull method which overrides @Nullable", "IGNORE_ANNOTATED_METHODS"); + return optionsPanel; + } + + @Nullable private ProblemDescriptor createDescription(@NotNull PsiTypeCastExpression cast, @NotNull InspectionManager manager, boolean onTheFly) { PsiExpression operand = cast.getOperand(); PsiTypeElement castType = cast.getCastType(); if (operand == null || castType == null) return null; + PsiElement parent = cast.getParent(); + while (parent instanceof PsiParenthesizedExpression){ + parent = parent.getParent(); + } + if (parent instanceof PsiReferenceExpression) { + if (IGNORE_ANNOTATED_METHODS) { + final PsiElement gParent = parent.getParent(); + if (gParent instanceof PsiMethodCallExpression) { + final PsiMethod psiMethod = ((PsiMethodCallExpression)gParent).resolveMethod(); + if (psiMethod != null && AnnotationUtil.isNotNull(psiMethod)) { + final PsiClass superClass = PsiUtil.resolveClassInType(operand.getType()); + for (PsiMethod method : psiMethod.findSuperMethods(superClass)) { + if (AnnotationUtil.isNullable(method)) { + return null; + } + } + } + } + } + } else if (parent instanceof PsiExpressionList) { + final PsiElement gParent = parent.getParent(); + if (gParent instanceof PsiMethodCallExpression && IGNORE_SUSPICIOUS_METHOD_CALLS) { + final String message = SuspiciousCollectionsMethodCallsInspection + .getSuspiciousMethodCallMessage((PsiMethodCallExpression)gParent, operand.getType(), true, new ArrayList(), new IntArrayList()); + if (message != null) { + return null; + } + } + } + String message = InspectionsBundle.message("inspection.redundant.cast.problem.descriptor", "" + operand.getText() + "", "#ref #loc"); return manager.createProblemDescriptor(castType, message, myQuickFixAction, ProblemHighlightType.LIKE_UNUSED_SYMBOL, onTheFly); diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/expected.xml b/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/expected.xml new file mode 100644 index 000000000000..a34576ea01d1 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/expected.xml @@ -0,0 +1,9 @@ + + + + AmbigousParm1.java + 11 + Casting c to A is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/src/AmbigousParm1.java b/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/src/AmbigousParm1.java new file mode 100644 index 000000000000..d2e90c4196d2 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm1/src/AmbigousParm1.java @@ -0,0 +1,13 @@ +interface A {} + +interface B {} + +class C implements A, B {} + +public class AmbigousParameter { + public void ua(A a) {} + + public void caller(C c) { + ua((A)c); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/expected.xml b/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/expected.xml new file mode 100644 index 000000000000..4190a659ddce --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/expected.xml @@ -0,0 +1,14 @@ + + + + AmbigousParm2.java + 14 + Casting c to A is redundant + + + AmbigousParm2.java + 15 + Casting a to A is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/.AmbigousParm2.java.swp b/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/.AmbigousParm2.java.swp new file mode 100644 index 0000000000000000000000000000000000000000..17471d1ee90b7fdc8399d3a270061fdc695a97b5 GIT binary patch literal 12288 zcmeI&%}?7f7zS{|h1wTv};LD3f-Xpi0Yy0}>Kq_cyLL862mwogP4A|2nTj zCoxsP8T43s+UBw2D8FNq`tax3IejliO2(#Af5Iu3>7Iu_O^ zuUrKM1R(I7z_+8(;lchM?QCB?w*)-|AOHafKmY;|fB*y_@Jz3j+cWfB*y_009U<00Izz00bZafp;RnGkNC!L8&hv<%Z<>fBp|(EWcmM zUzxv`u;fxQk&Gk$3y{0uX=z1Rwwb2tWV=5P$##An+Ch{wN~qKZu&apc?Y< zN3Mt}Vmc;i^s?xuedpZ26@8%}kLF$Ntfob4XQbIV69!Y#L%LIWx4v!$6RM@@ueNOD wB7L(wT|17Ep1cyzjY%ftT^^^VWShA&jqyp=eWgj>PUSc9!!Oom<+#f85AG#*o&W#< literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/AmbigousParm2.java b/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/AmbigousParm2.java new file mode 100644 index 000000000000..714aee653550 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm2/src/AmbigousParm2.java @@ -0,0 +1,17 @@ +interface A {} + +interface B {} + +class C implements A, B {} + +public class AmbigousParameter { + void m(A a) {} + void m(B b) {} + + public void caller(C c) { + m((A)c); + m((A)null); + A a = (A)c; + m((A)a); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/expected.xml b/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/expected.xml new file mode 100644 index 000000000000..e211556e6065 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/expected.xml @@ -0,0 +1,9 @@ + + + + AmbigousParm3.java + 13 + Casting null to A is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/src/AmbigousParm3.java b/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/src/AmbigousParm3.java new file mode 100644 index 000000000000..70356c0c8016 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm3/src/AmbigousParm3.java @@ -0,0 +1,15 @@ +interface A {} +interface B {} + +public class AmbigousParameter { + public void f(A a) {} + public void f(B b) {} + public void f(Object o) {} + + public void g(Object o) {} + + public void caller() { + f((A)null); + g((A)null); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/expected.xml b/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/src/AmbigousParm4.java b/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/src/AmbigousParm4.java new file mode 100644 index 000000000000..3ca606903d1b --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm4/src/AmbigousParm4.java @@ -0,0 +1,8 @@ +import javax.swing.*; +import java.awt.*; + +public class AmbigousParameter { + public void caller() { + new JDialog((Frame)null, "Title", true); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/expected.xml b/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/src/AmbigousParm5.java b/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/src/AmbigousParm5.java new file mode 100644 index 000000000000..fb61553a80bc --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AmbigousParm5/src/AmbigousParm5.java @@ -0,0 +1,8 @@ +import javax.swing.*; +import java.awt.*; + +public class AmbigousParameter { + public void caller() { + new JDialog( ((Frame)null), "Title", true); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/expected.xml b/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/src/AnyOfTwo.java b/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/src/AnyOfTwo.java new file mode 100644 index 000000000000..fb922acf6071 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/AnyOfTwo/src/AnyOfTwo.java @@ -0,0 +1,11 @@ +package com; + +public class Test { + static void f(Object s, Object o){} + static void f(String s, String o){} + + void foo(){ + Object o; + f((String)o, (String)o); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/Assignment1/expected.xml b/java/java-tests/testData/inspection/redundantCast/Assignment1/expected.xml new file mode 100644 index 000000000000..706f86ed9ae0 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Assignment1/expected.xml @@ -0,0 +1,9 @@ + + + + Assignment1.java + 4 + Casting null to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/Assignment1/src/Assignment1.java b/java/java-tests/testData/inspection/redundantCast/Assignment1/src/Assignment1.java new file mode 100644 index 000000000000..0ff6c4b45cad --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Assignment1/src/Assignment1.java @@ -0,0 +1,6 @@ +class Test{ + static f(){ + Object o; + o = (String)null; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/ComparingToNull/expected.xml b/java/java-tests/testData/inspection/redundantCast/ComparingToNull/expected.xml new file mode 100644 index 000000000000..c942f37a7bd0 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ComparingToNull/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 4 + Casting o to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/ComparingToNull/src/Test.java b/java/java-tests/testData/inspection/redundantCast/ComparingToNull/src/Test.java new file mode 100644 index 000000000000..68d9829f951b --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ComparingToNull/src/Test.java @@ -0,0 +1,6 @@ +public class Test { + public boolean foo() { + Object o = null; + return (String) o == null; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/DifferentFields/expected.xml b/java/java-tests/testData/inspection/redundantCast/DifferentFields/expected.xml new file mode 100644 index 000000000000..5e933496b9cf --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DifferentFields/expected.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/DifferentFields/src/Test.java b/java/java-tests/testData/inspection/redundantCast/DifferentFields/src/Test.java new file mode 100644 index 000000000000..df25a830ee47 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DifferentFields/src/Test.java @@ -0,0 +1,12 @@ +class Y { + int size = 4; +} + +class Z extends Y { + int size = 5; + + public static void main(String[] args) { + Z z = new Z(); + System.out.println("z.size = " + ((Y)z).size); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast1/expected.xml b/java/java-tests/testData/inspection/redundantCast/DoubleCast1/expected.xml new file mode 100644 index 000000000000..89a59ecef41a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast1/expected.xml @@ -0,0 +1,9 @@ + + + + DoubleCast1.java + 7 + Casting o to List is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast1/src/DoubleCast1.java b/java/java-tests/testData/inspection/redundantCast/DoubleCast1/src/DoubleCast1.java new file mode 100644 index 000000000000..f05698dc1f8f --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast1/src/DoubleCast1.java @@ -0,0 +1,9 @@ +import java.util.List; +import java.util.ArrayList; + +class Test{ + static f(){ + Object o; + ArrayList list = (ArrayList)(List)o; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast2/expected.xml b/java/java-tests/testData/inspection/redundantCast/DoubleCast2/expected.xml new file mode 100644 index 000000000000..56829e12fe37 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast2/expected.xml @@ -0,0 +1,9 @@ + + + + DoubleCast2.java + 7 + Casting o to List is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast2/src/DoubleCast2.java b/java/java-tests/testData/inspection/redundantCast/DoubleCast2/src/DoubleCast2.java new file mode 100644 index 000000000000..8bb8b64e0805 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast2/src/DoubleCast2.java @@ -0,0 +1,9 @@ +import java.util.List; +import java.util.ArrayList; + +class Test{ + static f(){ + Object o; + ArrayList list = (ArrayList)((List)o); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast3/expected.xml b/java/java-tests/testData/inspection/redundantCast/DoubleCast3/expected.xml new file mode 100644 index 000000000000..e8c201ce3315 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast3/expected.xml @@ -0,0 +1,14 @@ + + + + DoubleCast3.java + 4 + Casting '(String) o' to String is redundant + + + DoubleCast3.java + 4 + Casting 'o' to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast3/src/DoubleCast3.java b/java/java-tests/testData/inspection/redundantCast/DoubleCast3/src/DoubleCast3.java new file mode 100644 index 000000000000..36da9cba2007 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast3/src/DoubleCast3.java @@ -0,0 +1,6 @@ +class Test{ + static f(){ + Object o; + String s = (String) (String) o; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast4/expected.xml b/java/java-tests/testData/inspection/redundantCast/DoubleCast4/expected.xml new file mode 100644 index 000000000000..70d5cfefdd37 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast4/expected.xml @@ -0,0 +1,14 @@ + + + + DoubleCast4.java + 4 + Casting '(String) o' to Object is redundant + + + DoubleCast4.java + 4 + Casting 'o' to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast4/src/DoubleCast4.java b/java/java-tests/testData/inspection/redundantCast/DoubleCast4/src/DoubleCast4.java new file mode 100644 index 000000000000..24b90094595a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast4/src/DoubleCast4.java @@ -0,0 +1,6 @@ +class Test{ + static f(){ + Object o; + Object o2 = (Object) (String) o; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast5/expected.xml b/java/java-tests/testData/inspection/redundantCast/DoubleCast5/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast5/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/DoubleCast5/src/DoubleCast5.java b/java/java-tests/testData/inspection/redundantCast/DoubleCast5/src/DoubleCast5.java new file mode 100644 index 000000000000..b0d970329170 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/DoubleCast5/src/DoubleCast5.java @@ -0,0 +1,5 @@ +class Test{ + static f(double a){ + double b = (double)(int)a / 100; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/expected.xml b/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/expected.xml new file mode 100644 index 000000000000..796a315e49f5 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/expected.xml @@ -0,0 +1,2 @@ + + diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/src/Test.java b/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/src/Test.java new file mode 100644 index 000000000000..5bda42c6e8e6 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV15170/src/Test.java @@ -0,0 +1,16 @@ +class A { + void foo() throws Exception {} +} + +class B extends A { + void foo() { + + } +} + +class C { + { + A a = new B(); + ((B) a).foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/expected.xml b/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/expected.xml new file mode 100644 index 000000000000..c440a49c4378 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/expected.xml @@ -0,0 +1,9 @@ + + + + A.java + 3 + Casting 'array' to String[] is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/src/A.java b/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/src/A.java new file mode 100644 index 000000000000..cbead21aa913 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV25675/src/A.java @@ -0,0 +1,9 @@ +public class Test { + public void foo(Object[] array) { + ((String[]) array)[0] = " "; + } + + public void bar(String[] array) { + ((Object[]) array)[0] = new Object(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/expected.xml b/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/expected.xml new file mode 100644 index 000000000000..0d178e909db5 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/expected.xml @@ -0,0 +1,9 @@ + + + + A.java + 13 + Casting prices.get(null) to BidAsk is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/src/A.java b/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/src/A.java new file mode 100644 index 000000000000..00e6fbd46922 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IDEADEV6818/src/A.java @@ -0,0 +1,15 @@ +class Getter { + BidAsk get(String s) { + return null; + } +} + +class BidAsk { + public Object getOpenQuote; +} + +public class A { + static Object f(Getter prices) { + return System.currentTimeMillis() == 2.0 ? ((BidAsk) prices.get(null)).getOpenQuote : null; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/InConditional/expected.xml b/java/java-tests/testData/inspection/redundantCast/InConditional/expected.xml new file mode 100644 index 000000000000..d93fb1cec86d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/InConditional/expected.xml @@ -0,0 +1,9 @@ + + + + A.java + 3 + Redundant type cast + Casting <code>null</code> to <code>String</code> is redundant + + diff --git a/java/java-tests/testData/inspection/redundantCast/InConditional/src/A.java b/java/java-tests/testData/inspection/redundantCast/InConditional/src/A.java new file mode 100644 index 000000000000..24ac60c1f4e0 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/InConditional/src/A.java @@ -0,0 +1,5 @@ +class A { + { + String s = true ? "" : (String) null; //cast is needed + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/Inaccessible/expected.xml b/java/java-tests/testData/inspection/redundantCast/Inaccessible/expected.xml new file mode 100644 index 000000000000..580a889dbfd6 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Inaccessible/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/Inaccessible/src/Test.java b/java/java-tests/testData/inspection/redundantCast/Inaccessible/src/Test.java new file mode 100644 index 000000000000..4c36d5bd0c28 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Inaccessible/src/Test.java @@ -0,0 +1,12 @@ +class Entry { + private final Object obj; + protected Entry(Directory parent) { + obj = ((Entry)parent).obj; //cast is needed because 'obj' is not visible with 'Directory' access class + } +} + +class Directory extends Entry { + public Directory(Directory parent) { + super(parent); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/Initializer1/expected.xml b/java/java-tests/testData/inspection/redundantCast/Initializer1/expected.xml new file mode 100644 index 000000000000..5054e5bbb001 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Initializer1/expected.xml @@ -0,0 +1,9 @@ + + + + Initializer1.java + 3 + Casting null to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/Initializer1/src/Initializer1.java b/java/java-tests/testData/inspection/redundantCast/Initializer1/src/Initializer1.java new file mode 100644 index 000000000000..de9bef7abe55 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Initializer1/src/Initializer1.java @@ -0,0 +1,5 @@ +class Test{ + static f(){ + Object o = (String)null; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/IntToDouble/expected.xml b/java/java-tests/testData/inspection/redundantCast/IntToDouble/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IntToDouble/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/IntToDouble/src/Test.java b/java/java-tests/testData/inspection/redundantCast/IntToDouble/src/Test.java new file mode 100644 index 000000000000..0790268df735 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/IntToDouble/src/Test.java @@ -0,0 +1,5 @@ +class A{ + void f(){ + double d = (double)1 / 5; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/NestedCast/expected.xml b/java/java-tests/testData/inspection/redundantCast/NestedCast/expected.xml new file mode 100644 index 000000000000..ee594a2a237a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/NestedCast/expected.xml @@ -0,0 +1,9 @@ + + + + CastTest.java + 7 + Redundant type cast + Casting <code>ct1</code> to <code>CastTest</code> is redundant + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/NestedCast/src/CastTest.java b/java/java-tests/testData/inspection/redundantCast/NestedCast/src/CastTest.java new file mode 100644 index 000000000000..84bbabbf665e --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/NestedCast/src/CastTest.java @@ -0,0 +1,9 @@ +class CastTest +{ + public static void main (String[] args) throws CloneNotSupportedException + { + CastTest ct1 = new CastTest (); + // The cast of ct1 is obviously redundant (although the cast of the result is necessary) + CastTest ct2 = (CastTest) ((CastTest)ct1).clone(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/NestedThings/expected.xml b/java/java-tests/testData/inspection/redundantCast/NestedThings/expected.xml new file mode 100644 index 000000000000..c381c3410379 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/NestedThings/expected.xml @@ -0,0 +1,9 @@ + + + + NestedThings.java + 13 + Casting "" to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/NestedThings/src/NestedThings.java b/java/java-tests/testData/inspection/redundantCast/NestedThings/src/NestedThings.java new file mode 100644 index 000000000000..ab19af9b39d9 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/NestedThings/src/NestedThings.java @@ -0,0 +1,26 @@ +class XXX { + String f() { + new Runnable() { + public void run() { + new Runnable() { + public void run() { + new Runnable() { + public void run() { + new Runnable() { + public void run() { + new Runnable() { + public void run() { + String s = (String)""; + } + }; + } + }; + } + }; + } + }; + } + }; + return ""; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/New1/expected.xml b/java/java-tests/testData/inspection/redundantCast/New1/expected.xml new file mode 100644 index 000000000000..a35fe675e263 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/New1/expected.xml @@ -0,0 +1,9 @@ + + + + New1.java + 5 + Casting null to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/New1/src/New1.java b/java/java-tests/testData/inspection/redundantCast/New1/src/New1.java new file mode 100644 index 000000000000..f1a6625c1b93 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/New1/src/New1.java @@ -0,0 +1,7 @@ +class Test{ + Test(Object o){} + + static f(){ + new Test((String)null); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/OneOfTwo/expected.xml b/java/java-tests/testData/inspection/redundantCast/OneOfTwo/expected.xml new file mode 100644 index 000000000000..f19096e540f0 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/OneOfTwo/expected.xml @@ -0,0 +1,9 @@ + + + + OneOfTwo.java + 8 + Casting o to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/OneOfTwo/src/OneOfTwo.java b/java/java-tests/testData/inspection/redundantCast/OneOfTwo/src/OneOfTwo.java new file mode 100644 index 000000000000..dff6850ac77f --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/OneOfTwo/src/OneOfTwo.java @@ -0,0 +1,10 @@ +package com; + +public class Test { + static void f(String s, Object o){} + + void foo(){ + Object o; + f((String)o, (String)o); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/SCR11555/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR11555/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR11555/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR11555/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR11555/src/Test.java new file mode 100644 index 000000000000..439a70b1a530 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR11555/src/Test.java @@ -0,0 +1,9 @@ + +import java.awt.*; + +public class Test { + void foo(){ + Component c = null; + ((Frame) c).show(); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/SCR13397/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR13397/expected.xml new file mode 100644 index 000000000000..ec272abeaa3a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR13397/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR13397/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR13397/src/Test.java new file mode 100644 index 000000000000..772f47c2a11f --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR13397/src/Test.java @@ -0,0 +1,21 @@ +class RedundantCastProblem { + public abstract static class Top { + public String f(Object o) { + return "Top.f(Object)"; + } + } + + public static class Sub extends Top { + public String f(String s) { + return "Middle.f(String)"; + } + } + + public static void main(String[] args) { + Sub sub = new Sub(); + String aString = ""; + + System.out.println(((Top)sub).f(aString)); + System.out.println(sub.f(aString)); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/SCR14502/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR14502/expected.xml new file mode 100644 index 000000000000..ea60f9b517be --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR14502/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 3 + Casting new Test() to Test is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR14502/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR14502/src/Test.java new file mode 100644 index 000000000000..844664c0506c --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR14502/src/Test.java @@ -0,0 +1,5 @@ +public class Test { + public void foo(Test t) { + foo(((Test) new Test())); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/SCR14559/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR14559/expected.xml new file mode 100644 index 000000000000..ec272abeaa3a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR14559/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR14559/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR14559/src/Test.java new file mode 100644 index 000000000000..26eb609277c1 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR14559/src/Test.java @@ -0,0 +1,15 @@ +public class Test { + class Super { + Object foo() { return new Object(); } + } + class Sub extends Super{ + String foo() { return ""; } + } + public String get(final Super obj) { + if (obj instanceof Sub) { + return ((Sub)obj).foo(); + } else { + return "The value is " + obj.foo(); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/SCR15236/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR15236/expected.xml new file mode 100644 index 000000000000..ab033e5de25a --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR15236/expected.xml @@ -0,0 +1,8 @@ + + + + Test.java + 3 + Casting s to String is redundant + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR15236/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR15236/src/Test.java new file mode 100644 index 000000000000..dbb5fe9f13a7 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR15236/src/Test.java @@ -0,0 +1,5 @@ +public class Test { + public void test(Object s) { + Object o = ((String) s); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/SCR6907/expected.xml b/java/java-tests/testData/inspection/redundantCast/SCR6907/expected.xml new file mode 100644 index 000000000000..ca36c52f7ead --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR6907/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 7 + Casting null to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/SCR6907/src/Test.java b/java/java-tests/testData/inspection/redundantCast/SCR6907/src/Test.java new file mode 100644 index 000000000000..6747030c9222 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/SCR6907/src/Test.java @@ -0,0 +1,9 @@ + +public class Test { + void foo(String msg){} + void foo(Object o){} + + void method(){ + foo((String)null); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/ShortToShort/expected.xml b/java/java-tests/testData/inspection/redundantCast/ShortToShort/expected.xml new file mode 100644 index 000000000000..a30bea023369 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ShortToShort/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 4 + Casting v to short is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/ShortToShort/src/Test.java b/java/java-tests/testData/inspection/redundantCast/ShortToShort/src/Test.java new file mode 100644 index 000000000000..ede4aa3808a6 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ShortToShort/src/Test.java @@ -0,0 +1,7 @@ +class Test{ + short foo(){ + short v = 0; + short s = (short)v; + return s; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/ShortVsInt/expected.xml b/java/java-tests/testData/inspection/redundantCast/ShortVsInt/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ShortVsInt/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/ShortVsInt/src/ShortVsInt.java b/java/java-tests/testData/inspection/redundantCast/ShortVsInt/src/ShortVsInt.java new file mode 100644 index 000000000000..d0b690d83fc8 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/ShortVsInt/src/ShortVsInt.java @@ -0,0 +1,8 @@ +class A{ + String toHex(int i) {} + String toHex(short i) {} + + void f(){ + String result = toHex((short)'i'); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/Truncation/expected.xml b/java/java-tests/testData/inspection/redundantCast/Truncation/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Truncation/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/Truncation/src/Test.java b/java/java-tests/testData/inspection/redundantCast/Truncation/src/Test.java new file mode 100644 index 000000000000..68707f630414 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/Truncation/src/Test.java @@ -0,0 +1,5 @@ +class A{ + void f(){ + double d = (int) 1.5; + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/expected.xml b/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/expected.xml new file mode 100644 index 000000000000..e2ed2b831218 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/expected.xml @@ -0,0 +1,9 @@ + + + + VirtualMethod1.java + 12 + Casting a B is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/src/VirtualMethod1.java b/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/src/VirtualMethod1.java new file mode 100644 index 000000000000..f6d174179343 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod1/src/VirtualMethod1.java @@ -0,0 +1,14 @@ +class A{ + void f(){} +} + +class B extends A{ + void f(){} +} + +class Test{ + static foo(){ + A a; + ((B)a).f(); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/expected.xml b/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/expected.xml new file mode 100644 index 000000000000..9ac879d78616 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/src/VirtualMethod2.java b/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/src/VirtualMethod2.java new file mode 100644 index 000000000000..ab027cff9687 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod2/src/VirtualMethod2.java @@ -0,0 +1,14 @@ +class A{ + private void f(){} +} + +class B extends A{ + void f(){} +} + +class Test{ + static foo(){ + A a; + ((B)a).f(); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/expected.xml b/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/expected.xml new file mode 100644 index 000000000000..bbf660d0e243 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/expected.xml @@ -0,0 +1,9 @@ + + + + VirtualMethod3.java + 4 + Casting o to String is redundant + + + diff --git a/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/src/VirtualMethod3.java b/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/src/VirtualMethod3.java new file mode 100644 index 000000000000..9c13b2ee2a30 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/VirtualMethod3/src/VirtualMethod3.java @@ -0,0 +1,6 @@ +class Test{ + static foo(){ + Object o; + boolean res = ((String)o).equals(null); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/expected.xml new file mode 100644 index 000000000000..580a889dbfd6 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/src/Test.java new file mode 100644 index 000000000000..dd4dd2d8df7b --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/BoxingInRef/src/Test.java @@ -0,0 +1,7 @@ +//This is a test for JDK_15 LanguageLevel +public class Test { + void foo () { + int x = 4; + ((Integer) x).toString(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/expected.xml new file mode 100644 index 000000000000..c8c865b6cf6e --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 3 + Redundant type cast + Casting <code>""</code> to <code>String</code> is redundant + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/src/Test.java new file mode 100644 index 000000000000..1dcbdccb6477 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/EnumConstant/src/Test.java @@ -0,0 +1,7 @@ + +enum Test { + A((String) ""); + + Test(String s) { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Ignore/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/expected.xml new file mode 100644 index 000000000000..e6aeaad02d23 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/expected.xml @@ -0,0 +1,14 @@ + + + Test.java + 11 + Redundant type cast + Casting <code>this</code> to <code>CastPreventsNPEDetection</code> is redundant + + + Suspicious.java + 9 + Redundant type cast + Casting <code>str</code> to <code>String</code> is redundant + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Suspicious.java b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Suspicious.java new file mode 100644 index 000000000000..45719b08de72 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Suspicious.java @@ -0,0 +1,12 @@ +import java.util.Map; + +public class Suspicious { + Map map; + + void f(Object s){ + String str = (String) s; + map.remove((String)s); + map.remove((String)str); + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Test.java new file mode 100644 index 000000000000..f712d3338e9d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Ignore/scr/Test.java @@ -0,0 +1,21 @@ +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +class CastPreventsNPEDetection { + @Nullable Object getParent() { + return null; + } + + void f() { + ((ChildCastImpl)this).getParent().toString(); + ((CastPreventsNPEDetection)this).getParent().toString(); + } +} + +class ChildCastImpl extends CastPreventsNPEDetection { + @NotNull + @Override + Object getParent() { + return super.getParent(); //To change body of overridden methods use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference1/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/Inference1/expected.xml new file mode 100644 index 000000000000..580a889dbfd6 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference1/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference1/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/Inference1/src/Test.java new file mode 100644 index 000000000000..7e3836a62573 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference1/src/Test.java @@ -0,0 +1,20 @@ +import java.util.Map; +class Test2 { + public String s; + public void maina(Object key, Map parameters) { + s = ((String[]) parameters.get(key))[0]; + } +} + +public class Test { + static class SomeClass { + public T getX() { + return null; + } + } + + public static void main(String[] args) { + //cast is needed for 'String' to be infered! + System.getProperty((String)new SomeClass().getX()); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference2/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/Inference2/expected.xml new file mode 100644 index 000000000000..5e933496b9cf --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference2/expected.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference2/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/Inference2/src/Test.java new file mode 100644 index 000000000000..c121c0569a29 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference2/src/Test.java @@ -0,0 +1,32 @@ +import java.util.HashSet; +import java.util.Set; + +final class Pair { + public final A first; + public final B second; + + public Pair(A first, B second) { + this.first = first; + this.second = second; + } + + public final A getFirst() { + return first; + } + + public final B getSecond() { + return second; + } + + public static Pair create(A first, B second) { + return new Pair(first, second); + } + +} + +class Test { + final Set strings = new HashSet(); + final Pair, Set> x = Boolean.TRUE.booleanValue() + ? Pair.create(strings, strings) + : Pair.create(((Set) null), (Set) null); //these casts are not redundant +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference3/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/Inference3/expected.xml new file mode 100644 index 000000000000..380236bb5a9d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference3/expected.xml @@ -0,0 +1,13 @@ + + + + Test.java + 31 + Casting 'null' to 'Set<String>' is redundant + + + Test.java + 31 + Casting 'null' to 'Set<String>' is redundant + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/Inference3/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/Inference3/src/Test.java new file mode 100644 index 000000000000..64cf6d2e0a12 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/Inference3/src/Test.java @@ -0,0 +1,32 @@ +import java.util.HashSet; +import java.util.Set; + +final class Pair { + public final A first; + public final B second; + + public Pair(A first, B second) { + this.first = first; + this.second = second; + } + + public final A getFirst() { + return first; + } + + public final B getSecond() { + return second; + } + + public static Pair create(A first, A second) { + return new Pair(first, second); + } + +} + +class Test { + final Set strings = new HashSet(); + final Pair, Set> x = Boolean.TRUE.booleanValue() + ? Pair.create(strings, strings) + : Pair.create(((Set) null), (Set) null); //both casts are marked, but one is required for correct inference +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/expected.xml new file mode 100644 index 000000000000..48906bd0df8b --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/expected.xml @@ -0,0 +1,13 @@ + + + + Test.java + 8 + Casting null to Class[] is redundant + + + Test.java + 9 + Casting null to Class[] is redundant + + diff --git a/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/src/Test.java new file mode 100644 index 000000000000..c17d2647711d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/NullInVarargsParameter/src/Test.java @@ -0,0 +1,11 @@ +class Test { + void f(Class... classes) { + } + + void g() { + f(((Class[])null)); + f(((Class)null)); + f(((Class)null), + ((Class)null)); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/RawCast/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/RawCast/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/RawCast/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/RawCast/src/Test.java b/java/java-tests/testData/inspection/redundantCast/generics/RawCast/src/Test.java new file mode 100644 index 000000000000..2039039b8691 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/RawCast/src/Test.java @@ -0,0 +1,11 @@ +import java.util.Map; +import java.util.Properties; + +public class Main { + public static void main(String[] args) throws Exception { + Properties properties = new Properties(); + + Map map = (Map) properties; + System.out.println(map); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/expected.xml new file mode 100644 index 000000000000..c63c9258595e --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/expected.xml @@ -0,0 +1,2 @@ + + diff --git a/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/CastCast.java b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/CastCast.java new file mode 100644 index 000000000000..ef81defd32fc --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/CastCast.java @@ -0,0 +1,13 @@ +import java.util.List; + + +class RedundantCasts { + List myTranslators; + void t() { + b((List) (List)myTranslators); + } + + void b(List l){} +} +interface Compiler{} +interface TranslatingCompiler extends Compiler{} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/ReturnValue.java b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/ReturnValue.java new file mode 100644 index 000000000000..f30870b78d53 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/RawCastsToAvoidIncompatibility/src/ReturnValue.java @@ -0,0 +1,16 @@ +interface GenericValue { + T getValue(); +} + +interface GenericAttValue extends GenericValue { +} + +interface Property { + GenericAttValue getValue(); +} + +class RedCast { + public GenericValue getDataSourceName(Property property) { + return (GenericValue) property.getValue(); + } +} diff --git a/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/expected.xml new file mode 100644 index 000000000000..7574cc740a49 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/expected.xml @@ -0,0 +1,48 @@ + + + + WrapperToPrimitiveCast.java + 8 + Redundant type cast + Casting <code>J</code> to <code>int</code> is redundant + + + + WrapperToPrimitiveCast.java + 9 + Redundant type cast + Casting <code>I</code> to <code>int</code> is redundant + + + + WrapperToPrimitiveCast.java + 12 + Redundant type cast + Casting <code>p</code> to <code>Integer</code> is redundant + + + + WrapperToPrimitiveCast.java + 15 + Redundant type cast + Casting <code>p</code> to <code>Integer</code> is redundant + + + + + WrapperToPrimitiveCast.java + 24 + Redundant type cast + Casting <code>lnumber</code> to <code>long</code> is redundant + + + + + WrapperToPrimitiveCast.java + 24 + Redundant type cast + Casting <code>lnumber</code> to <code>long</code> is redundant + + + + diff --git a/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/src/WrapperToPrimitiveCast.java b/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/src/WrapperToPrimitiveCast.java new file mode 100644 index 000000000000..d9397902bf91 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/WrapperToPrimitiveCast/src/WrapperToPrimitiveCast.java @@ -0,0 +1,26 @@ +public class Main { + public static void main(String[] args) { + Integer J = 4; + Integer I = new Integer(4); + + System.out.println(I == J); + System.out.println((int) I == J); + int j = (int)J; + System.out.println((int) I == j); + + int p = 555555; + Integer W = (Integer) p; + System.out.println((Integer) p == W); + int w = W; + System.out.println((Integer) p == w); + + Integer test = 10; + double d = ((double)test/100); + + Double number = Double.valueOf(3); + long integerPart = (long) (double) number; + + Long lnumber = Long.valueOf(3); + long integerPartL = (long) (long) lnumber; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java new file mode 100644 index 000000000000..9fc42f08319b --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java @@ -0,0 +1,47 @@ +package com.intellij.codeInspection; + +import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; +import com.intellij.codeInspection.redundantCast.RedundantCastInspection; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.testFramework.InspectionTestCase; + +public class RedundantCast15Test extends InspectionTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5); + } + + + private void doTest() throws Exception { + final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(new RedundantCastInspection()); + doTest("redundantCast/generics/" + getTestName(false), tool, "java 1.5"); + } + + public void testBoxingInRef() throws Exception { doTest(); } + + public void testInference1() throws Exception { doTest(); } + + public void testInference2() throws Exception { doTest(); } + + public void testInference3() throws Exception { doTest(); } + + public void testNullInVarargsParameter() throws Exception { doTest(); } + + public void testWrapperToPrimitiveCast() throws Exception { doTest(); } + + public void testEnumConstant() throws Exception { doTest(); } + + public void testRawCast() throws Exception { doTest();} + + public void testRawCastsToAvoidIncompatibility() throws Exception { doTest();} + + public void testIgnore() throws Exception { + final RedundantCastInspection castInspection = new RedundantCastInspection(); + castInspection.IGNORE_ANNOTATED_METHODS = true; + castInspection.IGNORE_SUSPICIOUS_METHOD_CALLS = true; + final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(castInspection); + doTest("redundantCast/generics/" + getTestName(false), tool, "java 1.5"); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCastTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCastTest.java new file mode 100644 index 000000000000..0e04743e8dce --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCastTest.java @@ -0,0 +1,93 @@ +package com.intellij.codeInspection; + +import com.intellij.codeInspection.redundantCast.RedundantCastInspection; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.testFramework.InspectionTestCase; + +public class RedundantCastTest extends InspectionTestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_3); + } + + private void doTest() throws Exception { + doTest("redundantCast/" + getTestName(false), new RedundantCastInspection()); + } + + public void testAmbigousParm1() throws Exception { doTest(); } + + public void testAmbigousParm2() throws Exception { doTest(); } + + public void testAmbigousParm3() throws Exception { doTest(); } + + public void testAmbigousParm4() throws Exception { doTest(); } + + public void testAmbigousParm5() throws Exception { doTest(); } + + public void testOneOfTwo() throws Exception { doTest(); } + + public void testAnyOfTwo() throws Exception { doTest(); } + + public void testNew1() throws Exception { doTest(); } + + public void testAssignment1() throws Exception { doTest(); } + + public void testInitializer1() throws Exception { doTest(); } + + public void testShortToShort() throws Exception { doTest(); } + + public void testVirtualMethod1() throws Exception { doTest(); } + + public void testVirtualMethod2() throws Exception { doTest(); } + + public void testVirtualMethod3() throws Exception { doTest(); } + + public void testDoubleCast1() throws Exception { doTest(); } + + public void testDoubleCast2() throws Exception { doTest(); } + + public void testDoubleCast3() throws Exception { doTest(); } + + public void testDoubleCast4() throws Exception { doTest(); } + + public void testDoubleCast5() throws Exception { doTest(); } + + public void testShortVsInt() throws Exception { doTest(); } + + public void testTruncation() throws Exception { doTest(); } + + public void testIntToDouble() throws Exception { doTest(); } + + public void testSCR6907() throws Exception { doTest(); } + + public void testSCR11555() throws Exception { doTest(); } + + public void testSCR13397() throws Exception { doTest(); } + + public void testSCR14502() throws Exception { doTest(); } + + public void testSCR14559() throws Exception { doTest(); } + + public void testSCR15236() throws Exception { doTest(); } + + public void testComparingToNull() throws Exception { doTest(); } + + public void testInaccessible() throws Exception { doTest(); } + + public void testInConditional() throws Exception { doTest(); } + + public void testDifferentFields() throws Exception { doTest(); } + + public void testNestedThings() throws Exception { doTest(); } + + public void testIDEADEV6818() throws Exception { doTest(); } + + public void testIDEADEV15170() throws Exception { doTest(); } + + public void testIDEADEV25675() throws Exception { doTest(); } + + public void testNestedCast() throws Exception { doTest(); } +} From 8525da6f4e7fbe891d86f59d2376b92fcb5ea1b2 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Fri, 24 Jun 2011 15:55:07 +0400 Subject: [PATCH 21/45] IDEA-67915 Matching brace highlighing Don't search forward if caret is at the line end already --- .../codeInsight/highlighting/BraceHighlightingHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java index 468ba53943ba..e2aad53fe08e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java @@ -240,8 +240,8 @@ public class BraceHighlightingHandler { // Example: // public void test() { // } - boolean searchForward = true; char c = chars.charAt(offset); + boolean searchForward = c != '\n'; // Try to find matched brace backwards. if (offset >= originalOffset || c != '\n') { @@ -260,8 +260,8 @@ public class BraceHighlightingHandler { // Try to find matched brace forward. if (searchForward) { - int forwardOffset = CharArrayUtil.shiftForward(chars, c == '\n' ? offset + 1 : offset, "\t "); - if (forwardOffset > offset || c == ' ' || c == '\t' || c == '\n') { + int forwardOffset = CharArrayUtil.shiftForward(chars, offset, "\t "); + if (forwardOffset > offset || c == ' ' || c == '\t') { iterator = getEditorHighlighter().createIterator(forwardOffset); FileType newFileType = getFileTypeByIterator(iterator); if (BraceMatchingUtil.isLBraceToken(iterator, chars, newFileType) || From 7f0b52ac52fb37cd81cee4d36f2d494e9afd7cf8 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 16:28:29 +0400 Subject: [PATCH 22/45] IDEA-71244 (NPE at single-type/single-static import conflict fixed) --- .../daemon/impl/analysis/HighlightUtil.java | 6 ++--- .../impl/analysis/HighlightVisitorImpl.java | 14 +++++++---- .../staticImportConflict/UsageMixed.java | 23 +++++++++++++++++++ .../staticImportConflict/x/Base1.java | 1 + .../staticImportConflict/x/Base2.java | 1 + .../daemon/AdvHighlightingJdk7Test.java | 4 ++++ 6 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/UsageMixed.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index a59afce9f1fd..691dd3d4c1d2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -2019,18 +2019,18 @@ public class HighlightUtil { @Nullable public static HighlightInfo checkSingleImportClassConflict(PsiImportStatement statement, - Map> singleImportedClasses) { + Map> importedClasses) { if (statement.isOnDemand()) return null; PsiElement element = statement.resolve(); if (element instanceof PsiClass) { String name = ((PsiClass)element).getName(); - Pair imported = singleImportedClasses.get(name); + Pair imported = importedClasses.get(name); PsiClass importedClass = imported == null ? null : imported.getSecond(); if (importedClass != null && !element.getManager().areElementsEquivalent(importedClass, element)) { String description = JavaErrorMessages.message("single.import.class.conflict", formatClass(importedClass)); return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, statement, description); } - singleImportedClasses.put(name, Pair.create((PsiImportStaticReferenceElement)statement.getReference(), (PsiClass)element)); + importedClasses.put(name, Pair.create((PsiImportStaticReferenceElement)null, (PsiClass)element)); } return null; } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 716d63dfabba..555f9f518ff4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -445,7 +445,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitImportStatement(final PsiImportStatement statement) { - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkSingleImportClassConflict(statement, mySingleImportedClasses)); + if (!myHolder.hasErrorResults()) { + myHolder.add(HighlightUtil.checkSingleImportClassConflict(statement, mySingleImportedClasses)); + } } @Override @@ -471,9 +473,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh final Pair imported = mySingleImportedClasses.get(refName); final PsiClass aClass = imported == null ? null : imported.getSecond(); if (aClass != null && !manager.areElementsEquivalent(aClass, element)) { - description = imported.getFirst().equals(ref) - ? JavaErrorMessages.message("class.is.ambiguous.in.single.static.import", refName) - : JavaErrorMessages.message("class.is.already.defined.in.single.static.import", refName); + description = imported.first == null + ? JavaErrorMessages.message("single.import.class.conflict", refName) + : imported.first.equals(ref) + ? JavaErrorMessages.message("class.is.ambiguous.in.single.static.import", refName) + : JavaErrorMessages.message("class.is.already.defined.in.single.static.import", refName); } mySingleImportedClasses.put(refName, Pair.create(ref, (PsiClass)element)); } @@ -481,7 +485,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh final Pair imported = mySingleImportedFields.get(refName); final PsiField field = imported == null ? null : imported.getSecond(); if (field != null && !manager.areElementsEquivalent(field, element)) { - description = imported.getFirst().equals(ref) + description = imported.first.equals(ref) ? JavaErrorMessages.message("field.is.ambiguous.in.single.static.import", refName) : JavaErrorMessages.message("field.is.already.defined.in.single.static.import", refName); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/UsageMixed.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/UsageMixed.java new file mode 100644 index 000000000000..9b5acd3cb554 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/UsageMixed.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import x.Base1.D; +import static x.Base2.D; + +class UsageMixed { + void use() { + D.class.getName(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base1.java index 197ec8d762fc..8dc9bb80de30 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base1.java @@ -19,6 +19,7 @@ public class Base1 { public static final int F = 1; public static void m(int i) { } public static class F { } + public static class D { } public interface I1 { int IF = 1; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base2.java index 2086a8e2d96b..c27f30779dbf 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/x/Base2.java @@ -19,6 +19,7 @@ public class Base2 extends Base1 { public static final float F = 2.0f; public static void m(float f) { } public static class F { } + public static class D { } public interface II extends I1, I2 { } public enum E { } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java index 4cdb0d4c29cc..4bd5bfaf58d8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java @@ -56,4 +56,8 @@ public class AdvHighlightingJdk7Test extends DaemonAnalyzerTestCase { public void testStaticImportMethodShadowing() throws Exception { doTest(BASE_PATH + "staticImports/P1/MethodShadowing.java", BASE_PATH + "/staticImports", false, false); } + + public void testStaticAndSingleImportConflict() throws Exception { + doTest(BASE_PATH + "staticImportConflict/UsageMixed.java", BASE_PATH + "/staticImportConflict", false, false); + } } From 74e16105a3a87dcb6a8370b1b8bd9188e022fa0c Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 24 Jun 2011 14:46:15 +0200 Subject: [PATCH 23/45] quickfix --- ...fAnotherObjectsPrivateFieldInspection.java | 97 ++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java index 75bdc8a422cc..8b4502706d8c 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 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. @@ -15,12 +15,18 @@ */ package com.siyeh.ig.encapsulation; +import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.util.PropertyUtil; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; +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.MethodUtils; import org.jetbrains.annotations.NotNull; @@ -65,6 +71,93 @@ public class UseOfAnotherObjectsPrivateFieldInspection return panel; } + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + final PsiField field = (PsiField) infos[0]; + final String propertyName = field.getName(); + final PsiReferenceExpression referenceExpression = + (PsiReferenceExpression) infos[1]; + final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); + final PsiClass containingClass = field.getContainingClass(); + if (PsiUtil.isAccessedForReading(referenceExpression)) { + if (PsiUtil.isAccessedForWriting(referenceExpression)) { + return null; + } + final PsiMethod getter = + PropertyUtil.findPropertyGetter(containingClass, + propertyName, isStatic, true); + if (getter == null) { + return null; + } + return new UseOfAnotherObjectsPrivateFieldFix(getter); + } else if (PsiUtil.isAccessedForWriting(referenceExpression)) { + final PsiMethod setter = + PropertyUtil.findPropertySetter(containingClass, + propertyName, isStatic, true); + if (setter == null) { + return null; + } + return new UseOfAnotherObjectsPrivateFieldFix(setter); + } + return null; + } + + private static class UseOfAnotherObjectsPrivateFieldFix + extends InspectionGadgetsFix { + + private final PsiMethod method; + + public UseOfAnotherObjectsPrivateFieldFix(PsiMethod method) { + this.method = method; + } + + @NotNull + @Override + public String getName() { + return "Replace with call to '" + method.getName() + "'"; + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) + throws IncorrectOperationException { + final PsiElement element = descriptor.getPsiElement(); + final PsiElement parent = element.getParent(); + if (!(parent instanceof PsiReferenceExpression)) { + return; + } + final PsiReferenceExpression referenceExpression = + (PsiReferenceExpression) parent; + final StringBuilder methodCallText = new StringBuilder(); + final PsiExpression qualifierExpression = + referenceExpression.getQualifierExpression(); + if (qualifierExpression != null) { + methodCallText.append(qualifierExpression.getText()); + methodCallText.append('.'); + } + methodCallText.append(method.getName()); + if (!PsiUtil.isOnAssignmentLeftHand(referenceExpression)) { + methodCallText.append("()"); + replaceExpression(referenceExpression, + methodCallText.toString()); + } else { + final PsiAssignmentExpression assignmentExpression = + PsiTreeUtil.getParentOfType(referenceExpression, + PsiAssignmentExpression.class); + if (assignmentExpression == null) { + return; + } + methodCallText.append('('); + final PsiExpression rhs = assignmentExpression.getRExpression(); + if (rhs != null) { + methodCallText.append(rhs.getText()); + } + methodCallText.append(')'); + replaceExpression(assignmentExpression, + methodCallText.toString()); + } + } + } + @Override public BaseInspectionVisitor buildVisitor(){ return new UseOfAnotherObjectsPrivateFieldVisitor(); @@ -112,7 +205,7 @@ public class UseOfAnotherObjectsPrivateFieldInspection if(fieldNameElement == null){ return; } - registerError(fieldNameElement); + registerError(fieldNameElement, field, expression); } } } From be804ad1776688d83827e72cf74e44ebb220d92d Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Thu, 23 Jun 2011 21:17:07 +0400 Subject: [PATCH 24/45] Jdbc console terminate action --- platform/platform-resources/src/idea/Keymap_Default.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index c56878c6df3e..6eec61b2a34f 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -915,6 +915,7 @@ + From 3ca9f88b5d0a70c7cc907f25eb99ead36ae0247f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 24 Jun 2011 14:51:13 +0200 Subject: [PATCH 25/45] better quickfix --- .../siyeh/InspectionGadgetsBundle.properties | 2 +- .../PackageVisibleFieldInspection.java | 7 +- .../ProtectedFieldInspection.java | 12 ++- .../encapsulation/PublicFieldInspection.java | 13 ++- ...fAnotherObjectsPrivateFieldInspection.java | 91 +------------------ .../ig/fixes/EncapsulateVariableFix.java | 34 ++++++- 6 files changed, 56 insertions(+), 103 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 876789340eba..81d3d7f48c05 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1227,7 +1227,7 @@ unused.catch.parameter.ignore.catch.option=Ignore for 'catch' blocks containing unused.catch.parameter.ignore.empty.option=Ignore unused 'catch' parameters in tests add.serialversionuidfield.quickfix=Add 'serialVersionUID' field delete.import.quickfix=Delete unnecessary import -encapsulate.variable.quickfix=Encapsulate variable +encapsulate.variable.quickfix=Encapsulate field ''{0}'' extract.method.quickfix=Extract method inline.call.quickfix=Inline call inline.variable.quickfix=Inline variable diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PackageVisibleFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PackageVisibleFieldInspection.java index d1a39cefa173..b8f9cd1a2931 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PackageVisibleFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PackageVisibleFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 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. @@ -42,7 +42,8 @@ public class PackageVisibleFieldInspection extends BaseInspection { @Override protected InspectionGadgetsFix buildFix(Object... infos) { - return new EncapsulateVariableFix(); + final PsiField field = (PsiField) infos[0]; + return new EncapsulateVariableFix(field.getName()); } @Override @@ -68,7 +69,7 @@ public class PackageVisibleFieldInspection extends BaseInspection { field.hasModifierProperty(PsiModifier.FINAL)) { return; } - registerFieldError(field); + registerFieldError(field, field); } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ProtectedFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ProtectedFieldInspection.java index 731c7ded378a..219835032abf 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ProtectedFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ProtectedFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 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. @@ -26,25 +26,31 @@ import org.jetbrains.annotations.NotNull; public class ProtectedFieldInspection extends BaseInspection { + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message("protected.field.display.name"); } + @Override @NotNull public String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "protected.field.problem.descriptor"); } + @Override protected InspectionGadgetsFix buildFix(Object... infos) { - return new EncapsulateVariableFix(); + final PsiField field = (PsiField) infos[0]; + return new EncapsulateVariableFix(field.getName()); } + @Override protected boolean buildQuickFixesOnlyForOnTheFlyErrors() { return true; } + @Override public BaseInspectionVisitor buildVisitor() { return new ProtectedFieldVisitor(); } @@ -59,7 +65,7 @@ public class ProtectedFieldInspection extends BaseInspection { field.hasModifierProperty(PsiModifier.FINAL)) { return; } - registerFieldError(field); + registerFieldError(field, field); } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PublicFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PublicFieldInspection.java index 36510dbcdc6c..1514a712ff4f 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PublicFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/PublicFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 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. @@ -33,17 +33,20 @@ public class PublicFieldInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean ignoreEnums = false; + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message("public.field.display.name"); } + @Override @NotNull public String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "public.field.problem.descriptor"); } + @Override @Nullable public JComponent createOptionsPanel() { return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message( @@ -51,14 +54,18 @@ public class PublicFieldInspection extends BaseInspection { "ignoreEnums"); } + @Override protected InspectionGadgetsFix buildFix(Object... infos) { - return new EncapsulateVariableFix(); + final PsiField field = (PsiField) infos[0]; + return new EncapsulateVariableFix(field.getName()); } + @Override protected boolean buildQuickFixesOnlyForOnTheFlyErrors() { return true; } + @Override public BaseInspectionVisitor buildVisitor() { return new PublicFieldVisitor(); } @@ -87,7 +94,7 @@ public class PublicFieldInspection extends BaseInspection { } } } - registerFieldError(field); + registerFieldError(field, field); } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java index 8b4502706d8c..cc465c6166c5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/UseOfAnotherObjectsPrivateFieldInspection.java @@ -15,18 +15,14 @@ */ package com.siyeh.ig.encapsulation; -import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; -import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.intellij.psi.util.PropertyUtil; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.util.PsiUtil; -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.fixes.EncapsulateVariableFix; import com.siyeh.ig.psiutils.MethodUtils; import org.jetbrains.annotations.NotNull; @@ -74,88 +70,7 @@ public class UseOfAnotherObjectsPrivateFieldInspection @Override protected InspectionGadgetsFix buildFix(Object... infos) { final PsiField field = (PsiField) infos[0]; - final String propertyName = field.getName(); - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression) infos[1]; - final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); - final PsiClass containingClass = field.getContainingClass(); - if (PsiUtil.isAccessedForReading(referenceExpression)) { - if (PsiUtil.isAccessedForWriting(referenceExpression)) { - return null; - } - final PsiMethod getter = - PropertyUtil.findPropertyGetter(containingClass, - propertyName, isStatic, true); - if (getter == null) { - return null; - } - return new UseOfAnotherObjectsPrivateFieldFix(getter); - } else if (PsiUtil.isAccessedForWriting(referenceExpression)) { - final PsiMethod setter = - PropertyUtil.findPropertySetter(containingClass, - propertyName, isStatic, true); - if (setter == null) { - return null; - } - return new UseOfAnotherObjectsPrivateFieldFix(setter); - } - return null; - } - - private static class UseOfAnotherObjectsPrivateFieldFix - extends InspectionGadgetsFix { - - private final PsiMethod method; - - public UseOfAnotherObjectsPrivateFieldFix(PsiMethod method) { - this.method = method; - } - - @NotNull - @Override - public String getName() { - return "Replace with call to '" + method.getName() + "'"; - } - - @Override - protected void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { - final PsiElement element = descriptor.getPsiElement(); - final PsiElement parent = element.getParent(); - if (!(parent instanceof PsiReferenceExpression)) { - return; - } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression) parent; - final StringBuilder methodCallText = new StringBuilder(); - final PsiExpression qualifierExpression = - referenceExpression.getQualifierExpression(); - if (qualifierExpression != null) { - methodCallText.append(qualifierExpression.getText()); - methodCallText.append('.'); - } - methodCallText.append(method.getName()); - if (!PsiUtil.isOnAssignmentLeftHand(referenceExpression)) { - methodCallText.append("()"); - replaceExpression(referenceExpression, - methodCallText.toString()); - } else { - final PsiAssignmentExpression assignmentExpression = - PsiTreeUtil.getParentOfType(referenceExpression, - PsiAssignmentExpression.class); - if (assignmentExpression == null) { - return; - } - methodCallText.append('('); - final PsiExpression rhs = assignmentExpression.getRExpression(); - if (rhs != null) { - methodCallText.append(rhs.getText()); - } - methodCallText.append(')'); - replaceExpression(assignmentExpression, - methodCallText.toString()); - } - } + return new EncapsulateVariableFix(field.getName()); } @Override @@ -205,7 +120,7 @@ public class UseOfAnotherObjectsPrivateFieldInspection if(fieldNameElement == null){ return; } - registerError(fieldNameElement, field, expression); + registerError(fieldNameElement, field); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EncapsulateVariableFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EncapsulateVariableFix.java index d889b8bffba4..1ef9201f1d9a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EncapsulateVariableFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EncapsulateVariableFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005 Dave Griffith + * Copyright 2003-2011 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. @@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiField; +import com.intellij.psi.PsiReferenceExpression; import com.intellij.refactoring.JavaRefactoringActionHandlerFactory; import com.intellij.refactoring.RefactoringActionHandler; import com.siyeh.InspectionGadgetsBundle; @@ -27,14 +28,37 @@ import org.jetbrains.annotations.NotNull; public class EncapsulateVariableFix extends InspectionGadgetsFix { - @NotNull - public String getName() { - return InspectionGadgetsBundle.message("encapsulate.variable.quickfix"); + private final String fieldName; + + public EncapsulateVariableFix(String fieldName) { + this.fieldName = fieldName; } + @Override + @NotNull + public String getName() { + return InspectionGadgetsBundle.message("encapsulate.variable.quickfix", + fieldName); + } + + @Override public void doFix(Project project, ProblemDescriptor descriptor) { final PsiElement nameElement = descriptor.getPsiElement(); - final PsiField field = (PsiField) nameElement.getParent(); + final PsiElement parent = nameElement.getParent(); + final PsiField field; + if (parent instanceof PsiField) { + field = (PsiField) parent; + } else if (parent instanceof PsiReferenceExpression) { + final PsiReferenceExpression referenceExpression = + (PsiReferenceExpression) parent; + final PsiElement target = referenceExpression.resolve(); + if (!(target instanceof PsiField)) { + return; + } + field = (PsiField) target; + } else { + return; + } final JavaRefactoringActionHandlerFactory factory = JavaRefactoringActionHandlerFactory.getInstance(); final RefactoringActionHandler renameHandler = From addd41e6acc0e17a2d7ef02b0497fa5053d6c13a Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Fri, 24 Jun 2011 16:16:51 +0400 Subject: [PATCH 26/45] IDEA-69782 IDEA-67009 converter for onClick xml attribute --- .../jetbrains/android/dom/AndroidDomUtil.java | 9 +- .../dom/converters/OnClickConverter.java | 165 ++++++++++++++++++ .../inspections/AndroidDomInspection.java | 4 +- .../testData/dom/layout/OnClick_Class1.java | 27 +++ .../testData/dom/layout/OnClick_Class2.java | 9 + .../testData/dom/layout/OnClick_Class3.java | 14 ++ .../testData/dom/layout/OnClick_Class4.java | 11 ++ .../testData/dom/layout/onClickCompletion.xml | 5 + .../dom/layout/onClickHighlighting.xml | 16 ++ .../testData/dom/layout/onClickNavigation.xml | 5 + .../android/dom/AndroidLayoutDomTest.java | 39 ++++- 11 files changed, 298 insertions(+), 6 deletions(-) create mode 100644 plugins/android/src/org/jetbrains/android/dom/converters/OnClickConverter.java create mode 100644 plugins/android/testData/dom/layout/OnClick_Class1.java create mode 100644 plugins/android/testData/dom/layout/OnClick_Class2.java create mode 100644 plugins/android/testData/dom/layout/OnClick_Class3.java create mode 100644 plugins/android/testData/dom/layout/OnClick_Class4.java create mode 100644 plugins/android/testData/dom/layout/onClickCompletion.xml create mode 100644 plugins/android/testData/dom/layout/onClickHighlighting.xml create mode 100644 plugins/android/testData/dom/layout/onClickNavigation.xml diff --git a/plugins/android/src/org/jetbrains/android/dom/AndroidDomUtil.java b/plugins/android/src/org/jetbrains/android/dom/AndroidDomUtil.java index f3c062599a22..bdb68532e840 100644 --- a/plugins/android/src/org/jetbrains/android/dom/AndroidDomUtil.java +++ b/plugins/android/src/org/jetbrains/android/dom/AndroidDomUtil.java @@ -23,6 +23,7 @@ import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.HashMap; +import com.intellij.util.xml.Converter; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.ResolvingConverter; import com.intellij.util.xml.XmlName; @@ -59,6 +60,7 @@ public class AndroidDomUtil { public static final StaticEnumConverter BOOLEAN_CONVERTER = new StaticEnumConverter("true", "false"); public static final Map SPECIAL_RESOURCE_TYPES = new HashMap(); private static final PackageClassConverter ACTIVITY_CONVERTER = new PackageClassConverter(AndroidUtils.ACTIVITY_BASE_CLASS_NAME); + private static final OnClickConverter ON_CLICK_CONVERTER = new OnClickConverter(); static { addSpecialResourceType("string", "label", "description", "title"); @@ -146,7 +148,7 @@ public class AndroidDomUtil { } @Nullable - public static ResolvingConverter getSpecificConverter(@NotNull XmlName attrName, DomElement context) { + public static Converter getSpecificConverter(@NotNull XmlName attrName, DomElement context) { if (context == null) { return null; } @@ -168,6 +170,11 @@ public class AndroidDomUtil { return ACTIVITY_CONVERTER; } } + else if (context instanceof LayoutViewElement) { + if ("onClick".equals(localName)) { + return ON_CLICK_CONVERTER; + } + } return null; } diff --git a/plugins/android/src/org/jetbrains/android/dom/converters/OnClickConverter.java b/plugins/android/src/org/jetbrains/android/dom/converters/OnClickConverter.java new file mode 100644 index 000000000000..be9d864c9916 --- /dev/null +++ b/plugins/android/src/org/jetbrains/android/dom/converters/OnClickConverter.java @@ -0,0 +1,165 @@ +package org.jetbrains.android.dom.converters; + +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Iconable; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.*; +import com.intellij.psi.impl.PsiManagerEx; +import com.intellij.psi.impl.source.resolve.ResolveCache; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.ProjectScope; +import com.intellij.psi.search.PsiShortNamesCache; +import com.intellij.psi.search.searches.ClassInheritorsSearch; +import com.intellij.psi.xml.XmlAttributeValue; +import com.intellij.util.ArrayUtil; +import com.intellij.util.Processor; +import com.intellij.util.containers.HashSet; +import com.intellij.util.xml.ConvertContext; +import com.intellij.util.xml.Converter; +import com.intellij.util.xml.CustomReferenceConverter; +import com.intellij.util.xml.GenericDomValue; +import org.jetbrains.android.util.AndroidUtils; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * @author Eugene.Kudelevsky + */ +public class OnClickConverter extends Converter implements CustomReferenceConverter { + @NotNull + @Override + public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) { + final int length = element.getTextLength(); + if (length > 1) { + return new PsiReference[]{new MyReference((XmlAttributeValue)element, new TextRange(1, length - 1))}; + } + return PsiReference.EMPTY_ARRAY; + } + + @Override + public String fromString(@Nullable @NonNls String s, ConvertContext context) { + return s; + } + + @Override + public String toString(@Nullable String s, ConvertContext context) { + return s; + } + + private static class MyReference extends PsiPolyVariantReferenceBase { + + public MyReference(XmlAttributeValue value, TextRange range) { + super(value, range, true); + } + + @NotNull + @Override + public ResolveResult[] multiResolve(boolean incompleteCode) { + return ((PsiManagerEx)getElement().getManager()).getResolveCache() + .resolveWithCaching(this, new ResolveCache.PolyVariantResolver() { + @Override + public ResolveResult[] resolve(MyReference myReference, boolean incompleteCode) { + return resolveInner(); + } + }, false, incompleteCode); + } + + private ResolveResult[] resolveInner() { + final String methodName = myElement.getValue(); + if (methodName == null) { + return ResolveResult.EMPTY_ARRAY; + } + + final Project project = myElement.getProject(); + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); + final PsiShortNamesCache cache = psiFacade.getShortNamesCache(); + + final PsiMethod[] methods = cache.getMethodsByName(methodName, GlobalSearchScope.projectScope(project)); + if (methods.length == 0) { + return ResolveResult.EMPTY_ARRAY; + } + + final List result = new ArrayList(); + for (PsiMethod method : methods) { + if (checkSignature(method)) { + result.add(new PsiElementResolveResult(method)); + } + } + return result.toArray(new ResolveResult[result.size()]); + } + + private static boolean checkSignature(PsiMethod method) { + if (method.getReturnType() != PsiType.VOID) { + return false; + } + + if (method.hasModifierProperty(PsiModifier.STATIC) || + method.hasModifierProperty(PsiModifier.ABSTRACT) || + !method.hasModifierProperty(PsiModifier.PUBLIC)) { + return false; + } + + final PsiClass aClass = method.getContainingClass(); + if (aClass == null || aClass.isInterface()) { + return false; + } + + final PsiParameter[] parameters = method.getParameterList().getParameters(); + if (parameters.length != 1) { + return false; + } + + final PsiType paramType = parameters[0].getType(); + if (!(paramType instanceof PsiClassType)) { + return false; + } + + final PsiClass paramClass = ((PsiClassType)paramType).resolve(); + return paramClass != null && AndroidUtils.VIEW_CLASS_NAME.equals(paramClass.getQualifiedName()); + } + + @NotNull + @Override + public Object[] getVariants() { + final Project project = myElement.getProject(); + final GlobalSearchScope scope = ProjectScope.getAllScope(project); + + final PsiClass activityClass = JavaPsiFacade.getInstance(project).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, scope); + if (activityClass == null) { + return EMPTY_ARRAY; + } + + final List result = new ArrayList(); + final Set methodNames = new HashSet(); + + ClassInheritorsSearch.search(activityClass, scope, true).forEach(new Processor() { + public boolean process(PsiClass c) { + for (PsiMethod method : c.getMethods()) { + if (checkSignature(method) && methodNames.add(method.getName())) { + result.add(createLookupElement(method)); + } + } + return true; + } + }); + return ArrayUtil.toObjectArray(result); + } + } + + private static LookupElement createLookupElement(PsiMethod method) { + final LookupElementBuilder builder = LookupElementBuilder.create(method, method.getName()) + .setIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY)) + .setPresentableText(method.getName()); + final PsiClass containingClass = method.getContainingClass(); + return containingClass != null + ? builder.setTailText(" (" + containingClass.getQualifiedName() + ')') + : builder; + } +} diff --git a/plugins/android/src/org/jetbrains/android/inspections/AndroidDomInspection.java b/plugins/android/src/org/jetbrains/android/inspections/AndroidDomInspection.java index 20afa22bd832..95d71a6ba263 100644 --- a/plugins/android/src/org/jetbrains/android/inspections/AndroidDomInspection.java +++ b/plugins/android/src/org/jetbrains/android/inspections/AndroidDomInspection.java @@ -21,6 +21,7 @@ import com.intellij.util.xml.WrappingConverter; import com.intellij.util.xml.highlighting.BasicDomElementsInspection; import org.jetbrains.android.dom.AndroidDomElement; import org.jetbrains.android.dom.converters.AndroidPackageConverter; +import org.jetbrains.android.dom.converters.OnClickConverter; import org.jetbrains.android.util.AndroidBundle; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; @@ -55,6 +56,7 @@ public class AndroidDomInspection extends BasicDomElementsInspection + + + + diff --git a/plugins/android/testData/dom/layout/onClickHighlighting.xml b/plugins/android/testData/dom/layout/onClickHighlighting.xml new file mode 100644 index 000000000000..37709a9f8d51 --- /dev/null +++ b/plugins/android/testData/dom/layout/onClickHighlighting.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/plugins/android/testData/dom/layout/onClickNavigation.xml b/plugins/android/testData/dom/layout/onClickNavigation.xml new file mode 100644 index 000000000000..40d0f1fa29b9 --- /dev/null +++ b/plugins/android/testData/dom/layout/onClickNavigation.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java index 2dc52e01bf13..28a771d99517 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java @@ -1,13 +1,12 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; +import com.intellij.codeInsight.TargetElementUtilBase; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; +import com.intellij.psi.*; import com.intellij.util.ArrayUtil; +import java.io.IOException; import java.util.List; /** @@ -282,5 +281,37 @@ public class AndroidLayoutDomTest extends AndroidDomTest { PsiElement rootViewClass = rootReference.resolve(); assertTrue("Must be PsiClass reference", rootViewClass instanceof PsiClass); } + + public void testOnClickCompletion() throws Throwable { + copyOnClickClasses(); + doTestCompletionVariants(getTestName(true) + ".xml", "clickHandler1", "clickHandler7"); + } + + public void testOnClickHighlighting() throws Throwable { + copyOnClickClasses(); + doTestHighlighting(); + } + + public void testOnClickNavigation() throws Throwable { + copyOnClickClasses(); + final VirtualFile file = copyFileToProject(getTestName(true) + ".xml"); + myFixture.configureFromExistingVirtualFile(file); + + final PsiReference reference = TargetElementUtilBase.findReference(myFixture.getEditor(), myFixture.getCaretOffset()); + assertNotNull(reference); + assertInstanceOf(reference, PsiPolyVariantReference.class); + final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false); + assertEquals(3, results.length); + for (ResolveResult result : results) { + assertInstanceOf(result.getElement(), PsiMethod.class); + } + } + + private void copyOnClickClasses() throws IOException { + copyFileToProject("OnClick_Class1.java", "src/p1/p2/OnClick_Class1.java"); + copyFileToProject("OnClick_Class2.java", "src/p1/p2/OnClick_Class2.java"); + copyFileToProject("OnClick_Class3.java", "src/p1/p2/OnClick_Class3.java"); + copyFileToProject("OnClick_Class4.java", "src/p1/p2/OnClick_Class4.java"); + } } From bf914b45f34dc77e3b0b0a22258616cf44ce25c4 Mon Sep 17 00:00:00 2001 From: Nikolay Matveev Date: Mon, 20 Jun 2011 15:01:54 +0400 Subject: [PATCH 27/45] EA-28340 (cherry picked from commit 25fbaf91470df9c74070c80949e833e1f763fc1c) --- .../impl/statistics/RunConfigurationTypeUsagesCollector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java b/platform/lang-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java index f60197c77711..6ee3a40c1091 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java @@ -49,7 +49,7 @@ public class RunConfigurationTypeUsagesCollector extends AbstractApplicationUsag final Set runConfigurationTypes = new HashSet(); final RunManager runManager = RunManager.getInstance(project); for (RunConfiguration runConfiguration : runManager.getAllConfigurations()) { - if (!runManager.isTemporary(runConfiguration)) { + if ((runConfiguration != null) && (!runManager.isTemporary(runConfiguration))) { final ConfigurationFactory configurationFactory = runConfiguration.getFactory(); final ConfigurationType configurationType = configurationFactory.getType(); final StringBuilder keyBuilder = new StringBuilder(); From c97b774a2f9e74b68172d582e2b8f93c7708b3af Mon Sep 17 00:00:00 2001 From: Nikolay Matveev Date: Thu, 23 Jun 2011 16:10:22 +0400 Subject: [PATCH 28/45] More useful methods to ScriptRunnerUtil --- .../execution/process/ScriptRunnerUtil.java | 70 +++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java b/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java index c1380bae4ae1..ec48dd795a43 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java +++ b/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java @@ -19,24 +19,82 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * Created by IntelliJ IDEA. - * User: lene - * Date: 26.04.11 - * Time: 23:10 + * @author Elena Shaverdova + * @author Nikolay Matveev */ -public class ScriptRunnerUtil { - private static final Logger LOG = Logger.getInstance(ScriptRunnerUtil.class.getName()); +public final class ScriptRunnerUtil { + + private static final Logger LOG = Logger.getInstance("com.intellij.execution.process.ScriptRunnerUtil"); + + public static final Condition STDOUT_OUTPUT_KEY_FILTER = new Condition() { + @Override + public boolean value(Key key) { + return ProcessOutputTypes.STDOUT.equals(key); + } + }; + + public static final Condition STDERR_OUTPUT_KEY_FILTER = new Condition() { + @Override + public boolean value(Key key) { + return ProcessOutputTypes.STDERR.equals(key); + } + }; + + public static final Condition STDOUT_OR_STDERR_OUTPUT_KEY_FILTER = Conditions.or(STDOUT_OUTPUT_KEY_FILTER, STDERR_OUTPUT_KEY_FILTER); + + private static final int DEFAULT_TIMEOUT = 30000; private ScriptRunnerUtil() { } + public static String getProcessOutput(@NotNull GeneralCommandLine commandLine, + @NotNull Condition outputTypeFilter) + throws ExecutionException { + return getProcessOutput(commandLine, outputTypeFilter, DEFAULT_TIMEOUT); + } + + public static String getProcessOutput(@NotNull GeneralCommandLine commandLine, + @NotNull Condition outputTypeFilter, + long timeout) + throws ExecutionException { + return getProcessOutput(new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()), outputTypeFilter, + timeout); + } + + public static String getProcessOutput(@NotNull final ProcessHandler processHandler, + @NotNull final Condition outputTypeFilter, + final long timeout) + throws ExecutionException { + final StringBuilder outputBuilder = new StringBuilder(); + processHandler.addProcessListener(new ProcessAdapter() { + @Override + public void onTextAvailable(ProcessEvent event, Key outputType) { + if (outputTypeFilter.value(outputType)) { + final String text = event.getText(); + outputBuilder.append(text); + if (LOG.isDebugEnabled()) { + LOG.debug(text); + } + } + } + }); + processHandler.startNotify(); + if (!processHandler.waitFor(timeout)) { + throw new ExecutionException(ExecutionBundle.message("script.execution.timeout", String.valueOf(timeout / 1000))); + } + return outputBuilder.toString(); + } + public static OSProcessHandler execute(String exePath, @Nullable String workingDirectory, @Nullable VirtualFile scriptFile, From ce21b91d8b83234d291a9d3177e79e22a9209474 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 15:54:52 +0400 Subject: [PATCH 29/45] EA-27995 java.lang.AssertionError: Already disposed: Project (Disposed) HMEncyclopedia at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:215) at com.intellij.ide.util.PropertiesComponent.getInstance(PropertiesComponent.java:27) at com.intellij.openapi.vcs.changes.ui.ChangesTreeList$ToggleShowDirectoriesAction.isSelected(ChangesTreeList.java:724) at com.intellij.openapi.actionSystem.ToggleAction.update(ToggleAction.java:60) at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:98) at com.intellij.openapi.actionSystem.impl.Utils.doUpdate(Utils.java:161) at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:123) at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:83) at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:140) at com.intellij.openapi.actionSystem.impl.ActionToolbarImpl$2.run(ActionToolbarImpl.java:787) --- .../com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java index e0316aab7902..453ebc59aafd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java @@ -721,7 +721,7 @@ public abstract class ChangesTreeList extends JPanel { } public boolean isSelected(AnActionEvent e) { - return !PropertiesComponent.getInstance(myProject).isTrueValue(FLATTEN_OPTION_KEY); + return (! myProject.isDisposed()) && !PropertiesComponent.getInstance(myProject).isTrueValue(FLATTEN_OPTION_KEY); } public void setSelected(AnActionEvent e, boolean state) { From c2c51add0246f10a40fe2fba91c84ab9bf2d1311 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 17:39:19 +0400 Subject: [PATCH 30/45] EA-26379 debug info java.lang.AssertionError at com.intellij.openapi.vcs.checkin.StepIntersection.dataStep(StepIntersection.java:126) at com.intellij.openapi.vcs.checkin.StepIntersection.process(StepIntersection.java:93) at com.intellij.openapi.vcs.checkin.TodoCheckinHandlerWorker$MyEditedFileProcessor.process(TodoCheckinHandlerWorker.java:202) at com.intellij.openapi.vcs.checkin.TodoCheckinHandlerWorker.execute(TodoCheckinHandlerWorker.java:131) at com.intellij.openapi.vcs.checkin.TodoCheckinHandler$2.run(TodoCheckinHandler.java:148) --- .../openapi/vcs/checkin/StepIntersection.java | 22 +++++++++++++++---- .../vcs/checkin/TodoCheckinHandlerWorker.java | 16 ++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StepIntersection.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StepIntersection.java index 225a761947a4..2d40bc977135 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StepIntersection.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StepIntersection.java @@ -15,11 +15,15 @@ */ package com.intellij.openapi.vcs.checkin; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.TextRange; import com.intellij.util.PairConsumer; import com.intellij.util.containers.Convertor; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; /** * @author irengrig @@ -39,9 +43,15 @@ public class StepIntersection { private Area myCurArea; private final List myAreas; private HackSearch myHackSearch; + // EA-28497, EA-26379 + private Getter myDebugDocumentTextGetter; - public StepIntersection(Convertor dataConvertor, Convertor areasConvertor, final List areas) { + public StepIntersection(Convertor dataConvertor, + Convertor areasConvertor, + final List areas, + Getter debugDocumentTextGetter) { myAreas = areas; + myDebugDocumentTextGetter = debugDocumentTextGetter; myAreaIndex = 0; myDataConvertor = dataConvertor; myAreasConvertor = areasConvertor; @@ -116,14 +126,18 @@ public class StepIntersection { if (myAreaIndex >= myAreas.size()) { return; } - assert myAreaRange == null || myAreaRange.getEndOffset() < myAreasConvertor.convert(myAreas.get(myAreaIndex)).getStartOffset(); + assert myAreaRange == null || myAreaRange.getEndOffset() < myAreasConvertor.convert(myAreas.get(myAreaIndex)).getStartOffset() : + "Area ranges intersect: first: " + myAreaRange + ", second: " + myAreasConvertor.convert(myAreas.get(myAreaIndex)) + ", text: '" + + myDebugDocumentTextGetter.get() + "'"; myCurArea = myAreas.get(myAreaIndex); myAreaRange = myAreasConvertor.convert(myCurArea); } private void dataStep() { myCurData = myDataIterator.next(); - assert myDataRange == null || myDataRange.getEndOffset() < myDataConvertor.convert(myCurData).getStartOffset(); + assert myDataRange == null || myDataRange.getEndOffset() < myDataConvertor.convert(myCurData).getStartOffset() : + "Data ranges intersect: first: " + myDataRange + ", second: " + myDataConvertor.convert(myCurData) + ", text: '" + + myDebugDocumentTextGetter.get() + "'"; myDataRange = myDataConvertor.convert(myCurData); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java index bd2a2d6ceab9..cc261cc2de8b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java @@ -28,6 +28,7 @@ import com.intellij.openapi.diff.impl.processing.DiffPolicy; import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; @@ -198,7 +199,13 @@ public class TodoCheckinHandlerWorker { } } final StepIntersection intersection = - new StepIntersection(TodoItemConvertor.getInstance(), LineFragmentConvertor.getInstance(), lineFragments); + new StepIntersection(TodoItemConvertor.getInstance(), LineFragmentConvertor.getInstance(), lineFragments, + new Getter() { + @Override + public String get() { + return myAfterContent; + } + }); intersection.process(newTodoItems, new PairConsumer() { @@ -247,7 +254,12 @@ public class TodoCheckinHandlerWorker { } if (myOldTodoTexts == null) { final StepIntersection intersection = new StepIntersection( - LineFragmentConvertor.getInstance(), TodoItemConvertor.getInstance(), myOldItems); + LineFragmentConvertor.getInstance(), TodoItemConvertor.getInstance(), myOldItems, new Getter() { + @Override + public String get() { + return myBeforeContent; + } + }); myOldTodoTexts = new HashSet(); intersection.process(Collections.singletonList(myCurrentLineFragment), new PairConsumer() { @Override From 7ef50f65dc474ce7ba975fbabcc6b798e48abeec Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 17:48:40 +0400 Subject: [PATCH 31/45] EA-28354 java.lang.AssertionError: Already disposed: Project (Disposed) HMS092 at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:215) at com.intellij.openapi.vcs.FileStatusManager.getInstance(FileStatusManager.java:29) at com.intellij.cvsSupport2.CvsVcs2.fireFileStatusChanged(CvsVcs2.java:264) at com.intellij.cvsSupport2.CvsVcs2.entryChanged(CvsVcs2.java:259) at com.intellij.cvsSupport2.application.CvsEntriesManager.onEntryChanged(CvsEntriesManager.java:299) --- plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index b0cacea64fdf..f969db0befbc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -241,6 +241,7 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil } public void entryChanged(VirtualFile file) { + if (myProject.isDisposed()) return; // invoke later is possible fireFileStatusChanged(file); VcsDirtyScopeManager.getInstance(getProject()).fileDirty(file); } From 1be098997de1a6e095309804014e8f7d187626b7 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 17:53:34 +0400 Subject: [PATCH 32/45] EA-27713 java.lang.NullPointerException at org.jetbrains.idea.svn.history.SvnCommittedChangesProvider.getOneList(SvnCommittedChangesProvider.java:497) at com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction$1.run(ShowAllAffectedGenericAction.java:70) at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:464) --- .../jetbrains/idea/svn/history/SvnCommittedChangesProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnCommittedChangesProvider.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnCommittedChangesProvider.java index 188c1a6754f4..3748041e86e5 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnCommittedChangesProvider.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnCommittedChangesProvider.java @@ -494,6 +494,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi @Override public Pair getOneList(final VirtualFile file, VcsRevisionNumber number) throws VcsException { final RootUrlInfo rootUrlInfo = myVcs.getSvnFileUrlMapping().getWcRootForFilePath(new File(file.getPath())); + if (rootUrlInfo == null) return null; final VirtualFile root = rootUrlInfo.getVirtualFile(); if (root == null) return null; final SvnRepositoryLocation svnRootLocation = (SvnRepositoryLocation)getLocationFor(new FilePathImpl(root)); From ff7344f78ca25d54b0e749faed2e94dffab0ae18 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 18:31:18 +0400 Subject: [PATCH 33/45] EA-26512 java.lang.NullPointerException at git4idea.history.wholeTree.BranchSelectorAction.createActions(BranchSelectorAction.java:71) at git4idea.history.wholeTree.BasePopupAction.asTextAction(BasePopupAction.java:131) at git4idea.history.wholeTree.GitLogUI.createContextMenu(GitLogUI.java:527) --- .../git4idea/history/wholeTree/BranchSelectorAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/BranchSelectorAction.java b/plugins/git4idea/src/git4idea/history/wholeTree/BranchSelectorAction.java index 2c3b66a442b3..ac663d942241 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/BranchSelectorAction.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/BranchSelectorAction.java @@ -21,7 +21,6 @@ import com.intellij.util.Consumer; import git4idea.GitBranch; import git4idea.history.browser.SymbolicRefs; -import java.awt.*; import java.util.TreeSet; /** @@ -64,11 +63,12 @@ public class BranchSelectorAction extends BasePopupAction { actionConsumer.consume(new SelectBranchAction("*" + minusRefs(current.getFullName()), current.getFullName())); } final TreeSet locals = mySymbolicRefs.getLocalBranches(); + final String currentName = current == null ? null : current.getName(); if (locals != null && (! locals.isEmpty())) { final DefaultActionGroup local = new DefaultActionGroup("Local", true); actionConsumer.consume(local); for (String s : locals) { - final String presentation = s.equals(current.getName()) ? ("*" + s) : s; + final String presentation = s.equals(currentName) ? ("*" + s) : s; local.add(new SelectBranchAction(presentation, s)); } } @@ -77,7 +77,7 @@ public class BranchSelectorAction extends BasePopupAction { final DefaultActionGroup remote = new DefaultActionGroup("Remote", true); actionConsumer.consume(remote); for (String s : remotes) { - final String presentation = s.equals(current.getName()) ? ("*" + s) : s; + final String presentation = s.equals(currentName) ? ("*" + s) : s; remote.add(new SelectBranchAction(presentation, GitBranch.REFS_REMOTES_PREFIX + s)); } } From c061e2fe9c309d385b22dcb2b87dfc2a444736a4 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 24 Jun 2011 15:36:05 +0400 Subject: [PATCH 34/45] view offline inspection results: do not try to use root profile instead of inspection based => use profile by loaded data instead --- .../codeInspection/actions/ViewOfflineResultsAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java index 4eea092f0c7b..25b76da3a900 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java @@ -149,7 +149,7 @@ public class ViewOfflineResultsAction extends AnAction implements DumbAware { final String title) { Profile profile; if (profileName != null) { - profile = InspectionProjectProfileManager.getInstance(project).getProfile(profileName); + profile = InspectionProjectProfileManager.getInstance(project).getProfile(profileName, false); if (profile == null) { profile = InspectionProfileManager.getInstance().getProfile(profileName, false); } @@ -162,7 +162,7 @@ public class ViewOfflineResultsAction extends AnAction implements DumbAware { inspectionProfile = (InspectionProfile)profile; } else { - inspectionProfile = new InspectionProfileImpl("Server Side") { + inspectionProfile = new InspectionProfileImpl(profileName) { public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) { return resMap.containsKey(key.toString()); } From 1431f5a8f2fb409a0516f29c2c3cda55a571ae35 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 24 Jun 2011 19:04:00 +0400 Subject: [PATCH 35/45] inplace introduce: restore local variable before actual refactoring --- .../inplace/AbstractInplaceIntroducer.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index 07dc063c4d31..488ee578a001 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -19,7 +19,9 @@ import com.intellij.codeInsight.highlighting.HighlightManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ScrollType; @@ -186,10 +188,11 @@ public abstract class AbstractInplaceIntroducer refs) { - final V variable = getVariable(); + super.addReferenceAtCaret(refs); + final V variable = getLocalVariable(); if (variable != null) { for (PsiReference reference : ReferencesSearch.search(variable)) { - refs.remove(reference); + refs.add(reference); } } } @@ -292,6 +295,14 @@ public abstract class AbstractInplaceIntroducer Date: Fri, 24 Jun 2011 19:29:24 +0400 Subject: [PATCH 36/45] disable editing in src/trg fields --- .../com/intellij/openapi/diff/impl/dir/DirDiffPanel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index 9970f84cf88f..459786cc019f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -34,7 +34,6 @@ import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLoadingPanel; import com.intellij.ui.table.JBTable; import com.intellij.util.diff.FilesTooBigForDiffException; -import com.intellij.util.containers.Convertor; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -213,6 +212,9 @@ public class DirDiffPanel implements Disposable { myFilterLabel.setLabelFor(myFilter); final Callable srcChooser = myModel.getSourceDir().getElementChooser(project); final Callable trgChooser = myModel.getTargetDir().getElementChooser(project); + mySourceDirField.setEditable(false); + myTargetDirField.setEditable(false); + if (srcChooser != null) { mySourceDirField.setButtonEnabled(true); mySourceDirField.addActionListener(new AbstractAction() { @@ -233,7 +235,6 @@ public class DirDiffPanel implements Disposable { } else { mySourceDirField.setButtonEnabled(false); mySourceDirField.getButton().setVisible(false); - mySourceDirField.setEditable(false); } if (trgChooser != null) { @@ -256,7 +257,6 @@ public class DirDiffPanel implements Disposable { } else { myTargetDirField.setButtonEnabled(false); myTargetDirField.getButton().setVisible(false); - myTargetDirField.setEditable(false); } } From 083c26f8585b7a058cb743d2d084442a5ba9819e Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 17:29:07 +0400 Subject: [PATCH 37/45] @Nullable --- .../intellij/openapi/progress/ProgressManager.java | 8 ++++---- .../openapi/progress/impl/ProgressManagerImpl.java | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java index f7e1f58d3b0a..6f06a809ed7d 100644 --- a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java +++ b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ public abstract class ProgressManager { public abstract boolean runProcessWithProgressSynchronously(@NotNull Runnable process, @NotNull @Nls String progressTitle, boolean canBeCanceled, - Project project); + @Nullable Project project); /** * Runs the specified operation in a background thread and shows a modal progress dialog in the @@ -97,8 +97,8 @@ public abstract class ProgressManager { public abstract boolean runProcessWithProgressSynchronously(@NotNull Runnable process, @NotNull @Nls String progressTitle, boolean canBeCanceled, - Project project, - JComponent parentComponent); + @Nullable Project project, + @Nullable JComponent parentComponent); /** * Runs a specified process in a background thread and shows a progress dialog, which can be made non-modal by pressing diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java index 0016d67bbcf6..e1f1f7a0b923 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -227,11 +227,18 @@ public class ProgressManagerImpl extends ProgressManager { return myThreadIndicator.get(); } - public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process, @NotNull String progressTitle, boolean canBeCanceled, Project project) { + public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process, + @NotNull String progressTitle, + boolean canBeCanceled, + @Nullable Project project) { return runProcessWithProgressSynchronously(process, progressTitle, canBeCanceled, project, null); } - public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process, @NotNull String progressTitle, boolean canBeCanceled, Project project, JComponent parentComponent) { + public boolean runProcessWithProgressSynchronously(@NotNull final Runnable process, + @NotNull String progressTitle, + boolean canBeCanceled, + @Nullable Project project, + @Nullable JComponent parentComponent) { Task.Modal task = new Task.Modal(project, progressTitle, canBeCanceled) { public void run(@NotNull ProgressIndicator indicator) { process.run(); From cb9a48ba48eb95ccd4f1a9e9dc211d71abac7516 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 19:08:40 +0400 Subject: [PATCH 38/45] Fix table header glitch in update plugins dialog --- .../src/com/intellij/ui/OrderPanel.java | 30 +++++++++--------- .../impl/DetectedPluginsPanel.java | 31 ++++++++++++------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/OrderPanel.java b/platform/platform-api/src/com/intellij/ui/OrderPanel.java index 76883cd2fd02..f8107af50aac 100644 --- a/platform/platform-api/src/com/intellij/ui/OrderPanel.java +++ b/platform/platform-api/src/com/intellij/ui/OrderPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,8 @@ */ package com.intellij.ui; -import com.intellij.util.ui.Table; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.table.JBTable; import javax.swing.*; import javax.swing.table.DefaultTableModel; @@ -26,6 +27,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.List; public abstract class OrderPanel extends JPanel{ private String CHECKBOX_COLUMN_NAME; @@ -33,7 +35,7 @@ public abstract class OrderPanel extends JPanel{ private final Class myEntryClass; private final JTable myEntryTable; - private final java.util.List myListeners = new ArrayList(); + private final List myListeners = new ArrayList(); private boolean myEntryEditable = false; @@ -41,12 +43,12 @@ public abstract class OrderPanel extends JPanel{ this(entryClass, true); } - protected OrderPanel(Class entryClass, boolean showSheckboxes) { + protected OrderPanel(Class entryClass, boolean showCheckboxes) { super(new BorderLayout()); myEntryClass = entryClass; - myEntryTable = new Table(new MyTableModel(showSheckboxes)); + myEntryTable = new JBTable(new MyTableModel(showCheckboxes)); myEntryTable.setShowGrid(false); myEntryTable.setDragEnabled(false); myEntryTable.setShowHorizontalLines(false); @@ -89,11 +91,11 @@ public abstract class OrderPanel extends JPanel{ myEntryEditable = entryEditable; } - public void setCheckboxColumnName(String name) { + public void setCheckboxColumnName(final String name) { final int width; - if(name == null) { - width = 0; + if (StringUtil.isEmpty(name)) { CHECKBOX_COLUMN_NAME = ""; + width = new JCheckBox().getPreferredSize().width; } else { CHECKBOX_COLUMN_NAME = name; @@ -101,7 +103,7 @@ public abstract class OrderPanel extends JPanel{ width = fontMetrics.stringWidth(" " + name + " ") + 4; } - final TableColumn checkboxColumn = myEntryTable.getTableHeader().getColumnModel().getColumn(getCheckboxColumn()); + final TableColumn checkboxColumn = myEntryTable.getColumnModel().getColumn(getCheckboxColumn()); checkboxColumn.setWidth(width); checkboxColumn.setPreferredWidth(width); checkboxColumn.setMaxWidth(width); @@ -192,6 +194,7 @@ public abstract class OrderPanel extends JPanel{ private class MyTableModel extends DefaultTableModel { private final boolean myShowCheckboxes; + public MyTableModel(boolean showCheckboxes) { myShowCheckboxes = showCheckboxes; } @@ -244,7 +247,8 @@ public abstract class OrderPanel extends JPanel{ } public T getValueAt(int row) { - return (T)((MyTableModel)myEntryTable.getModel()).getValueAt(row, getEntryColumn()); + //noinspection unchecked + return (T)myEntryTable.getModel().getValueAt(row, getEntryColumn()); } public abstract boolean isCheckable(T entry); @@ -258,16 +262,14 @@ public abstract class OrderPanel extends JPanel{ return CHECKBOX_COLUMN_NAME; } - public java.util.List getEntries() { + public List getEntries() { final TableModel model = myEntryTable.getModel(); final int size = model.getRowCount(); - java.util.List result = new ArrayList(size); + List result = new ArrayList(size); for (int idx = 0; idx < size; idx++) { result.add(getValueAt(idx)); } return result; } - - } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/DetectedPluginsPanel.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/DetectedPluginsPanel.java index fae9d89b8570..77bbdce5b179 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/DetectedPluginsPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/DetectedPluginsPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 04-Dec-2007 - */ package com.intellij.openapi.updateSettings.impl; import com.intellij.ide.plugins.IdeaPluginDescriptor; @@ -30,6 +25,10 @@ import com.intellij.ui.SimpleTextAttributes; import javax.swing.*; import java.util.ArrayList; +/** + * @author anna + * Date: 04-Dec-2007 + */ public class DetectedPluginsPanel extends OrderPanel { private final ArrayList myListeners = new ArrayList(); private static final String AVAILABLE_VERSION = "available version: "; @@ -37,14 +36,25 @@ public class DetectedPluginsPanel extends OrderPanel { protected DetectedPluginsPanel() { super(PluginDownloader.class); - getEntryTable().setDefaultRenderer(PluginDownloader.class, new ColoredTableCellRenderer(){ - protected void customizeCellRenderer(final JTable table, final Object value, final boolean selected, final boolean hasFocus, final int row, final int column) { + final JTable entryTable = getEntryTable(); + entryTable.setTableHeader(null); + entryTable.setDefaultRenderer(PluginDownloader.class, new ColoredTableCellRenderer() { + protected void customizeCellRenderer(final JTable table, + final Object value, + final boolean selected, + final boolean hasFocus, + final int row, + final int column) { final PluginDownloader downloader = (PluginDownloader)value; append(downloader.getPluginName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(PluginId.getId(downloader.getPluginId())); final String loadedVersion = downloader.getPluginVersion(); if (loadedVersion != null || (ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null)) { - append(" (" + (ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null ? INSTALLED_VERSION + ideaPluginDescriptor.getVersion() + (loadedVersion != null ? ", " : "") :"") + (loadedVersion != null ? AVAILABLE_VERSION + loadedVersion : "") + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); + final String installedVersion = ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null + ? INSTALLED_VERSION + ideaPluginDescriptor.getVersion() + (loadedVersion != null ? ", " : "") + : ""; + final String availableVersion = loadedVersion != null ? AVAILABLE_VERSION + loadedVersion : ""; + append(" (" + installedVersion + availableVersion + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); } } }); @@ -78,8 +88,7 @@ public class DetectedPluginsPanel extends OrderPanel { myListeners.add(l); } - public static interface Listener { + public interface Listener { void stateChanged(); } - } \ No newline at end of file From 3fa6ce31f2c7792987f8b74234f2f746d5b63403 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 19:31:44 +0400 Subject: [PATCH 39/45] Allow to set up plugins from file:// filesystem --- .../updateSettings/impl/PluginDownloader.java | 153 ++++++++---------- .../updateSettings/impl/UpdateChecker.java | 73 +++++---- .../src/messages/IdeBundle.properties | 1 + 3 files changed, 108 insertions(+), 119 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java index 7b46296af291..2211e8b5809a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 10-Aug-2007 - */ package com.intellij.openapi.updateSettings.impl; import com.intellij.ide.IdeBundle; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.IdeaPluginDescriptorImpl; import com.intellij.ide.plugins.PluginManager; -import com.intellij.ide.plugins.RepositoryHelper; import com.intellij.ide.startup.StartupActionScriptManager; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; @@ -41,15 +35,17 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.io.UrlConnectionUtil; import com.intellij.util.io.ZipUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLEncoder; +import java.net.URLConnection; +/** + * @author anna + * Date: 10-Aug-2007 + */ public class PluginDownloader { - private static final Logger LOG = Logger.getInstance("#" + PluginDownloader.class.getName()); @NonNls private static final String FILENAME = "filename="; @@ -143,12 +139,14 @@ public class PluginDownloader { } final BuildNumber currentBuildNumber = ApplicationInfo.getInstance().getBuild(); String sinceBuildString = descriptor.getSinceBuild(); - final BuildNumber sinceBuild = StringUtil.isEmptyOrSpaces(sinceBuildString) ? null : BuildNumber.fromString(sinceBuildString, descriptor.getName()); + final BuildNumber sinceBuild = StringUtil.isEmptyOrSpaces(sinceBuildString) + ? null : BuildNumber.fromString(sinceBuildString, descriptor.getName()); if (sinceBuild != null && sinceBuild.compareTo(currentBuildNumber) > 0) { return false; } String untilBuildString = descriptor.getUntilBuild(); - final BuildNumber untilBuild = StringUtil.isEmptyOrSpaces(untilBuildString) ? null : BuildNumber.fromString(untilBuildString, descriptor.getName()); + final BuildNumber untilBuild = StringUtil.isEmptyOrSpaces(untilBuildString) + ? null : BuildNumber.fromString(untilBuildString, descriptor.getName()); if (untilBuild != null && untilBuild.compareTo(currentBuildNumber) < 0) { return false; } @@ -190,85 +188,85 @@ public class PluginDownloader { StartupActionScriptManager.addActionCommand(deleteTemp); } - private File downloadPlugin(ProgressIndicator pi) throws IOException { - HttpURLConnection connection = (HttpURLConnection)new URL(myPluginUrl).openConnection(); - try - { - pi.setText(IdeBundle.message("progress.connecting")); + private File downloadPlugin(final ProgressIndicator pi) throws IOException { + final File pluginsTemp = new File(PathManager.getPluginTempPath()); + if (!pluginsTemp.exists() && !pluginsTemp.mkdirs()) { + throw new IOException(IdeBundle.message("error.cannot.create.temp.dir", pluginsTemp)); + } + final File file = FileUtil.createTempFile(pluginsTemp, "plugin", "download", true, false); - InputStream is = UrlConnectionUtil.getConnectionInputStream(connection, pi); + pi.setText(IdeBundle.message("progress.connecting")); + final URLConnection connection = new URL(myPluginUrl).openConnection(); + try { + if (connection instanceof HttpURLConnection) { + final int responseCode = ((HttpURLConnection)connection).getResponseCode(); + if (responseCode != HttpURLConnection.HTTP_OK) { + throw new IOException(IdeBundle.message("error.connection.failed.with.http.code.N", responseCode)); + } + } + + final InputStream is = UrlConnectionUtil.getConnectionInputStream(connection, pi); if (is == null) { throw new IOException("Failed to open connection"); } pi.setText(IdeBundle.message("progress.downloading.plugin", getPluginName())); - - final File pluginsTemp = new File(PathManager.getPluginTempPath()); - - if (!pluginsTemp.exists()) { - pluginsTemp.mkdirs(); - } - - File file = FileUtil.createTempFile(pluginsTemp, "plugin", "download", true, false); - - int responseCode = connection.getResponseCode(); - switch (responseCode) { - case HttpURLConnection.HTTP_OK: - break; - default: - // some problems - throw new IOException(IdeBundle.message("error.connection.failed.with.http.code.N", responseCode)); - } - pi.setIndeterminate(connection.getContentLength() == -1); - OutputStream fos = null; try { - fos = new BufferedOutputStream(new FileOutputStream(file, false)); - StreamUtil.copyStreamContent(is, fos); - } - finally { - if (fos != null) { + final OutputStream fos = new BufferedOutputStream(new FileOutputStream(file, false)); + try { + StreamUtil.copyStreamContent(is, fos); + } + finally { fos.close(); } + } + finally { is.close(); } - if (myFileName == null) { - String contentDisposition = connection.getHeaderField("Content-Disposition"); - if (contentDisposition == null || contentDisposition.indexOf(FILENAME) < 0) { - // try to find filename in URL - String usedURL = connection.getURL().toString(); - int startPos = usedURL.lastIndexOf("/"); - myFileName = usedURL.substring(startPos + 1); - if (myFileName.length() == 0 || myFileName.contains("?")) { - myFileName = myPluginUrl.substring(myPluginUrl.lastIndexOf("/") + 1); - } - } - else { - int startIdx = contentDisposition.indexOf(FILENAME); - myFileName = contentDisposition.substring(startIdx + FILENAME.length(), contentDisposition.length()); - // according to the HTTP spec, the filename is a quoted string, but some servers don't quote it - // for example: http://www.jspformat.com/Download.do?formAction=d&id=8 - if (myFileName.startsWith("\"") && myFileName.endsWith("\"")) { - myFileName = myFileName.substring(1, myFileName.length()-1); - } - if (myFileName.indexOf('\\') >= 0 || myFileName.indexOf('/') >= 0 || myFileName.indexOf(File.separatorChar) >= 0 || - myFileName.indexOf('\"') >= 0) { - // invalid path name passed by the server - fail to download - FileUtil.delete(file); - throw new IOException("Invalid filename returned by server"); - } - } + if (myFileName == null) { + guessFileName(connection, file); } - File newFile = new File (file.getParentFile(), myFileName); + final File newFile = new File(file.getParentFile(), myFileName); FileUtil.rename(file, newFile); return newFile; } finally { - connection.disconnect(); + if (connection instanceof HttpURLConnection) { + ((HttpURLConnection)connection).disconnect(); + } + } + } + + private void guessFileName(final URLConnection connection, final File file) throws IOException { + String contentDisposition = connection.getHeaderField("Content-Disposition"); + if (contentDisposition == null || !contentDisposition.contains(FILENAME)) { + // try to find filename in URL + String usedURL = connection.getURL().toString(); + int startPos = usedURL.lastIndexOf("/"); + myFileName = usedURL.substring(startPos + 1); + if (myFileName.length() == 0 || myFileName.contains("?")) { + myFileName = myPluginUrl.substring(myPluginUrl.lastIndexOf("/") + 1); + } + } + else { + int startIdx = contentDisposition.indexOf(FILENAME); + myFileName = contentDisposition.substring(startIdx + FILENAME.length(), contentDisposition.length()); + // according to the HTTP spec, the filename is a quoted string, but some servers don't quote it + // for example: http://www.jspformat.com/Download.do?formAction=d&id=8 + if (myFileName.startsWith("\"") && myFileName.endsWith("\"")) { + myFileName = myFileName.substring(1, myFileName.length() - 1); + } + if (myFileName.indexOf('\\') >= 0 || myFileName.indexOf('/') >= 0 || myFileName.indexOf(File.separatorChar) >= 0 || + myFileName.indexOf('\"') >= 0) { + // invalid path name passed by the server - fail to download + FileUtil.delete(file); + throw new IOException("Invalid filename returned by server"); + } } } @@ -293,19 +291,4 @@ public class PluginDownloader { public String getPluginVersion() { return myPluginVersion; } - - /** - * Updates given plugin from Repository - * @param pluginId given plugin id - * @param pluginVersion available version or null if plugin must be uploaded even if current version is greater than uploading - * @throws IOException - */ - public static void updateFromRepository(final String pluginId, final @Nullable String pluginVersion) throws IOException { - @NonNls final String url = - RepositoryHelper.DOWNLOAD_URL + URLEncoder.encode(pluginId, "UTF8") + "&build=" + ApplicationInfo.getInstance().getBuild().asString(); - final PluginDownloader downloader = new PluginDownloader(pluginId, url, pluginVersion); - if (downloader.prepareToInstall()) { - downloader.install(); - } - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 63cd68b481bb..55ad6a48da08 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Created by IntelliJ IDEA. - * User: mike - * Date: Oct 31, 2002 - * Time: 6:33:01 PM - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). - */ package com.intellij.openapi.updateSettings.impl; import com.intellij.ide.IdeBundle; @@ -44,9 +35,9 @@ import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.ex.http.HttpFileSystem; +import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.util.PlatformUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.UrlConnectionUtil; @@ -72,15 +63,20 @@ import java.util.concurrent.TimeoutException; /** * XML sample: + *
{@code
  * 
- * 456
- * 4.5.2
- * New Intellij IDEA Version
- * 
- * New version of IntelliJ IDEA is available.
- * Please visit http://www.intellij.com/ for more info.
- * 
+ *   456
+ *   4.5.2
+ *   New Intellij IDEA Version
+ *   
+ *     New version of IntelliJ IDEA is available.
+ *     Please visit http://www.intellij.com/ for more info.
+ *   
  * 
+ * }
+ * + * @author mike + * Date: Oct 31, 2002 */ public final class UpdateChecker { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.updateSettings.impl.UpdateChecker"); @@ -110,6 +106,7 @@ public final class UpdateChecker { private static class StringHolder { private static final String UPDATE_URL = ApplicationInfoEx.getInstanceEx().getUpdateUrls().getCheckingUrl(); private static final String PATCHES_URL = ApplicationInfoEx.getInstanceEx().getUpdateUrls().getPatchesUrl(); + private StringHolder() { } } private static String getUpdateUrl() { @@ -190,12 +187,14 @@ public final class UpdateChecker { public static boolean checkPluginsHost(final String host, final List downloaded) throws Exception { final Document document = loadVersionInfo(host); if (document == null) return false; + boolean success = true; for (Object plugin : document.getRootElement().getChildren("plugin")) { - Element pluginElement = (Element)plugin; + final Element pluginElement = (Element)plugin; final String pluginId = pluginElement.getAttributeValue("id"); - String pluginUrl = pluginElement.getAttributeValue("url"); + final String pluginUrl = pluginElement.getAttributeValue("url"); final String pluginVersion = pluginElement.getAttributeValue("version"); + if (pluginId == null) { LOG.info("plugin id should not be null"); success = false; @@ -208,19 +207,25 @@ public final class UpdateChecker { continue; } - - if (!pluginUrl.startsWith(HttpFileSystem.PROTOCOL)) { - final HttpFileSystem fileSystem = HttpFileSystem.getInstance(); - final VirtualFile hostFile = fileSystem.findFileByPath(VfsUtil.urlToPath(host)); - LOG.assertTrue(hostFile != null); - final VirtualFile pluginByRelativePath = findPluginByRelativePath(hostFile.getParent(), pluginUrl, fileSystem); - if (pluginByRelativePath != null) { - pluginUrl = pluginByRelativePath.getUrl(); + final VirtualFileManager fileManager = VirtualFileManager.getInstance(); + VirtualFile pluginFile = fileManager.findFileByUrl(pluginUrl); + if (pluginFile == null) { + final VirtualFile hostFile = fileManager.findFileByUrl(host); + if (hostFile == null) { + LOG.error("can't find file by url '" + host + "'"); + success = false; + break; + } + pluginFile = findPluginByRelativePath(hostFile.getParent(), pluginUrl, hostFile.getFileSystem()); + if (pluginFile == null) { + LOG.error("can't find '" + pluginUrl + "' relative to '" + host + "'"); + success = false; + continue; } } - final String finalPluginUrl = pluginUrl; - Runnable updatePluginRunnable = new Runnable() { + final String finalPluginUrl = pluginFile.getUrl(); + final Runnable updatePluginRunnable = new Runnable() { public void run() { try { final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); @@ -248,9 +253,9 @@ public final class UpdateChecker { } @Nullable - public static VirtualFile findPluginByRelativePath(VirtualFile hostFile, - @NotNull @NonNls String relPath, - final HttpFileSystem fileSystem) { + public static VirtualFile findPluginByRelativePath(@NotNull final VirtualFile hostFile, + @NotNull @NonNls final String relPath, + @NotNull final VirtualFileSystem fileSystem) { if (relPath.length() == 0) return hostFile; int index = relPath.indexOf('/'); if (index < 0) index = relPath.length(); diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 172c3cebe06b..cb518f053e97 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -512,6 +512,7 @@ plugin.status.installed=Installed progress.waiting.for.reply.from.plugin.manager=Waiting for reply from {0} progress.connecting=Connecting... progress.downloading.plugin=Downloading plugin ''{0}'' +error.cannot.create.temp.dir=Unable to create temp directory ''{0}'' error.connection.failed.with.http.code.N=Connection failed with HTTP code {0} progress.connecting.to.plugin.manager=Connecting to {0} label.plugin.vendor.email=E-mail: From e8a94b16a73b3f56d326bc9121464902925475bf Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Jun 2011 19:32:14 +0400 Subject: [PATCH 40/45] To JB dictionary --- plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index 5ffc7bc0b5bd..32dfba4754ae 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -44,6 +44,7 @@ ccflags cdata charset checkbox +checkboxes checksum chmod classpath From 829bc33f7ba9e05e9177f27ec197f5af5f86bc6b Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 19:11:28 +0400 Subject: [PATCH 41/45] IDEA-71188 Tell me the name of the module type if it's unknown so I could understand what plugin I miss --- .../intellij/openapi/module/impl/ModuleManagerImpl.java | 9 +++++---- .../src/messages/ProjectBundle.properties | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index aa8b407972a6..214863e04f1a 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -272,15 +272,16 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent if (!app.isHeadlessEnvironment() && !modulesWithUnknownTypes.isEmpty()) { String message; if (modulesWithUnknownTypes.size() == 1) { - message = ProjectBundle.message("module.unknown.type.single.error", modulesWithUnknownTypes.get(0).getName()); + message = ProjectBundle.message("module.unknown.type.single.error", modulesWithUnknownTypes.get(0).getName(), + modulesWithUnknownTypes.get(0).getModuleType().getId()); } else { StringBuilder modulesBuilder = new StringBuilder(); for (final Module module : modulesWithUnknownTypes) { - modulesBuilder.append("\n\""); - modulesBuilder.append(module.getName()); - modulesBuilder.append("\""); + modulesBuilder.append("
\""); + modulesBuilder.append(module.getName()).append("\" (type '").append(module.getModuleType().getId()).append("')"); } + modulesBuilder.append("
"); message = ProjectBundle.message("module.unknown.type.multiple.error", modulesBuilder.toString()); } // it is not modal warning at all diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index fb4f6f4e9645..2f24cad05654 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -250,7 +250,7 @@ module.source.roots.not.configured.title=No Source Roots Configured module.cannot.load.error=Cannot load module file ''{0}'':\n{1} module.corrupted.file.error=Invalid or corrupted module file ''{0}'':\n{1} module.corrupted.data.error=Corrupted module data at: {0} -module.unknown.type.single.error=Cannot determine module type for the following module:\n\"{0}\"\nThe module will be treated as a Unknown module. +module.unknown.type.single.error=Cannot determine module type (\"{1}\") for the following module:\"{0}\"
The module will be treated as a Unknown module. module.unknown.type.multiple.error=Cannot determine module type for the following modules:\n{0}\nAll mentioned modules will be treated as Unknown modules. module.unknown.type.title=Unknown Module Type module.web.title=Web Module From 6997afc859a3e47552b98b19be39c5e98ca6d9ef Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 20:32:35 +0400 Subject: [PATCH 42/45] IDEA-71379 Throwable at org.zmlx.hg4idea.execution.HgCommandExecutor.executeInCurrentThread also, report when files just edited, but not changed --- ...kgroundSynchronousInvisibleComputable.java | 49 +++++++++++++++++++ .../FragmentedDiffRequestFromChange.java | 20 +++++++- .../vcs/changes/VcsChangeDetailsManager.java | 7 ++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java b/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java new file mode 100644 index 000000000000..4f62bcbd3f3f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/progress/BackgroundSynchronousInvisibleComputable.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.progress; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.concurrency.Semaphore; + +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author irengrig + * Date: 6/24/11 + * Time: 7:34 PM + */ +public abstract class BackgroundSynchronousInvisibleComputable { + protected abstract T runImpl(); + + public T compute() { + final Semaphore semaphore = new Semaphore(); + semaphore.down(); + final AtomicReference reference = new AtomicReference(); + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + try { + reference.set(runImpl()); + } + finally { + semaphore.up(); + } + } + }); + semaphore.waitFor(); + return reference.get(); + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java index 5a3a20a7441b..3f97ae57b160 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java @@ -25,8 +25,10 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.progress.BackgroundSynchronousInvisibleComputable; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FilePath; @@ -220,7 +222,23 @@ public class FragmentedDiffRequestFromChange implements DiffRequestFromChange ref = new Ref(); + final String s = new BackgroundSynchronousInvisibleComputable() { + @Override + protected String runImpl() { + try { + return cr.getContent(); + } + catch (VcsException e) { + ref.set(e); + return null; + } + } + }.compute(); + if (! ref.isNull()) { + throw ref.get(); + } return s == null ? "" : s; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java index f9c9272ae0ad..32bed1d69f64 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangeDetailsManager.java @@ -16,6 +16,7 @@ package com.intellij.openapi.vcs.changes; import com.intellij.openapi.Disposable; +import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.diff.DiffContent; import com.intellij.openapi.diff.DiffPanel; import com.intellij.openapi.diff.ShiftedSimpleContent; @@ -148,7 +149,11 @@ public class VcsChangeDetailsManager { public Pair convert(Change o) { try { final List> requestForChange = myRequestFromChange.createRequestForChange(o, extraLines); - if (requestForChange == null || requestForChange.isEmpty()) return null; + if (requestForChange == null) return null; + if (requestForChange.isEmpty()) { + return new Pair( + errorPanel(DiffBundle.message("diff.contents.have.differences.only.in.line.separators.message.text"), false), null); + } final ChangesFragmentedDiffPanel panel = new ChangesFragmentedDiffPanel(myProject, requestForChange, myDiffPanelCache, changeDescription(o)); return new Pair(panel.getPanel(), panel); From 228a15f0030ead053b5db2aa51ba8a0c925f92f6 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 24 Jun 2011 20:41:33 +0400 Subject: [PATCH 43/45] IDEA-71374 Changes details view: incorrect behavior in case of 'show virtual space at the bottom' option set --- .../src/com/intellij/openapi/diff/impl/DiffPanelImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java index cd190db6dcc1..86ff219f1331 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java @@ -142,9 +142,11 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid if (getEditor1() != null) { getEditor1().getSettings().setAdditionalLinesCount(0); + getEditor1().getSettings().setAdditionalPageAtBottom(false); } if (getEditor2() != null) { getEditor2().getSettings().setAdditionalLinesCount(0); + getEditor2().getSettings().setAdditionalPageAtBottom(false); } myPanel.setPrefferedWidth(20); myPanel.setPreferredHeightGetter(new Getter() { From 92f5c71192463731c2434ff8548771479d35bafe Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 24 Jun 2011 11:11:28 +0200 Subject: [PATCH 44/45] register "show container info" action in platform --- .../intellij/codeInsight/hint/ShowContainerInfoHandler.java | 5 ++++- platform/platform-resources/src/idea/LangActions.xml | 1 + resources/src/idea/RichPlatformActions.xml | 5 ----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java index 803b5d94b165..8ef7ca97e746 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowContainerInfoHandler.java @@ -77,7 +77,10 @@ public class ShowContainerInfoHandler implements CodeInsightActionHandler { return; } - final TextRange range = DeclarationRangeUtil.getDeclarationRange(container); + final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container); + if (range == null) { + return; + } ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { LightweightHint hint = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true); diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index c649df86ff3a..87474960e2ce 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -138,6 +138,7 @@ + diff --git a/resources/src/idea/RichPlatformActions.xml b/resources/src/idea/RichPlatformActions.xml index 3ec21f35101c..9b1386d1c87b 100644 --- a/resources/src/idea/RichPlatformActions.xml +++ b/resources/src/idea/RichPlatformActions.xml @@ -74,11 +74,6 @@ - - - - - From bcb7014a81a38736147312c4b024fec1f48cb907 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 24 Jun 2011 19:00:09 +0200 Subject: [PATCH 45/45] it's about time we changed the default language level to Java 6 --- .../openapi/roots/impl/LanguageLevelProjectExtensionImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java index 9e5d8a95c294..58c4c4290371 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java @@ -1,4 +1,4 @@ -/* + /* * Copyright 2000-2009 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,7 +41,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten @Deprecated @NonNls private static final String JDK_15_ATTR = "jdk-15"; - private LanguageLevel myLanguageLevel = LanguageLevel.JDK_1_5; + private LanguageLevel myLanguageLevel = LanguageLevel.JDK_1_6; private LanguageLevel myOriginalLanguageLevel = myLanguageLevel; private final Project myProject;