├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── media ├── example_beta.gif └── example_with_rxjava.gif ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── fooock │ │ └── experimental │ │ └── and │ │ └── beta │ │ └── icons │ │ └── LineMarker.java └── resources │ ├── META-INF │ └── plugin.xml │ └── icons │ ├── explosion.png │ └── fire.png └── test └── java └── com └── fooock └── experimental └── and └── beta └── icons └── LineMarkerTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | ### Idea 26 | .idea/ 27 | *.iml 28 | out/ 29 | build/ 30 | 31 | ### gradle 32 | .gradle/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Javi 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IDE icons for experimental and beta Java annotations 2 | [![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0) 3 | 4 | This is an IntelliJ/Android Studio IDE plugin to detect the code with 5 | **@Experimental** and **@Beta** annotations and show a custom icon on the gutter 6 | when you use it. 7 | 8 | ![](media/example_with_rxjava.gif) 9 | 10 | Note that the method `switchMapSingle()` is annotated with the `io.reactivex.annotations.Experimental` 11 | annotation. Another example of function annotated with a custom `Beta` annotation: 12 | 13 | ![](media/example_beta.gif) 14 | 15 | ## Why would I want to use this plugin? 16 | We are developers, and we write hundreds of lines of code and use tons 17 | of libraries each day. How many of these libraries contain beta and 18 | experimental classes and functions?. Which is the answer?. 19 | Well, you've probably never thought of that, but I can tell you that there are **many!** 20 | 21 | You don't trust me? Take a look to [RxJava](https://github.com/ReactiveX/RxJava) (I :cupid: RxJava). 22 | You are probably using **beta** and **experimental** functions/classes in your 23 | production code and you don't know it! 24 | 25 | With this plugin you know when you are using a beta or experimental piece of 26 | code 27 | 28 | ## Install the plugin 29 | There are two methods to install this plugin. The first, clone this repo and build the plugin 30 | jar to install it manually into the IDE. The second method, the recommended, search 31 | into the Jetbrains plugin manager this plugin `Icons for Java annotations` and install it 32 | > ~~Note that at this moment the plugin is pending JetBrains approval. If you want to 33 | test it you need to install it manually!~~ 34 | 35 | ### Automatic installation 36 | You can download the plugin using the Jetbrains plugin manager from your IntelliJ or 37 | Android Studio. Go to `Settings -> Plugins -> Browse repositories...` and search for 38 | `Icons for Java annotations`. Install and restart. This is the recommended option. You can check the plugin page 39 | [here](https://plugins.jetbrains.com/plugin/10038-icons-for-java-annotations). 40 | 41 | ### Manual installation 42 | First clone this repo: 43 | ```sh 44 | git clone https://github.com/fooock/detect-experimental-and-beta-code.git 45 | cd detect-experimental-and-beta-code 46 | ``` 47 | Build the plugin using gradle 48 | ```sh 49 | ./gradlew build 50 | ``` 51 | The compiled plugin is in the `build/libs` directory. Now open your IDE and go to `Settings -> Plugins -> Install plugin from disk...` 52 | and select the plugin. **Restart** your IDE. 53 | 54 | Do you have any question? [Ask here](https://github.com/fooock/detect-experimental-and-beta-code/issues) 55 | 56 | ## How it works? 57 | The operation of this plugin is very simple, it reads the code of the file that is currently 58 | open and if it finds an annotation that is called `Experimental` or `Beta` it paints an icon 59 | in the IDE gutter. That's all! 60 | 61 | Is important to note that the annotation package name is ignored. Using this behavior allows us to 62 | always display the icons, regardless of the library that is being used to annotate our code. Do you 63 | have any question? [Ask here](https://github.com/fooock/detect-experimental-and-beta-code/issues) 64 | 65 | ## Icons 66 | The icons used by this plugin are from the github markdown emoji markup. I 67 | found in [this repo](https://gist.github.com/rxaviers/7360908) a complete list. 68 | For the detected `@Experimental` annotations the :boom: icon is used, and for 69 | the `@Beta` annotation the :fire: icon is used. 70 | 71 | ## Credits 72 | To create the gifs for this readme I used the online service from [cloudconvert](https://cloudconvert.com/webm-to-gif). 73 | For the video record I use the [Icecream apps screen recorder](https://icecreamapps.com/Screen-Recorder/) application. 74 | Thanks! 75 | 76 | * [Petar Marijanović](https://github.com/PetarMarijanovic): Show tooltip text when on mouse hover 77 | ## License 78 | ``` 79 | Copyright (c) 2018 Javi 80 | 81 | Licensed under the Apache License, Version 2.0 (the "License"); 82 | you may not use this file except in compliance with the License. 83 | You may obtain a copy of the License at 84 | 85 | http://www.apache.org/licenses/LICENSE-2.0 86 | 87 | Unless required by applicable law or agreed to in writing, software 88 | distributed under the License is distributed on an "AS IS" BASIS, 89 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 90 | See the License for the specific language governing permissions and 91 | limitations under the License. 92 | ``` -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Javi 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | repositories { 19 | mavenCentral() 20 | } 21 | } 22 | 23 | plugins { 24 | id 'java' 25 | id 'org.jetbrains.intellij' version '0.2.17' 26 | } 27 | 28 | sourceCompatibility = JavaVersion.VERSION_1_8 29 | targetCompatibility = JavaVersion.VERSION_1_8 30 | 31 | intellij { 32 | version "2017.2.4" 33 | updateSinceUntilBuild false 34 | } 35 | 36 | repositories { 37 | mavenCentral() 38 | } 39 | 40 | dependencies { 41 | testCompile 'junit:junit:4.12' 42 | } 43 | 44 | task wrapper(type: Wrapper) { 45 | gradleVersion = '4.1' 46 | } 47 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fooock/detect-experimental-and-beta-code/0d0cba5290feee8cc53950528d47b3f626a0f032/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 17 20:50:36 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /media/example_beta.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fooock/detect-experimental-and-beta-code/0d0cba5290feee8cc53950528d47b3f626a0f032/media/example_beta.gif -------------------------------------------------------------------------------- /media/example_with_rxjava.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fooock/detect-experimental-and-beta-code/0d0cba5290feee8cc53950528d47b3f626a0f032/media/example_with_rxjava.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 newhouse 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = "icons-for-java-annotations" -------------------------------------------------------------------------------- /src/main/java/com/fooock/experimental/and/beta/icons/LineMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Javi 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.fooock.experimental.and.beta.icons; 18 | 19 | import com.intellij.codeHighlighting.Pass; 20 | import com.intellij.codeInsight.daemon.LineMarkerInfo; 21 | import com.intellij.codeInsight.daemon.LineMarkerProvider; 22 | import com.intellij.openapi.editor.markup.GutterIconRenderer; 23 | import com.intellij.openapi.util.IconLoader; 24 | import com.intellij.psi.*; 25 | import org.jetbrains.annotations.NonNls; 26 | import org.jetbrains.annotations.NotNull; 27 | import org.jetbrains.annotations.Nullable; 28 | 29 | import javax.swing.*; 30 | import java.util.Collection; 31 | import java.util.List; 32 | 33 | /** 34 | * Plugin main entry point 35 | */ 36 | public final class LineMarker implements LineMarkerProvider { 37 | 38 | // Documentation: 39 | // -------------- 40 | // https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/line_marker_provider.html 41 | 42 | private static final String EXPERIMENTAL_ANNOTATION_NAME = "Experimental"; 43 | private static final String BETA_ANNOTATION_NAME = "Beta"; 44 | private static final String TOOLTIP = "This method is annotated as @%s"; 45 | 46 | private static final Icon ICON_EXPERIMENTAL_ANNOTATION = IconLoader.getIcon("/icons/explosion.png"); 47 | private static final Icon ICON_BETA_ANNOTATION = IconLoader.getIcon("/icons/fire.png"); 48 | 49 | private static final PsiAnnotation[] EMPTY_ANNOTATION_ARRAY = new PsiAnnotation[0]; 50 | 51 | @Nullable 52 | @Override 53 | public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { 54 | // check if the element is a reference with method. Note that if the method reference 55 | // find an annotation, this method don't continue, if not, check the method params 56 | if (isReferenceWithMethod(psiElement)) { 57 | final PsiMethod method = getMethodFrom(psiElement); 58 | final PsiAnnotation[] annotationsFromMethod = getAnnotationsFrom(method); 59 | 60 | // if no annotations found we check if the method has parameters and if these params 61 | // are annotated or not 62 | if (!hasAnnotations(annotationsFromMethod)) { 63 | 64 | // if annotations > 0 then check if the methods have annotations, if not then 65 | // return nothing 66 | if (isMethodParameters(method)) { 67 | for (PsiParameter parameter : getParametersFrom(method)) { 68 | // get the annotations by parameter 69 | final PsiAnnotation[] annotationsFromParam = getAnnotationsFrom(parameter); 70 | if (!hasAnnotations(annotationsFromParam)) continue; 71 | return getLineMarkerInfo(psiElement, annotationsFromParam); 72 | } 73 | } 74 | // the method doesn't have annotations and doesn't have 75 | // any parameters, then return null 76 | return null; 77 | } 78 | return getLineMarkerInfo(psiElement, annotationsFromMethod); 79 | } 80 | return null; 81 | } 82 | 83 | /** 84 | * This method get the line marker for the current element when is know that it has annotations. If the 85 | * annotations found are know, this is, {@link #EXPERIMENTAL_ANNOTATION_NAME} or {@link #BETA_ANNOTATION_NAME}, 86 | * the icon for each one is shown. If the annotations not match any of these two, this method return null 87 | * 88 | * @param psiElement Current element 89 | * @param annotationsFromMethod Array of annotations from the element. Always more than zero 90 | * @return LineMarkerInfo if find know annotation or null if not found 91 | */ 92 | @Nullable 93 | private LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement, 94 | @NotNull PsiAnnotation[] annotationsFromMethod) { 95 | // at this point we can check if the existing annotations match 96 | for (PsiAnnotation annotation : annotationsFromMethod) { 97 | final String qualifiedName = annotation.getQualifiedName(); 98 | if (qualifiedName == null || qualifiedName.isEmpty()) continue; 99 | final int index = qualifiedName.lastIndexOf("."); 100 | // if index is equal to -1, then check directly in the qualified name contain 101 | // Experimental or Beta 102 | if (index == -1) { 103 | if (!isAnnotationKnow(qualifiedName)) continue; 104 | return markerFromAnnotationName(qualifiedName, psiElement); 105 | } 106 | // Remove from the final annotation name the '.' (index + 1) 107 | final String annotationName = qualifiedName.substring(index + 1, qualifiedName.length()).trim(); 108 | if (!isAnnotationKnow(annotationName)) continue; 109 | return markerFromAnnotationName(annotationName, psiElement); 110 | } 111 | return null; 112 | } 113 | 114 | /** 115 | * @param annotationName Current annotation 116 | * @return True if the annotation is know, false if not. 117 | * @see #BETA_ANNOTATION_NAME 118 | * @see #EXPERIMENTAL_ANNOTATION_NAME 119 | */ 120 | private boolean isAnnotationKnow(String annotationName) { 121 | return annotationName.equals(EXPERIMENTAL_ANNOTATION_NAME) || annotationName.equals(BETA_ANNOTATION_NAME); 122 | } 123 | 124 | /** 125 | * Get the {@link LineMarkerInfo} for the given annotation type if is any of {@link #EXPERIMENTAL_ANNOTATION_NAME} 126 | * or {@link #BETA_ANNOTATION_NAME}, otherwise this method return null 127 | * 128 | * @param annotationName Annotation name 129 | * @param element Current element 130 | * @return LineMarkerInfo of null 131 | */ 132 | @Nullable 133 | private LineMarkerInfo markerFromAnnotationName(@NotNull String annotationName, @NotNull PsiElement element) { 134 | if (EXPERIMENTAL_ANNOTATION_NAME.equals(annotationName)) { 135 | // here return the line marker with the specified experimental icon 136 | return createLineMarkerFor(element, ICON_EXPERIMENTAL_ANNOTATION, 137 | String.format(TOOLTIP, EXPERIMENTAL_ANNOTATION_NAME)); 138 | } 139 | if (BETA_ANNOTATION_NAME.equals(annotationName)) { 140 | // here return the line marker with the specified beta icon 141 | return createLineMarkerFor(element, ICON_BETA_ANNOTATION, 142 | String.format(TOOLTIP, BETA_ANNOTATION_NAME)); 143 | } 144 | return null; 145 | } 146 | 147 | /** 148 | * Create the {@link LineMarkerInfo} for the given {@link PsiElement} with the required {@link Icon}. This 149 | * method never return null. Note that the line marker is aligned always to the left. When the mouse is 150 | * over the icon a tooltip indicating the name of the function and if is experimental or beta is shown 151 | * 152 | * @param element Current element 153 | * @param icon Icon for the required annotation 154 | * @param tooltip Type of the line marker 155 | * @return LineMarkerInfo 156 | */ 157 | @NotNull 158 | private LineMarkerInfo createLineMarkerFor(@NotNull PsiElement element, 159 | @NotNull Icon icon, 160 | @NotNull @NonNls String tooltip) { 161 | return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.UPDATE_ALL, 162 | psiElement -> tooltip, null, GutterIconRenderer.Alignment.CENTER); 163 | } 164 | 165 | /** 166 | * Check if in the given array has more than zero elements 167 | * 168 | * @param annotations Array if annotations 169 | * @return True if more than zero elements, false otherwise 170 | */ 171 | private boolean hasAnnotations(@NotNull PsiAnnotation[] annotations) { 172 | return annotations.length > 0; 173 | } 174 | 175 | /** 176 | * Get the current {@link PsiAnnotation}s from the given elements. Note that this method can return 177 | * empty elements 178 | * 179 | * @param psiElement Current element 180 | * @return Array of annotations from element if exists, empty if not 181 | */ 182 | private PsiAnnotation[] getAnnotationsFrom(PsiElement psiElement) { 183 | if (psiElement instanceof PsiModifierListOwner) { 184 | final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner) psiElement; 185 | final PsiModifierList modifiers = modifierListOwner.getModifierList(); 186 | // modifiers can be null 187 | if (modifiers == null) { 188 | return EMPTY_ANNOTATION_ARRAY; 189 | } 190 | return modifiers.getAnnotations(); 191 | } 192 | return EMPTY_ANNOTATION_ARRAY; 193 | } 194 | 195 | /** 196 | * Check if the given {@link PsiElement} is a method and has more than zero parameters 197 | * 198 | * @param psiElement Current element 199 | * @return True if the element is a field, false if not 200 | */ 201 | private boolean isMethodParameters(PsiElement psiElement) { 202 | return psiElement instanceof PsiMethod 203 | && ((PsiMethod) psiElement).getParameterList().getParametersCount() > 0; 204 | } 205 | 206 | /** 207 | * Get the method parameters from the given {@link PsiElement} 208 | * 209 | * @param psiElement Current element 210 | * @return The method parameters 211 | */ 212 | private PsiParameter[] getParametersFrom(@NotNull PsiElement psiElement) { 213 | return ((PsiMethod) psiElement).getParameterList().getParameters(); 214 | } 215 | 216 | /** 217 | * Check if the given {@link PsiElement} is a valid reference and has a method. Note that this method 218 | * only return true when the element is a reference and has a method, for example: 219 | *
220 |      *  MyObject obj = new MyObject();
221 |      *  obj.test();
222 |      * 
223 | * This method return true when the {@code obj.pre()} is detected 224 | * 225 | * @param psiElement Current element 226 | * @return True if the element is a reference that has a method, false if not 227 | */ 228 | private boolean isReferenceWithMethod(PsiElement psiElement) { 229 | return psiElement instanceof PsiReferenceExpression 230 | && ((PsiReferenceExpression) psiElement).resolve() instanceof PsiMethod; 231 | } 232 | 233 | /** 234 | * Get the {@link PsiMethod} from the given {@link PsiElement}. When this method is called is 235 | * because the {@link #isReferenceWithMethod(PsiElement)} return {@code true} 236 | * 237 | * @param psiElement Current element 238 | * @return The method of the current reference 239 | */ 240 | private PsiMethod getMethodFrom(@NotNull PsiElement psiElement) { 241 | return (PsiMethod) ((PsiReferenceExpression) psiElement).resolve(); 242 | } 243 | 244 | @Override 245 | public void collectSlowLineMarkers(@NotNull List list, 246 | @NotNull Collection collection) { 247 | // not used for the moment 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.fooock.experimental.and.beta.icons 3 | Icons for Java annotations 4 | 1.1.2 5 | fooock 6 | 7 | @Experimental and @Beta Java annotations
9 | When this annotations are detected by the plugin, it show an icon in the IDE gutter. 10 | This plugin is compatible with IntelliJ and Android Studio.

11 | To see the documentation and more examples see here 12 | ]]>
13 | 14 | 16 |
    17 |
  • Show a tooltip when the mouse is over the icon
  • 18 |
  • At this moment we only detect annotations in methods
  • 19 |
20 | ]]> 21 |
22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
-------------------------------------------------------------------------------- /src/main/resources/icons/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fooock/detect-experimental-and-beta-code/0d0cba5290feee8cc53950528d47b3f626a0f032/src/main/resources/icons/explosion.png -------------------------------------------------------------------------------- /src/main/resources/icons/fire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fooock/detect-experimental-and-beta-code/0d0cba5290feee8cc53950528d47b3f626a0f032/src/main/resources/icons/fire.png -------------------------------------------------------------------------------- /src/test/java/com/fooock/experimental/and/beta/icons/LineMarkerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Javi 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.fooock.experimental.and.beta.icons; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * 23 | */ 24 | public class LineMarkerTest { 25 | 26 | @Test 27 | public void testHasAnnotationsIsTrue() { 28 | 29 | } 30 | } 31 | --------------------------------------------------------------------------------