├── .gitignore ├── LICENSE ├── README.md ├── README_EN.md ├── build.gradle ├── doc └── img │ ├── choose_mapper_folder.jpg │ ├── create_mapper.png │ ├── create_statement.jpg │ ├── gzh_logo.jpg │ ├── gzh_qrcode.jpg │ ├── mgu_1.png │ ├── mgu_2.png │ ├── mgu_3.png │ ├── mgu_4.png │ ├── to_code.jpg │ └── to_mapper.jpg ├── gradlew ├── gradlew.bat ├── lib ├── gene-plugin-1.0-SNAPSHOT.jar └── mybatis-generator-core-1.4.0.jar ├── settings.gradle └── src └── main ├── java └── com │ └── wuzhizhan │ └── mybatis │ ├── action │ ├── MybatisGeneratorMainAction.java │ └── MybatisTypedHandler.java │ ├── alias │ ├── AliasClassReference.java │ ├── AliasDesc.java │ ├── AliasFacade.java │ ├── AliasResolver.java │ ├── AliasResolverFactory.java │ ├── AnnotationAliasResolver.java │ ├── BeanAliasResolver.java │ ├── ConfigPackageAliasResolver.java │ ├── InnerAliasResolver.java │ ├── PackageAliasResolver.java │ └── SingleAliasResolver.java │ ├── annotation │ └── Annotation.java │ ├── contributor │ ├── JavaMenthodCompletionContributor.java │ ├── SqlParamCompletionContributor.java │ └── TestParamContributor.java │ ├── definitionsearch │ └── MapperDefinitionSearch.java │ ├── dom │ ├── MapperBacktrackingUtils.java │ ├── converter │ │ ├── AliasConverter.java │ │ ├── ConverterAdaptor.java │ │ ├── DaoMethodConverter.java │ │ ├── IdBasedTagConverter.java │ │ ├── ParameterMapConverter.java │ │ ├── PropertyConverter.java │ │ ├── ResultMapConverter.java │ │ └── SqlConverter.java │ ├── description │ │ ├── ConfigurationDescription.java │ │ └── MapperDescription.java │ └── model │ │ ├── Arg.java │ │ ├── Association.java │ │ ├── Bean.java │ │ ├── BeanProperty.java │ │ ├── Beans.java │ │ ├── Bind.java │ │ ├── Cache.java │ │ ├── CacheRef.java │ │ ├── Case.java │ │ ├── Choose.java │ │ ├── Collection.java │ │ ├── Configuration.java │ │ ├── Constructor.java │ │ ├── Delete.java │ │ ├── Discriminator.java │ │ ├── Foreach.java │ │ ├── GroupFour.java │ │ ├── GroupOne.java │ │ ├── GroupThree.java │ │ ├── GroupTwo.java │ │ ├── Id.java │ │ ├── IdArg.java │ │ ├── IdDomElement.java │ │ ├── If.java │ │ ├── Include.java │ │ ├── Insert.java │ │ ├── Mapper.java │ │ ├── Otherwise.java │ │ ├── Package.java │ │ ├── Parameter.java │ │ ├── ParameterMap.java │ │ ├── Property.java │ │ ├── PropertyGroup.java │ │ ├── Result.java │ │ ├── ResultMap.java │ │ ├── ResultMapGroup.java │ │ ├── Select.java │ │ ├── SelectKey.java │ │ ├── Set.java │ │ ├── Sql.java │ │ ├── Trim.java │ │ ├── TypeAlias.java │ │ ├── TypeAliases.java │ │ ├── Update.java │ │ ├── When.java │ │ └── Where.java │ ├── generate │ ├── DeleteGenerator.java │ ├── GenerateModel.java │ ├── InsertGenerator.java │ ├── MybatisGenerator.java │ ├── SelectGenerator.java │ ├── StatementGenerator.java │ └── UpdateGenerator.java │ ├── inspection │ ├── GenericQuickFix.java │ ├── MapperInspection.java │ ├── MapperMethodInspection.java │ ├── MapperXmlInspection.java │ ├── ResultTypeQuickFix.java │ └── StatementNotExistsQuickFix.java │ ├── intention │ ├── GenerateMapperChooser.java │ ├── GenerateMapperIntention.java │ ├── GenerateParamAnnotationIntention.java │ ├── GenerateParamChooser.java │ ├── GenerateStatementChooser.java │ ├── GenerateStatementIntention.java │ ├── GenericIntention.java │ ├── IntentionChooser.java │ └── JavaFileIntentionChooser.java │ ├── locator │ ├── LocateStrategy.java │ ├── MapperLocator.java │ ├── MapperXmlPackageProvider.java │ ├── PackageLocateStrategy.java │ └── PackageProvider.java │ ├── model │ ├── Config.java │ ├── DbType.java │ ├── TableInfo.java │ └── User.java │ ├── provider │ ├── InjectionLineMarkerProvider.java │ ├── MapperLineMarkerProvider.java │ ├── MarkerProviderAdaptor.java │ ├── SimpleLineMarkerProvider.java │ └── StatementLineMarkerProvider.java │ ├── refactoring │ └── MapperRefactoringProvider.java │ ├── reference │ ├── ContextPsiFieldReference.java │ ├── ContextReferenceSetResolver.java │ ├── PsiFieldReferenceSetResolver.java │ ├── ReferenceSetResolverFactory.java │ └── ResultPropertyReferenceSet.java │ ├── service │ ├── AnnotationService.java │ ├── EditorService.java │ ├── JavaService.java │ └── TableInfoService.java │ ├── setting │ ├── MybatisConfigurable.java │ ├── MybatisGeneratorConfigurable.java │ ├── MybatisSetting.java │ ├── MybatisSettingForm.form │ ├── MybatisSettingForm.java │ └── PersistentConfig.java │ ├── template │ └── MybatisFileTemplateDescriptorFactory.java │ ├── ui │ ├── ClickableListener.java │ ├── ExecutableListener.java │ ├── ListSelectionListener.java │ ├── MybatisGeneratorMainUI.java │ ├── MybatisGeneratorSettingUI.java │ └── UiComponentFacade.java │ └── util │ ├── ArrayUtils.java │ ├── CollectionUtils.java │ ├── DbToolsUtils.java │ ├── DomUtils.java │ ├── GeneratorCallback.java │ ├── Icons.java │ ├── JTextFieldHintListener.java │ ├── JavaUtils.java │ ├── MapperUtils.java │ ├── MybatisConstants.java │ └── StringUtils.java └── resources ├── META-INF └── plugin.xml ├── fileTemplates └── j2ee │ └── Mybatis Mapper.xml.ft ├── images ├── 7.png ├── 7d.png ├── injection.png ├── logo.png ├── mapper_method.png ├── s.png └── statement.png └── liveTemplates └── sql.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | 3 | log.roo 4 | .idea/ 5 | out/ 6 | .DS_Store 7 | .gradle/ 8 | gradle/ 9 | build/ 10 | out/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 基于升级,支持2020.2.4版本。 2 | 3 | [中文](README.md) | 4 | [ENGLISH](README_EN.md) 5 | 6 | ## Description 7 | A idea plugin for mybatis . 8 | free-mybatis-plugin 是一款增强idea对mybatis支持的插件,主要功能如下: 9 | - 生成mapper xml文件 10 | - 快速从代码跳转到mapper及从mapper返回代码 11 | - mybatis自动补全及语法错误提示 12 | 13 | ## 使用方法 14 | free-mybatis-plugin是一个提高mybatis编码的插件。实现了dao代码跳转到mapper,mapper跳转回dao,mapper文件、statement查询自动生成功能。 15 | ### 灵活使用alt+enter和ctrl+B实现提示和跳转 16 | - 生成mapper文件 17 | - alter+enter弹出 18 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_26a01dec_131460.png) 19 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_59d74c18_131460.jpeg) 20 | - 生成statement语句 21 | - alter+enter弹出 22 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_594bfd4d_131460.jpeg) 23 | - dao跳转到mapper(也可以ctrl+B跳入) 24 | - ![](https://images.gitee.com/uploads/images/2020/0121/151850_9821ea07_131460.jpeg) 25 | - mapper跳转回dao(也可以ctrl+b跳入) 26 | - ![](https://images.gitee.com/uploads/images/2020/0121/151850_6ff9859f_131460.jpeg) 27 |


28 | ## mybatis generator gui使用方法 29 | - 配置数据库
30 | ![](https://images.gitee.com/uploads/images/2020/0121/151850_7decd93e_131460.png) 31 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_3b35abd0_131460.png) 32 | - 在需要生成代码的表上右键,选择mybatis generator,打开预览界面。
33 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_6552ab20_131460.png) 34 | - 配置生成参数
35 | ![](https://images.gitee.com/uploads/images/2020/0121/151849_7fd4ada5_131460.png) 36 | - 注意:当数据库用mysql8,在URL上定义时区,推荐使用'?serverTimezone=GMT',配置中勾选上mysql8选项。
37 | 38 | ## TODO 39 | - 根据数据库字段生产bean 40 | - 快捷生成CURD操作 41 | 42 | ## 参考 43 | - better-mybatis-generator https://github.com/kmaster/better-mybatis-generator 44 | - mybatis-generator-gui https://github.com/zouzg/mybatis-generator-gui 45 | - MyBatisCodeHelper-Pro https://github.com/gejun123456/MyBatisCodeHelper-Pro 46 | ## 我的微信公众号 - it新技术 47 | 更多内容,欢迎关注公众号 【it新技术】 48 | - ![](https://images.gitee.com/uploads/images/2020/0121/151850_6e6ac5da_131460.jpeg) 49 | ![](https://images.gitee.com/uploads/images/2020/0121/151850_003d690f_131460.jpeg) -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | Based on support to idea 2020.2.4。 2 | 3 | [中文](README.md) | 4 | [ENGLISH](README_EN.md) 5 | 6 | 7 | ## Description 8 | A idea plugin for mybatis . 9 | free-mybatis-plugin is an enchange plugin for idea to supoort mybatis,here is the main functions: 10 | - generate mapper xml files 11 | - navigate from the code to mapper and from the mapper back to code 12 | - auto code and error tips 13 | 14 | ## How To Use 15 | - generate mapper files 16 | - alter+enter 17 | ![](https://raw.githubusercontent.com/wuzhizhan/free-idea-mybatis/master/doc/img/create_mapper.png) 18 | ![](https://raw.githubusercontent.com/wuzhizhan/free-idea-mybatis/master/doc/img/choose_mapper_folder.jpg) 19 | - generate statement 20 | - alter+enter 21 | ![](https://raw.githubusercontent.com/wuzhizhan/free-idea-mybatis/master/doc/img/create_statement.jpg) 22 | - from dao to mapper(can also use ctrl+B) 23 | ![](https://raw.githubusercontent.com/wuzhizhan/free-idea-mybatis/master/doc/img/to_mapper.jpg) 24 | - from mapper to dao(can also use ctrl+b) 25 | ![](https://raw.githubusercontent.com/wuzhizhan/free-idea-mybatis/master/doc/img/to_code.jpg) 26 | 27 | 28 | ## mybatis generator gui usage 29 | - database configuration
30 | ![](https://github.com/wuzhizhan/free-idea-mybatis/blob/master/doc/img/mgu_1.png) 31 | ![](https://github.com/wuzhizhan/free-idea-mybatis/blob/master/doc/img/mgu_2.png) 32 | - elect one or more tables,right click and select mybatis generator to open generatoe main UI.
33 | ![](https://github.com/wuzhizhan/free-idea-mybatis/blob/master/doc/img/mgu_3.png) 34 | - mybatis generator configuration
35 | ![](https://github.com/wuzhizhan/free-idea-mybatis/blob/master/doc/img/mgu_4.png) 36 | - notice:If your database is mysql8,please add '?serverTimezone=GMT' and select mysql8 option
37 | 38 | ## Reference 39 | - better-mybatis-generator https://github.com/kmaster/better-mybatis-generator 40 | - mybatis-generator-gui https://github.com/zouzg/mybatis-generator-gui 41 | - MyBatisCodeHelper-Pro https://github.com/gejun123456/MyBatisCodeHelper-Pro 42 | ## TODO 43 | - generate bean accourding to database field 44 | - generate CURD code 45 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 4 | mavenLocal() 5 | mavenCentral() 6 | } 7 | 8 | } 9 | plugins { 10 | id "org.jetbrains.intellij" version "0.4.15" 11 | } 12 | 13 | group = 'cn.wuzhizhan.idea.mybatis' 14 | version = '2020.12.09' 15 | 16 | apply plugin: 'java' 17 | sourceCompatibility = 1.8 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'lib', includes: ['*jar']) 25 | compile group: 'com.softwareloop', name: 'mybatis-generator-lombok-plugin', version: '1.0' 26 | compile group: 'uk.com.robust-it', name: 'cloning', version: '1.9.2' 27 | testCompile group: 'junit', name: 'junit', version: '4.12' 28 | } 29 | buildPlugin { 30 | buildSearchableOptions.enabled = false 31 | } 32 | intellij { 33 | version "2020.2.4" 34 | type "IU" 35 | pluginName = 'free-mybatis-plugin' 36 | plugins = ['coverage', 'Spring', 'DatabaseTools', 'java'] 37 | intellij.updateSinceUntilBuild false 38 | } 39 | patchPluginXml { 40 | changeNotes """ 41 |

2020.12.09

42 | 46 |

2020.12.08

47 | 50 |

2019.12.18

51 | 58 | """ 59 | } 60 | 61 | tasks.withType(JavaCompile) { 62 | options.encoding = "UTF-8" 63 | } 64 | -------------------------------------------------------------------------------- /doc/img/choose_mapper_folder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/choose_mapper_folder.jpg -------------------------------------------------------------------------------- /doc/img/create_mapper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/create_mapper.png -------------------------------------------------------------------------------- /doc/img/create_statement.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/create_statement.jpg -------------------------------------------------------------------------------- /doc/img/gzh_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/gzh_logo.jpg -------------------------------------------------------------------------------- /doc/img/gzh_qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/gzh_qrcode.jpg -------------------------------------------------------------------------------- /doc/img/mgu_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/mgu_1.png -------------------------------------------------------------------------------- /doc/img/mgu_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/mgu_2.png -------------------------------------------------------------------------------- /doc/img/mgu_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/mgu_3.png -------------------------------------------------------------------------------- /doc/img/mgu_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/mgu_4.png -------------------------------------------------------------------------------- /doc/img/to_code.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/to_code.jpg -------------------------------------------------------------------------------- /doc/img/to_mapper.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/doc/img/to_mapper.jpg -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /lib/gene-plugin-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/lib/gene-plugin-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /lib/mybatis-generator-core-1.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sppan24/free-mybatis-plugin/2fa27af059e2e47f9f746fb1af6876b805c1a0a9/lib/mybatis-generator-core-1.4.0.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'free-mybatis-plugin' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/action/MybatisGeneratorMainAction.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.action; 2 | 3 | 4 | import com.intellij.database.psi.DbTable; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | import com.intellij.openapi.actionSystem.LangDataKeys; 8 | import com.intellij.openapi.ui.Messages; 9 | import com.intellij.psi.PsiElement; 10 | import com.wuzhizhan.mybatis.ui.MybatisGeneratorMainUI; 11 | 12 | public class MybatisGeneratorMainAction extends AnAction { 13 | 14 | 15 | /** 16 | * 点击后打开插件主页面 17 | * 18 | * @param e 19 | */ 20 | @Override 21 | public void actionPerformed(AnActionEvent e) { 22 | PsiElement[] psiElements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY); 23 | if (psiElements == null || psiElements.length == 0) { 24 | Messages.showMessageDialog("Please select one or more tables", "Notice", Messages.getInformationIcon()); 25 | return; 26 | } 27 | for (PsiElement psiElement : psiElements) { 28 | if (!(psiElement instanceof DbTable)) { 29 | Messages.showMessageDialog("Please select one or more tables", "Notice", Messages.getInformationIcon()); 30 | return; 31 | } 32 | } 33 | new MybatisGeneratorMainUI(e); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/action/MybatisTypedHandler.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.action; 2 | 3 | import com.intellij.codeInsight.AutoPopupController; 4 | import com.intellij.codeInsight.editorActions.TypedHandlerDelegate; 5 | import com.intellij.openapi.editor.Editor; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiFile; 8 | import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; 9 | import com.wuzhizhan.mybatis.util.DomUtils; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class MybatisTypedHandler extends TypedHandlerDelegate { 16 | 17 | @Override 18 | public Result checkAutoPopup(char charTyped, final Project project, final Editor editor, PsiFile file) { 19 | if (charTyped == '.' && DomUtils.isMybatisFile(file)) { 20 | autoPopupParameter(project, editor); 21 | return Result.STOP; 22 | } 23 | return super.checkAutoPopup(charTyped, project, editor, file); 24 | } 25 | 26 | @Override 27 | public Result charTyped(char c, final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { 28 | int index = editor.getCaretModel().getOffset() - 2; 29 | PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(file); 30 | boolean parameterCase = c == '{' && 31 | index >= 0 && 32 | editor.getDocument().getText().charAt(index) == '#' && 33 | // file instanceof SqlFile && 34 | DomUtils.isMybatisFile(topLevelFile); 35 | if (parameterCase) { 36 | autoPopupParameter(project, editor); 37 | return Result.STOP; 38 | } 39 | return super.charTyped(c, project, editor, file); 40 | } 41 | 42 | private static void autoPopupParameter(final Project project, final Editor editor) { 43 | AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, psiFile -> true); 44 | } 45 | 46 | 47 | } -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AliasClassReference.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.Collections2; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.psi.PsiReferenceBase; 7 | import com.intellij.psi.xml.XmlAttributeValue; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.Collection; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class AliasClassReference extends PsiReferenceBase { 17 | 18 | private Function function = new Function() { 19 | @Override 20 | public String apply(AliasDesc input) { 21 | return input.getAlias(); 22 | } 23 | }; 24 | 25 | public AliasClassReference(@NotNull XmlAttributeValue element) { 26 | super(element, true); 27 | } 28 | 29 | @Nullable 30 | @Override 31 | public PsiElement resolve() { 32 | XmlAttributeValue attributeValue = getElement(); 33 | return AliasFacade.getInstance(attributeValue.getProject()).findPsiClass(attributeValue, attributeValue.getValue()).orElse(null); 34 | } 35 | 36 | @NotNull 37 | @Override 38 | public Object[] getVariants() { 39 | AliasFacade aliasFacade = AliasFacade.getInstance(getElement().getProject()); 40 | Collection result = Collections2.transform(aliasFacade.getAliasDescs(getElement()), function); 41 | return result.toArray(new String[result.size()]); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AliasDesc.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | /** 7 | * @author yanglin 8 | */ 9 | public class AliasDesc { 10 | 11 | private PsiClass clazz; 12 | 13 | private String alias; 14 | 15 | public AliasDesc() { 16 | } 17 | 18 | public static AliasDesc create(@NotNull PsiClass psiClass, @NotNull String alias) { 19 | return new AliasDesc(psiClass, alias); 20 | } 21 | 22 | public AliasDesc(PsiClass clazz, String alias) { 23 | this.clazz = clazz; 24 | this.alias = alias; 25 | } 26 | 27 | public PsiClass getClazz() { 28 | return clazz; 29 | } 30 | 31 | public void setClazz(PsiClass clazz) { 32 | this.clazz = clazz; 33 | } 34 | 35 | public String getAlias() { 36 | return alias; 37 | } 38 | 39 | public void setAlias(String alias) { 40 | this.alias = alias; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) { 46 | return true; 47 | } 48 | if (o == null || getClass() != o.getClass()) { 49 | return false; 50 | } 51 | 52 | AliasDesc aliasDesc = (AliasDesc) o; 53 | 54 | if (alias != null ? !alias.equalsIgnoreCase(aliasDesc.alias) : aliasDesc.alias != null) { 55 | return false; 56 | } 57 | if (clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null) { 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | int result = clazz != null ? clazz.hashCode() : 0; 67 | result = 31 * result + (alias != null ? alias.hashCode() : 0); 68 | return result; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AliasFacade.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.intellij.openapi.components.ServiceManager; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.JavaPsiFacade; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.search.GlobalSearchScope; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.List; 16 | import java.util.Optional; 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public class AliasFacade { 22 | 23 | private Project project; 24 | 25 | private JavaPsiFacade javaPsiFacade; 26 | 27 | private List resolvers; 28 | 29 | public static final AliasFacade getInstance(@NotNull Project project) { 30 | return ServiceManager.getService(project, AliasFacade.class); 31 | } 32 | 33 | public AliasFacade(Project project) { 34 | this.project = project; 35 | this.resolvers = Lists.newArrayList(); 36 | this.javaPsiFacade = JavaPsiFacade.getInstance(project); 37 | initResolvers(); 38 | } 39 | 40 | private void initResolvers() { 41 | try { 42 | Class.forName("com.intellij.spring.model.utils.SpringModelUtils"); 43 | this.registerResolver(AliasResolverFactory.createBeanResolver(project)); 44 | } catch (ClassNotFoundException e) { 45 | } 46 | this.registerResolver(AliasResolverFactory.createSingleAliasResolver(project)); 47 | this.registerResolver(AliasResolverFactory.createConfigPackageResolver(project)); 48 | this.registerResolver(AliasResolverFactory.createAnnotationResolver(project)); 49 | this.registerResolver(AliasResolverFactory.createInnerAliasResolver(project)); 50 | } 51 | 52 | @NotNull 53 | public Optional findPsiClass(@Nullable PsiElement element, @NotNull String shortName) { 54 | PsiClass clazz = javaPsiFacade.findClass(shortName, GlobalSearchScope.allScope(project)); 55 | if (null != clazz) { 56 | return Optional.of(clazz); 57 | } 58 | for (AliasResolver resolver : resolvers) { 59 | for (AliasDesc desc : resolver.getClassAliasDescriptions(element)) { 60 | if (shortName.equalsIgnoreCase(desc.getAlias())) { 61 | return Optional.of(desc.getClazz()); 62 | } 63 | } 64 | } 65 | return Optional.empty(); 66 | } 67 | 68 | @NotNull 69 | public Collection getAliasDescs(@Nullable PsiElement element) { 70 | ArrayList result = Lists.newArrayList(); 71 | for (AliasResolver resolver : resolvers) { 72 | result.addAll(resolver.getClassAliasDescriptions(element)); 73 | } 74 | return result; 75 | } 76 | 77 | public Optional findAliasDesc(@Nullable PsiClass clazz) { 78 | if (clazz == null) { 79 | return Optional.empty(); 80 | } 81 | for (AliasResolver resolver : resolvers) { 82 | for (AliasDesc desc : resolver.getClassAliasDescriptions(clazz)) { 83 | if (clazz.equals(desc.getClazz())) { 84 | return Optional.of(desc); 85 | } 86 | } 87 | } 88 | return Optional.empty(); 89 | } 90 | 91 | public void registerResolver(@NotNull AliasResolver resolver) { 92 | this.resolvers.add(resolver); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.intellij.openapi.project.Project; 4 | import com.intellij.psi.PsiClass; 5 | import com.intellij.psi.PsiElement; 6 | import com.wuzhizhan.mybatis.util.JavaUtils; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Optional; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public abstract class AliasResolver { 17 | 18 | protected Project project; 19 | 20 | public AliasResolver(Project project) { 21 | this.project = project; 22 | } 23 | 24 | @NotNull 25 | protected Optional addAliasDesc(@NotNull Set descs, @Nullable PsiClass clazz, @Nullable String alias) { 26 | if (null == alias || !JavaUtils.isModelClazz(clazz)) { 27 | return Optional.empty(); 28 | } 29 | AliasDesc desc = new AliasDesc(); 30 | descs.add(desc); 31 | desc.setClazz(clazz); 32 | desc.setAlias(alias); 33 | return Optional.of(desc); 34 | } 35 | 36 | @NotNull 37 | public abstract Set getClassAliasDescriptions(@Nullable PsiElement element); 38 | 39 | public Project getProject() { 40 | return project; 41 | } 42 | 43 | public void setProject(Project project) { 44 | this.project = project; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AliasResolverFactory.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.intellij.openapi.project.Project; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | /** 7 | * @author yanglin 8 | */ 9 | public class AliasResolverFactory { 10 | 11 | @NotNull 12 | public static AliasResolver createInnerAliasResolver(@NotNull Project project) { 13 | return new InnerAliasResolver(project); 14 | } 15 | 16 | @NotNull 17 | public static AliasResolver createAnnotationResolver(@NotNull Project project) { 18 | return new AnnotationAliasResolver(project); 19 | } 20 | 21 | @NotNull 22 | public static AliasResolver createBeanResolver(@NotNull Project project) { 23 | return new BeanAliasResolver(project); 24 | } 25 | 26 | @NotNull 27 | public static AliasResolver createConfigPackageResolver(@NotNull Project project) { 28 | return new ConfigPackageAliasResolver(project); 29 | } 30 | 31 | @NotNull 32 | public static AliasResolver createSingleAliasResolver(@NotNull Project project) { 33 | return new SingleAliasResolver(project); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/AnnotationAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.Collections2; 5 | import com.google.common.collect.Sets; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.search.GlobalSearchScope; 10 | import com.intellij.psi.search.searches.AnnotatedElementsSearch; 11 | import com.wuzhizhan.mybatis.annotation.Annotation; 12 | import com.wuzhizhan.mybatis.util.JavaUtils; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | 16 | import java.util.Collection; 17 | import java.util.Collections; 18 | import java.util.Optional; 19 | import java.util.Set; 20 | 21 | /** 22 | * @author yanglin 23 | */ 24 | public class AnnotationAliasResolver extends AliasResolver { 25 | 26 | private static final Function FUN = new Function() { 27 | @Override 28 | public AliasDesc apply(PsiClass psiClass) { 29 | Optional txt = JavaUtils.getAnnotationValueText(psiClass, Annotation.ALIAS); 30 | if (!txt.isPresent()) return null; 31 | AliasDesc ad = new AliasDesc(); 32 | ad.setAlias(txt.get()); 33 | ad.setClazz(psiClass); 34 | return ad; 35 | } 36 | }; 37 | 38 | public AnnotationAliasResolver(Project project) { 39 | super(project); 40 | } 41 | 42 | public static final AnnotationAliasResolver getInstance(@NotNull Project project) { 43 | return project.getComponent(AnnotationAliasResolver.class); 44 | } 45 | 46 | @NotNull 47 | @Override 48 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 49 | Optional clazz = Annotation.ALIAS.toPsiClass(project); 50 | if (clazz.isPresent()) { 51 | Collection res = AnnotatedElementsSearch.searchPsiClasses(clazz.get(), GlobalSearchScope.allScope(project)).findAll(); 52 | return Sets.newHashSet(Collections2.transform(res, FUN)); 53 | } 54 | return Collections.emptySet(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/BeanAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.Sets; 4 | import com.intellij.openapi.module.Module; 5 | import com.intellij.openapi.module.ModuleManager; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.spring.CommonSpringModel; 10 | import com.intellij.spring.SpringManager; 11 | import com.intellij.spring.model.SpringBeanPointer; 12 | import com.intellij.spring.model.utils.SpringPropertyUtils; 13 | import com.intellij.spring.model.xml.beans.SpringPropertyDefinition; 14 | import com.wuzhizhan.mybatis.util.JavaUtils; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | import java.util.Collection; 19 | import java.util.Optional; 20 | import java.util.Set; 21 | 22 | /** 23 | * @author yanglin 24 | */ 25 | public class BeanAliasResolver extends PackageAliasResolver { 26 | 27 | private static final String MAPPER_ALIAS_PACKAGE_CLASS = "org.mybatis.spring.SqlSessionFactoryBean"; 28 | private static final String MAPPER_ALIAS_PROPERTY = "typeAliasesPackage"; 29 | private ModuleManager moduleManager; 30 | private SpringManager springManager; 31 | 32 | public BeanAliasResolver(Project project) { 33 | super(project); 34 | this.moduleManager = ModuleManager.getInstance(project); 35 | this.springManager = SpringManager.getInstance(project); 36 | } 37 | 38 | @NotNull 39 | @Override 40 | public Collection getPackages(@Nullable PsiElement element) { 41 | Set res = Sets.newHashSet(); 42 | for (Module module : moduleManager.getModules()) { 43 | for (CommonSpringModel springModel : springManager.getCombinedModel(module).getRelatedModels()) { 44 | addPackages(res, springModel); 45 | } 46 | } 47 | return res; 48 | } 49 | 50 | private void addPackages(Set res, CommonSpringModel springModel) { 51 | Optional sqlSessionFactoryClazzOpt = JavaUtils.findClazz(project, MAPPER_ALIAS_PACKAGE_CLASS); 52 | if (sqlSessionFactoryClazzOpt.isPresent()) { 53 | Collection domBeans = springModel.getAllCommonBeans(); 54 | PsiClass sqlSessionFactoryClazz = (PsiClass) sqlSessionFactoryClazzOpt.get(); 55 | 56 | for (Object domBean : domBeans) { 57 | SpringBeanPointer pointer = (SpringBeanPointer) domBean; 58 | PsiClass beanClass = pointer.getBeanClass(); 59 | if (beanClass != null && beanClass.equals(sqlSessionFactoryClazz)) { 60 | SpringPropertyDefinition basePackages = SpringPropertyUtils.findPropertyByName(pointer.getSpringBean(), MAPPER_ALIAS_PROPERTY); 61 | if (basePackages != null) { 62 | final String value = basePackages.getValueElement().getStringValue(); 63 | if (value != null) { 64 | res.add(value); 65 | } 66 | } 67 | } 68 | } 69 | 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/ConfigPackageAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.util.Processor; 7 | import com.wuzhizhan.mybatis.dom.model.Package; 8 | import com.wuzhizhan.mybatis.util.MapperUtils; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public class ConfigPackageAliasResolver extends PackageAliasResolver { 19 | 20 | public ConfigPackageAliasResolver(Project project) { 21 | super(project); 22 | } 23 | 24 | @NotNull 25 | @Override 26 | public Collection getPackages(@Nullable PsiElement element) { 27 | final ArrayList result = Lists.newArrayList(); 28 | MapperUtils.processConfiguredPackage(project, new Processor() { 29 | @Override 30 | public boolean process(Package pkg) { 31 | result.add(pkg.getName().getStringValue()); 32 | return true; 33 | } 34 | }); 35 | return result; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/InnerAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiElement; 6 | import com.wuzhizhan.mybatis.util.JavaUtils; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Set; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class InnerAliasResolver extends AliasResolver { 16 | 17 | private final Set innerAliasDescs = ImmutableSet.of( 18 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.String").get(), "string"), 19 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Byte").get(), "byte"), 20 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Long").get(), "long"), 21 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Short").get(), "short"), 22 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Integer").get(), "int"), 23 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Integer").get(), "integer"), 24 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Double").get(), "double"), 25 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Float").get(), "float"), 26 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Boolean").get(), "boolean"), 27 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.Date").get(), "date"), 28 | AliasDesc.create(JavaUtils.findClazz(project, "java.math.BigDecimal").get(), "decimal"), 29 | AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Object").get(), "object"), 30 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.Map").get(), "map"), 31 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.HashMap").get(), "hashmap"), 32 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.List").get(), "list"), 33 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.ArrayList").get(), "arraylist"), 34 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.Collection").get(), "collection"), 35 | AliasDesc.create(JavaUtils.findClazz(project, "java.util.Iterator").get(), "iterator") 36 | ); 37 | 38 | public InnerAliasResolver(Project project) { 39 | super(project); 40 | } 41 | 42 | @NotNull 43 | @Override 44 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 45 | return innerAliasDescs; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/PackageAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.Sets; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.JavaPsiFacade; 6 | import com.intellij.psi.PsiClass; 7 | import com.intellij.psi.PsiElement; 8 | import com.intellij.psi.PsiPackage; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.Collection; 13 | import java.util.Set; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public abstract class PackageAliasResolver extends AliasResolver { 19 | 20 | private JavaPsiFacade javaPsiFacade; 21 | 22 | public PackageAliasResolver(Project project) { 23 | super(project); 24 | this.javaPsiFacade = JavaPsiFacade.getInstance(project); 25 | } 26 | 27 | @NotNull 28 | @Override 29 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 30 | Set result = Sets.newHashSet(); 31 | for (String pkgName : getPackages(element)) { 32 | if (null == pkgName) { 33 | continue; 34 | } 35 | PsiPackage pkg = javaPsiFacade.findPackage(pkgName); 36 | if (null != pkg) { 37 | addAliasDesc(result, pkg); 38 | for (PsiPackage tmp : pkg.getSubPackages()) { 39 | addAliasDesc(result, tmp); 40 | } 41 | } 42 | } 43 | return result; 44 | } 45 | 46 | private void addAliasDesc(Set result, PsiPackage pkg) { 47 | for (PsiClass clazz : pkg.getClasses()) { 48 | addAliasDesc(result, clazz, clazz.getName()); 49 | } 50 | } 51 | 52 | @NotNull 53 | public abstract Collection getPackages(@Nullable PsiElement element); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/alias/SingleAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.alias; 2 | 3 | import com.google.common.collect.Sets; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.util.Processor; 7 | import com.wuzhizhan.mybatis.dom.model.TypeAlias; 8 | import com.wuzhizhan.mybatis.util.MapperUtils; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.Set; 13 | 14 | /** 15 | * @author yanglin 16 | */ 17 | public class SingleAliasResolver extends AliasResolver { 18 | 19 | public SingleAliasResolver(Project project) { 20 | super(project); 21 | } 22 | 23 | @NotNull 24 | @Override 25 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 26 | final Set result = Sets.newHashSet(); 27 | MapperUtils.processConfiguredTypeAliases(project, new Processor() { 28 | @Override 29 | public boolean process(TypeAlias typeAlias) { 30 | addAliasDesc(result, typeAlias.getType().getValue(), typeAlias.getAlias().getStringValue()); 31 | return true; 32 | } 33 | }); 34 | return result; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/annotation/Annotation.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.annotation; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.collect.Iterables; 5 | import com.google.common.collect.Maps; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.JavaPsiFacade; 8 | import com.intellij.psi.PsiClass; 9 | import com.intellij.psi.search.GlobalSearchScope; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.util.Map; 13 | import java.util.Optional; 14 | import java.util.Set; 15 | 16 | /** 17 | * Simple implementation 18 | * 19 | * @author yanglin 20 | */ 21 | public class Annotation implements Cloneable { 22 | 23 | public static final Annotation PARAM = new Annotation("@Param", "org.apache.ibatis.annotations.Param"); 24 | 25 | public static final Annotation SELECT = new Annotation("@Select", "org.apache.ibatis.annotations.Select"); 26 | 27 | public static final Annotation UPDATE = new Annotation("@Update", "org.apache.ibatis.annotations.Update"); 28 | 29 | public static final Annotation INSERT = new Annotation("@Insert", "org.apache.ibatis.annotations.Insert"); 30 | 31 | public static final Annotation DELETE = new Annotation("@Delete", "org.apache.ibatis.annotations.Delete"); 32 | 33 | public static final Annotation ALIAS = new Annotation("@Alias", "org.apache.ibatis.type.Alias"); 34 | 35 | public static final Annotation AUTOWIRED = new Annotation("@Autowired", "org.springframework.beans.factory.annotation.Autowired"); 36 | 37 | public static final Annotation RESOURCE = new Annotation("@Resource", "javax.annotation.Resource"); 38 | 39 | public static final Set STATEMENT_SYMMETRIES = ImmutableSet.of(SELECT, UPDATE, INSERT, DELETE); 40 | 41 | private final String label; 42 | 43 | private final String qualifiedName; 44 | 45 | private Map attributePairs; 46 | 47 | public interface AnnotationValue { 48 | } 49 | 50 | public static class StringValue implements AnnotationValue { 51 | 52 | private String value; 53 | 54 | public StringValue(@NotNull String value) { 55 | this.value = value; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "\"" + value + "\""; 61 | } 62 | 63 | } 64 | 65 | public Annotation(@NotNull String label, @NotNull String qualifiedName) { 66 | this.label = label; 67 | this.qualifiedName = qualifiedName; 68 | attributePairs = Maps.newHashMap(); 69 | } 70 | 71 | private Annotation addAttribute(String key, AnnotationValue value) { 72 | this.attributePairs.put(key, value); 73 | return this; 74 | } 75 | 76 | public Annotation withAttribute(@NotNull String key, @NotNull AnnotationValue value) { 77 | Annotation copy = this.clone(); 78 | copy.attributePairs = Maps.newHashMap(this.attributePairs); 79 | return copy.addAttribute(key, value); 80 | } 81 | 82 | public Annotation withValue(@NotNull AnnotationValue value) { 83 | return withAttribute("value", value); 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | StringBuilder builder = new StringBuilder(label); 89 | if (!Iterables.isEmpty(attributePairs.entrySet())) { 90 | builder.append(setupAttributeText()); 91 | } 92 | return builder.toString(); 93 | } 94 | 95 | private String setupAttributeText() { 96 | Optional singleValue = getSingleValue(); 97 | return singleValue.isPresent() ? singleValue.get() : getComplexValue(); 98 | } 99 | 100 | private String getComplexValue() { 101 | StringBuilder builder = new StringBuilder("("); 102 | for (String key : attributePairs.keySet()) { 103 | builder.append(key); 104 | builder.append(" = "); 105 | builder.append(attributePairs.get(key).toString()); 106 | builder.append(", "); 107 | } 108 | builder.deleteCharAt(builder.length() - 1); 109 | builder.deleteCharAt(builder.length() - 1); 110 | builder.append(")"); 111 | return builder.toString(); 112 | } 113 | 114 | @NotNull 115 | public Optional toPsiClass(@NotNull Project project) { 116 | return Optional.ofNullable(JavaPsiFacade.getInstance(project).findClass(getQualifiedName(), GlobalSearchScope.allScope(project))); 117 | } 118 | 119 | private Optional getSingleValue() { 120 | try { 121 | String value = Iterables.getOnlyElement(attributePairs.keySet()); 122 | StringBuilder builder = new StringBuilder("("); 123 | builder.append(attributePairs.get(value).toString()); 124 | builder.append(")"); 125 | return Optional.of(builder.toString()); 126 | } catch (Exception e) { 127 | return Optional.empty(); 128 | } 129 | } 130 | 131 | @NotNull 132 | public String getLabel() { 133 | return label; 134 | } 135 | 136 | @NotNull 137 | public String getQualifiedName() { 138 | return qualifiedName; 139 | } 140 | 141 | @Override 142 | protected Annotation clone() { 143 | try { 144 | return (Annotation) super.clone(); 145 | } catch (CloneNotSupportedException e) { 146 | throw new IllegalStateException(); 147 | } 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/contributor/JavaMenthodCompletionContributor.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.contributor; 2 | 3 | import com.intellij.codeInsight.completion.CompletionContributor; 4 | import com.intellij.codeInsight.completion.CompletionParameters; 5 | import com.intellij.codeInsight.completion.CompletionResultSet; 6 | import com.intellij.codeInsight.completion.CompletionType; 7 | 8 | public class JavaMenthodCompletionContributor extends CompletionContributor { 9 | @Override 10 | public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) { 11 | if (parameters.getCompletionType() != CompletionType.BASIC) { 12 | return; 13 | } 14 | 15 | //todo 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/contributor/SqlParamCompletionContributor.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.contributor; 2 | 3 | import com.intellij.codeInsight.completion.CompletionContributor; 4 | import com.intellij.codeInsight.completion.CompletionParameters; 5 | import com.intellij.codeInsight.completion.CompletionResultSet; 6 | import com.intellij.codeInsight.completion.CompletionType; 7 | import com.intellij.injected.editor.DocumentWindow; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.PsiFile; 10 | import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; 11 | import com.wuzhizhan.mybatis.dom.model.IdDomElement; 12 | import com.wuzhizhan.mybatis.util.DomUtils; 13 | import com.wuzhizhan.mybatis.util.MapperUtils; 14 | 15 | import java.util.Optional; 16 | 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public class SqlParamCompletionContributor extends CompletionContributor { 22 | 23 | @Override 24 | public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) { 25 | if (parameters.getCompletionType() != CompletionType.BASIC) { 26 | return; 27 | } 28 | 29 | PsiElement position = parameters.getPosition(); 30 | PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(position); 31 | if (DomUtils.isMybatisFile(topLevelFile)) { 32 | if (shouldAddElement(position.getContainingFile(), parameters.getOffset())) { 33 | process(topLevelFile, result, position); 34 | } 35 | } 36 | } 37 | 38 | private void process(PsiFile xmlFile, CompletionResultSet result, PsiElement position) { 39 | DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(position); 40 | if (null != documentWindow) { 41 | int offset = documentWindow.injectedToHost(position.getTextOffset()); 42 | Optional idDomElement = MapperUtils.findParentIdDomElement(xmlFile.findElementAt(offset)); 43 | if (idDomElement.isPresent()) { 44 | TestParamContributor.addElementForPsiParameter(position.getProject(), result, idDomElement.get()); 45 | result.stopHere(); 46 | } 47 | } 48 | } 49 | 50 | private boolean shouldAddElement(PsiFile file, int offset) { 51 | String text = file.getText(); 52 | for (int i = offset - 1; i > 0; i--) { 53 | char c = text.charAt(i); 54 | if (c == '{' && text.charAt(i - 1) == '#') return true; 55 | } 56 | return false; 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/contributor/TestParamContributor.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.contributor; 2 | 3 | import com.intellij.codeInsight.completion.*; 4 | import com.intellij.codeInsight.lookup.LookupElement; 5 | import com.intellij.codeInsight.lookup.LookupElementBuilder; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.patterns.XmlPatterns; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.PsiMethod; 10 | import com.intellij.psi.PsiParameter; 11 | import com.intellij.util.ProcessingContext; 12 | import com.wuzhizhan.mybatis.annotation.Annotation; 13 | import com.wuzhizhan.mybatis.dom.model.IdDomElement; 14 | import com.wuzhizhan.mybatis.util.Icons; 15 | import com.wuzhizhan.mybatis.util.JavaUtils; 16 | import com.wuzhizhan.mybatis.util.MapperUtils; 17 | import com.wuzhizhan.mybatis.util.MybatisConstants; 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.util.Optional; 24 | 25 | /** 26 | * @author yanglin 27 | */ 28 | public class TestParamContributor extends CompletionContributor { 29 | private static final Logger logger = LoggerFactory.getLogger(TestParamContributor.class); 30 | 31 | public TestParamContributor() { 32 | extend(CompletionType.BASIC, 33 | XmlPatterns.psiElement() 34 | .inside(XmlPatterns.xmlAttributeValue() 35 | .inside(XmlPatterns.xmlAttribute().withName("test"))), 36 | new CompletionProvider() { 37 | @Override 38 | protected void addCompletions( 39 | @NotNull final CompletionParameters parameters, 40 | final ProcessingContext context, 41 | @NotNull final CompletionResultSet result) { 42 | final PsiElement position = parameters.getPosition(); 43 | addElementForPsiParameter( 44 | position.getProject(), 45 | result, 46 | MapperUtils.findParentIdDomElement(position).orElse(null)); 47 | } 48 | }); 49 | } 50 | 51 | static void addElementForPsiParameter( 52 | @NotNull final Project project, 53 | @NotNull final CompletionResultSet result, 54 | @Nullable final IdDomElement element) { 55 | if (element == null) { 56 | return; 57 | } 58 | 59 | final PsiMethod method = JavaUtils.findMethod(project, element).orElse(null); 60 | 61 | if (method == null) { 62 | logger.info("psiMethod null"); 63 | return; 64 | } 65 | 66 | final PsiParameter[] parameters = method.getParameterList().getParameters(); 67 | 68 | // For a single parameter MyBatis uses its name, while for a multitude they're 69 | // named as param1, param2, etc. I'll check if the @Param annotation [value] is present 70 | // and eventually I'll use its text. 71 | if (parameters.length == 1) { 72 | final PsiParameter parameter = parameters[0]; 73 | result.addElement(buildLookupElementWithIcon( 74 | parameter.getName(), 75 | parameter.getType().getPresentableText())); 76 | } else { 77 | for (int i = 0; i < parameters.length; i++) { 78 | final PsiParameter parameter = parameters[i]; 79 | final Optional value = JavaUtils.getAnnotationValueText(parameter, Annotation.PARAM); 80 | result.addElement(buildLookupElementWithIcon( 81 | value.isPresent() ? value.get() : "param" + (i + 1), 82 | parameter.getType().getPresentableText())); 83 | } 84 | } 85 | } 86 | 87 | private static LookupElement buildLookupElementWithIcon( 88 | final String parameterName, 89 | final String parameterType) { 90 | return PrioritizedLookupElement.withPriority( 91 | LookupElementBuilder.create(parameterName) 92 | .withTypeText(parameterType) 93 | .withIcon(Icons.PARAM_COMPLETION_ICON), 94 | MybatisConstants.PRIORITY); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/definitionsearch/MapperDefinitionSearch.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.definitionsearch; 2 | 3 | import com.intellij.openapi.application.QueryExecutorBase; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiTypeParameterListOwner; 6 | import com.intellij.psi.xml.XmlElement; 7 | import com.intellij.util.Processor; 8 | import com.intellij.util.xml.DomElement; 9 | import com.wuzhizhan.mybatis.service.JavaService; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class MapperDefinitionSearch extends QueryExecutorBase { 17 | 18 | public MapperDefinitionSearch() { 19 | super(true); 20 | } 21 | 22 | @Override 23 | public void processQuery(@NotNull PsiElement queryParameters, @NotNull Processor consumer) { 24 | if (!(queryParameters instanceof PsiTypeParameterListOwner)) return; 25 | 26 | Processor processor = domElement -> consumer.process(domElement.getXmlElement()); 27 | 28 | JavaService.getInstance(queryParameters.getProject()).process(queryParameters, processor); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/MapperBacktrackingUtils.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.util.PsiTreeUtil; 5 | import com.intellij.psi.xml.XmlAttributeValue; 6 | import com.intellij.psi.xml.XmlElement; 7 | import com.intellij.psi.xml.XmlTag; 8 | import com.intellij.util.xml.DomElement; 9 | import com.intellij.util.xml.DomUtil; 10 | import com.wuzhizhan.mybatis.dom.model.Association; 11 | import com.wuzhizhan.mybatis.dom.model.Collection; 12 | import com.wuzhizhan.mybatis.dom.model.ParameterMap; 13 | import com.wuzhizhan.mybatis.dom.model.ResultMap; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import java.util.Optional; 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public final class MapperBacktrackingUtils { 22 | 23 | private MapperBacktrackingUtils() { 24 | throw new UnsupportedOperationException(); 25 | } 26 | 27 | public static Optional getPropertyClazz(XmlAttributeValue attributeValue) { 28 | DomElement domElement = DomUtil.getDomElement(attributeValue); 29 | if (null == domElement) { 30 | return Optional.empty(); 31 | } 32 | 33 | Collection collection = DomUtil.getParentOfType(domElement, Collection.class, true); 34 | if (null != collection && !isWithinSameTag(collection, attributeValue)) { 35 | return Optional.ofNullable(collection.getOfType().getValue()); 36 | } 37 | 38 | Association association = DomUtil.getParentOfType(domElement, Association.class, true); 39 | if (null != association && !isWithinSameTag(association, attributeValue)) { 40 | return Optional.ofNullable(association.getJavaType().getValue()); 41 | } 42 | 43 | ParameterMap parameterMap = DomUtil.getParentOfType(domElement, ParameterMap.class, true); 44 | if (null != parameterMap && !isWithinSameTag(parameterMap, attributeValue)) { 45 | return Optional.ofNullable(parameterMap.getType().getValue()); 46 | } 47 | 48 | ResultMap resultMap = DomUtil.getParentOfType(domElement, ResultMap.class, true); 49 | if (null != resultMap && !isWithinSameTag(resultMap, attributeValue)) { 50 | return Optional.ofNullable(resultMap.getType().getValue()); 51 | } 52 | return Optional.empty(); 53 | } 54 | 55 | public static boolean isWithinSameTag(@NotNull DomElement domElement, @NotNull XmlElement xmlElement) { 56 | XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class); 57 | return null != xmlElement && domElement.getXmlTag().equals(xmlTag); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/AliasConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.openapi.util.text.StringUtil; 4 | import com.intellij.psi.PsiClass; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.psi.PsiReference; 7 | import com.intellij.psi.search.GlobalSearchScope; 8 | import com.intellij.psi.xml.XmlAttributeValue; 9 | import com.intellij.util.xml.*; 10 | import com.wuzhizhan.mybatis.alias.AliasClassReference; 11 | import com.wuzhizhan.mybatis.alias.AliasFacade; 12 | import com.wuzhizhan.mybatis.util.MybatisConstants; 13 | import org.jetbrains.annotations.NonNls; 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.Nullable; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public class AliasConverter extends ConverterAdaptor implements CustomReferenceConverter { 21 | 22 | private PsiClassConverter delegate = new PsiClassConverter(); 23 | 24 | @Nullable 25 | @Override 26 | public PsiClass fromString(@Nullable @NonNls String s, ConvertContext context) { 27 | if (StringUtil.isEmptyOrSpaces(s)) return null; 28 | if (!s.contains(MybatisConstants.DOT_SEPARATOR)) { 29 | return AliasFacade.getInstance(context.getProject()).findPsiClass(context.getXmlElement(), s).orElse(null); 30 | } 31 | return DomJavaUtil.findClass(s.trim(), context.getFile(), context.getModule(), GlobalSearchScope.allScope(context.getProject())); 32 | } 33 | 34 | @Nullable 35 | @Override 36 | public String toString(@Nullable PsiClass psiClass, ConvertContext context) { 37 | return delegate.toString(psiClass, context); 38 | } 39 | 40 | @NotNull 41 | @Override 42 | public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) { 43 | if (((XmlAttributeValue) element).getValue().contains(MybatisConstants.DOT_SEPARATOR)) { 44 | return delegate.createReferences(value, element, context); 45 | } else { 46 | return new PsiReference[]{new AliasClassReference((XmlAttributeValue) element)}; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/ConverterAdaptor.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.intellij.util.xml.ResolvingConverter; 5 | import org.jetbrains.annotations.NonNls; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.util.Collection; 10 | import java.util.Collections; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public abstract class ConverterAdaptor extends ResolvingConverter { 16 | 17 | @NotNull 18 | @Override 19 | public Collection getVariants(ConvertContext context) { 20 | return Collections.emptyList(); 21 | } 22 | 23 | @Nullable 24 | @Override 25 | public String toString(@Nullable T t, ConvertContext context) { 26 | // throw new UnsupportedOperationException(); 27 | return null; 28 | } 29 | 30 | @Nullable 31 | @Override 32 | public T fromString(@Nullable @NonNls String s, ConvertContext context) { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/DaoMethodConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.psi.PsiMethod; 4 | import com.intellij.util.xml.ConvertContext; 5 | import com.wuzhizhan.mybatis.dom.model.Mapper; 6 | import com.wuzhizhan.mybatis.util.JavaUtils; 7 | import com.wuzhizhan.mybatis.util.MapperUtils; 8 | import org.jetbrains.annotations.NonNls; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class DaoMethodConverter extends ConverterAdaptor { 15 | 16 | @Nullable 17 | @Override 18 | public PsiMethod fromString(@Nullable @NonNls String id, ConvertContext context) { 19 | Mapper mapper = MapperUtils.getMapper(context.getInvocationElement()); 20 | return JavaUtils.findMethod(context.getProject(), MapperUtils.getNamespace(mapper), id).orElse(null); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/ParameterMapConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.wuzhizhan.mybatis.dom.model.IdDomElement; 5 | import com.wuzhizhan.mybatis.dom.model.Mapper; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.util.Collection; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class ParameterMapConverter extends IdBasedTagConverter { 15 | 16 | @NotNull 17 | @Override 18 | public Collection getComparisons(@Nullable Mapper mapper, 19 | ConvertContext context) { 20 | return mapper.getParameterMaps(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/PropertyConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.psi.ElementManipulators; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiReference; 6 | import com.intellij.psi.xml.XmlAttributeValue; 7 | import com.intellij.util.xml.*; 8 | import com.wuzhizhan.mybatis.reference.ResultPropertyReferenceSet; 9 | import org.jetbrains.annotations.NonNls; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class PropertyConverter extends ConverterAdaptor implements CustomReferenceConverter { 17 | 18 | @NotNull 19 | @Override 20 | public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) { 21 | final String s = value.getStringValue(); 22 | if (s == null) { 23 | return PsiReference.EMPTY_ARRAY; 24 | } 25 | return new ResultPropertyReferenceSet(s, element, ElementManipulators.getOffsetInElement(element)).getPsiReferences(); 26 | } 27 | 28 | @Nullable 29 | @Override 30 | public XmlAttributeValue fromString(@Nullable @NonNls String s, ConvertContext context) { 31 | DomElement ctxElement = context.getInvocationElement(); 32 | return ctxElement instanceof GenericAttributeValue ? ((GenericAttributeValue) ctxElement).getXmlAttributeValue() : null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/ResultMapConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.google.common.base.Predicate; 4 | import com.google.common.collect.Collections2; 5 | import com.intellij.util.xml.ConvertContext; 6 | import com.intellij.util.xml.DomElement; 7 | import com.wuzhizhan.mybatis.dom.model.IdDomElement; 8 | import com.wuzhizhan.mybatis.dom.model.Mapper; 9 | import com.wuzhizhan.mybatis.dom.model.ResultMap; 10 | import com.wuzhizhan.mybatis.util.MapperUtils; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.Collection; 15 | 16 | /** 17 | * @author yanglin 18 | */ 19 | public class ResultMapConverter extends IdBasedTagConverter { 20 | 21 | @NotNull 22 | @Override 23 | public Collection getComparisons(@Nullable Mapper mapper, ConvertContext context) { 24 | DomElement invocationElement = context.getInvocationElement(); 25 | if (isContextElementOfResultMap(mapper, invocationElement)) { 26 | return doFilterResultMapItself(mapper, (ResultMap) invocationElement.getParent()); 27 | } else { 28 | return mapper.getResultMaps(); 29 | } 30 | } 31 | 32 | private boolean isContextElementOfResultMap(Mapper mapper, DomElement invocationElement) { 33 | return MapperUtils.isMapperWithSameNamespace(MapperUtils.getMapper(invocationElement), mapper) 34 | && invocationElement.getParent() instanceof ResultMap; 35 | } 36 | 37 | private Collection doFilterResultMapItself(Mapper mapper, final ResultMap resultMap) { 38 | return Collections2.filter(mapper.getResultMaps(), new Predicate() { 39 | @Override 40 | public boolean apply(ResultMap input) { 41 | return !MapperUtils.getId(input).equals(MapperUtils.getId(resultMap)); 42 | } 43 | }); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/converter/SqlConverter.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.wuzhizhan.mybatis.dom.model.IdDomElement; 5 | import com.wuzhizhan.mybatis.dom.model.Mapper; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.util.Collection; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class SqlConverter extends IdBasedTagConverter { 15 | 16 | @NotNull 17 | @Override 18 | public Collection getComparisons(@Nullable Mapper mapper, ConvertContext context) { 19 | return mapper.getSqls(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/description/ConfigurationDescription.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.description; 2 | 3 | import com.intellij.openapi.module.Module; 4 | import com.intellij.psi.xml.XmlFile; 5 | import com.intellij.util.xml.DomFileDescription; 6 | import com.wuzhizhan.mybatis.dom.model.Configuration; 7 | import com.wuzhizhan.mybatis.util.DomUtils; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class ConfigurationDescription extends DomFileDescription { 15 | 16 | public ConfigurationDescription() { 17 | super(Configuration.class, "configuration"); 18 | } 19 | 20 | @Override 21 | public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) { 22 | return DomUtils.isMybatisConfigurationFile(file); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/description/MapperDescription.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.description; 2 | 3 | import com.intellij.openapi.module.Module; 4 | import com.intellij.psi.xml.XmlFile; 5 | import com.intellij.util.xml.DomFileDescription; 6 | import com.wuzhizhan.mybatis.dom.model.Mapper; 7 | import com.wuzhizhan.mybatis.util.DomUtils; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class MapperDescription extends DomFileDescription { 15 | 16 | public MapperDescription() { 17 | super(Mapper.class, "mapper"); 18 | } 19 | 20 | @Override 21 | public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) { 22 | return DomUtils.isMybatisFile(file); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Arg.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public interface Arg extends DomElement { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Association.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.wuzhizhan.mybatis.dom.converter.AliasConverter; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public interface Association extends GroupFour, ResultMapGroup, PropertyGroup { 14 | 15 | @NotNull 16 | @Attribute("javaType") 17 | @Convert(AliasConverter.class) 18 | public GenericAttributeValue getJavaType(); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Bean.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Bean extends DomElement { 13 | 14 | @NotNull 15 | @SubTagList("property") 16 | public List getBeanProperties(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/BeanProperty.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.DomElement; 5 | import com.intellij.util.xml.GenericAttributeValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface BeanProperty extends DomElement { 12 | 13 | @NotNull 14 | @Attribute("name") 15 | public GenericAttributeValue getName(); 16 | 17 | @NotNull 18 | @Attribute("value") 19 | public GenericAttributeValue getValue(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Beans.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Beans extends DomElement { 13 | 14 | @NotNull 15 | @SubTagList("bean") 16 | public List getBeans(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Bind.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public interface Bind extends DomElement { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Cache.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface Cache extends DomElement { 12 | 13 | @SubTagList("property") 14 | public List getProperties(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/CacheRef.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public interface CacheRef extends DomElement { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Case.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Case extends GroupFour { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Choose.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.Required; 5 | import com.intellij.util.xml.SubTag; 6 | import com.intellij.util.xml.SubTagList; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface Choose extends DomElement { 15 | 16 | @NotNull 17 | @Required 18 | @SubTagList("when") 19 | public List getWhens(); 20 | 21 | @SubTag("otherwise") 22 | public Otherwise getOtherwise(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Collection.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.wuzhizhan.mybatis.dom.converter.AliasConverter; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public interface Collection extends GroupFour, ResultMapGroup, PropertyGroup { 14 | 15 | @NotNull 16 | @Attribute("ofType") 17 | @Convert(AliasConverter.class) 18 | public GenericAttributeValue getOfType(); 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Configuration extends DomElement { 13 | 14 | @NotNull 15 | @SubTagList("typeAliases") 16 | public List getTypeAliases(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Constructor.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface Constructor extends DomElement { 12 | 13 | @SubTagList("arg") 14 | public List getArgs(); 15 | 16 | @SubTagList("idArg") 17 | public List getIdArgs(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Delete.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Delete extends GroupTwo { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Discriminator.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.Required; 5 | import com.intellij.util.xml.SubTagList; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Discriminator extends DomElement { 13 | 14 | @Required 15 | @SubTagList("case") 16 | public List getCases(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Foreach.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Foreach extends GroupOne { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/GroupFour.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTag; 5 | import com.intellij.util.xml.SubTagList; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface GroupFour extends DomElement { 13 | 14 | @SubTag("constructor") 15 | public Constructor getConstructor(); 16 | 17 | @SubTagList("id") 18 | public List getIds(); 19 | 20 | @SubTagList("result") 21 | public List getResults(); 22 | 23 | @SubTagList("association") 24 | public List getAssociations(); 25 | 26 | @SubTagList("collection") 27 | public List getCollections(); 28 | 29 | @SubTag("discriminator") 30 | public Discriminator getDiscriminator(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/GroupOne.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | import com.intellij.util.xml.SubTagList; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface GroupOne extends DomElement { 13 | 14 | @NotNull 15 | @SubTagList("include") 16 | public List getIncludes(); 17 | 18 | @NotNull 19 | @SubTagList("trim") 20 | public List getTrims(); 21 | 22 | @NotNull 23 | @SubTagList("where") 24 | public List getWheres(); 25 | 26 | @NotNull 27 | @SubTagList("set") 28 | public List getSets(); 29 | 30 | @NotNull 31 | @SubTagList("foreach") 32 | public List getForeachs(); 33 | 34 | @NotNull 35 | @SubTagList("choose") 36 | public List getChooses(); 37 | 38 | @NotNull 39 | @SubTagList("if") 40 | public List getIfs(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/GroupThree.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public interface GroupThree extends GroupTwo { 11 | 12 | @SubTagList("selectKey") 13 | public List getSelectKey(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/GroupTwo.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.xml.XmlTag; 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.GenericAttributeValue; 8 | import com.intellij.util.xml.SubTagList; 9 | import com.wuzhizhan.mybatis.dom.converter.AliasConverter; 10 | import com.wuzhizhan.mybatis.dom.converter.DaoMethodConverter; 11 | import com.wuzhizhan.mybatis.dom.converter.ParameterMapConverter; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @author yanglin 18 | */ 19 | public interface GroupTwo extends GroupOne, IdDomElement { 20 | 21 | @SubTagList("bind") 22 | public List getBinds(); 23 | 24 | @NotNull 25 | @Attribute("parameterMap") 26 | @Convert(ParameterMapConverter.class) 27 | public GenericAttributeValue getParameterMap(); 28 | 29 | @Attribute("id") 30 | @Convert(DaoMethodConverter.class) 31 | public GenericAttributeValue getId(); 32 | 33 | @NotNull 34 | @Attribute("parameterType") 35 | @Convert(AliasConverter.class) 36 | public GenericAttributeValue getParameterType(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Id.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Id extends PropertyGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/IdArg.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.DomElement; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public interface IdArg extends DomElement { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/IdDomElement.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.*; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public interface IdDomElement extends DomElement { 9 | 10 | @Required 11 | @NameValue 12 | @Attribute("id") 13 | public GenericAttributeValue getId(); 14 | 15 | public void setValue(String content); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/If.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface If extends GroupOne { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Include.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlTag; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.DomElement; 7 | import com.intellij.util.xml.GenericAttributeValue; 8 | import com.wuzhizhan.mybatis.dom.converter.SqlConverter; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public interface Include extends DomElement { 14 | 15 | @Attribute("refid") 16 | @Convert(SqlConverter.class) 17 | public GenericAttributeValue getRefId(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Insert.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Insert extends GroupThree { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/wuzhizhan/mybatis/dom/model/Mapper.java: -------------------------------------------------------------------------------- 1 | package com.wuzhizhan.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.*; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface Mapper extends DomElement { 12 | 13 | @NotNull 14 | @SubTagsList({"insert", "update", "delete", "select"}) 15 | public List getDaoElements(); 16 | 17 | @Required 18 | @NameValue 19 | @NotNull 20 | @Attribute("namespace") 21 | public GenericAttributeValue getNamespace(); 22 | 23 | @NotNull 24 | @SubTagList("resultMap") 25 | public List getResultMaps(); 26 | 27 | @NotNull 28 | @SubTagList("parameterMap") 29 | public List getParameterMaps(); 30 | 31 | @NotNull 32 | @SubTagList("sql") 33 | public List getSqls(); 34 | 35 | @NotNull 36 | @SubTagList("insert") 37 | public List getInserts(); 38 | 39 | @NotNull 40 | @SubTagList("update") 41 | public List getUpdates(); 42 | 43 | @NotNull 44 | @SubTagList("delete") 45 | public List getDeletes(); 46 | 47 | @NotNull 48 | @SubTagList("select") 49 | public List