diff --git a/.idea/libraries/gant_groovy.xml b/.idea/libraries/gant_groovy.xml new file mode 100644 index 000000000000..6bbdba4df2dd --- /dev/null +++ b/.idea/libraries/gant_groovy.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/jgoodies_common.xml b/.idea/libraries/jgoodies_common.xml index b28cc7072292..9f61581b7d53 100644 --- a/.idea/libraries/jgoodies_common.xml +++ b/.idea/libraries/jgoodies_common.xml @@ -1,9 +1,12 @@ - + + - + - + + + \ No newline at end of file diff --git a/build/dependencies/setupBuildScriptsDeps.gradle b/build/dependencies/setupBuildScriptsDeps.gradle index b688134b689f..6c6cbee60e09 100644 --- a/build/dependencies/setupBuildScriptsDeps.gradle +++ b/build/dependencies/setupBuildScriptsDeps.gradle @@ -35,6 +35,7 @@ dependencies { buildScriptsDeps loadLibraryMavenId("Trove4j") buildScriptsDeps loadLibraryMavenId("NanoXML") buildScriptsDeps loadLibraryMavenId("Guava") + buildScriptsDeps(loadLibraryMavenId("gant-groovy"), { transitive = false }) } /** diff --git a/build/gant.xml b/build/gant.xml index c7a81b2ce857..93955df3f5ec 100644 --- a/build/gant.xml +++ b/build/gant.xml @@ -1,7 +1,6 @@ - @@ -24,9 +23,6 @@ - - - diff --git a/build/lib/gant/README_Install.txt b/build/lib/gant/README_Install.txt deleted file mode 100644 index 5f6cc4ae2aa6..000000000000 --- a/build/lib/gant/README_Install.txt +++ /dev/null @@ -1,110 +0,0 @@ -Gant -- A Groovy way of scripting Ant tasks. - - -This is Gant, a Groovy way of working with Ant tasks -- no more XML :-) - -The method of installation depends on whether you have downloaded a tarball or -zipfile distribution, or you have a Git clone -- or even a Bazaar branch -- of -the source. - - -Distribution ------------- - -The Gant distributions contain a ready-made install directory hierarchy. -Untar the tarball or unzip the zipfile to the location where you want the Gant -installation to reside. A directory with the name structured -gant- will be created in the location specified for the -untar or unzip. - -There are a number of distinct distributions: - - 1. Requires a separate Groovy installation. There are builds: - a. compiled against Groovy 1.7.10; and - b. compiled against Groovy 1.8.6; and - c. compiled against Groovy 2.0.0-beta-2 - - 2. Self-contained, includes all dependent jars. - -You might like to set up an environment variable GANT_HOME set to the -directory created by the untar or unzip, though this is not essential, it is -just an efficiency. - -The script $GANT_HOME/bin/gant for systems with a Posix shell, or -$GANT_HOME/bin/gant.bat on Windows is the mechanism for launching a Gant run. - -Distributions 1a, 1b and 1c only include the direct Gant materials. The Maven -target set depends on use of the Maven Ant tasks, and the Ivy tool depends on -the Ivy jar, these will have to be downloaded and installed into -$GANT_HOME/lib unless they are already available on on your CLASSPATH. - - -Using a Git Clone ------------------ - -Gant's mainline is a Git repository on GitHub, see - - https://github.com/Gant/Gant - -you should fork this on GitHub and then clone to give you a local repository. - -The repository on Codehaus at: - - git://git.codehaus.org/gant.git - -is an administrative clone of the GitHub mainline and should not be used in -normal circumstances. - -Gradle is used as the build system for Gant, so you will need to set the -gant_installPath property in ~/.gradle/gradle.properties so you can install -Gant. So for example: - - gant_installPath = ${System.properties.'user.home'}/lib/JavaPackages/gant-trunk - -Then you type: - - ./gradlew :gant:install - -and all the necessary magic happens. The first time you use the Gradle -Wrapper, it will connect to the Internet to download the various jars that -comprise Gradle. This takes a while. However this is only needed the first -time, thereafter it uses the version you downloaded. - -You probably want to set the GROOVY_HOME environment variable to point at the -Groovy installation that the Gant installation is to work with. - - -Using a Bazaar Branch ---------------------- - -For anyone prefering to use Bazaar rather than Git, there is an automated -bridge of the master branch of the Git clone on Launchpad. - -To get a branch: - - bzr branch lp:gant Gant - -or if you want to use bzr-git directly: - - bzr branch git://github.com/Gant/Gant.git Gant - -(If you are going to actively develop Gant, you almost certainly want to have -a shared repository in which this mirror branch is kept so that you can then -make feature branches from it.) - -All the information in the previous section about Gradle and building Gant -apply when using Bazaar. - - -Contact -------- - -If you have any problems using Gant, or have any ideas for improvements, -please make use of the Gant users mailing list: user@gant.codehaus.org - -Russel Winder - - -;;; Local Variables: *** -;;; fill-column: 78 *** -;;; End: *** diff --git a/build/lib/gant/bin/gant b/build/lib/gant/bin/gant deleted file mode 100755 index 327e4542ac51..000000000000 --- a/build/lib/gant/bin/gant +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/sh - -# Gant -- A Groovy way of scripting Ant tasks. -# -# Copyright © 2006–2010, 2013 Russel Winder -# -# 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. -# -# Author : Russel Winder - -# Gant initiation script for Linux and UNIX -- requires Groovy version. - -# Solaris 10 does not have readlink as standard -- though some people will have the version from -# Sunfreeware which is the same as the version on Ubuntu, Cygwin, MSYS, etc. Mac OS X has a version of -# readlink that is very different to that on Ubuntu, Solaris/Sunfreeware, Cygwin, MSYS, etc. -# -# This function attempts to just do the right thing. - -doReadLink() { - case `uname` in - Darwin) - gantLocation=`dirname $1` - gantPath=`readlink "$1"` - if [ "$gantPath" = "" ] - then - readlinkValue="$1" - else - linkDir=`dirname $gantPath` - currentDirectory=`pwd` - cd $gantLocation - cd $linkDir - gantLocation=`pwd` - gantPath=`basename $gantPath` - readlinkValue="$gantLocation/$gantPath" - cd $currentDirectory - fi - ;; - SunOS) - readlinkPath=`which readlink` - if [ `expr "$readlinkPath" : '\([^ ]*\)'` = "no" ] - then - echo "No readlink command available, please set $2." - exit 1 - else - readlinkValue=`readlink -f $1` - fi - ;; - *) - readlinkValue=`readlink -f $1` - ;; - esac -} - -# If GANT_HOME is not set, deduce a path. Assume the executable is in $GANT_HOME/bin. - -if [ -z "$GANT_HOME" ] -then - if [ -h $0 ] - then - doReadLink $0 GANT_HOME - GANT_HOME=$readlinkValue - GANT_HOME=`dirname $GANT_HOME` - else - GANT_HOME=`dirname $0` - fi - GANT_HOME=`dirname $GANT_HOME` -fi - -# If GROOVY_HOME is not set, deduce a path -- this is needed in order to discover the location of the -# startGroovy script. Assume the executable is in $GROOVY_HOME/bin. - -if [ -z "$GROOVY_HOME" ] -then - GROOVY_HOME=`which groovy` - if [ -h $GROOVY_HOME ] - then - doReadLink $GROOVY_HOME GROOVY_HOME - GROOVY_HOME=$readlinkValue - fi - GROOVY_HOME=`dirname "$GROOVY_HOME"` - GROOVY_HOME=`dirname "$GROOVY_HOME"` -fi - -# If ANT_HOME is not set, deduce a path -- this is needed in order to discover the location of the jars -# associated with the Ant installation. Assume the executable is in $ANT_HOME/bin. - -if [ -z "$ANT_HOME" ] -then - ANT_HOME=`which ant` - if [ -h $ANT_HOME ] - then - doReadLink $ANT_HOME ANT_HOME - ANT_HOME=$readlinkValue - fi - ANT_HOME=`dirname "$ANT_HOME"` - ANT_HOME=`dirname "$ANT_HOME"` -fi - -GROOVY_APP_NAME=Gant -GROOVY_CONF="$GANT_HOME/conf/gant-starter.conf" - -. "$GROOVY_HOME/bin/startGroovy" - -if $cygwin -then - GANT_HOME=`cygpath --mixed "$GANT_HOME"` - ANT_HOME=`cygpath --mixed "$ANT_HOME"` -fi -JAVA_OPTS="$JAVA_OPTS -Dgant.home=$GANT_HOME -Dant.home=$ANT_HOME" - -startGroovy gant.Gant "$@" diff --git a/build/lib/gant/bin/gant.bat b/build/lib/gant/bin/gant.bat deleted file mode 100755 index ccd28602158e..000000000000 --- a/build/lib/gant/bin/gant.bat +++ /dev/null @@ -1,71 +0,0 @@ -@if "%DEBUG%" == "" @echo off - -@rem Gant -- A Groovy way of scripting Ant tasks. -@rem -@rem Copyright © 2008,2010 Russel Winder -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in -@rem compliance with the License. You may obtain a copy of the License at -@rem -@rem http://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software distributed under the License is -@rem distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -@rem implied. See the License for the specific language governing permissions and limitations under the -@rem License. -@rem -@rem Author : Russel Winder - -@rem Gant initiation script for Windows. - -@rem Set local scope for the variables with windows NT shell -if "%OS%" == "Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=.\ - -@rem If GANT_HOME is not set, deduce a path. - -if not "%GANT_HOME%" == "" goto endSetGantHome - set GANT_HOME="%DIRNAME%.." -:endSetGantHome - -@rem If GROOVY_HOME is not set, deduce a path -- this is needed in order to discover the location of the -@rem startGroovy script. - -if not "%GROOVY_HOME%" == "" goto endSetGroovyHome - for %%P in ( %PATH% ) do if exist %%P\groovy.exe set GROOVY_HOME=%%P\.. - if not "%GROOVY_HOME%" == "" goto endSetGroovyHome - for %%P in ( %PATH% ) do if exist %%P\groovy.bat set GROOVY_HOME=%%P\.. - if not "%GROOVY_HOME%" == "" goto endSetGroovyHome - call :environmentVariableError GROOVY_HOME - goto :EOF -:endSetGroovyHome - -@rem If ANT_HOME is not set, deduce a path -- this is needed in order to discover the location of the jars -@rem asscoiated with the Ant installation. - -if not "%ANT_HOME%" == "" goto endSetAntHome - for %%P in ( %PATH% ) do if exist %%P\ant.bat set ANT_HOME=%%P\.. - if not "%ANT_HOME%" == "" goto endSetAntHome - call :environmentVariableError ANT_HOME - goto :EOF -:endSetAntHome - -set PROGNAME=gant.bat -set GROOVY_SCRIPT_NAME=gant.bat -set STARTER_CONF="%GANT_HOME%\conf\gant-starter.conf" -set JAVA_OPTS=%JAVA_OPTS% -Dgant.home="%GANT_HOME%" -Dant.home="%ANT_HOME%" - -"%GANT_HOME%\bin\startGroovy.bat" "%DIRNAME%" gant.Gant %* - -@rem End local scope for the variables with windows NT shell -if "%OS%" == "Windows_NT" endlocal - -%COMSPEC% /C exit /B %ERRORLEVEL% - -:environmentVariableError - echo. - echo ERROR: Environment variable %1 has not been set. - echo Attempting to find %1 from PATH also failed. - goto :EOF diff --git a/build/lib/gant/bin/startGroovy.bat b/build/lib/gant/bin/startGroovy.bat deleted file mode 100755 index 5f4540b22c7e..000000000000 --- a/build/lib/gant/bin/startGroovy.bat +++ /dev/null @@ -1,258 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem ## -@rem Groovy JVM Bootstrap for Windowz ## -@rem ## -@rem ########################################################################## - -@rem -@rem $Revision$ $Date$ -@rem - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal enabledelayedexpansion - -set DIRNAME=%~1 -shift - -set CLASS=%~1 -shift - -if exist "%USERPROFILE%/.groovy/preinit.bat" call "%USERPROFILE%/.groovy/preinit.bat" - -@rem Determine the command interpreter to execute the "CD" later -set COMMAND_COM="cmd.exe" -if exist "%SystemRoot%\system32\cmd.exe" set COMMAND_COM="%SystemRoot%\system32\cmd.exe" -if exist "%SystemRoot%\command.com" set COMMAND_COM="%SystemRoot%\command.com" - -@rem Use explicit find.exe to prevent cygwin and others find.exe from being used -set FIND_EXE="find.exe" -if exist "%SystemRoot%\system32\find.exe" set FIND_EXE="%SystemRoot%\system32\find.exe" -if exist "%SystemRoot%\command\find.exe" set FIND_EXE="%SystemRoot%\command\find.exe" - -:check_JAVA_HOME -@rem Make sure we have a valid JAVA_HOME -if not "%JAVA_HOME%" == "" goto have_JAVA_HOME -set PATHTMP=%PATH% -:loop -for /f "delims=; tokens=1*" %%i in ("!PATHTMP!") do ( - if exist "%%i\..\bin\java.exe" ( - set "JAVA_HOME=%%i\.." - goto found_JAVA_HOME - ) - set PATHTMP=%%j - goto loop -) -goto check_default_JAVA_EXE - -:found_JAVA_HOME -@rem Remove trailing \bin\.. from JAVA_HOME -if "%JAVA_HOME:~-7%"=="\bin\.." SET "JAVA_HOME=%JAVA_HOME:~0,-7%" -set JAVA_EXE=%JAVA_HOME%\bin\java.exe - -:check_default_JAVA_EXE -if not "%JAVA_HOME%" == "" goto valid_JAVA_HOME -java -version 2>NUL -if not ERRORLEVEL 1 goto default_JAVA_EXE - -echo. -echo ERROR: Environment variable JAVA_HOME has not been set. -echo Attempting to find JAVA_HOME from PATH also failed. -goto common_error - -:have_JAVA_HOME -@rem Remove trailing slash from JAVA_HOME if found -if "%JAVA_HOME:~-1%"=="\" SET JAVA_HOME=%JAVA_HOME:~0,-1% - -@rem Validate JAVA_HOME -%COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul -if not errorlevel 1 goto valid_JAVA_HOME_DIR - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% - -:common_error -echo Please set the JAVA_HOME variable in your environment -echo to match the location of your Java installation. -goto end - -:default_JAVA_EXE -set JAVA_EXE=java.exe -goto check_GROOVY_HOME - -:valid_JAVA_HOME_DIR -set JAVA_EXE=%JAVA_HOME%\bin\java.exe -if exist "%JAVA_EXE%" goto valid_JAVA_HOME - -echo. -echo ERROR: No java.exe found at: %JAVA_EXE% -goto common_error - -:valid_JAVA_HOME -if exist "%JAVA_HOME%\lib\tools.jar" set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar - -:check_GROOVY_HOME -@rem Define GROOVY_HOME if not set -if "%GROOVY_HOME%" == "" set GROOVY_HOME=%DIRNAME%.. - -@rem Remove trailing slash from GROOVY_HOME if found -if "%GROOVY_HOME:~-1%"=="\" SET GROOVY_HOME=%GROOVY_HOME:~0,-1% - -@rem classpath handling -set _SKIP=2 -set CP= -if "x%~1" == "x-cp" set CP=%~2 -if "x%~1" == "x-classpath" set CP=%~2 -if "x%~1" == "x--classpath" set CP=%~2 -if "x" == "x%CP%" goto init -set _SKIP=4 -shift -shift - -:init -@rem get name of script to launch with full path -set GROOVY_SCRIPT_NAME=%~f1 -@rem Get command-line arguments, handling Windowz variants -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -rem horrible roll your own arg processing inspired by jruby equivalent - -rem escape minus (-d), quotes (-q), star (-s). -set _ARGS=%* -if not defined _ARGS goto execute -set _ARGS=%_ARGS:-=-d% -set _ARGS=%_ARGS:"=-q% -rem Windowz will try to match * with files so we escape it here -rem but it is also a meta char for env var string substitution -rem so it can't be first char here, hack just for common cases. -rem If in doubt use a space or bracket before * if using -e. -set _ARGS=%_ARGS: *= -s% -set _ARGS=%_ARGS:)*=)-s% -set _ARGS=%_ARGS:0*=0-s% -set _ARGS=%_ARGS:1*=1-s% -set _ARGS=%_ARGS:2*=2-s% -set _ARGS=%_ARGS:3*=3-s% -set _ARGS=%_ARGS:4*=4-s% -set _ARGS=%_ARGS:5*=5-s% -set _ARGS=%_ARGS:6*=6-s% -set _ARGS=%_ARGS:7*=7-s% -set _ARGS=%_ARGS:8*=8-s% -set _ARGS=%_ARGS:9*=9-s% - -rem prequote all args for 'for' statement -set _ARGS="%_ARGS%" - -set _ARG= -:win9xME_args_loop -rem split args by spaces into first and rest -for /f "tokens=1,*" %%i in (%_ARGS%) do call :get_arg "%%i" "%%j" -goto process_arg - -:get_arg -rem remove quotes around first arg -for %%i in (%1) do set _ARG=%_ARG% %%~i -rem set the remaining args -set _ARGS=%2 -rem remove the leading space we'll add the first time -if "x%_ARG:~0,1%" == "x " set _ARG=%_ARG:~1% -rem return -goto :EOF - -:process_arg -if "%_ARG%" == "" goto execute - -rem collect all parts of a quoted argument containing spaces -if not "%_ARG:~0,2%" == "-q" goto :argIsComplete -if "%_ARG:~-2%" == "-q" goto :argIsComplete -rem _ARG starts with a quote but does not end with one: -rem add the next part to _ARG until the matching quote is found -goto :win9xME_args_loop - -:argIsComplete -if "x4" == "x%_SKIP%" goto skip_4 -if "x3" == "x%_SKIP%" goto skip_3 -if "x2" == "x%_SKIP%" goto skip_2 -if "x1" == "x%_SKIP%" goto skip_1 - -rem now unescape -q, -s, -d -set _ARG=%_ARG:-s=*% -set _ARG=%_ARG:-q="% -set _ARG=%_ARG:-d=-% - -set CMD_LINE_ARGS=%CMD_LINE_ARGS% %_ARG% -set _ARG= -goto win9xME_args_loop - -:skip_4 -set _ARG= -set _SKIP=3 -goto win9xME_args_loop - -:skip_3 -set _ARG= -set _SKIP=2 -goto win9xME_args_loop - -:skip_2 -set _ARG= -set _SKIP=1 -goto win9xME_args_loop - -:skip_1 -set _ARG= -set _SKIP=0 -goto win9xME_args_loop - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line -set STARTER_CLASSPATH=%GROOVY_HOME%\lib\groovy-all-2.3.0.jar - -if exist "%USERPROFILE%/.groovy/init.bat" call "%USERPROFILE%/.groovy/init.bat" - -@rem Setting a classpath using the -cp or -classpath option means not to use -@rem the global classpath. Groovy behaves then the same as the java -@rem interpreter -if "x" == "x%CP%" goto empty_cp -:non_empty_cp -set CP=%CP%;. -goto after_cp -:empty_cp -set CP=. -if "x" == "x%CLASSPATH%" goto after_cp -set CP=%CLASSPATH%;%CP% -:after_cp - -set STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter -set STARTER_CONF=%GROOVY_HOME%\conf\groovy-starter.conf - -set GROOVY_OPTS="-Xmx128m" -set GROOVY_OPTS=%GROOVY_OPTS% -Dprogram.name="%PROGNAME%" -set GROOVY_OPTS=%GROOVY_OPTS% -Dgroovy.home="%GROOVY_HOME%" -if not "%TOOLS_JAR%" == "" set GROOVY_OPTS=%GROOVY_OPTS% -Dtools.jar="%TOOLS_JAR%" -set GROOVY_OPTS=%GROOVY_OPTS% -Dgroovy.starter.conf="%STARTER_CONF%" -set GROOVY_OPTS=%GROOVY_OPTS% -Dscript.name="%GROOVY_SCRIPT_NAME%" - -if exist "%USERPROFILE%/.groovy/postinit.bat" call "%USERPROFILE%/.groovy/postinit.bat" - -@rem Execute Groovy -"%JAVA_EXE%" %GROOVY_OPTS% %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" endlocal - -@rem Optional pause the batch file -if "%GROOVY_BATCH_PAUSE%" == "on" pause -%COMSPEC% /C exit /B %ERRORLEVEL% diff --git a/build/lib/gant/conf/gant-starter.conf b/build/lib/gant/conf/gant-starter.conf deleted file mode 100644 index 75aef0043c9a..000000000000 --- a/build/lib/gant/conf/gant-starter.conf +++ /dev/null @@ -1,44 +0,0 @@ -# Gant -- A Groovy way of scripting Ant tasks. -# -# Copyright © 2008, 2010, 2013 Russel Winder -# -# 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. -# -# Author : Russel Winder - -# Load user specific libraries that are Gant specific. -load !{user.home}/.gant/lib/*.jar - -# Load user specific libraries that are Ant specific. -load !{user.home}/.ant/lib/*.jar - -# Load user specific libraries that are for Groovy. -load !{user.home}/.groovy/lib/*.jar - -# Load required libraries -load !{gant.home}/lib/*.jar - -# Load Ant libraries. If xml-apis.jar and xercesImpl.jar are in this directory then it leads to a: -# -# Caught: java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/NodeList" -# -# whenever an XML processing program that (possibly indirectly) uses a DOM is executed. Get round this by -# selecting jars, basically all the known Ant jars, and ignoring everything else. -# -# The directory might contain ant.jar but it would be bad to include this since Groovy is distributed -# with a version of Ant and that should be used. See next rule. -load !{ant.home}/lib/ant-*.jar - -# load required libraries -load !{groovy.home}/lib/*.jar - -# tools.jar for ant tasks -load ${tools.jar} diff --git a/build/lib/gant/lib/gant-1.9.11_groovy-2.3.0.jar b/build/lib/gant/lib/gant-1.9.11_groovy-2.3.0.jar deleted file mode 100644 index f3d98426914a..000000000000 Binary files a/build/lib/gant/lib/gant-1.9.11_groovy-2.3.0.jar and /dev/null differ diff --git a/build/update.sh b/build/update.sh index 0cdc4959029c..92c7133f8e1a 100755 --- a/build/update.sh +++ b/build/update.sh @@ -34,9 +34,8 @@ fi echo "Updating $WORK_IDEA_HOME from compiled classes in $DEV_IDEA_HOME" ANT_HOME="$DEV_IDEA_HOME/lib/ant" -ANT_CLASSPATH="$DEV_IDEA_HOME/build/lib/gant/lib/jps.jar" "$JAVA_BIN" -Xms64m -Xmx512m -Dant.home="$ANT_HOME" -classpath "$ANT_HOME/lib/ant-launcher.jar" org.apache.tools.ant.launch.Launcher \ - -lib "$ANT_CLASSPATH" -f "$DEV_IDEA_HOME/build/update.xml" -Dwork.idea.home="$WORK_IDEA_HOME" ${TARGET} + -f "$DEV_IDEA_HOME/build/update.xml" -Dwork.idea.home="$WORK_IDEA_HOME" ${TARGET} if [ "$?" != "0" ]; then echo "Update failed; work IDEA build not modified." diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml index 762ac1d64d37..9356fe90f2f9 100644 --- a/community-resources/src/idea/IdeaApplicationInfo.xml +++ b/community-resources/src/idea/IdeaApplicationInfo.xml @@ -2,7 +2,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jetbrains.org/intellij/schema/application-info http://jetbrains.org/intellij/schema/ApplicationInfo.xsd"> - + diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java index 6debbdffbb4c..bf3fea02edd8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java @@ -1,6 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.debugger.engine; import com.intellij.debugger.DebuggerBundle; @@ -13,10 +13,7 @@ import com.intellij.debugger.engine.events.DebuggerContextCommandImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.impl.DebuggerUtilsEx; -import com.intellij.debugger.jdi.DecompiledLocalVariable; -import com.intellij.debugger.jdi.LocalVariableProxyImpl; -import com.intellij.debugger.jdi.LocalVariablesUtil; -import com.intellij.debugger.jdi.StackFrameProxyImpl; +import com.intellij.debugger.jdi.*; import com.intellij.debugger.memory.utils.StackFrameItem; import com.intellij.debugger.settings.CapturePoint; import com.intellij.debugger.settings.DebuggerSettings; @@ -238,7 +235,7 @@ public class JavaStackFrame extends XStackFrame implements JVMStackFrameInfoProv //notifyCancelled(); } catch (InternalException e) { - if (e.errorCode() == 35) { + if (e.errorCode() == JvmtiError.INVALID_SLOT) { node.setErrorMessage(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())); //myChildren.add( // myNodeManager.createMessageNode(new MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())))); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java index d6670be3547d..f49efa8531b0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java @@ -1,21 +1,10 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.engine; import com.intellij.debugger.engine.events.DebuggerCommandImpl; +import com.intellij.debugger.jdi.JvmtiError; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.registry.Registry; @@ -77,7 +66,7 @@ public class SuspendManagerImpl implements SuspendManager { //InternalException 13 means that there are running threads that we are trying to resume //On MacOS it happened that native thread didn't stop while some java thread reached breakpoint //noinspection StatementWithEmptyBody - if (/*Patches.MAC_RESUME_VM_HACK && */e.errorCode() == 13) { + if (/*Patches.MAC_RESUME_VM_HACK && */e.errorCode() == JvmtiError.THREAD_NOT_SUSPENDED) { //Its funny, but second resume solves the problem } else { @@ -147,7 +136,8 @@ public class SuspendManagerImpl implements SuspendManager { //InternalException 13 means that there are running threads that we are trying to resume //On MacOS it happened that native thread didn't stop while some java thread reached breakpoint //noinspection StatementWithEmptyBody - if (/*Patches.MAC_RESUME_VM_HACK && */e.errorCode() == 13 && set.suspendPolicy() == EventRequest.SUSPEND_ALL) { + if (/*Patches.MAC_RESUME_VM_HACK && */e.errorCode() == JvmtiError.THREAD_NOT_SUSPENDED && + set.suspendPolicy() == EventRequest.SUSPEND_ALL) { //Its funny, but second resume solves the problem } else { diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java index f3f2fb5011a5..91cee0dfa291 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.debugger.engine.requests; import com.intellij.debugger.DebuggerBundle; @@ -6,6 +8,7 @@ import com.intellij.debugger.SourcePosition; import com.intellij.debugger.engine.*; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.impl.DebuggerUtilsEx; +import com.intellij.debugger.jdi.JvmtiError; import com.intellij.debugger.requests.ClassPrepareRequestor; import com.intellij.debugger.requests.RequestManager; import com.intellij.debugger.requests.Requestor; @@ -15,7 +18,6 @@ import com.intellij.diagnostic.ThreadDumper; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiClass; import com.intellij.ui.classFilter.ClassFilter; @@ -277,7 +279,7 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque } catch (InternalException e) { //noinspection StatementWithEmptyBody - if (e.errorCode() == 41) { + if (e.errorCode() == JvmtiError.NOT_FOUND) { //event request not found //there could be no requests after hotswap } @@ -337,9 +339,9 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque request.enable(); } catch (InternalException e) { switch (e.errorCode()) { - case 40 /* DUPLICATE */ : LOG.info(e); break; + case JvmtiError.DUPLICATE : LOG.info(e); break; - case 41 /* NOT_FOUND */ : break; + case JvmtiError.NOT_FOUND : break; //event request not found //there could be no requests after hotswap @@ -364,13 +366,8 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque public boolean isVerified(Requestor requestor) { DebuggerManagerThreadImpl.assertIsManagerThread(); - for (EventRequest request : findRequests(requestor)) { - /*ClassPrepareRequest is added in any case, so do not count it*/ - if (!(request instanceof ClassPrepareRequest)) { - return true; - } - } - return false; + //ClassPrepareRequest is added in any case, so do not count it + return findRequests(requestor).stream().anyMatch(r -> !(r instanceof ClassPrepareRequest)); } public void processDetached(DebugProcessImpl process, boolean closedByUser) { diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/JvmtiError.java b/java/debugger/impl/src/com/intellij/debugger/jdi/JvmtiError.java new file mode 100644 index 000000000000..ed84b7228767 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/JvmtiError.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.debugger.jdi; + +/** + * Copied from jvmti.h + * @author egor + */ +public class JvmtiError { + private JvmtiError() { + } + + public static final int NONE = 0; + public static final int INVALID_THREAD = 10; + public static final int INVALID_THREAD_GROUP = 11; + public static final int INVALID_PRIORITY = 12; + public static final int THREAD_NOT_SUSPENDED = 13; + public static final int THREAD_SUSPENDED = 14; + public static final int THREAD_NOT_ALIVE = 15; + public static final int INVALID_OBJECT = 20; + public static final int INVALID_CLASS = 21; + public static final int CLASS_NOT_PREPARED = 22; + public static final int INVALID_METHODID = 23; + public static final int INVALID_LOCATION = 24; + public static final int INVALID_FIELDID = 25; + public static final int NO_MORE_FRAMES = 31; + public static final int OPAQUE_FRAME = 32; + public static final int TYPE_MISMATCH = 34; + public static final int INVALID_SLOT = 35; + public static final int DUPLICATE = 40; + public static final int NOT_FOUND = 41; + public static final int INVALID_MONITOR = 50; + public static final int NOT_MONITOR_OWNER = 51; + public static final int INTERRUPT = 52; + public static final int INVALID_CLASS_FORMAT = 60; + public static final int CIRCULAR_CLASS_DEFINITION = 61; + public static final int FAILS_VERIFICATION = 62; + public static final int UNSUPPORTED_REDEFINITION_METHOD_ADDED = 63; + public static final int UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED = 64; + public static final int INVALID_TYPESTATE = 65; + public static final int UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED = 66; + public static final int UNSUPPORTED_REDEFINITION_METHOD_DELETED = 67; + public static final int UNSUPPORTED_VERSION = 68; + public static final int NAMES_DONT_MATCH = 69; + public static final int UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED = 70; + public static final int UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED = 71; + public static final int UNMODIFIABLE_CLASS = 79; + public static final int NOT_AVAILABLE = 98; + public static final int MUST_POSSESS_CAPABILITY = 99; + public static final int NULL_POINTER = 100; + public static final int ABSENT_INFORMATION = 101; + public static final int INVALID_EVENT_TYPE = 102; + public static final int ILLEGAL_ARGUMENT = 103; + public static final int NATIVE_METHOD = 104; + public static final int CLASS_LOADER_UNSUPPORTED = 106; + public static final int OUT_OF_MEMORY = 110; + public static final int ACCESS_DENIED = 111; + public static final int WRONG_PHASE = 112; + public static final int INTERNAL = 113; + public static final int UNATTACHED_THREAD = 115; + public static final int INVALID_ENVIRONMENT = 116; +} diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/ObjectReferenceProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/ObjectReferenceProxyImpl.java index d4365472d9d2..7c799dc79890 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/ObjectReferenceProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/ObjectReferenceProxyImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ /* @@ -21,10 +9,10 @@ package com.intellij.debugger.jdi; import com.intellij.util.ThreeState; import com.sun.jdi.*; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -104,18 +92,11 @@ public class ObjectReferenceProxyImpl extends JdiProxy { * @throws IncompatibleThreadStateException */ public List waitingThreads() throws IncompatibleThreadStateException { - List list = getObjectReference().waitingThreads(); - List proxiesList = new ArrayList<>(list.size()); - - for (ThreadReference threadReference : list) { - proxiesList.add(getVirtualMachineProxy().getThreadReferenceProxy(threadReference)); - } - return proxiesList; + return StreamEx.of(getObjectReference().waitingThreads()).map(getVirtualMachineProxy()::getThreadReferenceProxy).toList(); } public ThreadReferenceProxyImpl owningThread() throws IncompatibleThreadStateException { - ThreadReference threadReference = getObjectReference().owningThread(); - return getVirtualMachineProxy().getThreadReferenceProxy(threadReference); + return getVirtualMachineProxy().getThreadReferenceProxy(getObjectReference().owningThread()); } public int entryCount() throws IncompatibleThreadStateException { diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java index 41fe1f01b97c..1ed0ec8628f4 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ /* @@ -77,7 +65,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { clearCaches(); } catch (InternalException e) { - if (e.errorCode() == 23 /*INVALID_METHODID according to JDI sources*/) { + if (e.errorCode() == JvmtiError.INVALID_METHODID) { myIsObsolete = ThreeState.YES; return true; } @@ -229,7 +217,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { } catch (InternalException e) { // suppress some internal errors caused by bugs in specific JDI implementations - if (e.errorCode() != 23 && e.errorCode() != 35) { + if (e.errorCode() != JvmtiError.INVALID_METHODID && e.errorCode() != JvmtiError.INVALID_SLOT) { throw EvaluateExceptionUtil.createEvaluateException(e); } else { @@ -319,7 +307,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { clearCaches(); } catch (InternalException e) { - if (e.errorCode() == 35 || e.errorCode() == 101) { + if (e.errorCode() == JvmtiError.INVALID_SLOT || e.errorCode() == JvmtiError.ABSENT_INFORMATION) { throw new EvaluateException(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage()), e); } else throw e; @@ -341,7 +329,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { // From Oracle's forums: // This could be a JPDA bug. Unexpected JDWP Error: 32 means that an 'opaque' frame was detected at the lower JPDA levels, // typically a native frame. - if (e.errorCode() == 32 /*opaque frame JDI bug*/ ) { + if (e.errorCode() == JvmtiError.OPAQUE_FRAME /*opaque frame JDI bug*/ ) { return Collections.emptyList(); } else { @@ -373,7 +361,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { } catch (InternalException e) { // extra logging for IDEA-141270 - if (e.errorCode() == 35 || e.errorCode() == 101) { + if (e.errorCode() == JvmtiError.INVALID_SLOT || e.errorCode() == JvmtiError.ABSENT_INFORMATION) { LOG.info(e); myAllValues = Collections.emptyMap(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadGroupReferenceProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadGroupReferenceProxyImpl.java index 9b2cc6c77bc5..5ec174f59d7c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadGroupReferenceProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadGroupReferenceProxyImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ /* @@ -22,10 +10,9 @@ package com.intellij.debugger.jdi; import com.intellij.debugger.engine.jdi.ThreadGroupReferenceProxy; import com.intellij.openapi.diagnostic.Logger; import com.sun.jdi.ThreadGroupReference; -import com.sun.jdi.ThreadReference; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NonNls; -import java.util.ArrayList; import java.util.List; public class ThreadGroupReferenceProxyImpl extends ObjectReferenceProxyImpl implements ThreadGroupReferenceProxy{ @@ -73,23 +60,11 @@ public class ThreadGroupReferenceProxyImpl extends ObjectReferenceProxyImpl impl } public List threads() { - List list = getThreadGroupReference().threads(); - List proxies = new ArrayList<>(list.size()); - - for (ThreadReference threadReference : list) { - proxies.add(getVirtualMachineProxy().getThreadReferenceProxy(threadReference)); - } - return proxies; + return StreamEx.of(getThreadGroupReference().threads()).map(getVirtualMachineProxy()::getThreadReferenceProxy).toList(); } public List threadGroups() { - List list = getThreadGroupReference().threadGroups(); - List proxies = new ArrayList<>(list.size()); - - for (ThreadGroupReference threadGroupReference : list) { - proxies.add(getVirtualMachineProxy().getThreadGroupReferenceProxy(threadGroupReference)); - } - return proxies; + return StreamEx.of(getThreadGroupReference().threadGroups()).map(getVirtualMachineProxy()::getThreadGroupReferenceProxy).toList(); } public void clearCaches() { diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java index 47369b304354..82584eee1425 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java @@ -305,7 +305,7 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl imp catch (InvalidStackFrameException | ObjectCollectedException ignored) { } catch (InternalException e) { - if (e.errorCode() == 32) { + if (e.errorCode() == JvmtiError.OPAQUE_FRAME) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("drop.frame.error.no.information")); } else throw EvaluateExceptionUtil.createEvaluateException(e); diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java index 34f0643d6286..548354764af6 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ /* * @author Eugene Zhuravlev @@ -22,6 +24,7 @@ import com.sun.jdi.event.EventQueue; import com.sun.jdi.request.EventRequestManager; import com.sun.tools.jdi.JNITypeParser; import com.sun.tools.jdi.TargetVM; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -247,15 +250,7 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy { * @return a list of threadGroupProxies */ public List topLevelThreadGroups() { - List list = getVirtualMachine().topLevelThreadGroups(); - - List result = new ArrayList<>(list.size()); - - for (ThreadGroupReference threadGroup : list) { - result.add(getThreadGroupReferenceProxy(threadGroup)); - } - - return result; + return StreamEx.of(getVirtualMachine().topLevelThreadGroups()).map(this::getThreadGroupReferenceProxy).toList(); } public void threadGroupCreated(ThreadGroupReference threadGroupReference){ diff --git a/java/debugger/impl/src/com/intellij/debugger/settings/CompositeDataBinding.java b/java/debugger/impl/src/com/intellij/debugger/settings/CompositeDataBinding.java index 492f8ca74a0d..1537743628bd 100644 --- a/java/debugger/impl/src/com/intellij/debugger/settings/CompositeDataBinding.java +++ b/java/debugger/impl/src/com/intellij/debugger/settings/CompositeDataBinding.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.settings; @@ -29,23 +17,14 @@ public class CompositeDataBinding implements DataBinding{ } public void loadData(Object from) { - for (DataBinding myBinding : myBindings) { - myBinding.loadData(from); - } + myBindings.forEach(binding -> binding.loadData(from)); } public void saveData(Object to) { - for (DataBinding myBinding : myBindings) { - myBinding.saveData(to); - } + myBindings.forEach(binding -> binding.saveData(to)); } public boolean isModified(Object obj) { - for (DataBinding myBinding : myBindings) { - if (myBinding.isModified(obj)) { - return true; - } - } - return false; + return myBindings.stream().anyMatch(binding -> binding.isModified(obj)); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/HotSwapUIImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/HotSwapUIImpl.java index 85cdbc5d3e59..c8bd9bceec6b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/HotSwapUIImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/HotSwapUIImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui; @@ -105,12 +93,7 @@ public class HotSwapUIImpl extends HotSwapUI { return false; } // todo: return false if yourkit agent is inactive - for (DebuggerSession session : sessions) { - if (session.isPaused()) { - return true; - } - } - return false; + return sessions.stream().anyMatch(DebuggerSession::isPaused); } private void hotSwapSessions(final List sessions, @Nullable final Map> generatedPaths) { @@ -132,13 +115,7 @@ public class HotSwapUIImpl extends HotSwapUI { findClassesProgress = new HotSwapProgressImpl(myProject); } else { - boolean createProgress = false; - for (DebuggerSession session : sessions) { - if (session.isModifiedClassesScanRequired()) { - createProgress = true; - break; - } - } + boolean createProgress = sessions.stream().anyMatch(DebuggerSession::isModifiedClassesScanRequired); findClassesProgress = createProgress ? new HotSwapProgressImpl(myProject) : null; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java index 6d8f655707c0..6b46fcdb3a21 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui; @@ -25,6 +13,7 @@ import com.intellij.openapi.ui.MultiLineLabelUI; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.OptionsDialog; import com.intellij.util.ui.UIUtil; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -116,12 +105,7 @@ public class RunHotswapDialog extends OptionsDialog { } public Collection getSessionsToReload() { - final List markedElements = myElementsChooser.getMarkedElements(); - final List sessions = new ArrayList<>(markedElements.size()); - for (SessionItem item : markedElements) { - sessions.add(item.getSession()); - } - return sessions; + return StreamEx.of(myElementsChooser.getMarkedElements()).map(SessionItem::getSession).toList(); } private static class SessionItem { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/EditInstanceFiltersDialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/EditInstanceFiltersDialog.java index d4b873811fbf..c160222275da 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/EditInstanceFiltersDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/EditInstanceFiltersDialog.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui.breakpoints; @@ -26,6 +14,7 @@ import com.intellij.util.ui.JBUI; import javax.swing.*; import java.awt.*; +import java.util.Arrays; public class EditInstanceFiltersDialog extends DialogWrapper{ private InstanceFilterEditor myInstanceFilterEditor; @@ -69,11 +58,6 @@ public class EditInstanceFiltersDialog extends DialogWrapper{ } public InstanceFilter[] getFilters() { - ClassFilter [] cFilters = myInstanceFilterEditor.getFilters(); - InstanceFilter [] ifilters = new InstanceFilter[cFilters.length]; - for (int i = 0; i < ifilters.length; i++) { - ifilters[i] = InstanceFilter.create(cFilters[i]); - } - return ifilters; + return Arrays.stream(myInstanceFilterEditor.getFilters()).map(InstanceFilter::create).toArray(InstanceFilter[]::new); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluatorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluatorImpl.java index aef4cd5150dc..6548478c66ab 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluatorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluatorImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui.impl.watch; @@ -41,6 +29,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.refactoring.extractMethod.PrepareFailedException; import com.intellij.refactoring.extractMethodObject.ExtractLightMethodObjectHandler; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.incremental.java.JavaBuilder; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java index 74611a824609..3e4ea26a31b7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java @@ -20,10 +20,7 @@ import com.intellij.debugger.engine.events.DebuggerContextCommandImpl; import com.intellij.debugger.engine.events.SuspendContextCommandImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerUtilsEx; -import com.intellij.debugger.jdi.LocalVariableProxyImpl; -import com.intellij.debugger.jdi.StackFrameProxyImpl; -import com.intellij.debugger.jdi.ThreadGroupReferenceProxyImpl; -import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; +import com.intellij.debugger.jdi.*; import com.intellij.debugger.settings.NodeRendererSettings; import com.intellij.debugger.settings.ThreadsViewSettings; import com.intellij.debugger.ui.breakpoints.Breakpoint; @@ -505,7 +502,7 @@ public abstract class DebuggerTree extends DebuggerTreeBase implements DataProvi notifyCancelled(); } catch (InternalException e) { - if (e.errorCode() == 35) { + if (e.errorCode() == JvmtiError.INVALID_SLOT) { myChildren.add( myNodeManager.createMessageNode(new MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())))); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/NodeManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/NodeManagerImpl.java index 44350497219e..71ea9f4c444a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/NodeManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/NodeManagerImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui.impl.watch; @@ -20,6 +8,7 @@ import com.intellij.debugger.engine.evaluation.EvaluationContext; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerUtilsEx; +import com.intellij.debugger.jdi.JvmtiError; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.ui.impl.nodes.NodeComparator; import com.intellij.debugger.ui.tree.DebuggerTreeNode; @@ -131,7 +120,7 @@ public class NodeManagerImpl extends NodeDescriptorFactoryImpl implements NodeMa catch (EvaluateException ignored) { } catch (InternalException ie) { - if (ie.errorCode() != 23) { // INVALID_METHODID + if (ie.errorCode() != JvmtiError.INVALID_METHODID) { throw ie; } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StaticDescriptorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StaticDescriptorImpl.java index 6284de46b724..de1aca671572 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StaticDescriptorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StaticDescriptorImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ /* @@ -27,8 +15,8 @@ import com.intellij.debugger.settings.NodeRendererSettings; import com.intellij.debugger.ui.tree.StaticDescriptor; import com.intellij.debugger.ui.tree.render.ClassRenderer; import com.intellij.debugger.ui.tree.render.DescriptorLabelListener; -import com.sun.jdi.Field; import com.sun.jdi.ReferenceType; +import com.sun.jdi.TypeComponent; public class StaticDescriptorImpl extends NodeDescriptorImpl implements StaticDescriptor{ @@ -37,15 +25,7 @@ public class StaticDescriptorImpl extends NodeDescriptorImpl implements StaticDe public StaticDescriptorImpl(ReferenceType refType) { myType = refType; - - boolean hasStaticFields = false; - for (Field field : myType.allFields()) { - if (field.isStatic()) { - hasStaticFields = true; - break; - } - } - myHasStaticFields = hasStaticFields; + myHasStaticFields = myType.allFields().stream().anyMatch(TypeComponent::isStatic); } public ReferenceType getType() { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/BatchEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/BatchEvaluator.java index c119ab54e701..52db0f5fd63d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/BatchEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/BatchEvaluator.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui.tree.render; @@ -29,6 +17,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.rt.debugger.BatchEvaluatorServer; import com.intellij.util.containers.HashMap; import com.sun.jdi.*; +import one.util.streamex.StreamEx; import java.util.ArrayList; import java.util.Collections; @@ -160,11 +149,7 @@ public class BatchEvaluator { private boolean doEvaluateBatch(List requests, EvaluationContext evaluationContext) { try { DebugProcess debugProcess = evaluationContext.getDebugProcess(); - List values = new ArrayList<>(); - for (ToStringCommand toStringCommand : requests) { - Value value = toStringCommand.getValue(); - values.add(value instanceof ObjectReference ? ((ObjectReference)value) : value); - } + List values = StreamEx.of(requests).map(ToStringCommand::getValue).toList(); ArrayType objectArrayClass = (ArrayType)debugProcess.findClass( evaluationContext, diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java index 031ab5828ae7..ef1a86a335b1 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java @@ -14,7 +14,6 @@ import com.intellij.psi.PsiClass; import com.intellij.ui.FieldPanel; import com.intellij.ui.MultiLineTooltipUI; import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; @@ -204,12 +203,7 @@ public class JavaBreakpointFiltersPanel filters = new ArrayList<>(); - for (InstanceFilter instanceFilter : myInstanceFilters) { - if (instanceFilter.isEnabled()) { - filters.add(Long.toString(instanceFilter.getId())); - } - } + List filters = StreamEx.of(myInstanceFilters).filter(InstanceFilter::isEnabled).map(f -> Long.toString(f.getId())).toList(); if (updateText) { myInstanceFiltersField.setText(StringUtil.join(filters, " ")); } diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/JSR45PositionManager.java b/java/debugger/openapi/src/com/intellij/debugger/engine/JSR45PositionManager.java index 69ed26c20f0a..ecc646dfc380 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/JSR45PositionManager.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/JSR45PositionManager.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.engine; @@ -180,12 +168,9 @@ public abstract class JSR45PositionManager implements PositionManager { // Finds exact server file name (from available in type) // This is needed because some servers (e.g. WebSphere) put not exact file name such as 'A.jsp ' private String getSourceName(final String name, final ReferenceType type) throws AbsentInformationException { - for(String sourceNameFromType: type.sourceNames(myStratumId)) { - if (sourceNameFromType.contains(name)) { - return sourceNameFromType; - } - } - return name; + return type.sourceNames(myStratumId).stream() + .filter(sourceNameFromType -> sourceNameFromType.contains(name)) + .findFirst().orElse(name); } }); } diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/SourcePositionHighlighter.java b/java/debugger/openapi/src/com/intellij/debugger/engine/SourcePositionHighlighter.java index e95decf6e8ff..246041879d8b 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/SourcePositionHighlighter.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/SourcePositionHighlighter.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.engine; @@ -21,6 +9,8 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.util.TextRange; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + /** * During indexing, only extensions that implement {@link com.intellij.openapi.project.DumbAware} are called. * See also {@link DumbService}. diff --git a/java/debugger/openapi/src/com/intellij/debugger/ui/tree/NodeDescriptorNameAdjuster.java b/java/debugger/openapi/src/com/intellij/debugger/ui/tree/NodeDescriptorNameAdjuster.java index 5fa255b10957..fa5793b532c4 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/ui/tree/NodeDescriptorNameAdjuster.java +++ b/java/debugger/openapi/src/com/intellij/debugger/ui/tree/NodeDescriptorNameAdjuster.java @@ -1,23 +1,13 @@ /* - * Copyright 2000-2015 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.debugger.ui.tree; import com.intellij.openapi.extensions.ExtensionPointName; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; + /** * @author Nikolay.Tropin */ @@ -29,9 +19,6 @@ public abstract class NodeDescriptorNameAdjuster { public abstract String fixName(String name, @NotNull NodeDescriptor descriptor); public static NodeDescriptorNameAdjuster findFor(@NotNull NodeDescriptor descriptor) { - for (NodeDescriptorNameAdjuster adjuster:EP_NAME.getExtensions()) { - if (adjuster.isApplicable(descriptor)) return adjuster; - } - return null; + return Arrays.stream(EP_NAME.getExtensions()).filter(adjuster -> adjuster.isApplicable(descriptor)).findFirst().orElse(null); } } diff --git a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java index 4dda0a5007d3..5f1947f6bc66 100644 --- a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java +++ b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java @@ -38,6 +38,7 @@ import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView; import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm; import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView; import com.intellij.execution.util.JavaParametersUtil; +import com.intellij.execution.util.ProgramParametersConfigurator; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; @@ -398,7 +399,7 @@ public abstract class JavaTestFrameworkRunnableState - EP_NAME = ExtensionPointName.create("com.intellij.codeInsight.implementedAtRuntime"); - - public abstract boolean isImplementedAtRuntime(@NotNull PsiClass psiClass); -} diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/ImplementedAtRuntimeConditionImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/ImplementedAtRuntimeConditionImpl.java deleted file mode 100644 index 7fe21ad1ea12..000000000000 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/ImplementedAtRuntimeConditionImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000-2017 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.codeInspection.inheritance; - -import com.intellij.psi.PsiClass; -import org.jetbrains.annotations.NotNull; - -@Deprecated -public class ImplementedAtRuntimeConditionImpl extends ImplementedAtRuntimeCondition { - @Override - public boolean isImplementedAtRuntime(@NotNull PsiClass psiClass) { - for (ImplicitSubclassProvider provider : ImplicitSubclassProvider.EP_NAME.getExtensions()) { - ImplicitSubclassProvider.SubclassingInfo info = provider.getSubclassingInfo(psiClass); - if (info != null && !info.isAbstract()) { - return true; - } - } - return false; - } -} diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/ImportsAreUsedVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/ImportsAreUsedVisitor.java index 182296962b64..2d6e4e3963d8 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/ImportsAreUsedVisitor.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/ImportsAreUsedVisitor.java @@ -44,6 +44,11 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementWalkingVisitor { } } + @Override + public void visitImportList(PsiImportList list) { + //ignore imports + } + @Override public void visitElement(PsiElement element) { if (importStatements.isEmpty()) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/UnusedImportInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/UnusedImportInspection.java index b9bca62c92b6..a0bfcc033330 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/UnusedImportInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedImport/UnusedImportInspection.java @@ -16,7 +16,10 @@ package com.intellij.codeInspection.unusedImport; import com.intellij.codeInspection.*; -import com.intellij.psi.*; +import com.intellij.psi.PsiErrorElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiImportStatementBase; +import com.intellij.psi.PsiJavaFile; import com.intellij.psi.util.FileTypeUtils; import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.InspectionGadgetsBundle; @@ -37,22 +40,8 @@ public class UnusedImportInspection extends GlobalSimpleInspectionTool { @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) { if (!(file instanceof PsiJavaFile) || FileTypeUtils.isInServerPageFile(file)) return; PsiJavaFile javaFile = (PsiJavaFile)file; - final PsiPackageStatement packageStatement = javaFile.getPackageStatement(); - final PsiModifierList annotationList; - if (packageStatement != null) { - annotationList = packageStatement.getAnnotationList(); - } - else { - annotationList = null; - } - final ImportsAreUsedVisitor visitor = new ImportsAreUsedVisitor(javaFile); - for (PsiClass aClass : javaFile.getClasses()) { - aClass.accept(visitor); - } - if (annotationList != null) { - annotationList.accept(visitor); - } + javaFile.accept(visitor); for (PsiImportStatementBase unusedImportStatement : visitor.getUnusedImportStatements()) { if (unusedImportStatement.getImportReference() != null && !(PsiTreeUtil.skipWhitespacesForward(unusedImportStatement) instanceof PsiErrorElement)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java index aeb5cd20cd2e..725dd9685a49 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java @@ -621,7 +621,11 @@ public class JavaCompletionSorting { @Override public boolean shouldLift(LookupElement shorterElement, LookupElement longerElement) { Object object = shorterElement.getObject(); - if (object instanceof PsiClass && longerElement.getObject() instanceof PsiClass) { + if (!(object instanceof PsiClass)) return false; + + if (longerElement.getUserData(JavaGenerateMemberCompletionContributor.GENERATE_ELEMENT) != null) return true; + + if (longerElement.getObject() instanceof PsiClass) { PsiClass psiClass = (PsiClass)object; PsiFile file = psiClass.getContainingFile(); if (file != null) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java index 60f6f68c70f5..d200b280161b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java @@ -201,7 +201,8 @@ public class JavaGenerateMemberCompletionContributor { } PsiType type = substitutor.substitute(prototype.getReturnType()); - String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName; + String typeAndName = (type == null ? "" : type.getPresentableText() + " ") + methodName; + String signature = modifiers + typeAndName; String parameters = "(" + StringUtil.join(prototype.getParameterList().getParameters(), p -> getShortParameterName(substitutor, p) + " " + p.getName(), @@ -209,6 +210,7 @@ public class JavaGenerateMemberCompletionContributor { String overrideSignature = " @Override " + signature; // leading space to make it a middle match, under all annotation suggestions LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName). + withLookupString(typeAndName). withLookupString(signature).withLookupString(overrideSignature).withInsertHandler(insertHandler). appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon); if (prototype.isDeprecated()) { diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java index 88a35f376472..5ba141974e61 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java @@ -188,13 +188,16 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction { i = PsiTreeUtil.skipWhitespacesAndCommentsForward(i); if (!(child instanceof PsiDeclarationStatement)) continue; + int endOffset = last.getTextRange().getEndOffset(); + //declared after last usage + if (child.getTextOffset() > endOffset) break; PsiElement anchor = child; PsiElement[] declaredElements = ((PsiDeclarationStatement)child).getDeclaredElements(); for (PsiElement declared : declaredElements) { if (!(declared instanceof PsiLocalVariable)) continue; - int endOffset = last.getTextRange().getEndOffset(); + boolean contained = ReferencesSearch.search(declared, scope).forEach(ref -> ref.getElement().getTextOffset() <= endOffset); if (!contained) { diff --git a/java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java b/java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java index 7bfd3d822380..706ef85881a9 100644 --- a/java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java @@ -40,6 +40,7 @@ import com.intellij.psi.impl.JavaPsiImplementationHelper; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; import java.util.Collections; import java.util.Map; @@ -50,10 +51,12 @@ public class JavaDirectoryServiceImpl extends CoreJavaDirectoryService { @Override public PsiPackage getPackage(@NotNull PsiDirectory dir) { - ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(dir.getProject()).getFileIndex(); - String packageName = projectFileIndex.getPackageNameByDirectory(dir.getVirtualFile()); - if (packageName == null) return null; - return JavaPsiFacade.getInstance(dir.getProject()).findPackage(packageName); + Project project = dir.getProject(); + ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + VirtualFile virtualFile = dir.getVirtualFile(); + String packageName = projectFileIndex.getPackageNameByDirectory(virtualFile); + if (packageName == null || projectFileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.RESOURCES)) return null; + return JavaPsiFacade.getInstance(project).findPackage(packageName); } @Override diff --git a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java index 5705fd5edd35..dfc315d97499 100644 --- a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java +++ b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.unscramble; @@ -47,14 +35,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.intellij.icons.AllIcons.Debugger.ThreadStates.*; @@ -413,17 +402,6 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { myThreadStates = threadStates; } - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException {} - - @Override - public void removeSettingsChangedListener(ChangeListener listener) {} - @NotNull @Override public String getReportText() { @@ -447,11 +425,6 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { return ""; } - @Override - public void exportedTo(String filePath) { - - } - @Override public boolean canExport() { return !myThreadStates.isEmpty(); diff --git a/java/java-impl/src/com/intellij/usages/impl/rules/JavaClassGroupRuleProvider.java b/java/java-impl/src/com/intellij/usages/impl/rules/JavaClassGroupRuleProvider.java index 82b156c59385..7de349d0f808 100644 --- a/java/java-impl/src/com/intellij/usages/impl/rules/JavaClassGroupRuleProvider.java +++ b/java/java-impl/src/com/intellij/usages/impl/rules/JavaClassGroupRuleProvider.java @@ -1,30 +1,19 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl.rules; +import com.intellij.openapi.project.Project; import com.intellij.usages.impl.FileStructureGroupRuleProvider; import com.intellij.usages.rules.UsageGroupingRule; -import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class JavaClassGroupRuleProvider implements FileStructureGroupRuleProvider { @Override - public UsageGroupingRule getUsageGroupingRule(final Project project) { + public UsageGroupingRule getUsageGroupingRule(@NotNull final Project project) { return new ClassGroupingRule(); } } diff --git a/java/java-impl/src/com/intellij/usages/impl/rules/JavaMethodGroupRuleProvider.java b/java/java-impl/src/com/intellij/usages/impl/rules/JavaMethodGroupRuleProvider.java index 6ab324fcaa9c..545eeedcfc10 100644 --- a/java/java-impl/src/com/intellij/usages/impl/rules/JavaMethodGroupRuleProvider.java +++ b/java/java-impl/src/com/intellij/usages/impl/rules/JavaMethodGroupRuleProvider.java @@ -1,30 +1,25 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl.rules; +import com.intellij.openapi.project.Project; +import com.intellij.usages.UsageViewSettings; import com.intellij.usages.impl.FileStructureGroupRuleProvider; import com.intellij.usages.rules.UsageGroupingRule; -import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class JavaMethodGroupRuleProvider implements FileStructureGroupRuleProvider { @Override - public UsageGroupingRule getUsageGroupingRule(final Project project) { - return new MethodGroupingRule(); + public UsageGroupingRule getUsageGroupingRule(@NotNull Project project) { + return getUsageGroupingRule(project, UsageViewSettings.getInstance()); + } + + @Override + public UsageGroupingRule getUsageGroupingRule(@NotNull Project project, @NotNull UsageViewSettings usageViewSettings) { + return new MethodGroupingRule(usageViewSettings); } } diff --git a/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java b/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java index 910dc6a36063..57124edda828 100644 --- a/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java +++ b/java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl.rules; @@ -44,7 +32,13 @@ import javax.swing.*; * @author max */ public class MethodGroupingRule extends SingleParentUsageGroupingRule { - private static final Logger LOG = Logger.getInstance("#com.intellij.usages.impl.rules.MethodGroupingRule"); + private static final Logger LOG = Logger.getInstance(MethodGroupingRule.class); + @NotNull + private final UsageViewSettings myUsageViewSettings; + + public MethodGroupingRule(@NotNull UsageViewSettings usageViewSettings) { + myUsageViewSettings = usageViewSettings; + } @Nullable @Override @@ -70,7 +64,7 @@ public class MethodGroupingRule extends SingleParentUsageGroupingRule { while (true); if (containingMethod != null) { - return new MethodUsageGroup((PsiMethod)containingMethod); + return new MethodUsageGroup((PsiMethod)containingMethod, myUsageViewSettings); } } return null; @@ -82,7 +76,10 @@ public class MethodGroupingRule extends SingleParentUsageGroupingRule { private final Icon myIcon; private final Project myProject; - public MethodUsageGroup(PsiMethod psiMethod) { + @NotNull + private final UsageViewSettings myUsageViewSettings; + + public MethodUsageGroup(PsiMethod psiMethod, @NotNull UsageViewSettings usageViewSettings) { myName = PsiFormatUtil.formatMethod( psiMethod, PsiSubstitutor.EMPTY, @@ -93,6 +90,8 @@ public class MethodGroupingRule extends SingleParentUsageGroupingRule { myMethodPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(psiMethod); myIcon = getIconImpl(psiMethod); + + myUsageViewSettings = usageViewSettings; } @Override @@ -169,7 +168,7 @@ public class MethodGroupingRule extends SingleParentUsageGroupingRule { if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) { return 0; } - if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) { + if (!myUsageViewSettings.isSortAlphabetically()) { Segment segment1 = myMethodPointer.getRange(); Segment segment2 = other.myMethodPointer.getRange(); if (segment1 != null && segment2 != null) { diff --git a/java/java-impl/src/com/intellij/usages/impl/rules/NonJavaFileGroupRuleProvider.java b/java/java-impl/src/com/intellij/usages/impl/rules/NonJavaFileGroupRuleProvider.java index 41ccee880de4..d2086e777577 100644 --- a/java/java-impl/src/com/intellij/usages/impl/rules/NonJavaFileGroupRuleProvider.java +++ b/java/java-impl/src/com/intellij/usages/impl/rules/NonJavaFileGroupRuleProvider.java @@ -1,30 +1,19 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl.rules; +import com.intellij.openapi.project.Project; import com.intellij.usages.impl.FileStructureGroupRuleProvider; import com.intellij.usages.rules.UsageGroupingRule; -import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class NonJavaFileGroupRuleProvider implements FileStructureGroupRuleProvider { @Override - public UsageGroupingRule getUsageGroupingRule(final Project project) { + public UsageGroupingRule getUsageGroupingRule(@NotNull final Project project) { return new NonJavaFileGroupingRule(project); } } diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/PreferTypeToGeneratedMethod.java b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferTypeToGeneratedMethod.java new file mode 100644 index 000000000000..dd88fb8b78f1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferTypeToGeneratedMethod.java @@ -0,0 +1,4 @@ +class Foo { + private String zoo; + public Stri +} diff --git a/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable.java b/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable.java new file mode 100644 index 000000000000..e8a23dcfbc75 --- /dev/null +++ b/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable.java @@ -0,0 +1,14 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +class C { + void m(File file) throws IOException { + FileInputStream fileInputStream = new FileInputStream(file); + String s = "initial value";//Non-NLS + s = s + fileInputStream.read(); + s += "end"; + int time = 0; + System.out.println(time); + } +} diff --git a/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable_after.java b/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable_after.java new file mode 100644 index 000000000000..56dcf902e31b --- /dev/null +++ b/java/java-tests/testData/codeInsight/surroundAutoCloseable/UnrelatedVariable_after.java @@ -0,0 +1,17 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +class C { + void m(File file) throws IOException { + String s; + try (FileInputStream fileInputStream = new FileInputStream(file)) { + //Non-NLS + s = "initial value"; + s = s + fileInputStream.read(); + } + s += "end"; + int time = 0; + System.out.println(time); + } +} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionOrderingTest.groovy index 9ae118a03b6a..af9e031817e7 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -824,4 +824,8 @@ class Foo { myFixture.assertPreferredCompletionItems 0, 'out', 'exit' } + void testPreferTypeToGeneratedMethod() { + checkPreferredItems 0, 'String', 'public String getZoo', 'public String toString' + } + } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy index a462856892d4..f6f05ab6117a 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy @@ -1662,14 +1662,14 @@ class Bar { myFixture.configureByText('a.java', 'class Fooxxxxxxxxxx { Fooxxxxxa f;\n' + 'public void foo() {}\n' * 10000 + '}') def items = myFixture.completeBasic() - PsiClass c1 = items[0].object + PsiClass c1 = items[1].object assert !c1.physical assert CompletionUtil.getOriginalElement(c1) getLookup().hide() myFixture.type('x') items = myFixture.completeBasic() - PsiClass c2 = items[0].object + PsiClass c2 = items[1].object assert !c2.physical assert CompletionUtil.getOriginalElement(c2) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/SurroundAutoCloseableActionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/SurroundAutoCloseableActionTest.java index 8f088d62bc3b..7c98141535dd 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/SurroundAutoCloseableActionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/SurroundAutoCloseableActionTest.java @@ -35,6 +35,7 @@ public class SurroundAutoCloseableActionTest extends LightCodeInsightFixtureTest public void testSplitVar() { doTest(); } public void testExpression() { doTest(); } public void testExpressionIncomplete() { doTest(); } + public void testUnrelatedVariable() { doTest(); } public void testCommentsInVarDeclaration() { JavaCodeStyleSettings styleSettings = JavaCodeStyleSettings.getInstance(getProject()); boolean finalLocals = styleSettings.GENERATE_FINAL_LOCALS; diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java index 4fde37e81b44..be16220a76df 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java @@ -49,6 +49,7 @@ class JavaIntentionPolicy extends IntentionPolicy { protected static boolean mayBreakCompilation(String actionText) { return actionText.startsWith("Flip") || // doesn't care about compilability actionText.startsWith("Convert to string literal") || // can produce uncompilable code by design + actionText.startsWith("Replace string literal with character") || // can produce uncompilable code by design actionText.startsWith("Detail exceptions") || // can produce uncompilable code if 'catch' section contains 'instanceof's actionText.startsWith("Insert call to super method") || // super method can declare checked exceptions, unexpected at this point actionText.startsWith("Cast to ") || // produces uncompilable code by design diff --git a/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java b/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java index a5fe6d68bcc6..af5f8317edf7 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/usages/JavaUsageViewTreeTest.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.java.psi.usages; import com.intellij.openapi.util.Disposer; @@ -23,10 +25,10 @@ public class JavaUsageViewTreeTest extends LightCodeInsightFixtureTestCase { XmlSerializerUtil.copyBean(settings.getState(), oldSettingsState); disposeOnTearDown(() -> settings.loadState(oldSettingsState)); - settings.GROUP_BY_MODULE = false; - settings.GROUP_BY_FILE_STRUCTURE = true; - settings.GROUP_BY_USAGE_TYPE = false; - settings.GROUP_BY_PACKAGE = false; + settings.setGroupByModule(false); + settings.setGroupByFileStructure(true); + settings.setGroupByUsageType(false); + settings.setGroupByPackage(false); } public void testSimpleModule() { diff --git a/java/java-tests/testSrc/com/intellij/projectView/ModulesInProjectViewTest.kt b/java/java-tests/testSrc/com/intellij/projectView/ModulesInProjectViewTest.kt index 21e5edb58147..e2fb0755cbbf 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/ModulesInProjectViewTest.kt +++ b/java/java-tests/testSrc/com/intellij/projectView/ModulesInProjectViewTest.kt @@ -111,6 +111,25 @@ class ModulesInProjectViewTest : BaseProjectViewTestCase() { """.trimMargin()) } + fun `test do not show groups duplicating module names`() { + val root = directoryContent { + dir("foo") {} + dir("foo.bar") {} + }.generateInVirtualTempDir() + PsiTestUtil.addContentRoot(createModule("xxx.foo"), root.findChild("foo")) + PsiTestUtil.addContentRoot(createModule("xxx.foo.bar"), root.findChild("foo.bar")) + assertStructureEqual(""" + |Project + | Group: xxx + | foo + | foo.bar + | test do not show groups duplicating module names.iml + | xxx.foo.bar.iml + | xxx.foo.iml + | + """.trimMargin()) + } + fun `test modules with common parent group`() { val root = directoryContent { dir("module1") { diff --git a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewUpdatingTest.java index c60f526277a6..f3bcc99f8b8a 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/ProjectViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/ProjectViewUpdatingTest.java @@ -148,6 +148,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase { PlatformTestUtil.waitForAlarm(600); final PsiFile containingFile2 = aClass2.getContainingFile(); pane.select(aClass2, containingFile2.getVirtualFile(), true); + PlatformTestUtil.waitUntilBusy(pane.getTree()); PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: updateProjectView\n" + " -PsiDirectory: src\n" + @@ -227,6 +228,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase { final PsiField lastField = aClass.getFields()[1]; pane.select(lastField, containingFile.getVirtualFile(), true); + PlatformTestUtil.waitUntilBusy(pane.getTree()); PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + " -PsiDirectory: src\n" + diff --git a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java index b4290e02e227..1ce282558ad9 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java @@ -137,6 +137,7 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { svc.select(innerClassField, true); + PlatformTestUtil.waitUntilBusy(svc.getTree()); PlatformTestUtil.assertTreeEqual( svc.getTree(), "-Class2.java\n" + diff --git a/jps/standalone-builder/jps-standalone-builder.iml b/jps/standalone-builder/jps-standalone-builder.iml index dcfb8b9ed33a..787c9dc404b5 100644 --- a/jps/standalone-builder/jps-standalone-builder.iml +++ b/jps/standalone-builder/jps-standalone-builder.iml @@ -13,15 +13,7 @@ - - - - - - - - - + \ No newline at end of file diff --git a/lib/jgoodies-common-1.2.1.jar b/lib/jgoodies-common-1.2.1.jar deleted file mode 100644 index 5088a1fd84cf..000000000000 Binary files a/lib/jgoodies-common-1.2.1.jar and /dev/null differ diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java index ff19150c288c..eadd46e7b604 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.codeInspection.ex; @@ -87,7 +75,7 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper - - - - - - - - - + \ No newline at end of file diff --git a/platform/core-api/src/com/intellij/openapi/application/IdeUrlTrackingParametersProvider.java b/platform/core-api/src/com/intellij/openapi/application/IdeUrlTrackingParametersProvider.java new file mode 100644 index 000000000000..05a02ed6fe43 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/application/IdeUrlTrackingParametersProvider.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.openapi.application; + +import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; + +/** + * Allows IDEs to add tracking parameters to URLs which are opened from IDE and lead to company sites (e.g. download/update links, product documentation). + * Override this service in your IDE to append tracking parameters to these URLs if you need to collect statistics on your site. + *
+ * This service isn't supposed to be overridden in regular plugins. + */ +public class IdeUrlTrackingParametersProvider { + public static IdeUrlTrackingParametersProvider getInstance() { + return ServiceManager.getService(IdeUrlTrackingParametersProvider.class); + } + + /** + * @return {@code originalUrl} with appended parameters + */ + @NotNull + public String augmentUrl(@NotNull String originalUrl) { + return originalUrl; + } +} diff --git a/platform/core-api/src/com/intellij/psi/PsiLanguageInjectionHost.java b/platform/core-api/src/com/intellij/psi/PsiLanguageInjectionHost.java index 5c71e83a63d3..4f72f22a2a70 100644 --- a/platform/core-api/src/com/intellij/psi/PsiLanguageInjectionHost.java +++ b/platform/core-api/src/com/intellij/psi/PsiLanguageInjectionHost.java @@ -78,6 +78,9 @@ public interface PsiLanguageInjectionHost extends PsiElement { @Nullable PsiLanguageInjectionHost getHost(); + /** + * @return range in decoded PSI + */ @NotNull TextRange getRange(); diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java b/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java index d1d5dcfbd0ad..a744d0fafbb8 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java @@ -18,6 +18,7 @@ package com.intellij.openapi.application.impl; import com.google.common.annotations.VisibleForTesting; import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.application.IdeUrlTrackingParametersProvider; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.util.BuildNumber; @@ -28,7 +29,6 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.JBColor; import com.intellij.util.ArrayUtil; -import com.intellij.util.ObjectUtils; import com.intellij.util.PlatformUtils; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; @@ -331,7 +331,7 @@ public class ApplicationInfoImpl extends ApplicationInfoEx { @Override public String getCompanyURL() { - return myCompanyUrl; + return IdeUrlTrackingParametersProvider.getInstance().augmentUrl(myCompanyUrl); } @Nullable diff --git a/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeEventImpl.java b/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeEventImpl.java index a8f6faf8d074..d11bda895421 100644 --- a/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeEventImpl.java +++ b/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeEventImpl.java @@ -90,7 +90,7 @@ public class TreeChangeEventImpl implements TreeChangeEvent{ CompositeElement newParent = nextChange.getChangedParent(); for (TreeChangeImpl descendant : new ArrayList<>(myChangesByAllParents.get(newParent))) { - TreeElement ancestorChild = findAncestorChild(newParent, descendant.getChangedParent()); + TreeElement ancestorChild = findAncestorChild(newParent, descendant); if (ancestorChild != null) { nextChange.markChildChanged(ancestorChild, descendant.getLengthDelta()); } @@ -115,15 +115,14 @@ public class TreeChangeEventImpl implements TreeChangeEvent{ } } + /** @return a direct child of {@code ancestor} which contains {@code change} */ @Nullable - private static TreeElement findAncestorChild(@NotNull TreeElement ancestor, @NotNull TreeElement candidate) { - TreeElement element = candidate.getTreeParent(); - while (element != null) { - if (element == ancestor) return candidate; - candidate = element; - element = element.getTreeParent(); - } - return null; + private static TreeElement findAncestorChild(@NotNull CompositeElement ancestor, @NotNull TreeChangeImpl change) { + List superParents = change.getSuperParents(); + int index = superParents.indexOf(ancestor); + return index < 0 ? null : + index == 0 ? change.getChangedParent() : + superParents.get(index - 1); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java b/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java index 46a13dcb54c5..842be5ec7b15 100644 --- a/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java @@ -16,6 +16,7 @@ package com.intellij.psi; import com.intellij.injected.editor.DocumentWindow; +import com.intellij.injected.editor.VirtualFileWindow; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.lang.LanguageParserDefinitions; @@ -65,14 +66,17 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem private static final Logger LOG = Logger.getInstance("#com.intellij.psi.AbstractFileViewProvider"); public static final Key FREE_THREADED = Key.create("FREE_THREADED"); private static final Key> KNOWN_COPIES = Key.create("KNOWN_COPIES"); - @NotNull private final PsiManagerEx myManager; - @NotNull private final VirtualFile myVirtualFile; + @NotNull + private final PsiManagerEx myManager; + @NotNull + private final VirtualFile myVirtualFile; private final boolean myEventSystemEnabled; private final boolean myPhysical; private boolean myInvalidated; private volatile Content myContent; private volatile Reference myDocument; - @NotNull private final FileType myFileType; + @NotNull + private final FileType myFileType; private final PsiLock myPsiLock = new PsiLock(); protected AbstractFileViewProvider(@NotNull PsiManager manager, @@ -88,6 +92,9 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem !(virtualFile.getFileSystem() instanceof NonPhysicalFileSystem); virtualFile.putUserData(FREE_THREADED, isFreeThreaded(this)); myFileType = type; + if (virtualFile instanceof VirtualFileWindow && !(this instanceof FreeThreadedFileViewProvider)) { + throw new IllegalArgumentException("Must not create "+getClass()+" for injected file "+virtualFile+"; InjectedFileViewProvider must be used instead"); + } } public static boolean isFreeThreaded(@NotNull FileViewProvider provider) { @@ -383,6 +390,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem public abstract PsiFile getCachedPsi(@NotNull Language target); + @NotNull public abstract List getCachedPsiFiles(); @NotNull @@ -415,6 +423,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem } private interface Content { + @NotNull CharSequence getText(); int getTextLength(); @@ -422,6 +431,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem } private class VirtualFileContent implements Content { + @NotNull @Override public CharSequence getText() { final VirtualFile virtualFile = getVirtualFile(); @@ -459,10 +469,11 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem } } - private CharSequence getLastCommittedText(Document document) { + @NotNull + private CharSequence getLastCommittedText(@NotNull Document document) { return PsiDocumentManager.getInstance(myManager.getProject()).getLastCommittedText(document); } - private long getLastCommittedStamp(Document document) { + private long getLastCommittedStamp(@NotNull Document document) { return PsiDocumentManager.getInstance(myManager.getProject()).getLastCommittedStamp(document); } @@ -474,7 +485,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private final List myFileElementHardRefs = new SmartList<>(); - private PsiFileContent(final PsiFileImpl file, final long modificationStamp) { + private PsiFileContent(@NotNull PsiFileImpl file, final long modificationStamp) { myFile = file; myModificationStamp = modificationStamp; for (PsiFile aFile : getAllFiles()) { @@ -484,6 +495,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem } } + @NotNull @Override public CharSequence getText() { String content = myContent; diff --git a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index 35f32547fab0..14e9a81bee4d 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -167,7 +167,9 @@ public class FileManagerImpl implements FileManager { assert !file.isDirectory(); FileViewProvider viewProvider = findCachedViewProvider(file); if (viewProvider != null) return viewProvider; - + if (file instanceof VirtualFileWindow) { + throw new IllegalStateException("File " + file + " is invalid"); + } viewProvider = createFileViewProvider(file, true); if (file instanceof LightVirtualFile) { return file.putUserDataIfAbsent(myPsiHardRefKey, viewProvider); diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroup.java b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroup.java index f698143a8f7d..d4732a134145 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroup.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroup.java @@ -43,7 +43,7 @@ public abstract class BranchActionGroup extends ActionGroup implements DumbAware myIcon = new LayeredIcon(favorite, notFavorite); myHoveredIcon = new LayeredIcon(favoriteOnHover, notFavoriteOnHover); getTemplatePresentation().setIcon(myIcon); - getTemplatePresentation().setHoveredIcon(myHoveredIcon); + getTemplatePresentation().setSelectedIcon(myHoveredIcon); updateIcons(); } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java index a50be08ca200..d663eab99558 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java @@ -71,7 +71,6 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { preselectActionCondition, true); myProject = project; DataManager.registerDataProvider(getList(), dataId -> POPUP_MODEL.is(dataId) ? getListModel() : null); - installOnHoverIconsSupport(getListElementRenderer()); myKey = dimensionKey; if (myKey != null) { Dimension storedSize = WindowStateService.getInstance(myProject).getSizeFor(myProject, myKey); @@ -126,7 +125,6 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { // don't store children popup userSize; myKey = null; DataManager.registerDataProvider(getList(), dataId -> POPUP_MODEL.is(dataId) ? getListModel() : null); - installOnHoverIconsSupport(getListElementRenderer()); } private void trackDimensions(@Nullable String dimensionKey) { @@ -364,10 +362,7 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { super.customizeComponent(list, value, isSelected); myTextLabel.setIcon(null); myTextLabel.setDisabledIcon(null); - if (value instanceof PopupFactoryImpl.ActionItem) { - ((PopupFactoryImpl.ActionItem)value).setIconHovered(isSelected); - } - myIconLabel.setIcon(myDescriptor.getIconFor(value)); + myIconLabel.setIcon(isSelected ? myDescriptor.getSelectedIconFor(value) : myDescriptor.getIconFor(value)); PopupElementWithAdditionalInfo additionalInfoAction = getSpecificAction(value, PopupElementWithAdditionalInfo.class); updateInfoComponent(myInfoLabel, additionalInfoAction != null ? additionalInfoAction.getInfoText() : null, isSelected); } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java index a918161ad8a5..0af4b17f90d1 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java @@ -312,6 +312,7 @@ public final class Presentation implements Cloneable { setText(presentation.getTextWithMnemonic(), presentation.myDisplayedMnemonicIndex > -1); setDescription(presentation.getDescription()); setIcon(presentation.getIcon()); + setSelectedIcon(presentation.getSelectedIcon()); setDisabledIcon(presentation.getDisabledIcon()); setHoveredIcon(presentation.getHoveredIcon()); setVisible(presentation.isVisible()); diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleConstraints.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleConstraints.java index a4a4fbd67cba..ede0c2f9c9ec 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleConstraints.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleConstraints.java @@ -18,7 +18,7 @@ package com.intellij.psi.codeStyle; public interface CodeStyleConstraints { int MAX_RIGHT_MARGIN = 1000; int MIN_INDENT_SIZE = 0; - int MAX_INDENT_SIZE = 16; + int MAX_INDENT_SIZE = 32; int MIN_TAB_SIZE = 1; int MAX_TAB_SIZE = 16; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java index 266577a4d04e..e585664696c1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java @@ -1,6 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInsight.hint; @@ -140,9 +140,9 @@ public class ParameterInfoComponent extends JPanel { @Override public Dimension getPreferredSize() { - int size = myPanels.length; + long visibleRows = Stream.of(myPanels).filter(Component::isVisible).count(); final Dimension preferredSize = super.getPreferredSize(); - if (size >= 0 && size <= 20) { + if (visibleRows <= 20) { return preferredSize; } else { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/LiveTemplateBuilder.java b/platform/lang-impl/src/com/intellij/codeInsight/template/LiveTemplateBuilder.java index 5f28811983ca..9bdea5902942 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/LiveTemplateBuilder.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/LiveTemplateBuilder.java @@ -42,7 +42,7 @@ public class LiveTemplateBuilder { private final int mySegmentLimit; private final boolean myAddEndVariableAtTheEndOfTemplate; private String myLastEndVarName; - private boolean myIsToReformat = false; + private boolean myIsToReformat; @SuppressWarnings("UnusedDeclaration") @@ -133,15 +133,7 @@ public class LiveTemplateBuilder { } List variableOccurrences = getListWithLimit(myVariableOccurrences); - Collections.sort(variableOccurrences, (o1, o2) -> { - if (o1.myOffset < o2.myOffset) { - return -1; - } - if (o1.myOffset > o2.myOffset) { - return 1; - } - return 0; - }); + Collections.sort(variableOccurrences, Comparator.comparingInt(o -> o.myOffset)); int last = 0; for (VarOccurence occurence : variableOccurrences) { template.addTextSegment(myText.substring(last, occurence.myOffset)); @@ -161,7 +153,7 @@ public class LiveTemplateBuilder { return Collections.emptyList(); } if (mySegmentLimit > 0 && list.size() > mySegmentLimit) { - LOGGER.warn("Template with more than " + mySegmentLimit + " segments had been build (" + list.size() + "). Text: " + myText); + warnTooManySegments(list.size()); return list.subList(0, Math.min(list.size(), mySegmentLimit)); } return list; @@ -229,12 +221,12 @@ public class LiveTemplateBuilder { String text = template.getTemplateText(); insertText(offset, text, false); - Map newVarNames = new HashMap<>(); Set oldVarNames = new HashSet<>(); for (int i = 0; i < template.getVariableCount(); i++) { String varName = template.getVariableNameAt(i); oldVarNames.add(varName); } + Map newVarNames = new HashMap<>(); for (int i = 0; i < template.getVariableCount(); i++) { String varName = template.getVariableNameAt(i); if (!TemplateImpl.INTERNAL_VARS_SET.contains(varName)) { @@ -256,7 +248,7 @@ public class LiveTemplateBuilder { Variable var = new Variable(newVarName, template.getExpressionStringAt(i), template.getDefaultValueStringAt(i), template.isAlwaysStopAt(i)); if (mySegmentLimit >= 0 && myVariables.size() >= mySegmentLimit) { if (mySegmentLimit > 0) { - LOGGER.warn("Template with more than " + mySegmentLimit + " segments had been build. Text: " + myText); + warnTooManySegments(myVariables.size()); } break; } @@ -298,6 +290,11 @@ public class LiveTemplateBuilder { return endOffset; } + private void warnTooManySegments(int size) { + LOGGER.warn("Too many (" + size + " with the limit of " + mySegmentLimit + ") segments were requested" + + " for the template with the text: " + myText); + } + private void removeEndVarAtOffset(int offset) { for (Iterator it = myVariableOccurrences.iterator(); it.hasNext();) { VarOccurence occurence = it.next(); @@ -306,12 +303,7 @@ public class LiveTemplateBuilder { } if (occurence.myOffset == offset) { it.remove(); - for (Iterator it1 = myVariables.iterator(); it1.hasNext();) { - Variable variable = it1.next(); - if (occurence.myName.equals(variable.getName())) { - it1.remove(); - } - } + myVariables.removeIf(variable -> occurence.myName.equals(variable.getName())); } } } diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 29d6428d4405..c654cac6a303 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.find.actions; import com.intellij.codeInsight.TargetElementUtil; @@ -240,7 +242,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction { } Disposer.register(usageView, () -> { - showUsagesSettings.loadState(usageViewSettings); + showUsagesSettings.applyUsageViewSettings(usageViewSettings); usageViewSettings.loadState(savedGlobalSettings); }); diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java index 5cf59c0ed235..b514c164168a 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.favoritesTreeView; @@ -68,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; @@ -258,19 +245,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider, Dock private ExporterToTextFile createTextExporter() { return new ExporterToTextFile() { - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { @@ -325,10 +299,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider, Dock return myProject.getBasePath() + File.separator + "Favorites.txt"; } - @Override - public void exportedTo(String filePath) { - } - @Override public boolean canExport() { return true; diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java index 5095aa645704..fe89256bc2f2 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.hierarchy; @@ -20,11 +8,8 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import java.util.Enumeration; -import java.util.TooManyListenersException; class ExporterToTextFileHierarchy implements ExporterToTextFile { private static final Logger LOG = Logger.getInstance(ExporterToTextFileHierarchy.class); @@ -34,19 +19,6 @@ class ExporterToTextFileHierarchy implements ExporterToTextFile { myHierarchyBrowserBase = hierarchyBrowserBase; } - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { @@ -85,7 +57,7 @@ class ExporterToTextFileHierarchy implements ExporterToTextFile { } @Override - public void exportedTo(String filePath) { + public void exportedTo(@NotNull String filePath) { final HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myHierarchyBrowserBase.myProject).getState(); if (state != null) { state.EXPORT_FILE_PATH = filePath; diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ModuleGroup.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ModuleGroup.java index e5c99c5ca463..6867611e86bf 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ModuleGroup.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ModuleGroup.java @@ -65,21 +65,32 @@ public class ModuleGroup { @NotNull public Collection modulesInGroup(ModuleGrouper grouper, boolean recursively) { List result = new ArrayList<>(); + Set> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module)); for (final Module module : grouper.getAllModules()) { List group = grouper.getGroupPath(module); - if (myGroupPath.equals(group) || (recursively && isChild(myGroupPath, group))) { + if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || allIntermediatePathsAreFromSet(myGroupPath, group, moduleAsGroupsPaths))) { result.add(module); } } return result; } + private static boolean allIntermediatePathsAreFromSet(List parent, List descendant, Set> set) { + for (int i = parent.size() + 1; i < descendant.size() - 1; i++) { + if (!set.contains(descendant.subList(0, i))) { + return false; + } + } + return true; + } + @NotNull public Collection childGroups(ModuleGrouper grouper) { Set result = new THashSet<>(); + Set> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module)); for (Module module : grouper.getAllModules()) { List group = grouper.getGroupPath(module); - if (isChild(myGroupPath, group)) { + if (!moduleAsGroupsPaths.contains(group) && isChild(myGroupPath, group)) { final List directChild = ContainerUtil.append(myGroupPath, group.get(myGroupPath.size())); result.add(new ModuleGroup(directChild)); } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index b64b03afbab7..d48f60d29129 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -129,7 +129,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo private final Map myAutoscrollToSource = new THashMap<>(); private final Map myAutoscrollFromSource = new THashMap<>(); private static final boolean ourAutoscrollFromSourceDefaults = false; - + private boolean myFoldersAlwaysOnTop = true; private String myCurrentViewId; @@ -171,7 +171,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo private static final String ATTRIBUTE_ID = "id"; private JPanel myViewContentPanel; - private static final Comparator PANE_WEIGHT_COMPARATOR = (o1, o2) -> o1.getWeight() - o2.getWeight(); + private static final Comparator PANE_WEIGHT_COMPARATOR = Comparator.comparingInt(AbstractProjectViewPane::getWeight); private final FileEditorManager myFileEditorManager; private final MyPanel myDataProvider; private final SplitterProportionsData splitterProportions = new SplitterProportionsDataImpl(); @@ -611,10 +611,10 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo } @Override - public void update(AnActionEvent e) { + public void update(@NotNull AnActionEvent e) { super.update(e); - final Presentation presentation = e.getPresentation(); - presentation.setVisible(isFlattenPackages(myCurrentViewId)); + + e.getPresentation().setVisible(isFlattenPackages(myCurrentViewId)); } } if (ProjectViewDirectoryHelper.getInstance(myProject).supportsHideEmptyMiddlePackages()) { @@ -679,11 +679,6 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo titleActions.add(new ScrollFromSourceAction()); } AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(new TreeExpander() { - @Override - public void expandAll() { - - } - @Override public boolean canExpand() { return false; @@ -706,7 +701,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo collapseAllAction.getTemplatePresentation().setIcon(AllIcons.General.CollapseAll); collapseAllAction.getTemplatePresentation().setHoveredIcon(AllIcons.General.CollapseAllHover); titleActions.add(collapseAllAction); - getCurrentProjectViewPane().addToolbarActions(myActionGroup); + getProjectViewPaneById(myCurrentViewId == null ? ProjectViewPane.ID : myCurrentViewId).addToolbarActions(myActionGroup); ToolWindowEx window = (ToolWindowEx)ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.PROJECT_VIEW); if (window != null) { @@ -1117,7 +1112,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo if (PlatformDataKeys.HELP_ID.is(dataId)) { return HelpID.PROJECT_VIEWS; } - if (ProjectViewImpl.DATA_KEY.is(dataId)) { + if (DATA_KEY.is(dataId)) { return ProjectViewImpl.this; } if (PlatformDataKeys.PROJECT_CONTEXT.is(dataId)) { @@ -1276,7 +1271,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo } } - /** Project view has the same node for module and its single content root + /** Project view has the same node for module and its single content root * => MODULE_CONTEXT data key should return the module when its content root is selected * When there are multiple content roots, they have different nodes under the module node * => MODULE_CONTEXT should be only available for the module node @@ -1413,12 +1408,11 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo Element foldersElement = navigatorElement.getChild(ELEMENT_FOLDERS_ALWAYS_ON_TOP); if (foldersElement != null) myFoldersAlwaysOnTop = Boolean.valueOf(foldersElement.getAttributeValue("value")); - + try { splitterProportions.readExternal(navigatorElement); } - catch (InvalidDataException e) { - // ignore + catch (InvalidDataException ignored) { } } Element panesElement = parentNode.getChild(ELEMENT_PANES); @@ -1470,7 +1464,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo writeOption(navigatorElement, myAutoscrollFromSource, ELEMENT_AUTOSCROLL_FROM_SOURCE); writeOption(navigatorElement, mySortByType, ELEMENT_SORT_BY_TYPE); writeOption(navigatorElement, myManualOrder, ELEMENT_MANUAL_ORDER); - + Element foldersElement = new Element(ELEMENT_FOLDERS_ALWAYS_ON_TOP); foldersElement.setAttribute("value", Boolean.toString(myFoldersAlwaysOnTop)); navigatorElement.addContent(foldersElement); @@ -2002,7 +1996,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo } } } - + private class SortByTypeAction extends ToggleAction implements DumbAware { private SortByTypeAction() { super(IdeBundle.message("action.sort.by.type"), IdeBundle.message("action.sort.by.type"), AllIcons.ObjectBrowser.SortByType); diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java index 07e9ea32616b..655acd3e4767 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java @@ -60,7 +60,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeModel; @@ -673,22 +672,7 @@ public class DependenciesPanel extends JPanel implements Disposable, DataProvide } } - private class DependenciesExporterToTextFile implements ExporterToTextFile { - - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { - } - @NotNull @Override public String getReportText() { @@ -723,10 +707,6 @@ public class DependenciesPanel extends JPanel implements Disposable, DataProvide return ""; } - @Override - public void exportedTo(String filePath) { - } - @Override public boolean canExport() { return true; diff --git a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java index 981e6170e451..e045b575826e 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java +++ b/platform/lang-impl/src/com/intellij/slicer/SlicePanel.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.slicer; @@ -143,7 +131,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.RIGHT)); boolean vertical = myToolWindow.getAnchor() == ToolWindowAnchor.LEFT || myToolWindow.getAnchor() == ToolWindowAnchor.RIGHT; - Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS); + Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().getPreviewUsagesSplitterProportion()); splitter.setFirstComponent(pane); myUsagePreviewPanel = new UsagePreviewPanel(myProject, new UsageViewPresentation()); myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT)); @@ -167,7 +155,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, @Override public void dispose() { if (myUsagePreviewPanel != null) { - UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS = ((Splitter)myUsagePreviewPanel.getParent()).getProportion(); + UsageViewSettings.getInstance().setPreviewUsagesSplitterProportion(((Splitter)myUsagePreviewPanel.getParent()).getProportion()); myUsagePreviewPanel = null; } @@ -175,7 +163,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, ToolTipManager.sharedInstance().unregisterComponent(myTree); } - class MultiLanguageTreeCellRenderer implements TreeCellRenderer { + static class MultiLanguageTreeCellRenderer implements TreeCellRenderer { @NotNull private final SliceUsageCellRendererBase rootRenderer; @@ -382,7 +370,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, } myProvider.registerExtraPanelActions(actionGroup, myBuilder); - actionGroup.add(CommonActionsManager.getInstance().createExportToTextFileAction(new SliceToTextFileExporter(myBuilder))); + actionGroup.add(CommonActionsManager.getInstance().createExportToTextFileAction(new SliceToTextFileExporter(myBuilder, UsageViewSettings.getInstance()))); //actionGroup.add(new ContextHelpAction(HELP_ID)); diff --git a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java index 106a544196a4..901b1470cd13 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java +++ b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.slicer; @@ -20,33 +8,19 @@ import com.intellij.usages.UsageViewSettings; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.ChangeListener; import java.util.List; -import java.util.TooManyListenersException; /** * @author nik */ public class SliceToTextFileExporter implements ExporterToTextFile { private final SliceTreeBuilder myBuilder; + @NotNull private final UsageViewSettings myUsageViewSettings; private String myLineSeparator = SystemProperties.getLineSeparator(); - public SliceToTextFileExporter(SliceTreeBuilder builder) { + public SliceToTextFileExporter(@NotNull SliceTreeBuilder builder, @NotNull UsageViewSettings usageViewSettings) { myBuilder = builder; - } - - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { + myUsageViewSettings = usageViewSettings; } @NotNull @@ -78,12 +52,12 @@ public class SliceToTextFileExporter implements ExporterToTextFile { @NotNull @Override public String getDefaultFilePath() { - return UsageViewSettings.getInstance().EXPORT_FILE_NAME; + return myUsageViewSettings.getExportFileName(); } @Override - public void exportedTo(String filePath) { - UsageViewSettings.getInstance().EXPORT_FILE_NAME = filePath; + public void exportedTo(@NotNull String filePath) { + myUsageViewSettings.setExportFileName(filePath); } @Override diff --git a/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java b/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java index 852764a65a26..a7dafcac3b2e 100644 --- a/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java +++ b/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java @@ -1,23 +1,12 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -30,28 +19,34 @@ public abstract class CommonActionsManager { } public abstract AnAction createPrevOccurenceAction(OccurenceNavigator navigator); + public abstract AnAction createNextOccurenceAction(OccurenceNavigator navigator); @Deprecated public abstract AnAction createExpandAllAction(TreeExpander expander); + public abstract AnAction createExpandAllAction(TreeExpander expander, JComponent component); + public abstract AnAction createExpandAllHeaderAction(JTree tree); @Deprecated public abstract AnAction createCollapseAllAction(TreeExpander expander); + public abstract AnAction createCollapseAllAction(TreeExpander expander, JComponent component); + public abstract AnAction createCollapseAllHeaderAction(JTree tree); public abstract AnAction createHelpAction(String helpId); /** * Installs autoscroll capability support to JTree passed. Toggle action returned. + * * @param project - * @return toggle action to be inserted to appropriate toolbar - * @param tree should provide DataConstants.NAVIGATABLE for handler to work on + * @param tree should provide DataConstants.NAVIGATABLE for handler to work on * @param optionProvider get/set API to externalizable property. + * @return toggle action to be inserted to appropriate toolbar */ public abstract AnAction installAutoscrollToSourceHandler(Project project, JTree tree, AutoScrollToSourceOptionProvider optionProvider); - public abstract AnAction createExportToTextFileAction(ExporterToTextFile exporter); + public abstract AnAction createExportToTextFileAction(@NotNull ExporterToTextFile exporter); } diff --git a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java index 4fdf61f1b2ba..c8db680fbf4e 100644 --- a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java +++ b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java @@ -1,32 +1,35 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ChangeListener; import java.util.TooManyListenersException; public interface ExporterToTextFile { - JComponent getSettingsEditor(); - void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException; - void removeSettingsChangedListener(ChangeListener listener); - @NotNull String getReportText(); - @NotNull String getDefaultFilePath(); - void exportedTo(String filePath); + @Nullable + default JComponent getSettingsEditor() { + return null; + } + + default void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { + } + + default void removeSettingsChangedListener(ChangeListener listener) { + } + + @NotNull + String getReportText(); + + @NotNull + String getDefaultFilePath(); + + default void exportedTo(@NotNull String filePath) { + } + boolean canExport(); } diff --git a/platform/platform-api/src/com/intellij/ide/TreeExpander.java b/platform/platform-api/src/com/intellij/ide/TreeExpander.java index a1dc8a01f310..1b3b4f089075 100644 --- a/platform/platform-api/src/com/intellij/ide/TreeExpander.java +++ b/platform/platform-api/src/com/intellij/ide/TreeExpander.java @@ -1,23 +1,15 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide; public interface TreeExpander { - void expandAll(); + default void expandAll() { + } + boolean canExpand(); + void collapseAll(); + boolean canCollapse(); } diff --git a/platform/platform-api/src/com/intellij/ide/customization/UtmIdeUrlTrackingParametersProvider.java b/platform/platform-api/src/com/intellij/ide/customization/UtmIdeUrlTrackingParametersProvider.java new file mode 100644 index 000000000000..96d34e5746c4 --- /dev/null +++ b/platform/platform-api/src/com/intellij/ide/customization/UtmIdeUrlTrackingParametersProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.ide.customization; + +import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.application.IdeUrlTrackingParametersProvider; +import com.intellij.openapi.diagnostic.Logger; +import org.apache.http.client.utils.URIBuilder; +import org.jetbrains.annotations.NotNull; + +import java.net.URISyntaxException; + +/** + * @author nik + */ +public class UtmIdeUrlTrackingParametersProvider extends IdeUrlTrackingParametersProvider { + private static final Logger LOG = Logger.getInstance(UtmIdeUrlTrackingParametersProvider.class); + + @NotNull + @Override + public String augmentUrl(@NotNull String originalUrl) { + try { + ApplicationInfo info = ApplicationInfo.getInstance(); + String productVersion = info.getMajorVersion() + "." + info.getMinorVersionMainPart(); + return new URIBuilder(originalUrl).addParameter("utm_source", "product") + .addParameter("utm_medium", "link") + .addParameter("utm_campaign", info.getBuild().getProductCode()) + .addParameter("utm_content", productVersion) + .build().toString(); + } + catch (URISyntaxException e) { + LOG.warn(originalUrl, e); + return originalUrl; + } + } +} diff --git a/platform/platform-api/src/com/intellij/ide/mavenService/DownloadResult.java b/platform/platform-api/src/com/intellij/ide/mavenService/DownloadResult.java deleted file mode 100644 index 63645e685dc7..000000000000 --- a/platform/platform-api/src/com/intellij/ide/mavenService/DownloadResult.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2000-2010 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.ide.mavenService; - -import java.io.File; - -/** - * @author Dmitry Avdeev - */ -public interface DownloadResult { - - int BINARY = 0x01; - int SOURCE = 0x02; - int JAVADOCS = 0x04; - - File[] getFile(int option); -} diff --git a/platform/platform-api/src/com/intellij/openapi/ui/PanelWithActionsAndCloseButton.java b/platform/platform-api/src/com/intellij/openapi/ui/PanelWithActionsAndCloseButton.java index 167a6dd85b98..cbf56cf25d47 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/PanelWithActionsAndCloseButton.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/PanelWithActionsAndCloseButton.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2014 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.openapi.ui; @@ -69,8 +57,6 @@ public abstract class PanelWithActionsAndCloseButton extends JPanel implements D protected void init(){ addActionsTo(myToolbarGroup); myToolbarGroup.add(new MyCloseAction()); - myToolbarGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_CONTEXT_HELP)); - ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, myToolbarGroup, ! myVerticalToolbar); JComponent centerPanel = createCenterPanel(); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListItemDescriptor.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListItemDescriptor.java index ae9dee1448a5..e84e5ae5c7c3 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListItemDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListItemDescriptor.java @@ -32,6 +32,10 @@ public interface ListItemDescriptor { @Nullable Icon getIconFor(T value); + default Icon getSelectedIconFor(T value) { + return getIconFor(value); + } + boolean hasSeparatorAboveOf(T value); @Nullable diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStep.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStep.java index ca5192bea1ed..1871fbff7608 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStep.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStep.java @@ -55,6 +55,10 @@ public interface ListPopupStep extends PopupStep { @Nullable Icon getIconFor(T aValue); + default Icon getSelectedIconFor(T value) { + return getIconFor(value); + } + /** * Returns the text to display for the specified list item. * diff --git a/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java b/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java index be72ac021384..7a68ec1304b1 100644 --- a/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java @@ -23,6 +23,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.internal.statistic.UsageTrigger; import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.application.IdeUrlTrackingParametersProvider; import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; @@ -31,7 +32,6 @@ import com.intellij.openapi.help.WebHelpProvider; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.reference.SoftReference; -import com.intellij.util.PlatformUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -86,14 +86,7 @@ public class HelpManagerImpl extends HelpManager { if (!url.endsWith("/")) url += "/"; url += productVersion + "/?" + id; - if (PlatformUtils.isJetBrainsProduct()) { - String productCode = info.getBuild().getProductCode(); - if(!StringUtil.isEmpty(productCode)) { - url += "&utm_source=from_product&utm_medium=help_link&utm_campaign=" + productCode + "&utm_content=" + productVersion; - } - } - - BrowserUtil.browse(url); + BrowserUtil.browse(IdeUrlTrackingParametersProvider.getInstance().augmentUrl(url)); return; } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt b/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt index 334f06314e3c..d788b8867d63 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt +++ b/platform/platform-impl/src/com/intellij/ide/actions/project/convertModuleGroupsToQualifiedNames.kt @@ -162,6 +162,7 @@ class ConvertModuleGroupsToQualifiedNamesDialog(val project: Project) : DialogWr if (rememberOldNamesCheckBox.isSelected) { (ModulePointerManager.getInstance(project) as ModulePointerManagerImpl).setRenamingScheme(renamingScheme) } + project.save() } super.doOKAction() diff --git a/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java b/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java index e2d6e31151a1..0963518e3e5c 100644 --- a/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java +++ b/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.errorTreeView.impl; @@ -70,9 +58,6 @@ public class ErrorViewTextExporter implements ExporterToTextFile { return ""; } - public void exportedTo(String filePath) { - } - public boolean canExport() { return true; } diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java index f9a2e498a4c7..0f3636ac7d37 100644 --- a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java @@ -98,6 +98,15 @@ public final class ConsentOptions { return confirmedConsent == null? Permission.UNDEFINED : confirmedConsent.isAccepted()? Permission.YES : Permission.NO; } + public boolean setSendingUsageStatsAllowed(boolean allowed) { + final Consent defConsent = loadDefaultConsents().get(STATISTICS_OPTION_ID); + if (defConsent != null && !defConsent.isDeleted()) { + saveConfirmedConsents(Collections.singleton(new ConfirmedConsent(defConsent.getId(), defConsent.getVersion(), allowed, 0L))); + return true; + } + return false; + } + @Nullable public String getConfirmedConsentsString() { final Map defaults = loadDefaultConsents(); diff --git a/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java index a48aa7a49421..9aadad239b37 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.impl; @@ -21,6 +9,7 @@ import com.intellij.ide.actions.*; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.project.Project; import com.intellij.ui.AutoScrollToSourceHandler; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -90,7 +79,7 @@ public class CommonActionsManagerImpl extends CommonActionsManager { return handler.createToggleAction(); } - public AnAction createExportToTextFileAction(ExporterToTextFile exporter) { + public AnAction createExportToTextFileAction(@NotNull ExporterToTextFile exporter) { return new ExportToTextFileToolbarAction(exporter); } } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index bd253e0eb035..f5a3ed701c71 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -19,6 +19,7 @@ import com.intellij.ide.IdeEventQueue; import com.intellij.ide.ui.laf.DarculaMetalTheme; import com.intellij.ide.ui.laf.IdeaLaf; import com.intellij.ide.ui.laf.LafManagerImpl; +import com.intellij.ide.ui.laf.intellij.MacIntelliJIconCache; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; @@ -575,4 +576,19 @@ public class DarculaLaf extends BasicLookAndFeel { public static Icon loadIcon(String iconName) { return IconLoader.findIcon("/com/intellij/ide/ui/laf/darcula/icons/" + iconName, DarculaLaf.class, true); } + + public static Icon getCheckmarkIcon(boolean darcula) { + if (darcula) return loadIcon("checkmark.png"); + return MacIntelliJIconCache.getIcon("checkmark", false, false, true); + } + + public static Icon getCheckmarkSelectedIcon(boolean darcula) { + if (darcula) return loadIcon("checkmarkSelected.png"); + return MacIntelliJIconCache.getIcon("checkmark", true, false, true); + } + + public static Icon getCheckmarkDisabledIcon(boolean darcula) { + if (darcula) return loadIcon("checkmarkDisabled.png"); + return MacIntelliJIconCache.getIcon("checkmark", false, false, false); + } } diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index 51ee6a849f8f..91e55a82e0bf 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -130,7 +130,7 @@ public class StartupUtil { if (!Main.isHeadless()) { AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); AppUIUtil.registerBundledFonts(); - AppUIUtil.showEndUserAgreement(); + AppUIUtil.showUserAgreementAndConsentsIfNeeded(); } appStarter.start(newConfigFolder); diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/actions/SendStatisticsAction.java b/platform/platform-impl/src/com/intellij/internal/statistic/actions/SendStatisticsAction.java index 3e49fe81134d..05a4ddf2ae85 100755 --- a/platform/platform-impl/src/com/intellij/internal/statistic/actions/SendStatisticsAction.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/actions/SendStatisticsAction.java @@ -15,11 +15,11 @@ */ package com.intellij.internal.statistic.actions; -import com.intellij.internal.statistic.utils.StatisticsUploadAssistant; +import com.intellij.internal.statistic.ApplicationStatisticsPersistenceComponent; import com.intellij.internal.statistic.connect.StatisticsResult; import com.intellij.internal.statistic.connect.StatisticsService; -import com.intellij.internal.statistic.ApplicationStatisticsPersistenceComponent; import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; +import com.intellij.internal.statistic.utils.StatisticsUploadAssistant; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; @@ -45,10 +45,14 @@ public class SendStatisticsAction extends AnAction { @Override public void run(@NotNull ProgressIndicator indicator) { UsageStatisticsPersistenceComponent statisticsPersistenceComponent = UsageStatisticsPersistenceComponent.getInstance(); - boolean sendAllowed = statisticsPersistenceComponent.isAllowed(); - statisticsPersistenceComponent.setAllowed(true); - ApplicationStatisticsPersistenceComponent.persistOpenedProjects(); - statisticsPersistenceComponent.setAllowed(sendAllowed); + final boolean sendAllowed = statisticsPersistenceComponent.isAllowed(); + try { + statisticsPersistenceComponent.setAllowed(true); + ApplicationStatisticsPersistenceComponent.persistOpenedProjects(); + } + finally { + statisticsPersistenceComponent.setAllowed(sendAllowed); + } StatisticsService service = StatisticsUploadAssistant.getStatisticsService(); final StatisticsResult result = service.send(); diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java deleted file mode 100644 index 3ec9f7cf6d97..000000000000 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.internal.statistic.configurable; - -import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SearchableConfigurable; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -public class StatisticsConfigurable implements SearchableConfigurable, Configurable.NoScroll { - - private boolean modifiedByDefault; - - public StatisticsConfigurable() { - this(false); - } - - public StatisticsConfigurable(boolean isModifiedByDefault) { - modifiedByDefault = isModifiedByDefault; - } - - - private StatisticsConfigurationComponent myConfig; - - @Nls - public String getDisplayName() { - return "Usage Statistics"; - } - - @Override - @Nullable - @NonNls - public String getHelpTopic() { - return "preferences.usage.statictics"; - } - - public JComponent createComponent() { - myConfig = new StatisticsConfigurationComponent(); - return myConfig.getJComponent(); - } - - public boolean isModified() { - final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance(); - return myConfig.isAllowed() != persistenceComponent.isAllowed() || - myConfig.getPeriod() != persistenceComponent.getPeriod() || - modifiedByDefault; - } - - public void apply() throws ConfigurationException { - final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance(); - - //persistenceComponent.setPeriod(myConfig.getPeriod()); - persistenceComponent.setAllowed(myConfig.isAllowed()); - persistenceComponent.setShowNotification(false); - modifiedByDefault = false; - } - - public void reset() { - myConfig.reset(); - } - - public void disposeUIResources() { - myConfig = null; - } - - @NotNull - @Override - public String getId() { - return "usage.statistics"; - } -} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form deleted file mode 100644 index fc64eadf51ec..000000000000 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form +++ /dev/null @@ -1,74 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java deleted file mode 100644 index 3c87c7215cf6..000000000000 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.internal.statistic.configurable; - -import com.intellij.internal.statistic.StatisticsBundle; -import com.intellij.internal.statistic.connect.StatisticsService; -import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; -import com.intellij.internal.statistic.utils.StatisticsUploadAssistant; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.ui.RelativeFont; - -import javax.swing.*; -import java.util.Map; - -public class StatisticsConfigurationComponent { - - private JPanel myMainPanel; - private JLabel myTitle; - private JCheckBox myAllowToSendUsagesCheckBox; - private JLabel myLabel; - - public StatisticsConfigurationComponent() { - String product = ApplicationNamesInfo.getInstance().getFullProductName(); - String company = ApplicationInfo.getInstance().getCompanyName(); - myTitle.setText(StatisticsBundle.message("stats.title", product, company)); - myLabel.setText(StatisticsBundle.message("stats.config.details", company)); - RelativeFont.SMALL.install(myLabel); - - myAllowToSendUsagesCheckBox.setText(StatisticsBundle.message("stats.config.allow.send.stats.text", company)); - - // Let current statistics service override labels - StatisticsService service = StatisticsUploadAssistant.getStatisticsService(); - if (service != null) { - Map overrides = service.getStatisticsConfigurationLabels(); - if (overrides != null) { - String s = overrides.get(StatisticsService.TITLE); - if (s != null) { - myTitle.setText(s); - } - s = overrides.get(StatisticsService.DETAILS); - if (s != null) { - myLabel.setText(s); - } - s = overrides.get(StatisticsService.ALLOW_CHECKBOX); - if (s != null) { - myAllowToSendUsagesCheckBox.setText(s); - } - } - } - - myTitle.setText(myTitle.getText().replace("%company%", company)); - myLabel.setText(myLabel.getText().replace("%company%", company)); - myAllowToSendUsagesCheckBox.setText(myAllowToSendUsagesCheckBox.getText().replace("%company%", company)); - } - - public JPanel getJComponent() { - return myMainPanel; - } - - public boolean isAllowed() { - return myAllowToSendUsagesCheckBox.isSelected(); - } - - public void reset() { - myAllowToSendUsagesCheckBox.setSelected(UsageStatisticsPersistenceComponent.getInstance().isAllowed()); - } - - public SendPeriod getPeriod() { - return SendPeriod.DAILY; - } -} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java index 113a24249b0a..451ab4946533 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java @@ -2,6 +2,7 @@ package com.intellij.internal.statistic.persistence; +import com.intellij.ide.gdpr.ConsentOptions; import com.intellij.internal.statistic.beans.ConvertUsagesUtil; import com.intellij.internal.statistic.beans.GroupDescriptor; import com.intellij.internal.statistic.beans.UsageDescriptor; @@ -25,7 +26,6 @@ import java.util.Set; public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersistenceComponent implements NamedComponent, PersistentStateComponent { - @NonNls private boolean isAllowed = false; @NonNls private boolean isShowNotification = true; @NotNull private SendPeriod myPeriod = SendPeriod.DAILY; @@ -73,8 +73,11 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste setSentTime(0); } + // compatibility: if was previously allowed, transfer the setting to the new place final String isAllowedValue = element.getAttributeValue(IS_ALLOWED_ATTR); - setAllowed(!StringUtil.isEmptyOrSpaces(isAllowedValue) && Boolean.parseBoolean(isAllowedValue)); + if (!StringUtil.isEmptyOrSpaces(isAllowedValue) && Boolean.parseBoolean(isAllowedValue)) { + setAllowed(true); + } final String isShowNotificationValue = element.getAttributeValue(SHOW_NOTIFICATION_ATTR); setShowNotification(StringUtil.isEmptyOrSpaces(isShowNotificationValue) || Boolean.parseBoolean(isShowNotificationValue)); @@ -100,9 +103,9 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste element.setAttribute(LAST_TIME_ATTR, String.valueOf(lastTimeSent)); } - if (isAllowed()) { - element.setAttribute(IS_ALLOWED_ATTR, "true"); - } + //if (isAllowed()) { + // element.setAttribute(IS_ALLOWED_ATTR, "true"); + //} if (!isShowNotification()) { element.setAttribute(SHOW_NOTIFICATION_ATTR, "false"); } @@ -131,12 +134,12 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste } public void setAllowed(boolean allowed) { - isAllowed = allowed; + ConsentOptions.getInstance().setSendingUsageStatsAllowed(allowed); } @Override public boolean isAllowed() { - return isAllowed; + return ConsentOptions.getInstance().isSendingUsageStatsAllowed() == ConsentOptions.Permission.YES; } public void setShowNotification(boolean showNotification) { diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/updater/StatisticsNotificationManager.java b/platform/platform-impl/src/com/intellij/internal/statistic/updater/StatisticsNotificationManager.java index 327cbc773727..4293d84393c8 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/updater/StatisticsNotificationManager.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/updater/StatisticsNotificationManager.java @@ -1,19 +1,18 @@ package com.intellij.internal.statistic.updater; -import com.intellij.internal.statistic.configurable.StatisticsConfigurable; +import com.intellij.ide.gdpr.Consent; +import com.intellij.ide.gdpr.ConsentOptions; import com.intellij.internal.statistic.connect.StatisticsService; import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.wm.IdeFrame; -import com.intellij.openapi.wm.ex.WindowManagerEx; +import com.intellij.ui.AppUIUtil; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import javax.swing.event.HyperlinkEvent; +import java.util.Collection; public class StatisticsNotificationManager { @@ -56,9 +55,10 @@ public class StatisticsNotificationManager { notification.expire(); } else if ("settings".equals(description)) { - final ShowSettingsUtil util = ShowSettingsUtil.getInstance(); - IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); - util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true)); + final Collection result = AppUIUtil.confirmConsentOptions(ConsentOptions.getInstance().getConsents().first); + if (result != null) { + ConsentOptions.getInstance().setConsents(result); + } notification.expire(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java index 96aaad00585b..eeade5d0e45a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java @@ -4,7 +4,6 @@ package com.intellij.openapi.actionSystem.impl; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.ui.UISettings; import com.intellij.ide.ui.laf.darcula.DarculaLaf; -import com.intellij.ide.ui.laf.intellij.MacIntelliJIconCache; import com.intellij.internal.statistic.customUsageCollectors.actions.MainMenuCollector; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; @@ -221,9 +220,9 @@ public class ActionMenuItem extends JBCheckBoxMenuItem { else if (!(getUI() instanceof GtkMenuItemUI)) { if (myToggled) { boolean darcula = UIUtil.isUnderDarcula(); - setIcon(getIcon(darcula)); - setSelectedIcon(getSelectedIcon(darcula)); - setDisabledIcon(getDisabledIcon(darcula)); + setIcon(DarculaLaf.getCheckmarkIcon(darcula)); + setSelectedIcon(DarculaLaf.getCheckmarkSelectedIcon(darcula)); + setDisabledIcon(DarculaLaf.getCheckmarkDisabledIcon(darcula)); } else { setIcon(EmptyIcon.ICON_16); @@ -247,21 +246,6 @@ public class ActionMenuItem extends JBCheckBoxMenuItem { } } - private static Icon getIcon(boolean darcula) { - if (darcula) return DarculaLaf.loadIcon("checkmark.png"); - return MacIntelliJIconCache.getIcon("checkmark", false, false, true); - } - - private static Icon getSelectedIcon(boolean darcula) { - if (darcula) return DarculaLaf.loadIcon("checkmarkSelected.png"); - return MacIntelliJIconCache.getIcon("checkmark", true, false, true); - } - - private static Icon getDisabledIcon(boolean darcula) { - if (darcula) return DarculaLaf.loadIcon("checkmarkDisabled.png"); - return MacIntelliJIconCache.getIcon("checkmark", false, false, false); - } - @Override public void setIcon(Icon icon) { if (SystemInfo.isMacSystemMenu && ActionPlaces.MAIN_MENU.equals(myPlace)) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 2a31069dacca..c63b84387e7a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -2274,7 +2274,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } private void processMouseDragged(@NotNull MouseEvent e) { - if (!JBSwingUtilities.isLeftMouseButton(e) && !JBSwingUtilities.isMiddleMouseButton(e)) { + if (!JBSwingUtilities.isLeftMouseButton(e) && !JBSwingUtilities.isMiddleMouseButton(e) + || (Registry.is("editor.disable.drag.with.right.button") && JBSwingUtilities.isRightMouseButton(e))) { return; } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java index 5bf61c31fa2f..1ad463dfb18c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java @@ -8,10 +8,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.*; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.application.impl.ApplicationImpl; @@ -33,7 +30,6 @@ import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.DateFormatUtil; import com.intellij.util.ui.JBUI; -import org.apache.http.client.utils.URIBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,7 +39,6 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; @@ -338,18 +333,6 @@ class UpdateInfoDialog extends AbstractUpdateDialog { } private static String augmentUrl(String url) { - try { - ApplicationInfo info = ApplicationInfo.getInstance(); - String productVersion = info.getMajorVersion() + "." + info.getMinorVersionMainPart(); - return new URIBuilder(url).addParameter("utm_source", "product") - .addParameter("utm_medium", "link") - .addParameter("utm_campaign", info.getBuild().getProductCode()) - .addParameter("utm_content", productVersion) - .build().toString(); - } - catch (URISyntaxException e) { - Logger.getInstance(UpdateInfoDialog.class).warn(url, e); - return url; - } + return IdeUrlTrackingParametersProvider.getInstance().augmentUrl(url); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java index 0a8df4bc90cc..75c0b5e870af 100644 --- a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java @@ -25,10 +25,7 @@ import com.intellij.ui.popup.AbstractPopup; import com.intellij.ui.popup.MovablePopup; import com.intellij.util.Alarm; import com.intellij.util.ObjectUtils; -import com.intellij.util.ui.JBInsets; -import com.intellij.util.ui.MouseEventAdapter; -import com.intellij.util.ui.MouseEventHandler; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,7 +45,20 @@ public abstract class AbstractExpandableItemsHandler 0) { - g.drawString(wrapText(licenseRestrictionsMessages.get(0), font), x + offsetX, y + height - uiScale(offsetY - 16)); + g.drawString(licenseRestrictionsMessages.get(0), x + offsetX, y + height - uiScale(offsetY - 16)); } } return true; @@ -198,29 +196,6 @@ public class Splash extends JDialog implements StartupProgress { return false; } - private static AttributedCharacterIterator wrapText(String text, Font font) { - Font fallbackFont = createFont("Serif"); - AttributedString result = new AttributedString(text); - if (text.isEmpty()) return result.getIterator(); - - Font curFont = font.canDisplay(text.charAt(0)) ? font : fallbackFont; - int start = 0, end = 0; - - for (int i = 1; i < text.length(); i++) { - Font f = font.canDisplay(text.charAt(i)) ? font : fallbackFont; - if (f != curFont) { - result.addAttribute(TextAttribute.FONT, curFont, start, end); - start = i; - end = start; - curFont = f; - } else { - end++; - } - } - result.addAttribute(TextAttribute.FONT, curFont, start, end); - return result.getIterator(); - } - @NotNull protected static Font createFont(String name) { return new Font(name, Font.PLAIN, uiScale(Registry.is("ide.new.about") ? 12 : SystemInfo.isUnix ? 10 : 11)); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index ab55ac2da8c9..a1fcd8b503cb 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -20,6 +20,7 @@ import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.IdeTooltipManager; +import com.intellij.ide.ui.laf.darcula.DarculaLaf; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; @@ -47,16 +48,16 @@ import com.intellij.openapi.wm.impl.IdeFrameImpl; import com.intellij.ui.ColorUtil; import com.intellij.ui.FocusTrackback; import com.intellij.ui.HintHint; +import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.panels.NonOpaquePanel; -import com.intellij.ui.popup.list.IconListPopupRenderer; import com.intellij.ui.popup.list.ListPopupImpl; import com.intellij.ui.popup.mock.MockConfirmation; import com.intellij.ui.popup.tree.TreePopupImpl; -import com.intellij.util.IconUtil; import com.intellij.util.ObjectUtils; import com.intellij.util.PlatformIcons; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.StatusText; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -228,7 +229,6 @@ public class PopupFactoryImpl extends JBPopupFactory { private final Runnable myDisposeCallback; private final Component myComponent; private final String myActionPlace; - private IconHoverListener myIconsHoverListener; public ActionGroupPopup(final String title, @NotNull ActionGroup actionGroup, @@ -334,8 +334,6 @@ public class PopupFactoryImpl extends JBPopupFactory { if (myDisposeCallback != null) { myDisposeCallback.run(); } - getList().removeMouseMotionListener(myIconsHoverListener); - getList().removeListSelectionListener(myIconsHoverListener); ActionMenu.showDescriptionInStatusBar(true, myComponent, null); super.dispose(); } @@ -380,19 +378,6 @@ public class PopupFactoryImpl extends JBPopupFactory { getList().repaint(); } - public void installOnHoverIconsSupport(@NotNull IconListPopupRenderer iconListPopupRenderer) { - //OnHover icons listener should be installed once - assert myIconsHoverListener == null; - myIconsHoverListener = new IconHoverListener(iconListPopupRenderer); - } - - @Override - protected boolean beforeShow() { - getList().addMouseMotionListener(myIconsHoverListener); - getList().addListSelectionListener(myIconsHoverListener); - return super.beforeShow(); - } - @Nullable private static T getActionByClass(@Nullable Object value, @NotNull ActionPopupStep actionPopupStep, @NotNull Class actionClass) { ActionItem item = value instanceof ActionItem ? (ActionItem)value : null; @@ -400,42 +385,6 @@ public class PopupFactoryImpl extends JBPopupFactory { if (!actionPopupStep.isSelectable(item)) return null; return actionClass.isInstance(item.getAction()) ? actionClass.cast(item.getAction()) : null; } - - private class IconHoverListener extends MouseMotionAdapter implements ListSelectionListener { - @NotNull private IconListPopupRenderer myRenderer; - - public IconHoverListener(@NotNull IconListPopupRenderer renderer) { - myRenderer = renderer; - } - - @Override - public void mouseMoved(MouseEvent e) { - Point point = e.getPoint(); - int index = getList().locationToIndex(point); - Rectangle bounds = getList().getCellBounds(index, index); - Object selectedValue = getList().getSelectedValue(); - if (selectedValue instanceof ActionItem) { - ((ActionItem)selectedValue).setIconHovered(myRenderer.isIconAt(point)); - } - if (bounds != null) { - getList().repaint(bounds); - } - } - - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - int selected = getSelectedIndex(); - int unselected = e.getFirstIndex() == selected ? e.getLastIndex() : e.getFirstIndex(); - Object elementAt = getList().getModel().getElementAt(unselected); - if (elementAt instanceof ActionItem) { - ActionItem actionItem = (ActionItem)elementAt; - actionItem.setIconHovered(false); - getList().repaint(); - } - } - } - } } @NotNull @@ -645,8 +594,7 @@ public class PopupFactoryImpl extends JBPopupFactory { int[] selectionRows = tree.getSelectionRows(); if (selectionRows != null) { Arrays.sort(selectionRows); - for (int i = 0; i < selectionRows.length; i++) { - int row = selectionRows[i]; + for (int row : selectionRows) { Rectangle rowBounds = tree.getRowBounds(row); if (visibleRect.contains(rowBounds)) { popupMenuPoint = new Point(rowBounds.x + 2, rowBounds.y + rowBounds.height - 1); @@ -659,8 +607,7 @@ public class PopupFactoryImpl extends JBPopupFactory { int bestRow = -1; Point rowCenter; double distance; - for (int i = 0; i < selectionRows.length; i++) { - int row = selectionRows[i]; + for (int row : selectionRows) { Rectangle rowBounds = tree.getRowBounds(row); rowCenter = new Point(rowBounds.x + rowBounds.width / 2, rowBounds.y + rowBounds.height / 2); distance = visibleCenter.distance(rowCenter); @@ -745,7 +692,8 @@ public class PopupFactoryImpl extends JBPopupFactory { private final AnAction myAction; private String myText; private final boolean myIsEnabled; - @Nullable private ActionStepBuilder.IconWrapper myIcon; + private final Icon myIcon; + private final Icon mySelectedIcon; private final boolean myPrependWithSeparator; private final String mySeparatorText; private final String myDescription; @@ -754,36 +702,28 @@ public class PopupFactoryImpl extends JBPopupFactory { @NotNull String text, @Nullable String description, boolean enabled, - @Nullable ActionStepBuilder.IconWrapper icon, + @Nullable Icon icon, + @Nullable Icon selectedIcon, final boolean prependWithSeparator, String separatorText) { myAction = action; myText = text; myIsEnabled = enabled; myIcon = icon; + mySelectedIcon = selectedIcon; myPrependWithSeparator = prependWithSeparator; mySeparatorText = separatorText; myDescription = description; myAction.getTemplatePresentation().addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName() == PROP_ICON || evt.getPropertyName() == PROP_HOVERED_ICON) { - updateIcons(); - } - else if (evt.getPropertyName() == PROP_TEXT) { + if (evt.getPropertyName() == PROP_TEXT) { myText = myAction.getTemplatePresentation().getText(); } } }); } - private void updateIcons() { - // we can't set icons if it hasn't existed before, because alignment will be destroyed; use IconWrapper with null icon instead of null - if (myIcon == null) return; - Presentation presentation = myAction.getTemplatePresentation(); - myIcon.setIcons(presentation.getIcon(), presentation.getHoveredIcon()); - } - @NotNull public AnAction getAction() { return myAction; @@ -795,8 +735,8 @@ public class PopupFactoryImpl extends JBPopupFactory { } @Nullable - public ActionStepBuilder.IconWrapper getIcon() { - return myIcon; + public Icon getIcon(boolean selected) { + return selected && mySelectedIcon != null ? mySelectedIcon : myIcon; } public boolean isPrependWithSeparator() { @@ -823,12 +763,6 @@ public class PopupFactoryImpl extends JBPopupFactory { public String toString() { return myText; } - - public void setIconHovered(boolean isHovered) { - if (myIcon != null) { - myIcon.setHovered(isHovered); - } - } } private static class ActionPopupStep implements ListPopupStepEx, MnemonicNavigationFilter, SpeedSearchFilter { @@ -895,7 +829,12 @@ public class PopupFactoryImpl extends JBPopupFactory { @Override public Icon getIconFor(final ActionItem aValue) { - return aValue.getIcon(); + return aValue.getIcon(false); + } + + @Override + public Icon getSelectedIconFor(ActionItem value) { + return value.getIcon(true); } @Override @@ -1038,7 +977,7 @@ public class PopupFactoryImpl extends JBPopupFactory { private boolean myPrependWithSeparator; private String mySeparatorText; private final boolean myHonorActionMnemonics; - private IconWrapper myEmptyIcon; + private Icon myEmptyIcon; private int myMaxIconWidth = -1; private int myMaxIconHeight = -1; @NotNull private String myActionPlace; @@ -1069,12 +1008,12 @@ public class PopupFactoryImpl extends JBPopupFactory { public void buildGroup(@NotNull ActionGroup actionGroup) { calcMaxIconSize(actionGroup); - myEmptyIcon = myMaxIconHeight != -1 && myMaxIconWidth != -1 ? createWrapper(null) : null; + myEmptyIcon = myMaxIconHeight != -1 && myMaxIconWidth != -1 ? EmptyIcon.create(myMaxIconWidth, myMaxIconHeight) : null; appendActionsFromGroup(actionGroup); if (myListModel.isEmpty()) { - myListModel.add(new ActionItem(Utils.EMPTY_MENU_FILLER, Utils.NOTHING_HERE, null, false, null, false, null)); + myListModel.add(new ActionItem(Utils.EMPTY_MENU_FILLER, Utils.NOTHING_HERE, null, false, null, null, false, null)); } } @@ -1136,7 +1075,8 @@ public class PopupFactoryImpl extends JBPopupFactory { AnActionEvent event = createActionEvent(action); ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, true); - if ((myShowDisabled || presentation.isEnabled()) && presentation.isVisible()) { + boolean enabled = presentation.isEnabled(); + if ((myShowDisabled || enabled) && presentation.isVisible()) { String text = presentation.getText(); if (myShowNumbers) { if (myCurrentNumber < 9) { @@ -1151,76 +1091,38 @@ public class PopupFactoryImpl extends JBPopupFactory { myCurrentNumber++; } else if (myHonorActionMnemonics) { - text = Presentation.restoreTextWithMnemonic(text, action.getTemplatePresentation().getMnemonic()); + text = restoreTextWithMnemonic(text, action.getTemplatePresentation().getMnemonic()); } - Icon icon = presentation.isEnabled() ? presentation.getIcon() : IconLoader.getDisabledIcon(presentation.getIcon()); - IconWrapper iconWrapper; - if (icon == null && presentation.getHoveredIcon() == null) { + Icon icon = presentation.getIcon(); + Icon selectedIcon = presentation.getSelectedIcon(); + Icon disabledIcon = presentation.getDisabledIcon(); + if (icon == null && selectedIcon == null) { @NonNls final String actionId = ActionManager.getInstance().getId(action); if (actionId != null && actionId.startsWith("QuickList.")) { - iconWrapper = createWrapper(AllIcons.Actions.QuickList); + icon = AllIcons.Actions.QuickList; } - else if (action instanceof Toggleable) { - boolean toggled = Boolean.TRUE.equals(presentation.getClientProperty(Toggleable.SELECTED_PROPERTY)); - iconWrapper = toggled ? createWrapper(PlatformIcons.CHECK_ICON) : myEmptyIcon; - } - else { - iconWrapper = myEmptyIcon; + else if (action instanceof Toggleable && Boolean.TRUE.equals(presentation.getClientProperty(Toggleable.SELECTED_PROPERTY))) { + boolean darcula = UIUtil.isUnderDarcula(); + icon = DarculaLaf.getCheckmarkIcon(darcula); + selectedIcon = DarculaLaf.getCheckmarkSelectedIcon(darcula); + disabledIcon = DarculaLaf.getCheckmarkDisabledIcon(darcula); } } - else { - iconWrapper = new IconWrapper(icon, presentation.getHoveredIcon(), myMaxIconWidth, myMaxIconHeight); + if (!enabled) { + icon = disabledIcon != null ? disabledIcon : IconLoader.getDisabledIcon(icon); + selectedIcon = disabledIcon != null ? disabledIcon : IconLoader.getDisabledIcon(selectedIcon); } + if (icon == null) icon = selectedIcon != null ? selectedIcon : myEmptyIcon; boolean prependSeparator = (!myListModel.isEmpty() || mySeparatorText != null) && myPrependWithSeparator; assert text != null : action + " has no presentation"; myListModel.add( - new ActionItem(action, text, (String)presentation.getClientProperty(JComponent.TOOL_TIP_TEXT_KEY), presentation.isEnabled(), iconWrapper, - prependSeparator, mySeparatorText)); + new ActionItem(action, text, (String)presentation.getClientProperty(JComponent.TOOL_TIP_TEXT_KEY), + enabled, icon, selectedIcon, prependSeparator, mySeparatorText)); myPrependWithSeparator = false; mySeparatorText = null; } } - - /** - * Adjusts icon size to maximum, so that icons with different sizes were aligned correctly. - */ - public static class IconWrapper extends IconUtil.IconSizeWrapper { - - @Nullable private Icon myIcon; - @Nullable private Icon myHoverIcon; - - private boolean isHovered; - - public IconWrapper(@Nullable Icon icon, @Nullable Icon hoverIcon, int width, int height) { - super(null, width, height); - setIcons(icon, hoverIcon); - } - - @Override - public void paintIcon(Component c, Graphics g, int x, int y) { - paintIcon(myHoverIcon != null && isHovered ? myHoverIcon : myIcon, c, g, x, y); - } - - public boolean isHovered() { - return isHovered; - } - - public void setHovered(boolean hovered) { - isHovered = hovered; - } - - public void setIcons(@Nullable Icon icon, @Nullable Icon hoveredIcon) { - myIcon = icon; - myHoverIcon = hoveredIcon; - } - } - - @NotNull - public IconWrapper createWrapper(@Nullable Icon icon) { - return new IconWrapper(icon, null, myMaxIconWidth, myMaxIconHeight); - } - } @NotNull @@ -1267,11 +1169,9 @@ public class PopupFactoryImpl extends JBPopupFactory { final JPanel content = new NonOpaquePanel(new BorderLayout((int)(label.getIconTextGap() * 1.5), (int)(label.getIconTextGap() * 1.5))); final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout()); - JScrollPane scrolledText = new JScrollPane(text); + JScrollPane scrolledText = ScrollPaneFactory.createScrollPane(text, true); scrolledText.setBackground(fillColor); scrolledText.getViewport().setBackground(fillColor); - scrolledText.getViewport().setBorder(null); - scrolledText.setBorder(null); textWrapper.add(scrolledText); content.add(textWrapper, BorderLayout.CENTER); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java index 045c8a3eca21..3304403d9ce4 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java @@ -44,7 +44,7 @@ public class GroupedItemsListRenderer extends GroupedElementsRenderer.List im boolean hasSeparator = myDescriptor.hasSeparatorAboveOf(value); if (index == 0 && StringUtil.isEmptyOrSpaces(caption)) hasSeparator = false; - Icon icon = myDescriptor.getIconFor(value); + Icon icon = isSelected ? myDescriptor.getSelectedIconFor(value) : myDescriptor.getIconFor(value); final JComponent result = configureComponent(myDescriptor.getTextFor(value), myDescriptor.getTooltipFor(value), icon, icon, isSelected, hasSeparator, caption, -1); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java index 298391b936e1..695d609b4146 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java @@ -49,6 +49,11 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { return aPopup.getListStep().getIconFor(value); } + @Override + public Icon getSelectedIconFor(E value) { + return aPopup.getListStep().getSelectedIconFor(value); + } + @Override public boolean hasSeparatorAboveOf(E value) { return aPopup.getListModel().isSeparatorAboveOf(value); diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 499cd99cd8ea..ae273649247b 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -152,6 +152,8 @@ + + - - diff --git a/platform/platform-resources/src/PrivacyPolicy.html b/platform/platform-resources/src/PrivacyPolicy.html index c3fc6051e6fc..f89b18f35323 100644 --- a/platform/platform-resources/src/PrivacyPolicy.html +++ b/platform/platform-resources/src/PrivacyPolicy.html @@ -1,4 +1,4 @@ - + @@ -12,7 +12,7 @@

This Policy may be amended from time to time. The respective latest version of the policy at the point of time of the purchase/registration of a JetBrains Software Product (whichever occurs later) shall apply. The data controller is JetBrains s.r.o., Praha 4, Na hřebenech - II 1718/10, PSČ 147 00, Česká republika + II 1718/10, PSČ 140 00, Česká republika

In this Privacy Policy, we describe the type of data, including personal data (collectively, “data”), @@ -297,9 +297,6 @@ Website works

  • For security purposes
  • -
  • Make sure you connect to the right service on our Website when we make any changes to the way the - Website works -
  • Accepting these cookies is a condition of using the Website, so if you prevent these cookies we can't diff --git a/platform/platform-resources/src/consents.json b/platform/platform-resources/src/consents.json new file mode 100644 index 000000000000..a44ef27787b9 --- /dev/null +++ b/platform/platform-resources/src/consents.json @@ -0,0 +1,9 @@ +[ + { + "consentId": "rsch.send.usage.stat", + "version": "1.0", + "text": "I consent to submit anonymous usage statistics to help JetBrains improve their products. I agree that the following information will be sent to JetBrains and processed in accordance with JetBrains Privacy Policy https://www.jetbrains.com/company/privacy.html\n * Information about which product features are used\n * General statistics (number of files, file types) of the solutions I am working on\n * General information about my hardware configuration (for example, amount of RAM, CPU speed and number of cores)\n * General information about my software configuration (for example, OS version)\nI can revoke my consent at any time in this Data Sharing Options dialog available at Help | Data Sharing Options", + "printableName": "Send anonymous usage statistics to JetBrains", + "accepted": "false" + } +] \ No newline at end of file diff --git a/platform/platform-resources/src/idea/PlatformLangXmlApplicationInfo.xml b/platform/platform-resources/src/idea/PlatformLangXmlApplicationInfo.xml index 27f1a9225651..20ce569b7834 100644 --- a/platform/platform-resources/src/idea/PlatformLangXmlApplicationInfo.xml +++ b/platform/platform-resources/src/idea/PlatformLangXmlApplicationInfo.xml @@ -1,6 +1,6 @@ - + diff --git a/platform/platform-tests/testSrc/com/intellij/module/GroupModulesByQualifiedNamesTest.kt b/platform/platform-tests/testSrc/com/intellij/module/GroupModulesByQualifiedNamesTest.kt index 127d1bbc8231..6b4ed28aed56 100644 --- a/platform/platform-tests/testSrc/com/intellij/module/GroupModulesByQualifiedNamesTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/module/GroupModulesByQualifiedNamesTest.kt @@ -57,6 +57,20 @@ class GroupModulesByQualifiedNamesTest : PlatformTestCase() { assertEmpty(group.childGroups(grouper)) } + fun `test module as a group`() { + val module1 = createModule("a.foo") + val module2 = createModule("a.foo.bar") + + assertEquals("foo", grouper.getShortenedName(module1)) + assertEquals("bar", grouper.getShortenedName(module2)) + + val parentGroup = ModuleGroup(listOf("a")) + assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2) + assertSameElements(parentGroup.modulesInGroup(grouper, true), module1, module2) + + assertEmpty(parentGroup.childGroups(grouper)) + } + private val grouper: ModuleGrouper get() = getQualifiedNameModuleGrouper(myProject) } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java index c97a341efe92..83cd1ffe9799 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java @@ -109,8 +109,8 @@ public class FileTypesTest extends PlatformTestCase { String name = String.valueOf(i % 10 * 10 + i * 100 + i + 1); names[i] = name + name + name + name; } - PlatformTestUtil.startPerformanceTest("isFileIgnored", 150, () -> { - for (int i=0;i<1000;i++) { + PlatformTestUtil.startPerformanceTest("isFileIgnored", 15_000, () -> { + for (int i = 0; i < 100_000; i++) { for (String name : names) { myFileTypeManager.isFileIgnored(name); } @@ -262,9 +262,9 @@ public class FileTypesTest extends PlatformTestCase { public void test7BitIsText() throws IOException { File d = createTempDirectory(); - File f = new File(d, "xx.asfdasdfas"); byte[] bytes = {9, 10, 13, 'x', 'a', 'b'}; assertEquals(CharsetToolkit.GuessedEncoding.SEVEN_BIT, new CharsetToolkit(bytes).guessFromContent(bytes.length)); + File f = new File(d, "xx.asfdasdfas"); FileUtil.writeToFile(f, bytes); VirtualFile vFile = getVirtualFile(f); diff --git a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiEventConsistencyTest.kt b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiEventConsistencyTest.kt index 5e6e5b3e1ed7..e057ba0fab2a 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiEventConsistencyTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiEventConsistencyTest.kt @@ -22,6 +22,21 @@ import one.util.streamex.IntStreamEx */ class PsiEventConsistencyTest : LightPlatformCodeInsightFixtureTestCase() { + fun `test replacing child after changing its subtree`() { + WriteCommandAction.runWriteCommandAction(project) { + // prepare + val root = createEmptyFile().node + root.replaceChild(root.firstChildNode, createComposite(compositeTypes[0], listOf(createLeaf(leafTypes[0], "d")))) + + // actual composite change + ChangeUtil.prepareAndRunChangeAction(ChangeUtil.ChangeAction { + root.firstChildNode.removeChild(root.firstChildNode.firstChildNode) // remove "d" leaf + root.replaceChild(root.firstChildNode, createComposite(compositeTypes[0], listOf())) // replace now empty composite with another one + }, root as FileElement) + assertEquals("", root.text) + } + } + fun testPsiDocSynchronization() { PropertyChecker.forAll(commands).shouldHold { cmd -> runCommand(cmd) @@ -30,7 +45,7 @@ class PsiEventConsistencyTest : LightPlatformCodeInsightFixtureTestCase() { } private fun runCommand(cmd: AstCommand) { - val file = PsiFileFactory.getInstance(project).createFileFromText("a.txt", PlainTextLanguage.INSTANCE, "", true, false) + val file = createEmptyFile() val document = file.viewProvider.document!! WriteCommandAction.runWriteCommandAction(project) { cmd.performChange(file) @@ -39,6 +54,9 @@ class PsiEventConsistencyTest : LightPlatformCodeInsightFixtureTestCase() { } } + private fun createEmptyFile() : PsiFile = + PsiFileFactory.getInstance(project).createFileFromText("a.txt", PlainTextLanguage.INSTANCE, "", true, false) + private interface AstCommand { fun performChange(file: PsiFile) } diff --git a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilMatchingTest.java b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilMatchingTest.java index 5b0517bfe523..ce90d3e7c031 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilMatchingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilMatchingTest.java @@ -27,19 +27,14 @@ import com.intellij.testFramework.UsefulTestCase; import com.intellij.ui.SpeedSearchComparator; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.Matcher; +import junit.framework.TestCase; import org.jetbrains.annotations.NonNls; import org.junit.Assert; import java.util.ArrayList; import java.util.List; -/** - * @author max - * @author peter - * @author Konstantin Bulenkov - */ -public class NameUtilMatchingTest extends UsefulTestCase { - +public class NameUtilMatchingTest extends TestCase { public void testSimpleCases() { assertMatches("N", "NameUtilTest"); assertMatches("NU", "NameUtilTest"); @@ -473,34 +468,34 @@ public class NameUtilMatchingTest extends UsefulTestCase { public void testMatchingFragments() { @NonNls String sample = "NoClassDefFoundException"; // 0 2 7 10 15 21 - assertOrderedEquals(NameUtil.buildMatcher("ncldfou*ion", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), - TextRange.from(0, 1), TextRange.from(2, 2), TextRange.from(7, 1), TextRange.from(10, 3), TextRange.from(21, 3)); + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("ncldfou*ion", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + TextRange.from(0, 1), TextRange.from(2, 2), TextRange.from(7, 1), TextRange.from(10, 3), TextRange.from(21, 3)); sample = "doGet(HttpServletRequest, HttpServletResponse):void"; // 0 22 - assertOrderedEquals(NameUtil.buildMatcher("d*st", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("d*st", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 1), TextRange.from(22, 2)); - assertOrderedEquals(NameUtil.buildMatcher("doge*st", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("doge*st", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 4), TextRange.from(22, 2)); sample = "_test"; - assertOrderedEquals(NameUtil.buildMatcher("_", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("_", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 1)); - assertOrderedEquals(NameUtil.buildMatcher("_t", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("_t", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 2)); } public void testMatchingFragmentsSorted() { @NonNls String sample = "SWUPGRADEHDLRFSPR7TEST"; // 0 9 12 - assertOrderedEquals(NameUtil.buildMatcher("SWU*H*R", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("SWU*H*R", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 3), TextRange.from(9, 1), TextRange.from(12, 1)); } public void testPreferCapsMatching() { String sample = "getCurrentUser"; // 0 4 10 - assertOrderedEquals(NameUtil.buildMatcher("getCU", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), + UsefulTestCase.assertOrderedEquals(NameUtil.buildMatcher("getCU", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample), TextRange.from(0, 4), TextRange.from(10, 1)); } @@ -685,7 +680,7 @@ public class NameUtilMatchingTest extends UsefulTestCase { } public void testOnlyUnderscoresPerformance() { - PlatformTestUtil.startPerformanceTest(getTestName(false), 120, () -> { + PlatformTestUtil.startPerformanceTest(getName(), 120, () -> { String small = StringUtil.repeat("_", 50000); String big = StringUtil.repeat("_", small.length() + 1); assertMatches("*" + small, big); @@ -694,7 +689,7 @@ public class NameUtilMatchingTest extends UsefulTestCase { } public void testRepeatedLetterPerformance() { - PlatformTestUtil.startPerformanceTest(getTestName(false), 30, () -> { + PlatformTestUtil.startPerformanceTest(getName(), 30, () -> { String big = StringUtil.repeat("Aaaaaa", 50000); assertMatches("aaaaaaaaaaaaaaaaaaaaaaaa", big); assertDoesntMatch("aaaaaaaaaaaaaaaaaaaaaaaab", big); @@ -704,12 +699,12 @@ public class NameUtilMatchingTest extends UsefulTestCase { public void testMatchingAllOccurrences() { String text = "some text"; MinusculeMatcher matcher = new AllOccurrencesMatcher("*e", NameUtil.MatchingCaseSensitivity.NONE, ""); - assertOrderedEquals(matcher.matchingFragments(text), + UsefulTestCase.assertOrderedEquals(matcher.matchingFragments(text), new TextRange(3, 4), new TextRange(6, 7)); } public void testCamelHumpWinsOverConsecutiveCaseMismatch() { - assertSize(3, NameUtil.buildMatcher("GEN", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments("GetExtendedName")); + UsefulTestCase.assertSize(3, NameUtil.buildMatcher("GEN", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments("GetExtendedName")); assertPreference("GEN", "GetName", "GetExtendedName"); assertPreference("*GEN", "GetName", "GetExtendedName"); @@ -720,5 +715,4 @@ public class NameUtilMatchingTest extends UsefulTestCase { assertMatches("pl", "printlnFoo"); assertDoesntMatch("pl", "printlnx"); } - } diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java index 14cb9f85209e..5f10b4de9fbb 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -207,7 +195,7 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { assertEmpty(excluded); - String text = new ExporterToTextFile(usageView).getReportText(); + String text = new ExporterToTextFile(usageView, UsageViewSettings.getInstance()).getReportText(); assertEquals("Found usages (1 usage found)\n" + " Unclassified usage (1 usage found)\n" + " light_idea_test_case (1 usage found)\n" + diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java index 2416f18b16e1..9d1927aaa7fd 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTreeTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -61,9 +49,9 @@ public class UsageViewTreeTest extends UsefulTestCase { XmlSerializerUtil.copyBean(settings.getState(), oldSettingsState); disposeOnTearDown(() -> settings.loadState(oldSettingsState)); - settings.GROUP_BY_FILE_STRUCTURE = false; - settings.GROUP_BY_USAGE_TYPE = false; - settings.GROUP_BY_PACKAGE = false; + settings.setGroupByFileStructure(false); + settings.setGroupByUsageType(false); + settings.setGroupByPackage(false); } public void testSimpleModule() throws Exception { @@ -81,7 +69,7 @@ public class UsageViewTreeTest extends UsefulTestCase { addModule("xxx.main"); PsiFile file = myFixture.addFileToProject("xxx.main/A.txt", "hello"); Usage[] usages = {new UsageInfo2UsageAdapter(new UsageInfo(file))}; - UsageViewSettings.getInstance().FLATTEN_MODULES = false; + UsageViewSettings.getInstance().setFlattenModules(false); ModuleGroupTestsKt.runWithQualifiedModuleNamesEnabled(() -> { assertUsageViewStructureEquals(usages, "Usage (1 usage)\n" + " Non-code usages (1 usage)\n" + diff --git a/platform/platform-tests/testSrc/com/intellij/util/AlarmTest.java b/platform/platform-tests/testSrc/com/intellij/util/AlarmTest.java index bde2e349210f..f53953413f7b 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/AlarmTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/AlarmTest.java @@ -34,7 +34,7 @@ package com.intellij.util; import java.util.stream.Collectors; import java.util.stream.Stream; -public class AlarmTest extends PlatformTestCase { + public class AlarmTest extends PlatformTestCase { public void testTwoAddsWithZeroDelayMustExecuteSequentially() throws Exception { Alarm alarm = new Alarm(getTestRootDisposable()); assertRequestsExecuteSequentially(alarm); @@ -85,37 +85,41 @@ public class AlarmTest extends PlatformTestCase { public void testOneAlarmDoesNotStartTooManyThreads() { Alarm alarm = new Alarm(getTestRootDisposable()); - Map before = Thread.getAllStackTraces(); AtomicInteger executed = new AtomicInteger(); int N = 100000; - for (int i = 0; i < N; i++) { - alarm.addRequest(executed::incrementAndGet, 10); - } - while (executed.get() != N) { - UIUtil.dispatchAllInvocationEvents(); - } + checkNotTooManyThreadsCreatedIn(()->{ + for (int i = 0; i < N; i++) { + alarm.addRequest(executed::incrementAndGet, 10); + } + while (executed.get() != N) { + UIUtil.dispatchAllInvocationEvents(); + } + }); + } + + private static void checkNotTooManyThreadsCreatedIn(Runnable runnable) { + Map before = Thread.getAllStackTraces(); + runnable.run(); Map after = Thread.getAllStackTraces(); Map> diff = new HashMap<>(); after.forEach((key, value) -> diff.put(key, Arrays.asList(value))); - before.keySet().forEach(diff::remove); + diff.keySet().removeAll(before.keySet()); if (!(after.size() - before.size() < 10)) { - fail("before: "+before.size()+"; after: "+after.size()+"Diff:\n"+diff); + fail("before: "+before.size()+"; after: "+after.size()+"; Diff:\n"+diff); } } public void testManyAlarmsDoNotStartTooManyThreads() { - Map before = Thread.getAllStackTraces(); - AtomicInteger executed = new AtomicInteger(); - int N = 100000; - List alarms = Stream.generate(() -> new Alarm(getTestRootDisposable())).limit(N).collect(Collectors.toList()); - alarms.forEach(alarm -> alarm.addRequest(executed::incrementAndGet, 10)); + checkNotTooManyThreadsCreatedIn(()->{ + AtomicInteger executed = new AtomicInteger(); + int N = 100000; + List alarms = Stream.generate(() -> new Alarm(getTestRootDisposable())).limit(N).collect(Collectors.toList()); + alarms.forEach(alarm -> alarm.addRequest(executed::incrementAndGet, 10)); - while (executed.get() != N) { - UIUtil.dispatchAllInvocationEvents(); - } - Map after = Thread.getAllStackTraces(); - LOG.debug("before: "+before.size()+"; after: "+after.size()); - assertTrue(after.size() - before.size() < 10); + while (executed.get() != N) { + UIUtil.dispatchAllInvocationEvents(); + } + }); } public void testOrderIsPreservedAfterModalitySwitching() { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 4c103be48295..37252291a552 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -54,6 +54,7 @@ import com.intellij.ide.util.gotoByName.ChooseByNamePopup; import com.intellij.ide.util.gotoByName.GotoClassModel2; import com.intellij.injected.editor.DocumentWindow; import com.intellij.injected.editor.EditorWindow; +import com.intellij.injected.editor.VirtualFileWindow; import com.intellij.internal.DumpLookupElementWeights; import com.intellij.lang.Language; import com.intellij.lang.LanguageStructureViewBuilder; @@ -1139,7 +1140,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override protected void run(@NotNull Result result) { PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - EditorUtil.fillVirtualSpaceUntilCaret(myEditor); + EditorUtil.fillVirtualSpaceUntilCaret(getHostEditor()); checkResult("TEXT", stripTrailingSpaces, SelectionAndCaretMarkupLoader.fromText(text), getHostFile().getText()); } }.execute(); @@ -1462,8 +1463,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } private PsiFile getHostFile() { - PsiElement element = getFile(); - return InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element); + VirtualFile hostVFile = myFile instanceof VirtualFileWindow ? ((VirtualFileWindow)myFile).getDelegate() : myFile; + return ReadAction.compute(() -> PsiManager.getInstance(getProject()).findFile(hostVFile)); } private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingData data) { diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt index 5677d2724d24..2c7f77a9da9b 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt @@ -149,7 +149,7 @@ open class GuiTestCase { */ fun chooseFileInFileChooser(path: String, timeout: Long = defaultTimeout) { val macNativeFileChooser = SystemInfo.isMac() && (System.getProperty("ide.mac.file.chooser.native", "true").toLowerCase() == "true") - if (macNativeFileChooser) { + if (!macNativeFileChooser) { MacFileChooserDialogFixture(robot()).selectByPath(path) } else { @@ -170,6 +170,7 @@ open class GuiTestCase { } val dialogFixture = JDialogFixture(robot(), fileChooserDialog) with(dialogFixture) { + asyncProcessIcon().waitUntilStop(20) textfield("") invokeAction("\$SelectAll") typeText(path) diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/PluginTestCase.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/PluginTestCase.kt index 107f17ee59c9..5354b530b5f5 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/PluginTestCase.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/PluginTestCase.kt @@ -25,6 +25,7 @@ import com.intellij.testGuiFramework.launcher.system.SystemInfo import com.intellij.testGuiFramework.remote.transport.MessageType import com.intellij.testGuiFramework.remote.transport.TransportMessage import org.fest.swing.exception.WaitTimedOutError +import java.io.File import javax.swing.JDialog open class PluginTestCase : GuiTestCase() { @@ -34,6 +35,23 @@ open class PluginTestCase : GuiTestCase() { private val WIN_PLUGIN_HOME = "/Users/jetbrains/Documents/plugins/" private val LINUX_PLUGIN_HOME = "/Users/jetbrains/Documents/plugins/" + private fun getPluginHomePath(): String { + return when { + SystemInfo.isMac() -> MAC_PLUGIN_HOME + SystemInfo.isWin() -> WIN_PLUGIN_HOME + else -> { + LINUX_PLUGIN_HOME + } + } + } + + fun findPlugin(pluginName: String): String { + val f = File(getPluginHomePath()) + return f.listFiles { _, name -> + name.startsWith(pluginName) + }[0].toString() + } + fun installPluginAndRestart(installPluginsFunction: () -> Unit) { val PLUGINS_INSTALLED = "PLUGINS_INSTALLED" if (guiTestRule.getTestName() == GuiTestOptions.getResumeTestName() && @@ -69,14 +87,7 @@ open class PluginTestCase : GuiTestCase() { } } - fun installPluginFromDisk(pluginDir: String, pluginName: String) { - var pluginPath: String = when { - SystemInfo.isMac() -> MAC_PLUGIN_HOME - SystemInfo.isWin() -> WIN_PLUGIN_HOME - else -> { - LINUX_PLUGIN_HOME - } - } + pluginDir + fun installPluginFromDisk(pluginPath: String, pluginName: String) { welcomeFrame { actionLink("Configure").click() popupClick("Plugins") diff --git a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java deleted file mode 100644 index d3e2ecbc4d3b..000000000000 --- a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.usages; - -import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; -import com.intellij.util.xmlb.XmlSerializerUtil; -import org.jetbrains.annotations.Nullable; - -@State( - name = "ShowUsagesSettings", - storages = { - @Storage("usageView.xml") - } -) -public class ShowUsagesSettings implements PersistentStateComponent { - private final UsageViewSettings myState = new UsageViewSettings(); - - @Nullable - @Override - public UsageViewSettings getState() { - return myState; - } - - @Override - public void loadState(UsageViewSettings state) { - XmlSerializerUtil.copyBean(state, myState); - } - - public static ShowUsagesSettings getInstance() { - return ServiceManager.getService(ShowUsagesSettings.class); - } - - public ShowUsagesSettings() { - myState.GROUP_BY_FILE_STRUCTURE = false; - myState.GROUP_BY_MODULE = false; - myState.GROUP_BY_PACKAGE = false; - myState.GROUP_BY_USAGE_TYPE = false; - myState.GROUP_BY_SCOPE = false; - } -} diff --git a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt new file mode 100644 index 000000000000..7f6996f33383 --- /dev/null +++ b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.usages + +import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.components.State +import com.intellij.openapi.components.Storage + +@State(name = "ShowUsagesSettings", storages = arrayOf(Storage("usageView.xml"))) +class ShowUsagesSettings : PersistentStateComponent { + companion object { + @JvmStatic + val instance: ShowUsagesSettings + get() = ServiceManager.getService(ShowUsagesSettings::class.java) + } + + private var state = ShowUsageViewSettings() + + override fun getState() = state + + override fun loadState(state: ShowUsageViewSettings) { + this.state = state + } + + fun applyUsageViewSettings(otherState: UsageViewSettings) { + state.copyFrom(otherState) + } +} + +class ShowUsageViewSettings : UsageViewSettings(false, false, false, false, false) diff --git a/platform/usageView/src/com/intellij/usages/UsageView.java b/platform/usageView/src/com/intellij/usages/UsageView.java index b34a397609d5..0a1fefe24afb 100644 --- a/platform/usageView/src/com/intellij/usages/UsageView.java +++ b/platform/usageView/src/com/intellij/usages/UsageView.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages; @@ -61,7 +49,7 @@ public interface UsageView extends Disposable { boolean isSearchInProgress(); /** - * @deprecated please specify mnemonic by prefixing the mnenonic character with an ampersand (&& for Mac-specific ampersands) + * @deprecated please specify mnemonic by prefixing the mnemonic character with an ampersand (&& for Mac-specific ampersands) */ void addButtonToLowerPane(@NotNull Runnable runnable, @NotNull String text, char mnemonic); void addButtonToLowerPane(@NotNull Runnable runnable, @NotNull String text); diff --git a/platform/usageView/src/com/intellij/usages/UsageViewSettings.java b/platform/usageView/src/com/intellij/usages/UsageViewSettings.java deleted file mode 100644 index 86485f594240..000000000000 --- a/platform/usageView/src/com/intellij/usages/UsageViewSettings.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2000-2016 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.usages; - -import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; -import com.intellij.util.xmlb.XmlSerializerUtil; -import com.intellij.util.xmlb.annotations.Transient; -import org.jetbrains.annotations.NonNls; - -import java.io.File; - -@State( - name = "UsageViewSettings", - storages = { - @Storage("usageView.xml"), - @Storage(value = "other.xml", deprecated = true) - } -) -public class UsageViewSettings implements PersistentStateComponent { - @NonNls public String EXPORT_FILE_NAME = "report.txt"; - public boolean IS_EXPANDED; - public boolean IS_SHOW_PACKAGES = true; - public boolean IS_SHOW_METHODS; - public boolean IS_AUTOSCROLL_TO_SOURCE; - public boolean IS_FILTER_DUPLICATED_LINE = true; - public boolean IS_SHOW_MODULES; - public boolean IS_PREVIEW_USAGES; - public boolean IS_SORT_MEMBERS_ALPHABETICALLY = true; - public float PREVIEW_USAGES_SPLITTER_PROPORTIONS = 0.5f; - - public boolean GROUP_BY_USAGE_TYPE = true; - public boolean GROUP_BY_MODULE = true; - public boolean FLATTEN_MODULES = true; - public boolean GROUP_BY_PACKAGE = true; - public boolean GROUP_BY_FILE_STRUCTURE = true; - public boolean GROUP_BY_SCOPE; - - public static UsageViewSettings getInstance() { - return ServiceManager.getService(UsageViewSettings.class); - } - - public boolean isExpanded() { - return IS_EXPANDED; - } - - public void setExpanded(boolean val) { - IS_EXPANDED = val; - } - - public boolean isShowPackages() { - return IS_SHOW_PACKAGES; - } - - public void setShowPackages(boolean val) { - IS_SHOW_PACKAGES = val; - } - - public boolean isShowMethods() { - return IS_SHOW_METHODS; - } - - public boolean isShowModules() { - return IS_SHOW_MODULES; - } - - public void setShowMethods(boolean val) { - IS_SHOW_METHODS = val; - } - - public void setShowModules(boolean val) { - IS_SHOW_MODULES = val; - } - - public boolean isFilterDuplicatedLine() { - return IS_FILTER_DUPLICATED_LINE; - } - - public void setFilterDuplicatedLine(boolean val) { - IS_FILTER_DUPLICATED_LINE = val; - } - - @Transient - public String getExportFileName() { - return EXPORT_FILE_NAME != null ? EXPORT_FILE_NAME.replace('/', File.separatorChar) : null; - } - - public void setExportFileName(String s) { - if (s != null){ - s = s.replace(File.separatorChar, '/'); - } - EXPORT_FILE_NAME = s; - } - - @Override - public UsageViewSettings getState() { - return this; - } - - @Override - public void loadState(final UsageViewSettings object) { - XmlSerializerUtil.copyBean(object, this); - } -} diff --git a/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt b/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt new file mode 100644 index 000000000000..db5e6f5a7c7a --- /dev/null +++ b/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt @@ -0,0 +1,119 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.usages + +import com.intellij.openapi.components.* +import com.intellij.util.PathUtil +import com.intellij.util.xmlb.annotations.OptionTag +import com.intellij.util.xmlb.annotations.Transient + +/** + * Passed params will be used as default values, so, do not use constructor if instance will be used as a state (unless you want to change defaults) + */ +@State(name = "UsageViewSettings", storages = arrayOf(Storage("usageView.xml"), Storage(value = "other.xml", deprecated = true))) +open class UsageViewSettings( + isGroupByFileStructure: Boolean = true, + isGroupByModule: Boolean = true, + isGroupByPackage: Boolean = true, + isGroupByUsageType: Boolean = true, + isGroupByScope: Boolean = false +) : BaseState(), PersistentStateComponent { + companion object { + @JvmStatic + val instance: UsageViewSettings + get() = ServiceManager.getService(UsageViewSettings::class.java) + } + + @Suppress("unused") + @JvmField + @Transient + @Deprecated(message = "Use isGroupByModule") + var GROUP_BY_MODULE = isGroupByModule + + @Suppress("unused") + @JvmField + @Transient + @Deprecated(message = "Use isGroupByUsageType") + var GROUP_BY_USAGE_TYPE = isGroupByUsageType + + @Suppress("unused") + @JvmField + @Transient + @Deprecated(message = "Use isGroupByFileStructure") + var GROUP_BY_FILE_STRUCTURE = isGroupByFileStructure + + @Suppress("unused") + @JvmField + @Transient + @Deprecated(message = "Use isGroupByScope") + var GROUP_BY_SCOPE = isGroupByScope + + @Suppress("unused") + @JvmField + @Transient + @Deprecated(message = "Use isGroupByPackage") + var GROUP_BY_PACKAGE = isGroupByPackage + + @Suppress("MemberVisibilityCanPrivate") + @get:OptionTag("EXPORT_FILE_NAME") + internal var EXPORT_FILE_NAME by property("report.txt") + + @get:OptionTag("IS_EXPANDED") + var isExpanded by property(false) + + @get:OptionTag("IS_AUTOSCROLL_TO_SOURCE") + var isAutoScrollToSource by property(false) + + @get:OptionTag("IS_FILTER_DUPLICATED_LINE") + var isFilterDuplicatedLine by property(true) + + @get:OptionTag("IS_SHOW_METHODS") + var isShowModules by property(false) + + @get:OptionTag("IS_PREVIEW_USAGES") + var isPreviewUsages by property(false) + + @get:OptionTag("IS_SORT_MEMBERS_ALPHABETICALLY") + var isSortAlphabetically by property(false) + + @get:OptionTag("PREVIEW_USAGES_SPLITTER_PROPORTIONS") + var previewUsagesSplitterProportion by property(0.5f) + + @get:OptionTag("GROUP_BY_USAGE_TYPE") + var isGroupByUsageType by property(isGroupByUsageType) + + @get:OptionTag("GROUP_BY_MODULE") + var isGroupByModule by property(isGroupByModule) + + @get:OptionTag("FLATTEN_MODULES") + var isFlattenModules by property(true) + + @get:OptionTag("GROUP_BY_PACKAGE") + var isGroupByPackage by property(isGroupByPackage) + + @get:OptionTag("GROUP_BY_FILE_STRUCTURE") + var isGroupByFileStructure by property(isGroupByFileStructure) + + @get:OptionTag("GROUP_BY_SCOPE") + var isGroupByScope: Boolean by property(isGroupByScope) + + var exportFileName: String? + @Transient + get() = PathUtil.toSystemDependentName(EXPORT_FILE_NAME) + set(value) { + EXPORT_FILE_NAME = PathUtil.toSystemIndependentName(value) + } + + override fun getState() = this + + @Suppress("DEPRECATION") + override fun loadState(state: UsageViewSettings) { + copyFrom(state) + GROUP_BY_MODULE = isGroupByModule + GROUP_BY_USAGE_TYPE = isGroupByUsageType + GROUP_BY_FILE_STRUCTURE = isGroupByFileStructure + GROUP_BY_SCOPE = isGroupByScope + GROUP_BY_PACKAGE = isGroupByPackage + } +} diff --git a/platform/usageView/src/com/intellij/usages/impl/ExporterToTextFile.java b/platform/usageView/src/com/intellij/usages/impl/ExporterToTextFile.java index 84c3f171114c..165f68af86ee 100644 --- a/platform/usageView/src/com/intellij/usages/impl/ExporterToTextFile.java +++ b/platform/usageView/src/com/intellij/usages/impl/ExporterToTextFile.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -22,33 +10,20 @@ import com.intellij.usages.UsageViewSettings; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import java.util.Enumeration; -import java.util.TooManyListenersException; /** * @author max */ public class ExporterToTextFile implements com.intellij.ide.ExporterToTextFile { private final UsageViewImpl myUsageView; + @NotNull + private final UsageViewSettings myUsageViewSettings; - public ExporterToTextFile(@NotNull UsageViewImpl usageView) { + public ExporterToTextFile(@NotNull UsageViewImpl usageView, @NotNull UsageViewSettings usageViewSettings) { myUsageView = usageView; - } - - @Override - public JComponent getSettingsEditor() { - return null; - } - - @Override - public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException { - } - - @Override - public void removeSettingsChangedListener(ChangeListener listener) { + myUsageViewSettings = usageViewSettings; } @NotNull @@ -114,12 +89,12 @@ public class ExporterToTextFile implements com.intellij.ide.ExporterToTextFile { @NotNull @Override public String getDefaultFilePath() { - return UsageViewSettings.getInstance().EXPORT_FILE_NAME; + return myUsageViewSettings.getExportFileName(); } @Override - public void exportedTo(String filePath) { - UsageViewSettings.getInstance().EXPORT_FILE_NAME = filePath; + public void exportedTo(@NotNull String filePath) { + myUsageViewSettings.setExportFileName(filePath); } @Override diff --git a/platform/usageView/src/com/intellij/usages/impl/FileStructureGroupRuleProvider.java b/platform/usageView/src/com/intellij/usages/impl/FileStructureGroupRuleProvider.java index a39705c69320..fb52130e3f41 100644 --- a/platform/usageView/src/com/intellij/usages/impl/FileStructureGroupRuleProvider.java +++ b/platform/usageView/src/com/intellij/usages/impl/FileStructureGroupRuleProvider.java @@ -1,29 +1,22 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ - package com.intellij.usages.impl; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; +import com.intellij.usages.UsageViewSettings; import com.intellij.usages.rules.UsageGroupingRule; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface FileStructureGroupRuleProvider { ExtensionPointName EP_NAME = new ExtensionPointName<>("com.intellij.fileStructureGroupRuleProvider"); @Nullable - UsageGroupingRule getUsageGroupingRule(final Project project); + UsageGroupingRule getUsageGroupingRule(@NotNull Project project); + + default UsageGroupingRule getUsageGroupingRule(@NotNull Project project, @NotNull UsageViewSettings usageViewSettings) { + return getUsageGroupingRule(project); + } } diff --git a/platform/usageView/src/com/intellij/usages/impl/PreviewUsageAction.java b/platform/usageView/src/com/intellij/usages/impl/PreviewUsageAction.java index 107e1572578e..55a9681ed305 100644 --- a/platform/usageView/src/com/intellij/usages/impl/PreviewUsageAction.java +++ b/platform/usageView/src/com/intellij/usages/impl/PreviewUsageAction.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2014 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -19,7 +7,6 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.util.text.StringUtil; import com.intellij.usageView.UsageViewBundle; import com.intellij.usages.UsageView; -import com.intellij.usages.UsageViewSettings; import org.jetbrains.annotations.NotNull; /** @@ -32,11 +19,11 @@ class PreviewUsageAction extends RuleAction { @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().IS_PREVIEW_USAGES; + return myView.getUsageViewSettings().isPreviewUsages(); } @Override protected void setOptionValue(final boolean value) { - UsageViewSettings.getInstance().IS_PREVIEW_USAGES = value; + myView.getUsageViewSettings().setPreviewUsages(value); } } diff --git a/platform/usageView/src/com/intellij/usages/impl/RuleAction.java b/platform/usageView/src/com/intellij/usages/impl/RuleAction.java index ce7ef7f933a7..fff032a7cd4c 100644 --- a/platform/usageView/src/com/intellij/usages/impl/RuleAction.java +++ b/platform/usageView/src/com/intellij/usages/impl/RuleAction.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -29,7 +17,7 @@ import javax.swing.*; * @author Eugene Zhuravlev */ abstract class RuleAction extends ToggleAction implements DumbAware { - private final UsageViewImpl myView; + protected final UsageViewImpl myView; private boolean myState; RuleAction(@NotNull UsageView view, @NotNull String text, @NotNull Icon icon) { diff --git a/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java b/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java index 55907817eed9..9cb8854e9c00 100644 --- a/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java +++ b/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java @@ -1,40 +1,27 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; import com.intellij.icons.AllIcons; import com.intellij.usageView.UsageViewBundle; -import com.intellij.usages.UsageViewSettings; +import org.jetbrains.annotations.NotNull; /** * @author cdr */ class SortMembersAlphabeticallyAction extends RuleAction { - - SortMembersAlphabeticallyAction(UsageViewImpl usageView) { + SortMembersAlphabeticallyAction(@NotNull UsageViewImpl usageView) { super(usageView, UsageViewBundle.message("sort.alphabetically.action.text"), AllIcons.ObjectBrowser.Sorted); } @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY; + return myView.getUsageViewSettings().isSortAlphabetically(); } @Override protected void setOptionValue(final boolean value) { - UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY = value; + myView.getUsageViewSettings().setSortAlphabetically(value); } } diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java index 391ff369cefa..d3e6bc3beca3 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -40,7 +28,6 @@ import java.util.List; * @author max */ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider { - protected boolean supportsNonCodeRule() { return true; } @@ -53,29 +40,35 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider return true; } + @NotNull + @Override + public UsageGroupingRule[] getActiveRules(@NotNull Project project) { + return getActiveRules(project, UsageViewSettings.getInstance()); + } + @Override @NotNull - public UsageGroupingRule[] getActiveRules(Project project) { + public UsageGroupingRule[] getActiveRules(@NotNull Project project, @NotNull UsageViewSettings usageViewSettings) { List rules = new ArrayList<>(); if (supportsNonCodeRule()) { rules.add(new NonCodeUsageGroupingRule(project)); } - if (supportsScopesRule() && UsageViewSettings.getInstance().GROUP_BY_SCOPE) { + if (supportsScopesRule() && usageViewSettings.isGroupByScope()) { rules.add(new UsageScopeGroupingRule()); } - if (UsageViewSettings.getInstance().GROUP_BY_USAGE_TYPE) { + if (usageViewSettings.isGroupByUsageType()) { rules.add(new UsageTypeGroupingRule()); } - if (supportsModuleRule() && UsageViewSettings.getInstance().GROUP_BY_MODULE) { - rules.add(new ModuleGroupingRule(project, UsageViewSettings.getInstance().FLATTEN_MODULES)); + if (supportsModuleRule() && usageViewSettings.isGroupByModule()) { + rules.add(new ModuleGroupingRule(project, usageViewSettings.isFlattenModules())); } - if (UsageViewSettings.getInstance().GROUP_BY_PACKAGE) { + if (usageViewSettings.isGroupByPackage()) { rules.add(DirectoryGroupingRule.getInstance(project)); } - if (UsageViewSettings.getInstance().GROUP_BY_FILE_STRUCTURE) { + if (usageViewSettings.isGroupByFileStructure()) { FileStructureGroupRuleProvider[] providers = Extensions.getExtensions(FileStructureGroupRuleProvider.EP_NAME); for (FileStructureGroupRuleProvider ruleProvider : providers) { - ContainerUtil.addIfNotNull(rules, ruleProvider.getUsageGroupingRule(project)); + ContainerUtil.addIfNotNull(rules, ruleProvider.getUsageGroupingRule(project, usageViewSettings)); } } else { @@ -143,11 +136,11 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider } @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().GROUP_BY_USAGE_TYPE; + return myView.getUsageViewSettings().isGroupByUsageType(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().GROUP_BY_USAGE_TYPE = value; + myView.getUsageViewSettings().setGroupByUsageType(value); } } @@ -157,11 +150,11 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider } @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().GROUP_BY_SCOPE; + return myView.getUsageViewSettings().isGroupByScope(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().GROUP_BY_SCOPE = value; + myView.getUsageViewSettings().setGroupByScope(value); } } @@ -172,12 +165,12 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().GROUP_BY_MODULE; + return myView.getUsageViewSettings().isGroupByModule(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().GROUP_BY_MODULE = value; + myView.getUsageViewSettings().setGroupByModule(value); } } @@ -188,18 +181,18 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().FLATTEN_MODULES; + return myView.getUsageViewSettings().isFlattenModules(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().FLATTEN_MODULES = value; + myView.getUsageViewSettings().setFlattenModules(value); } @Override public void update(@NotNull AnActionEvent e) { super.update(e); - e.getPresentation().setEnabled(UsageViewSettings.getInstance().GROUP_BY_MODULE); + e.getPresentation().setEnabled(myView.getUsageViewSettings().isGroupByModule()); } } @@ -209,11 +202,11 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider } @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().GROUP_BY_PACKAGE; + return myView.getUsageViewSettings().isGroupByPackage(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().GROUP_BY_PACKAGE = value; + myView.getUsageViewSettings().setGroupByPackage(value); } } @@ -223,11 +216,11 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider } @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().GROUP_BY_FILE_STRUCTURE; + return myView.getUsageViewSettings().isGroupByFileStructure(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().GROUP_BY_FILE_STRUCTURE = value; + myView.getUsageViewSettings().setGroupByFileStructure(value); } } } diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index bb2b6370aafc..52aa1eeda481 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -103,7 +103,7 @@ public class UsageViewImpl implements UsageView { private final Project myProject; private volatile boolean mySearchInProgress = true; - private final ExporterToTextFile myTextFileExporter = new ExporterToTextFile(this); + private final ExporterToTextFile myTextFileExporter = new ExporterToTextFile(this, getUsageViewSettings()); private final Alarm myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); private final ExclusionHandler myExclusionHandler; @@ -181,7 +181,7 @@ public class UsageViewImpl implements UsageView { UsageModelTracker myModelTracker = new UsageModelTracker(project); Disposer.register(this, myModelTracker); - myBuilder = new UsageNodeTreeBuilder(myTargets, getActiveGroupingRules(project), getActiveFilteringRules(project), myRoot, myProject); + myBuilder = new UsageNodeTreeBuilder(myTargets, getActiveGroupingRules(project, getUsageViewSettings()), getActiveFilteringRules(project), myRoot, myProject); final MessageBusConnection messageBusConnection = myProject.getMessageBus().connect(this); messageBusConnection.subscribe(UsageFilteringRuleProvider.RULES_CHANGED, this::rulesChanged); @@ -347,6 +347,10 @@ public class UsageViewImpl implements UsageView { }; } + public UsageViewSettings getUsageViewSettings() { + return UsageViewSettings.getInstance(); + } + // nodes just changed: parent node -> changed child // this collection is needed for firing javax.swing.tree.DefaultTreeModel.nodesChanged() events in batch // has to be linked because events for child nodes should be fired after events for parent nodes @@ -504,8 +508,8 @@ public class UsageViewImpl implements UsageView { myCentralPanel.add(myPreviewSplitter, BorderLayout.CENTER); - if (UsageViewSettings.getInstance().IS_PREVIEW_USAGES) { - myPreviewSplitter.setProportion(UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS); + if (getUsageViewSettings().isPreviewUsages()) { + myPreviewSplitter.setProportion(getUsageViewSettings().getPreviewUsagesSplitterProportion()); treePane.putClientProperty(UIUtil.KEEP_BORDER_SIDES, SideBorder.RIGHT); final JBTabbedPane tabbedPane = new JBTabbedPane(SwingConstants.BOTTOM){ @NotNull @@ -580,11 +584,11 @@ public class UsageViewImpl implements UsageView { } @NotNull - private static UsageGroupingRule[] getActiveGroupingRules(@NotNull final Project project) { + private static UsageGroupingRule[] getActiveGroupingRules(@NotNull final Project project, @NotNull UsageViewSettings usageViewSettings) { final UsageGroupingRuleProvider[] providers = Extensions.getExtensions(UsageGroupingRuleProvider.EP_NAME); List list = new ArrayList<>(providers.length); for (UsageGroupingRuleProvider provider : providers) { - ContainerUtil.addAll(list, provider.getActiveRules(project)); + ContainerUtil.addAll(list, provider.getActiveRules(project, usageViewSettings)); } Collections.sort(list, Comparator.comparingInt(UsageGroupingRule::getRank)); @@ -740,7 +744,7 @@ public class UsageViewImpl implements UsageView { @Override public void expandAll() { UsageViewImpl.this.expandAll(); - UsageViewSettings.getInstance().setExpanded(true); + getUsageViewSettings().setExpanded(true); } @Override @@ -751,7 +755,7 @@ public class UsageViewImpl implements UsageView { @Override public void collapseAll() { UsageViewImpl.this.collapseAll(); - UsageViewSettings.getInstance().setExpanded(false); + getUsageViewSettings().setExpanded(false); } @Override @@ -783,7 +787,7 @@ public class UsageViewImpl implements UsageView { collapseAllAction, actionsManager.createPrevOccurenceAction(myRootPanel), actionsManager.createNextOccurenceAction(myRootPanel), - actionsManager.installAutoscrollToSourceHandler(myProject, myTree, new MyAutoScrollToSourceOptionProvider()), + actionsManager.installAutoscrollToSourceHandler(myProject, myTree, new MyAutoScrollToSourceOptionProvider(getUsageViewSettings())), actionsManager.createExportToTextFileAction(myTextFileExporter) }; } @@ -892,7 +896,7 @@ public class UsageViewImpl implements UsageView { Collections.sort(allUsages, USAGE_COMPARATOR); final Set excludedUsages = getExcludedUsages(); reset(); - myBuilder.setGroupingRules(getActiveGroupingRules(myProject)); + myBuilder.setGroupingRules(getActiveGroupingRules(myProject, getUsageViewSettings())); myBuilder.setFilteringRules(getActiveFilteringRules(myProject)); ApplicationManager.getApplication().runReadAction(() -> { for (Usage usage : allUsages) { @@ -1038,12 +1042,12 @@ public class UsageViewImpl implements UsageView { @Override protected boolean getOptionValue() { - return UsageViewSettings.getInstance().isFilterDuplicatedLine(); + return getUsageViewSettings().isFilterDuplicatedLine(); } @Override protected void setOptionValue(boolean value) { - UsageViewSettings.getInstance().setFilterDuplicatedLine(value); + getUsageViewSettings().setFilterDuplicatedLine(value); } } @@ -1268,7 +1272,7 @@ public class UsageViewImpl implements UsageView { } private void saveSplitterProportions() { - UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS = myPreviewSplitter.getProportion(); + getUsageViewSettings().setPreviewUsagesSplitterProportion(myPreviewSplitter.getProportion()); } @Override @@ -1314,7 +1318,7 @@ public class UsageViewImpl implements UsageView { return; } showNode(firstUsageNode); - if (UsageViewSettings.getInstance().isExpanded() && myUsageNodes.size() < 10000) { + if (getUsageViewSettings().isExpanded() && myUsageNodes.size() < 10000) { expandAll(); } }); @@ -1765,14 +1769,20 @@ public class UsageViewImpl implements UsageView { } private static class MyAutoScrollToSourceOptionProvider implements AutoScrollToSourceOptionProvider { + @NotNull private final UsageViewSettings myUsageViewSettings; + + public MyAutoScrollToSourceOptionProvider(@NotNull UsageViewSettings usageViewSettings) { + myUsageViewSettings = usageViewSettings; + } + @Override public boolean isAutoScrollMode() { - return UsageViewSettings.getInstance().IS_AUTOSCROLL_TO_SOURCE; + return myUsageViewSettings.isAutoScrollToSource(); } @Override public void setAutoScrollMode(boolean state) { - UsageViewSettings.getInstance().IS_AUTOSCROLL_TO_SOURCE = state; + myUsageViewSettings.setAutoScrollToSource(state); } } @@ -1940,7 +1950,7 @@ public class UsageViewImpl implements UsageView { } private boolean isFilterDuplicateLines() { - return myPresentation.isMergeDupLinesAvailable() && UsageViewSettings.getInstance().isFilterDuplicatedLine(); + return myPresentation.isMergeDupLinesAvailable() && getUsageViewSettings().isFilterDuplicatedLine(); } public Usage getNextToSelect(@NotNull Usage toDelete) { diff --git a/platform/usageView/src/com/intellij/usages/impl/rules/FileGroupingRuleProvider.java b/platform/usageView/src/com/intellij/usages/impl/rules/FileGroupingRuleProvider.java index 0c8e53fff250..d9c779a19d43 100644 --- a/platform/usageView/src/com/intellij/usages/impl/rules/FileGroupingRuleProvider.java +++ b/platform/usageView/src/com/intellij/usages/impl/rules/FileGroupingRuleProvider.java @@ -1,30 +1,19 @@ /* - * 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl.rules; import com.intellij.openapi.project.Project; import com.intellij.usages.impl.FileStructureGroupRuleProvider; import com.intellij.usages.rules.UsageGroupingRule; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class FileGroupingRuleProvider implements FileStructureGroupRuleProvider { @Override - public UsageGroupingRule getUsageGroupingRule(Project project) { + public UsageGroupingRule getUsageGroupingRule(@NotNull Project project) { return new FileGroupingRule(project); } } diff --git a/platform/usageView/src/com/intellij/usages/rules/UsageGroupingRuleProvider.java b/platform/usageView/src/com/intellij/usages/rules/UsageGroupingRuleProvider.java index 5ae0b562d012..90c58992210b 100644 --- a/platform/usageView/src/com/intellij/usages/rules/UsageGroupingRuleProvider.java +++ b/platform/usageView/src/com/intellij/usages/rules/UsageGroupingRuleProvider.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.rules; @@ -19,6 +7,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; import com.intellij.usages.UsageView; +import com.intellij.usages.UsageViewSettings; import org.jetbrains.annotations.NotNull; /** @@ -27,7 +16,11 @@ import org.jetbrains.annotations.NotNull; public interface UsageGroupingRuleProvider { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.usageGroupingRuleProvider"); - @NotNull UsageGroupingRule[] getActiveRules(Project project); + @NotNull UsageGroupingRule[] getActiveRules(@NotNull Project project); + + default @NotNull UsageGroupingRule[] getActiveRules(@NotNull Project project, @NotNull UsageViewSettings usageViewSettings) { + return getActiveRules(project); + } @NotNull AnAction[] createGroupingActions(UsageView view); diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 9577d9aba3c3..505e4895fa45 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1401,5 +1401,8 @@ editor.show.right.margin.in.read.only.files.description=Show right margin for re editor.text.fractional.metrics=false editor.text.fractional.metrics.description=Do not round glyph advances to integer values +editor.disable.drag.with.right.button=false +editor.disable.drag.with.right.button.description=Disable any mouse drag processing in editor with right mouse button pressed + idea.invalidate.caches.invalidates.vfs=false idea.invalidate.caches.invalidates.vfs.description=Invalidate caches tries to invalidate everything, including Local History \ No newline at end of file diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java index 83934550169c..c530101db6ff 100644 --- a/platform/util/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/src/com/intellij/openapi/util/TextRange.java @@ -226,7 +226,7 @@ public class TextRange implements Segment, Serializable { public static void assertProperRange(int startOffset, int endOffset, @NotNull Object message) { if (!isProperRange(startOffset, endOffset)) { - LOG.error("Invalid range specified: (" + startOffset + "," + endOffset + "); " + message); + LOG.error("Invalid range specified: (" + startOffset + ", " + endOffset + "); " + message); } } diff --git a/platform/util/src/com/intellij/util/ConcurrencyUtil.java b/platform/util/src/com/intellij/util/ConcurrencyUtil.java index afa62163c846..b9d098cd5a08 100644 --- a/platform/util/src/com/intellij/util/ConcurrencyUtil.java +++ b/platform/util/src/com/intellij/util/ConcurrencyUtil.java @@ -15,6 +15,7 @@ */ package com.intellij.util; +import com.intellij.ReviseWhenPortedToJDK; import com.intellij.diagnostic.ThreadDumper; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -92,6 +93,8 @@ public class ConcurrencyUtil { /** * @return defaultValue if the reference contains null (in that case defaultValue is placed there), or reference value otherwise. */ + @ReviseWhenPortedToJDK("8") // todo "replace with return ref.updateAndGet(prev -> prev == null ? defaultValue : prev)" + @NotNull public static T cacheOrGet(@NotNull AtomicReference ref, @NotNull T defaultValue) { T value = ref.get(); while (value == null) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointsFavoriteListProvider.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointsFavoriteListProvider.java index a1f199423bbc..2c7e7e66cdf6 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointsFavoriteListProvider.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointsFavoriteListProvider.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.xdebugger.impl.breakpoints; @@ -138,13 +126,7 @@ public class BreakpointsFavoriteListProvider extends AbstractFavoritesListProvid if (node.getValue() instanceof Navigatable && ((Navigatable)node.getValue()).canNavigate()) { return true; } - Collection children = node.getChildren(); - for (AbstractTreeNode child : children) { - if (checkNavigatable(child)) { - return true; - } - } - return false; + return node.getChildren().stream().anyMatch(BreakpointsFavoriteListProvider::checkNavigatable); } @Nullable diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java index 1686f5b5bb6a..863ce5652cac 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java @@ -15,34 +15,119 @@ */ package com.siyeh.ig.bugs; +import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; -import com.intellij.psi.CommonClassNames; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiMethod; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.psi.javadoc.PsiDocToken; import com.intellij.psi.util.MethodSignatureUtil; +import com.intellij.psi.util.PsiUtil; import com.siyeh.HardcodedMethodConstants; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; -import com.siyeh.ig.psiutils.MethodUtils; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.ClassUtils; +import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + public class ComparableImplementedButEqualsNotOverriddenInspection extends BaseInspection { @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "comparable.implemented.but.equals.not.overridden.display.name"); + return InspectionGadgetsBundle.message("comparable.implemented.but.equals.not.overridden.display.name"); } @Override @NotNull protected String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "comparable.implemented.but.equals.not.overridden.problem.descriptor"); + return InspectionGadgetsBundle.message("comparable.implemented.but.equals.not.overridden.problem.descriptor"); + } + + @NotNull + @Override + protected InspectionGadgetsFix[] buildFixes(Object... infos) { + return new InspectionGadgetsFix[] { + new GenerateEqualsMethodFix(), + new AddNoteFix() + }; + } + + private static class GenerateEqualsMethodFix extends InspectionGadgetsFix { + @Nls + @NotNull + @Override + public String getFamilyName() { + return "Generate 'equals()' method"; + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) { + final PsiClass aClass = (PsiClass)descriptor.getPsiElement().getParent(); + final StringBuilder methodText = new StringBuilder(); + if (PsiUtil.isLanguageLevel5OrHigher(aClass)) { + methodText.append("@java.lang.Override "); + } + methodText.append("public "); + methodText.append("boolean equals(Object o) {\n"); + methodText.append("if (!(o instanceof ").append(aClass.getName()).append("))").append("return false;"); + methodText.append("return compareTo((").append(aClass.getName()).append(")o)==0;\n"); + methodText.append("}"); + final PsiMethod method = + JavaPsiFacade.getElementFactory(project).createMethodFromText(methodText.toString(), aClass, PsiUtil.getLanguageLevel(aClass)); + final PsiElement newMethod = aClass.add(method); + CodeStyleManager.getInstance(project).reformat(newMethod); + } + } + + private static class AddNoteFix extends InspectionGadgetsFix { + + private static final Pattern PARAM_PATTERN = Pattern.compile("\\*[ \t]+@"); + + @Nls + @NotNull + @Override + public String getFamilyName() { + return "Add 'ordering inconsistent with equals' JavaDoc note"; + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) { + final PsiClass aClass = (PsiClass)descriptor.getPsiElement().getParent(); + final PsiDocComment comment = aClass.getDocComment(); + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); + if (comment == null) { + final PsiDocComment newComment = factory.createDocCommentFromText( + "/**\n" + + "* Note: this class has a natural ordering that is inconsistent with equals.\n" + + "*/", aClass); + aClass.addBefore(newComment, aClass.getFirstChild()); + } + else { + final String text = comment.getText(); + final Matcher matcher = PARAM_PATTERN.matcher(text); + String newCommentText; + if (matcher.find()) { + newCommentText = text.substring(0, matcher.start()) + + " * Note: this class has a natural ordering that is inconsistent with equals.\n" + + text.substring(matcher.start()); + } + else { + newCommentText = text.substring(0, text.length() - 2) + + " * Note: this class has a natural ordering that is inconsistent with equals.\n*/"; + } + final PsiDocComment newComment = factory.createDocCommentFromText(newCommentText); + comment.replace(newComment); + } + } } @Override @@ -56,43 +141,68 @@ public class ComparableImplementedButEqualsNotOverriddenInspection extends BaseI public void visitClass(PsiClass aClass) { super.visitClass(aClass); if (aClass.isInterface()) { + // the problem can't be fixed for an interface, so let's not report it return; } - final PsiMethod[] methods = aClass.findMethodsByName(HardcodedMethodConstants.COMPARE_TO, false); - if (methods.length == 0) { - return; - } - final Project project = aClass.getProject(); - final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); - final GlobalSearchScope scope = aClass.getResolveScope(); final PsiClass comparableClass = - psiFacade.findClass(CommonClassNames.JAVA_LANG_COMPARABLE, - scope); - if (comparableClass == null) { + JavaPsiFacade.getInstance(aClass.getProject()).findClass(CommonClassNames.JAVA_LANG_COMPARABLE, aClass.getResolveScope()); + if (comparableClass == null || !aClass.isInheritor(comparableClass, true)) { return; } - if (!aClass.isInheritor(comparableClass, true)) { + final PsiMethod[] comparableMethods = comparableClass.getMethods(); + if (comparableMethods.length != 1) { // incorrect/broken jdk return; } - final PsiMethod compareToMethod = comparableClass.getMethods()[0]; - boolean foundCompareTo = false; - for (PsiMethod method : methods) { - if (MethodSignatureUtil.isSuperMethod(compareToMethod, method)) { - foundCompareTo = true; - break; + final PsiMethod comparableMethod = MethodSignatureUtil.findMethodBySuperMethod(aClass, comparableMethods[0], false); + if (comparableMethod == null || comparableMethod.hasModifierProperty(PsiModifier.ABSTRACT) || + comparableMethod.getBody() == null) { + return; + } + final PsiClass objectClass = ClassUtils.findObjectClass(aClass); + if (objectClass == null) { + return; + } + final PsiMethod[] equalsMethods = objectClass.findMethodsByName(HardcodedMethodConstants.EQUALS, false); + if (equalsMethods.length != 1) { // incorrect/broken jdk + return; + } + final PsiMethod equalsMethod = MethodSignatureUtil.findMethodBySuperMethod(aClass, equalsMethods[0], false); + if (equalsMethod != null && !equalsMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { + return; + } + final String docCommentText = collapseWhitespace(getActualCommentText(aClass.getDocComment())); + if (StringUtil.containsIgnoreCase(docCommentText, "this class has a natural ordering that is inconsistent with equals")) { + // see Comparable.compareTo() javadoc + return; + } + registerClassError(aClass, aClass); + } + + private static String getActualCommentText(PsiDocComment comment) { + if (comment == null) return ""; + return Arrays.stream(comment.getChildren()) + .filter(e -> (e instanceof PsiDocToken) && ((PsiDocToken)e).getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) + .map(PsiElement::getText) + .collect(Collectors.joining()); + } + + private static String collapseWhitespace(String s) { + final StringBuilder result = new StringBuilder(); + boolean space = false; + for (int i = 0, length = s.length(); i < length; i++) { + char ch = s.charAt(i); + if (StringUtil.isWhiteSpace(ch)) { + if (!space) { + result.append(' '); + space = true; + } + } + else { + result.append(ch); + space = false; } } - if (!foundCompareTo) { - return; - } - final PsiMethod[] equalsMethods = aClass.findMethodsByName( - HardcodedMethodConstants.EQUALS, false); - for (PsiMethod equalsMethod : equalsMethods) { - if (MethodUtils.isEquals(equalsMethod)) { - return; - } - } - registerClassError(aClass); + return result.toString(); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java index d1544ee92858..33b8e44f1eda 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java @@ -76,7 +76,7 @@ public class TypeMayBeWeakenedInspection extends AbstractBaseJavaLocalInspection public OrderedSet myStopClassSet = new OrderedSet<>(); - private ListWrappingTableModel myStopClassesModel = new ListWrappingTableModel(myStopClassSet, InspectionGadgetsBundle + private final ListWrappingTableModel myStopClassesModel = new ListWrappingTableModel(myStopClassSet, InspectionGadgetsBundle .message("inspection.type.may.be.weakened.add.stop.class.selection.table")); class AddStopWordQuickfix implements LowPriorityAction, LocalQuickFix { diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass1.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass1.java new file mode 100644 index 000000000000..95bdc82ff4c6 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass1.java @@ -0,0 +1,8 @@ +abstract class AbstractClass1 implements Comparable { + + int field = 1; + + public int compareTo(AbstractClass1 other) { + return field > other.field ? 1 : (field == other.field ? 0 : -1); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass2.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass2.java new file mode 100644 index 000000000000..7b99a07e178c --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass2.java @@ -0,0 +1,4 @@ +abstract class AbstractClass2 implements Comparable { + + public abstract int compareTo(AbstractClass2 other); +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass3.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass3.java new file mode 100644 index 000000000000..9c9f5f9bfe83 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/AbstractClass3.java @@ -0,0 +1,10 @@ +abstract class AbstractClass3 implements Comparable { + + int field; + + public int compareTo(AbstractClass3 other) { + return field > other.field ? 1 : (field == other.field ? 0 : -1); + } + + public abstract boolean equals(Object other); +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/Note.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/Note.java new file mode 100644 index 000000000000..ea8235218929 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/comparable_implemented_but_equals_not_overridden/Note.java @@ -0,0 +1,11 @@ +/** + * Note: This class has a natural + * ordering that is INCONSISTENT with equals. + */ +class Note implements Comparable { + + @Override + public int compareTo(Note other) { + return 0; + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspectionTest.java index 11f392fbfd32..c1ab7d827162 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspectionTest.java @@ -26,6 +26,10 @@ public class ComparableImplementedButEqualsNotOverriddenInspectionTest extends L public void testInterfaceImplementingComparable() { doTest(); } public void testSimple() { doTest(); } + public void testAbstractClass1() { doTest(); } + public void testAbstractClass2() { doTest(); } + public void testAbstractClass3() { doTest(); } + public void testNote() { doTest(); } @Nullable @Override diff --git a/plugins/gradle/resources/i18n/GradleBundle.properties b/plugins/gradle/resources/i18n/GradleBundle.properties index 5a409331efe9..4854aa1f017e 100644 --- a/plugins/gradle/resources/i18n/GradleBundle.properties +++ b/plugins/gradle/resources/i18n/GradleBundle.properties @@ -2,8 +2,8 @@ gradle.name=Gradle gradle.settings.text.use.default_wrapper.configured=Use default gradle wrapper (recommended) gradle.settings.text.use.default_wrapper.not_configured=Use default gradle wrapper (not configured for the current project) -gradle.settings.text.use.customizable_wrapper=Use gradle wrapper task configuration -gradle.settings.text.wrapper.customization.compatibility=Gradle wrapper customization in script, works with Gradle 1.7 or later +gradle.settings.text.use.customizable_wrapper=Use gradle 'wrapper' task configuration +gradle.settings.text.wrapper.customization.compatibility=Gradle wrapper customization in build script gradle.settings.text.use.local.distribution=Use local gradle distribution gradle.settings.text.use.bundled.distribution=Use bundled gradle distribution: ({0}) gradle.settings.text.create.module.per.sourceset=Create separate module per source set diff --git a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesUtil.java b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesUtil.java index 2f90e88e033d..a910caaf60b9 100644 --- a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesUtil.java +++ b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesUtil.java @@ -152,7 +152,16 @@ public class PropertiesUtil { final String language = splitRawLocale[1]; final String country = splitRawLocale.length > 2 ? splitRawLocale[2] : ""; final String variant = splitRawLocale.length > 3 ? splitRawLocale[3] : ""; - return Pair.create(new Locale(language, country, variant), language + "_" + country + "_" + variant); + + StringBuilder trimmedSuffix = new StringBuilder(language); + if (!country.isEmpty()) { + trimmedSuffix.append("_").append(country); + } + if (!variant.isEmpty()) { + trimmedSuffix.append("_").append(variant); + } + + return Pair.create(new Locale(language, country, variant), trimmedSuffix.toString()); } } return Pair.create(DEFAULT_LOCALE, ""); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java index 715987c2d30a..427550bdf22e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/RepositoryBrowserDialog.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.idea.svn.dialogs; @@ -154,9 +142,6 @@ public class RepositoryBrowserDialog extends DialogWrapper { InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)), browser); AnAction action = CommonActionsManager.getInstance().createCollapseAllAction(new TreeExpander() { - public void expandAll() { - } - public boolean canExpand() { return false; } diff --git a/python/educational-python/resources/idea/PyCharmEduApplicationInfo.xml b/python/educational-python/resources/idea/PyCharmEduApplicationInfo.xml index bb5b1da9297d..57146632e3cc 100644 --- a/python/educational-python/resources/idea/PyCharmEduApplicationInfo.xml +++ b/python/educational-python/resources/idea/PyCharmEduApplicationInfo.xml @@ -2,7 +2,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jetbrains.org/intellij/schema/application-info http://jetbrains.org/intellij/schema/ApplicationInfo.xsd"> - + + diff --git a/python/helpers/pycharm_matplotlib_backend/backend_interagg.py b/python/helpers/pycharm_matplotlib_backend/backend_interagg.py index 317d9b86d622..1c70df0ab5ad 100644 --- a/python/helpers/pycharm_matplotlib_backend/backend_interagg.py +++ b/python/helpers/pycharm_matplotlib_backend/backend_interagg.py @@ -86,7 +86,7 @@ class FigureCanvasInterAgg(FigureCanvasAgg): sock.send(struct.pack('>i', plot_index)) sock.send(struct.pack('>i', len(buffer))) sock.send(buffer) - except ConnectionRefusedError as _: + except OSError as _: # nothing bad. It just means, that our tool window doesn't run yet pass diff --git a/python/ide/src/META-INF/PyCharmCorePlugin.xml b/python/ide/src/META-INF/PyCharmCorePlugin.xml index 3e1f95d0b15b..c60c1bcb06df 100644 --- a/python/ide/src/META-INF/PyCharmCorePlugin.xml +++ b/python/ide/src/META-INF/PyCharmCorePlugin.xml @@ -13,4 +13,10 @@ + + + + diff --git a/python/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml b/python/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml index edcfd1d9c8c7..c6350af0bd84 100644 --- a/python/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml +++ b/python/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml @@ -2,7 +2,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jetbrains.org/intellij/schema/application-info http://jetbrains.org/intellij/schema/ApplicationInfo.xsd"> - + { final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); progressIndicator.setText("Waiting for REPL response with " + (int)(TIMEOUT / 10e8) + "s timeout"); + progressIndicator.setIndeterminate(false); final long startTime = System.nanoTime(); while (nextResponse == null) { if (progressIndicator.isCanceled()) { diff --git a/python/src/com/jetbrains/python/findUsages/PyClassGroupingRuleProvider.java b/python/src/com/jetbrains/python/findUsages/PyClassGroupingRuleProvider.java index dfd8a78659cb..64550fa1c8a7 100644 --- a/python/src/com/jetbrains/python/findUsages/PyClassGroupingRuleProvider.java +++ b/python/src/com/jetbrains/python/findUsages/PyClassGroupingRuleProvider.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2014 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.jetbrains.python.findUsages; @@ -34,7 +22,7 @@ import org.jetbrains.annotations.Nullable; * @author yole */ public class PyClassGroupingRuleProvider implements FileStructureGroupRuleProvider { - public UsageGroupingRule getUsageGroupingRule(Project project) { + public UsageGroupingRule getUsageGroupingRule(@NotNull Project project) { return new PyClassGroupingRule(); } diff --git a/python/src/com/jetbrains/python/findUsages/PyFunctionGroupingRuleProvider.java b/python/src/com/jetbrains/python/findUsages/PyFunctionGroupingRuleProvider.java index bb8c560f0749..2454d12f541c 100644 --- a/python/src/com/jetbrains/python/findUsages/PyFunctionGroupingRuleProvider.java +++ b/python/src/com/jetbrains/python/findUsages/PyFunctionGroupingRuleProvider.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2014 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. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.jetbrains.python.findUsages; @@ -35,7 +23,7 @@ import org.jetbrains.annotations.Nullable; * @author yole */ public class PyFunctionGroupingRuleProvider implements FileStructureGroupRuleProvider { - public UsageGroupingRule getUsageGroupingRule(Project project) { + public UsageGroupingRule getUsageGroupingRule(@NotNull Project project) { return new PyFunctionGroupingRule(); } diff --git a/python/src/com/jetbrains/python/testing/PyTestSharedForm.form b/python/src/com/jetbrains/python/testing/PyTestSharedForm.form index 022ca667b564..92bbf9d5898f 100644 --- a/python/src/com/jetbrains/python/testing/PyTestSharedForm.form +++ b/python/src/com/jetbrains/python/testing/PyTestSharedForm.form @@ -8,38 +8,32 @@ - + - + - + - + - + - + - - - - - - @@ -56,10 +50,9 @@ - - + - + diff --git a/python/src/com/jetbrains/python/testing/PyTestSharedForm.java b/python/src/com/jetbrains/python/testing/PyTestSharedForm.java index f00a7bb10d18..b5f0e140dff1 100644 --- a/python/src/com/jetbrains/python/testing/PyTestSharedForm.java +++ b/python/src/com/jetbrains/python/testing/PyTestSharedForm.java @@ -25,13 +25,13 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.psi.PsiDirectory; +import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.TextAccessor; -import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBRadioButton; import com.intellij.ui.components.JBTextField; import com.intellij.uiDesigner.core.GridConstraints; -import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.util.ThreeState; +import com.intellij.util.ui.JBUI; import com.jetbrains.PySymbolFieldWithBrowseButton; import com.jetbrains.extenstions.ContextAnchor; import com.jetbrains.extenstions.ModuleBasedContextAnchor; @@ -78,10 +78,6 @@ public final class PyTestSharedForm implements SimplePropertiesProvider { * Panel for environment options */ private JPanel myOptionsPanel; - /** - * Test label - */ - private JBLabel myLabel; /** * Panel for custom options, specific for runner and for "Additional Arguments"al;sop */ @@ -143,6 +139,13 @@ public final class PyTestSharedForm implements SimplePropertiesProvider { }); } + /** + * Titles border used among test run configurations + */ + public static void setBorderToPanel(@NotNull final JPanel panel, @NotNull final String title) { + panel.setBorder(IdeBorderFactory.createTitledBorder(title, false)); + } + /** * @param configuration configuration to configure form on creation * @param customOptions additional option names this form shall support. Make sure your configuration has appropriate properties. @@ -153,7 +156,8 @@ public final class PyTestSharedForm implements SimplePropertiesProvider { final PyTestSharedForm form = new PyTestSharedForm(configuration.getModule(), configuration); for (final TestTargetType testTargetType : TestTargetType.values()) { - final JBRadioButton button = new JBRadioButton(StringUtil.capitalize(testTargetType.getCustomName().toLowerCase(Locale.getDefault()))); + final JBRadioButton button = + new JBRadioButton(StringUtil.capitalize(testTargetType.getCustomName().toLowerCase(Locale.getDefault()))); button.setActionCommand(testTargetType.name()); button.addActionListener(o -> form.onTargetTypeChanged()); form.myButtonGroup.add(button); @@ -166,9 +170,7 @@ public final class PyTestSharedForm implements SimplePropertiesProvider { constraints.setFill(GridConstraints.FILL_BOTH); form.myOptionsPanel.add(form.myOptionsForm.getMainPanel(), constraints); - - form.myLabel.setText(configuration.getTestFrameworkName()); - + setBorderToPanel(form.myPanel, configuration.getTestFrameworkName()); form.addCustomOptions( ObjectArrays.concat(customOptions, new CustomOption(PyTestsSharedKt.getAdditionalArgumentsPropertyName(), TestTargetType.values())) @@ -186,29 +188,28 @@ public final class PyTestSharedForm implements SimplePropertiesProvider { final JBTextField textField = new JBTextField(); optionValueFields.put(option.myName, textField); } - myCustomOptionsPanel.setLayout(new GridLayoutManager(customOptions.length, 2)); - for (int i = 0; i < customOptions.length; i++) { - final CustomOption option = customOptions[i]; + final GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = JBUI.insets(3); + constraints.gridy = 0; + constraints.anchor = GridBagConstraints.LINE_START; + + for (final CustomOption option : customOptions) { final JBTextField textField = optionValueFields.get(option.myName); - - final GridConstraints labelConstraints = new GridConstraints(); - labelConstraints.setFill(GridConstraints.FILL_VERTICAL); - labelConstraints.setRow(i); - labelConstraints.setColumn(0); - labelConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_SHRINK); - - final JLabel label = new JLabel(StringUtil.capitalize(CAPITAL_LETTER.matcher(option.myName).replaceAll(" "))); + final JLabel label = new JLabel(StringUtil.capitalize(CAPITAL_LETTER.matcher(option.myName).replaceAll(" ") + ':')); label.setHorizontalAlignment(SwingConstants.LEFT); - myCustomOptionsPanel.add(label, labelConstraints); + constraints.fill = GridBagConstraints.NONE; + constraints.gridx = 0; + constraints.weightx = 0; + myCustomOptionsPanel.add(label, constraints); - final GridConstraints textConstraints = new GridConstraints(); - textConstraints.setFill(GridConstraints.FILL_BOTH); - textConstraints.setRow(i); - textConstraints.setColumn(1); - textConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW); - myCustomOptionsPanel.add(textField, textConstraints); + constraints.gridx = 1; + constraints.weightx = 1.0; + constraints.fill = GridBagConstraints.HORIZONTAL; + myCustomOptionsPanel.add(textField, constraints); + + constraints.gridy++; myCustomOptions.put(option.myName, new OptionHolder(option, label, textField)); } diff --git a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestRunConfigurationForm.java b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestRunConfigurationForm.java index aab24dfcf210..e277624b0d03 100644 --- a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestRunConfigurationForm.java +++ b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestRunConfigurationForm.java @@ -18,10 +18,10 @@ package com.jetbrains.python.testing.doctest; import com.intellij.openapi.project.Project; import com.jetbrains.python.PyBundle; import com.jetbrains.python.testing.AbstractPythonTestRunConfigurationParams; +import com.jetbrains.python.testing.PyTestSharedForm; import com.jetbrains.python.testing.PythonTestLegacyRunConfigurationForm; import javax.swing.*; -import javax.swing.border.TitledBorder; import java.awt.*; public class PythonDocTestRunConfigurationForm implements PythonDocTestRunConfigurationParams { @@ -33,9 +33,7 @@ public class PythonDocTestRunConfigurationForm implements PythonDocTestRunConfig public PythonDocTestRunConfigurationForm(final Project project, final PythonDocTestRunConfiguration configuration) { myRootPanel = new JPanel(new BorderLayout()); myTestRunConfigurationForm = new PythonTestLegacyRunConfigurationForm(project, configuration); - TitledBorder border = (TitledBorder)myTestRunConfigurationForm.getTestsPanel().getBorder(); - border.setTitle(PyBundle.message("runcfg.doctest.display_name")); - + PyTestSharedForm.setBorderToPanel(myTestRunConfigurationForm.getTestsPanel(), PyBundle.message("runcfg.doctest.display_name")); myRootPanel.add(myTestRunConfigurationForm.getPanel(), BorderLayout.CENTER); } diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py b/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py new file mode 100644 index 000000000000..9ac4f278ea56 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py @@ -0,0 +1,19 @@ +import typing + + +T = typing.TypeVar('T') + + +class X(typing.Generic[T]): + pass + + +class Y(X[T]): + pass + + +class Z(Y[T]): + pass + + +Z[int] \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index a789363f4d20..e3d3a7763ce7 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -215,6 +215,11 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase doTest(); } + // PY-27102 + public void testTypingGenericIndirectInheritorGetItem() { + doTest(); + } + // PY-21655 public void testUsageOfFunctionDecoratedWithAsyncioCoroutine() { doMultiFileTest("a.py"); diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index fdbe334a18b2..30ad551070ed 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -143,13 +143,14 @@ + - -