Repository: chuntungho/free-mybatis-plugin
Branch: main
Commit: 055165d101be
Files: 143
Total size: 200.2 KB
Directory structure:
gitextract_isxqlwmr/
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src/
└── main/
├── java/
│ └── com/
│ └── wuzhizhan/
│ └── mybatis/
│ ├── action/
│ │ └── 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
│ │ ├── 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
│ ├── 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
│ │ ├── MybatisSetting.java
│ │ ├── MybatisSettingForm.form
│ │ └── MybatisSettingForm.java
│ ├── template/
│ │ └── MybatisFileTemplateDescriptorFactory.java
│ ├── ui/
│ │ ├── ClickableListener.java
│ │ ├── ExecutableListener.java
│ │ ├── ListSelectionListener.java
│ │ └── UiComponentFacade.java
│ └── util/
│ ├── ArrayUtils.java
│ ├── CollectionUtils.java
│ ├── DomUtils.java
│ ├── Icons.java
│ ├── JTextFieldHintListener.java
│ ├── JavaUtils.java
│ ├── MapperUtils.java
│ ├── MybatisConstants.java
│ └── StringUtils.java
└── resources/
├── META-INF/
│ └── plugin.xml
├── fileTemplates/
│ └── j2ee/
│ └── Mybatis Mapper.xml.ft
└── liveTemplates/
└── sql.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
log.roo
.idea/
out/
.DS_Store
.gradle/
gradle/
build/
out/
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
# free-mybatis-plugin
## Changes:
- Compatible with Intellij IC edition.
- Not to warn static method or the method with mybatis provider annotation.
- Remove MyBatis Generator.
================================================
FILE: build.gradle
================================================
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
mavenLocal()
mavenCentral()
}
}
plugins {
id 'org.jetbrains.intellij' version '1.2.1'
}
group = 'cn.wuzhizhan.idea.mybatis'
version = '2021.12.09'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildPlugin {
buildSearchableOptions.enabled = false
}
intellij {
version = "IC-2019.1"
pluginName = 'free-mybatis-plugin'
sameSinceUntilBuild = false
patchPluginXml {
untilBuild = "299.*"
changeNotes = """
Fix deprecated api alert
"""
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
================================================
FILE: gradlew
================================================
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
================================================
FILE: gradlew.bat
================================================
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
rootProject.name = 'free-mybatis-plugin'
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/action/MybatisTypedHandler.java
================================================
package com.wuzhizhan.mybatis.action;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.wuzhizhan.mybatis.util.DomUtils;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public class MybatisTypedHandler extends TypedHandlerDelegate {
@Override
public Result checkAutoPopup(char charTyped, final Project project, final Editor editor, PsiFile file) {
if (charTyped == '.' && DomUtils.isMybatisFile(file)) {
autoPopupParameter(project, editor);
return Result.STOP;
}
return super.checkAutoPopup(charTyped, project, editor, file);
}
@Override
public Result charTyped(char c, final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
int index = editor.getCaretModel().getOffset() - 2;
PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(file);
boolean parameterCase = c == '{' &&
index >= 0 &&
editor.getDocument().getText().charAt(index) == '#' &&
// file instanceof SqlFile &&
DomUtils.isMybatisFile(topLevelFile);
if (parameterCase) {
autoPopupParameter(project, editor);
return Result.STOP;
}
return super.charTyped(c, project, editor, file);
}
private static void autoPopupParameter(final Project project, final Editor editor) {
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, psiFile -> true);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AliasClassReference.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.xml.XmlAttributeValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* @author yanglin
*/
public class AliasClassReference extends PsiReferenceBase {
private Function function = new Function() {
@Override
public String apply(AliasDesc input) {
return input.getAlias();
}
};
public AliasClassReference(@NotNull XmlAttributeValue element) {
super(element, true);
}
@Nullable
@Override
public PsiElement resolve() {
XmlAttributeValue attributeValue = getElement();
return AliasFacade.getInstance(attributeValue.getProject()).findPsiClass(attributeValue, attributeValue.getValue()).orElse(null);
}
@NotNull
@Override
public Object[] getVariants() {
AliasFacade aliasFacade = AliasFacade.getInstance(getElement().getProject());
Collection result = Collections2.transform(aliasFacade.getAliasDescs(getElement()), function);
return result.toArray(new String[result.size()]);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AliasDesc.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public class AliasDesc {
private PsiClass clazz;
private String alias;
public AliasDesc() {
}
public static AliasDesc create(@NotNull PsiClass psiClass, @NotNull String alias) {
return new AliasDesc(psiClass, alias);
}
public AliasDesc(PsiClass clazz, String alias) {
this.clazz = clazz;
this.alias = alias;
}
public PsiClass getClazz() {
return clazz;
}
public void setClazz(PsiClass clazz) {
this.clazz = clazz;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AliasDesc aliasDesc = (AliasDesc) o;
if (alias != null ? !alias.equalsIgnoreCase(aliasDesc.alias) : aliasDesc.alias != null) {
return false;
}
if (clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = clazz != null ? clazz.hashCode() : 0;
result = 31 * result + (alias != null ? alias.hashCode() : 0);
return result;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AliasFacade.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.Lists;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
/**
* @author yanglin
*/
public class AliasFacade {
private Project project;
private JavaPsiFacade javaPsiFacade;
private List resolvers;
public static final AliasFacade getInstance(@NotNull Project project) {
return ServiceManager.getService(project, AliasFacade.class);
}
public AliasFacade(Project project) {
this.project = project;
this.resolvers = Lists.newArrayList();
this.javaPsiFacade = JavaPsiFacade.getInstance(project);
initResolvers();
}
private void initResolvers() {
try {
Class.forName("com.intellij.spring.model.utils.SpringModelUtils");
this.registerResolver(AliasResolverFactory.createBeanResolver(project));
} catch (ClassNotFoundException e) {
}
this.registerResolver(AliasResolverFactory.createSingleAliasResolver(project));
this.registerResolver(AliasResolverFactory.createConfigPackageResolver(project));
this.registerResolver(AliasResolverFactory.createAnnotationResolver(project));
this.registerResolver(AliasResolverFactory.createInnerAliasResolver(project));
}
@NotNull
public Optional findPsiClass(@Nullable PsiElement element, @NotNull String shortName) {
PsiClass clazz = javaPsiFacade.findClass(shortName, GlobalSearchScope.allScope(project));
if (null != clazz) {
return Optional.of(clazz);
}
for (AliasResolver resolver : resolvers) {
for (AliasDesc desc : resolver.getClassAliasDescriptions(element)) {
if (shortName.equalsIgnoreCase(desc.getAlias())) {
return Optional.of(desc.getClazz());
}
}
}
return Optional.empty();
}
@NotNull
public Collection getAliasDescs(@Nullable PsiElement element) {
ArrayList result = Lists.newArrayList();
for (AliasResolver resolver : resolvers) {
result.addAll(resolver.getClassAliasDescriptions(element));
}
return result;
}
public Optional findAliasDesc(@Nullable PsiClass clazz) {
if (clazz == null) {
return Optional.empty();
}
for (AliasResolver resolver : resolvers) {
for (AliasDesc desc : resolver.getClassAliasDescriptions(clazz)) {
if (clazz.equals(desc.getClazz())) {
return Optional.of(desc);
}
}
}
return Optional.empty();
}
public void registerResolver(@NotNull AliasResolver resolver) {
this.resolvers.add(resolver);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.wuzhizhan.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.Set;
/**
* @author yanglin
*/
public abstract class AliasResolver {
protected Project project;
public AliasResolver(Project project) {
this.project = project;
}
@NotNull
protected Optional addAliasDesc(@NotNull Set descs, @Nullable PsiClass clazz, @Nullable String alias) {
if (null == alias || !JavaUtils.isModelClazz(clazz)) {
return Optional.empty();
}
AliasDesc desc = new AliasDesc();
descs.add(desc);
desc.setClazz(clazz);
desc.setAlias(alias);
return Optional.of(desc);
}
@NotNull
public abstract Set getClassAliasDescriptions(@Nullable PsiElement element);
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AliasResolverFactory.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public class AliasResolverFactory {
@NotNull
public static AliasResolver createInnerAliasResolver(@NotNull Project project) {
return new InnerAliasResolver(project);
}
@NotNull
public static AliasResolver createAnnotationResolver(@NotNull Project project) {
return new AnnotationAliasResolver(project);
}
@NotNull
public static AliasResolver createBeanResolver(@NotNull Project project) {
return new BeanAliasResolver(project);
}
@NotNull
public static AliasResolver createConfigPackageResolver(@NotNull Project project) {
return new ConfigPackageAliasResolver(project);
}
@NotNull
public static AliasResolver createSingleAliasResolver(@NotNull Project project) {
return new SingleAliasResolver(project);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/AnnotationAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
import com.wuzhizhan.mybatis.annotation.Annotation;
import com.wuzhizhan.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
/**
* @author yanglin
*/
public class AnnotationAliasResolver extends AliasResolver {
private static final Function FUN = new Function() {
@Override
public AliasDesc apply(PsiClass psiClass) {
Optional txt = JavaUtils.getAnnotationValueText(psiClass, Annotation.ALIAS);
if (!txt.isPresent()) return null;
AliasDesc ad = new AliasDesc();
ad.setAlias(txt.get());
ad.setClazz(psiClass);
return ad;
}
};
public AnnotationAliasResolver(Project project) {
super(project);
}
public static final AnnotationAliasResolver getInstance(@NotNull Project project) {
return project.getComponent(AnnotationAliasResolver.class);
}
@NotNull
@Override
public Set getClassAliasDescriptions(@Nullable PsiElement element) {
Optional clazz = Annotation.ALIAS.toPsiClass(project);
if (clazz.isPresent()) {
Collection res = AnnotatedElementsSearch.searchPsiClasses(clazz.get(), GlobalSearchScope.allScope(project)).findAll();
return Sets.newHashSet(Collections2.transform(res, FUN));
}
return Collections.emptySet();
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/BeanAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.Sets;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Set;
/**
* @author yanglin
*/
public class BeanAliasResolver extends PackageAliasResolver {
private static final String MAPPER_ALIAS_PACKAGE_CLASS = "org.mybatis.spring.SqlSessionFactoryBean";
private static final String MAPPER_ALIAS_PROPERTY = "typeAliasesPackage";
private ModuleManager moduleManager;
public BeanAliasResolver(Project project) {
super(project);
this.moduleManager = ModuleManager.getInstance(project);
}
@NotNull
@Override
public Collection getPackages(@Nullable PsiElement element) {
Set res = Sets.newHashSet();
// for (Module module : moduleManager.getModules()) {
// for (CommonSpringModel springModel : springManager.getCombinedModel(module).getRelatedModels()) {
// addPackages(res, springModel);
// }
// }
return res;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/ConfigPackageAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.Lists;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.Processor;
import com.wuzhizhan.mybatis.dom.model.Package;
import com.wuzhizhan.mybatis.util.MapperUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author yanglin
*/
public class ConfigPackageAliasResolver extends PackageAliasResolver {
public ConfigPackageAliasResolver(Project project) {
super(project);
}
@NotNull
@Override
public Collection getPackages(@Nullable PsiElement element) {
final ArrayList result = Lists.newArrayList();
MapperUtils.processConfiguredPackage(project, new Processor() {
@Override
public boolean process(Package pkg) {
result.add(pkg.getName().getStringValue());
return true;
}
});
return result;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/InnerAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.ImmutableSet;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.wuzhizhan.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* @author yanglin
*/
public class InnerAliasResolver extends AliasResolver {
private final Set innerAliasDescs = ImmutableSet.of(
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.String").get(), "string"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Byte").get(), "byte"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Long").get(), "long"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Short").get(), "short"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Integer").get(), "int"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Integer").get(), "integer"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Double").get(), "double"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Float").get(), "float"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Boolean").get(), "boolean"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.Date").get(), "date"),
AliasDesc.create(JavaUtils.findClazz(project, "java.math.BigDecimal").get(), "decimal"),
AliasDesc.create(JavaUtils.findClazz(project, "java.lang.Object").get(), "object"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.Map").get(), "map"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.HashMap").get(), "hashmap"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.List").get(), "list"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.ArrayList").get(), "arraylist"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.Collection").get(), "collection"),
AliasDesc.create(JavaUtils.findClazz(project, "java.util.Iterator").get(), "iterator")
);
public InnerAliasResolver(Project project) {
super(project);
}
@NotNull
@Override
public Set getClassAliasDescriptions(@Nullable PsiElement element) {
return innerAliasDescs;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/PackageAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Set;
/**
* @author yanglin
*/
public abstract class PackageAliasResolver extends AliasResolver {
private JavaPsiFacade javaPsiFacade;
public PackageAliasResolver(Project project) {
super(project);
this.javaPsiFacade = JavaPsiFacade.getInstance(project);
}
@NotNull
@Override
public Set getClassAliasDescriptions(@Nullable PsiElement element) {
Set result = Sets.newHashSet();
for (String pkgName : getPackages(element)) {
if (null == pkgName) {
continue;
}
PsiPackage pkg = javaPsiFacade.findPackage(pkgName);
if (null != pkg) {
addAliasDesc(result, pkg);
for (PsiPackage tmp : pkg.getSubPackages()) {
addAliasDesc(result, tmp);
}
}
}
return result;
}
private void addAliasDesc(Set result, PsiPackage pkg) {
for (PsiClass clazz : pkg.getClasses()) {
addAliasDesc(result, clazz, clazz.getName());
}
}
@NotNull
public abstract Collection getPackages(@Nullable PsiElement element);
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/alias/SingleAliasResolver.java
================================================
package com.wuzhizhan.mybatis.alias;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.Processor;
import com.wuzhizhan.mybatis.dom.model.TypeAlias;
import com.wuzhizhan.mybatis.util.MapperUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* @author yanglin
*/
public class SingleAliasResolver extends AliasResolver {
public SingleAliasResolver(Project project) {
super(project);
}
@NotNull
@Override
public Set getClassAliasDescriptions(@Nullable PsiElement element) {
final Set result = Sets.newHashSet();
MapperUtils.processConfiguredTypeAliases(project, new Processor() {
@Override
public boolean process(TypeAlias typeAlias) {
addAliasDesc(result, typeAlias.getType().getValue(), typeAlias.getAlias().getStringValue());
return true;
}
});
return result;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/annotation/Annotation.java
================================================
package com.wuzhizhan.mybatis.annotation;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* Simple implementation
*
* @author yanglin
*/
public class Annotation implements Cloneable {
public static final Annotation PARAM = new Annotation("@Param", "org.apache.ibatis.annotations.Param");
public static final Annotation SELECT = new Annotation("@Select", "org.apache.ibatis.annotations.Select");
public static final Annotation UPDATE = new Annotation("@Update", "org.apache.ibatis.annotations.Update");
public static final Annotation INSERT = new Annotation("@Insert", "org.apache.ibatis.annotations.Insert");
public static final Annotation DELETE = new Annotation("@Delete", "org.apache.ibatis.annotations.Delete");
public static final Annotation ALIAS = new Annotation("@Alias", "org.apache.ibatis.type.Alias");
public static final Annotation AUTOWIRED = new Annotation("@Autowired", "org.springframework.beans.factory.annotation.Autowired");
public static final Annotation RESOURCE = new Annotation("@Resource", "javax.annotation.Resource");
public static final Annotation SelectProvider = new Annotation("@SelectProvider", "org.apache.ibatis.annotations.SelectProvider");
public static final Annotation InsertProvider = new Annotation("@InsertProvider", "org.apache.ibatis.annotations.InsertProvider");
public static final Annotation DeleteProvider = new Annotation("@DeleteProvider", "org.apache.ibatis.annotations.DeleteProvider");
public static final Annotation UpdateProvider = new Annotation("@UpdateProvider", "org.apache.ibatis.annotations.UpdateProvider");
public static final Set STATEMENT_SYMMETRIES = ImmutableSet.of(SELECT, UPDATE, INSERT, DELETE,
SelectProvider, InsertProvider, DeleteProvider, UpdateProvider);
private final String label;
private final String qualifiedName;
private Map attributePairs;
public interface AnnotationValue {
}
public static class StringValue implements AnnotationValue {
private String value;
public StringValue(@NotNull String value) {
this.value = value;
}
@Override
public String toString() {
return "\"" + value + "\"";
}
}
public Annotation(@NotNull String label, @NotNull String qualifiedName) {
this.label = label;
this.qualifiedName = qualifiedName;
attributePairs = Maps.newHashMap();
}
private Annotation addAttribute(String key, AnnotationValue value) {
this.attributePairs.put(key, value);
return this;
}
public Annotation withAttribute(@NotNull String key, @NotNull AnnotationValue value) {
Annotation copy = this.clone();
copy.attributePairs = Maps.newHashMap(this.attributePairs);
return copy.addAttribute(key, value);
}
public Annotation withValue(@NotNull AnnotationValue value) {
return withAttribute("value", value);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(label);
if (!Iterables.isEmpty(attributePairs.entrySet())) {
builder.append(setupAttributeText());
}
return builder.toString();
}
private String setupAttributeText() {
Optional singleValue = getSingleValue();
return singleValue.isPresent() ? singleValue.get() : getComplexValue();
}
private String getComplexValue() {
StringBuilder builder = new StringBuilder("(");
for (String key : attributePairs.keySet()) {
builder.append(key);
builder.append(" = ");
builder.append(attributePairs.get(key).toString());
builder.append(", ");
}
builder.deleteCharAt(builder.length() - 1);
builder.deleteCharAt(builder.length() - 1);
builder.append(")");
return builder.toString();
}
@NotNull
public Optional toPsiClass(@NotNull Project project) {
return Optional.ofNullable(JavaPsiFacade.getInstance(project).findClass(getQualifiedName(), GlobalSearchScope.allScope(project)));
}
private Optional getSingleValue() {
try {
String value = Iterables.getOnlyElement(attributePairs.keySet());
StringBuilder builder = new StringBuilder("(");
builder.append(attributePairs.get(value).toString());
builder.append(")");
return Optional.of(builder.toString());
} catch (Exception e) {
return Optional.empty();
}
}
@NotNull
public String getLabel() {
return label;
}
@NotNull
public String getQualifiedName() {
return qualifiedName;
}
@Override
protected Annotation clone() {
try {
return (Annotation) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException();
}
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/contributor/JavaMenthodCompletionContributor.java
================================================
package com.wuzhizhan.mybatis.contributor;
import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.completion.CompletionType;
public class JavaMenthodCompletionContributor extends CompletionContributor {
@Override
public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC) {
return;
}
//todo
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/contributor/SqlParamCompletionContributor.java
================================================
package com.wuzhizhan.mybatis.contributor;
import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.util.DomUtils;
import com.wuzhizhan.mybatis.util.MapperUtils;
import java.util.Optional;
/**
* @author yanglin
*/
public class SqlParamCompletionContributor extends CompletionContributor {
@Override
public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC) {
return;
}
PsiElement position = parameters.getPosition();
PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(position);
if (DomUtils.isMybatisFile(topLevelFile)) {
if (shouldAddElement(position.getContainingFile(), parameters.getOffset())) {
process(topLevelFile, result, position);
}
}
}
private void process(PsiFile xmlFile, CompletionResultSet result, PsiElement position) {
DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(position);
if (null != documentWindow) {
int offset = documentWindow.injectedToHost(position.getTextOffset());
Optional idDomElement = MapperUtils.findParentIdDomElement(xmlFile.findElementAt(offset));
if (idDomElement.isPresent()) {
TestParamContributor.addElementForPsiParameter(position.getProject(), result, idDomElement.get());
result.stopHere();
}
}
}
private boolean shouldAddElement(PsiFile file, int offset) {
String text = file.getText();
for (int i = offset - 1; i > 0; i--) {
char c = text.charAt(i);
if (c == '{' && text.charAt(i - 1) == '#') return true;
}
return false;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/contributor/TestParamContributor.java
================================================
package com.wuzhizhan.mybatis.contributor;
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import com.intellij.util.ProcessingContext;
import com.wuzhizhan.mybatis.annotation.Annotation;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.util.Icons;
import com.wuzhizhan.mybatis.util.JavaUtils;
import com.wuzhizhan.mybatis.util.MapperUtils;
import com.wuzhizhan.mybatis.util.MybatisConstants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Optional;
/**
* @author yanglin
*/
public class TestParamContributor extends CompletionContributor {
private static final Logger logger = LoggerFactory.getLogger(TestParamContributor.class);
public TestParamContributor() {
extend(CompletionType.BASIC,
XmlPatterns.psiElement()
.inside(XmlPatterns.xmlAttributeValue()
.inside(XmlPatterns.xmlAttribute().withName("test"))),
new CompletionProvider() {
@Override
protected void addCompletions(
@NotNull final CompletionParameters parameters,
final ProcessingContext context,
@NotNull final CompletionResultSet result) {
final PsiElement position = parameters.getPosition();
addElementForPsiParameter(
position.getProject(),
result,
MapperUtils.findParentIdDomElement(position).orElse(null));
}
});
}
static void addElementForPsiParameter(
@NotNull final Project project,
@NotNull final CompletionResultSet result,
@Nullable final IdDomElement element) {
if (element == null) {
return;
}
final PsiMethod method = JavaUtils.findMethod(project, element).orElse(null);
if (method == null) {
logger.info("psiMethod null");
return;
}
final PsiParameter[] parameters = method.getParameterList().getParameters();
// For a single parameter MyBatis uses its name, while for a multitude they're
// named as param1, param2, etc. I'll check if the @Param annotation [value] is present
// and eventually I'll use its text.
if (parameters.length == 1) {
final PsiParameter parameter = parameters[0];
result.addElement(buildLookupElementWithIcon(
parameter.getName(),
parameter.getType().getPresentableText()));
} else {
for (int i = 0; i < parameters.length; i++) {
final PsiParameter parameter = parameters[i];
final Optional value = JavaUtils.getAnnotationValueText(parameter, Annotation.PARAM);
result.addElement(buildLookupElementWithIcon(
value.isPresent() ? value.get() : "param" + (i + 1),
parameter.getType().getPresentableText()));
}
}
}
private static LookupElement buildLookupElementWithIcon(
final String parameterName,
final String parameterType) {
return PrioritizedLookupElement.withPriority(
LookupElementBuilder.create(parameterName)
.withTypeText(parameterType)
.withIcon(Icons.PARAM_COMPLETION_ICON),
MybatisConstants.PRIORITY);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/definitionsearch/MapperDefinitionSearch.java
================================================
package com.wuzhizhan.mybatis.definitionsearch;
import com.intellij.openapi.application.QueryExecutorBase;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiTypeParameterListOwner;
import com.intellij.psi.xml.XmlElement;
import com.intellij.util.Processor;
import com.intellij.util.xml.DomElement;
import com.wuzhizhan.mybatis.service.JavaService;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public class MapperDefinitionSearch extends QueryExecutorBase {
public MapperDefinitionSearch() {
super(true);
}
@Override
public void processQuery(@NotNull PsiElement queryParameters, @NotNull Processor super XmlElement> consumer) {
if (!(queryParameters instanceof PsiTypeParameterListOwner)) return;
Processor processor = domElement -> consumer.process(domElement.getXmlElement());
JavaService.getInstance(queryParameters.getProject()).process(queryParameters, processor);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/MapperBacktrackingUtils.java
================================================
package com.wuzhizhan.mybatis.dom;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.DomUtil;
import com.wuzhizhan.mybatis.dom.model.Association;
import com.wuzhizhan.mybatis.dom.model.Collection;
import com.wuzhizhan.mybatis.dom.model.ParameterMap;
import com.wuzhizhan.mybatis.dom.model.ResultMap;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
/**
* @author yanglin
*/
public final class MapperBacktrackingUtils {
private MapperBacktrackingUtils() {
throw new UnsupportedOperationException();
}
public static Optional getPropertyClazz(XmlAttributeValue attributeValue) {
DomElement domElement = DomUtil.getDomElement(attributeValue);
if (null == domElement) {
return Optional.empty();
}
Collection collection = DomUtil.getParentOfType(domElement, Collection.class, true);
if (null != collection && !isWithinSameTag(collection, attributeValue)) {
return Optional.ofNullable(collection.getOfType().getValue());
}
Association association = DomUtil.getParentOfType(domElement, Association.class, true);
if (null != association && !isWithinSameTag(association, attributeValue)) {
return Optional.ofNullable(association.getJavaType().getValue());
}
ParameterMap parameterMap = DomUtil.getParentOfType(domElement, ParameterMap.class, true);
if (null != parameterMap && !isWithinSameTag(parameterMap, attributeValue)) {
return Optional.ofNullable(parameterMap.getType().getValue());
}
ResultMap resultMap = DomUtil.getParentOfType(domElement, ResultMap.class, true);
if (null != resultMap && !isWithinSameTag(resultMap, attributeValue)) {
return Optional.ofNullable(resultMap.getType().getValue());
}
return Optional.empty();
}
public static boolean isWithinSameTag(@NotNull DomElement domElement, @NotNull XmlElement xmlElement) {
XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class);
return null != xmlElement && domElement.getXmlTag().equals(xmlTag);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/AliasConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.xml.*;
import com.wuzhizhan.mybatis.alias.AliasClassReference;
import com.wuzhizhan.mybatis.alias.AliasFacade;
import com.wuzhizhan.mybatis.util.MybatisConstants;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author yanglin
*/
public class AliasConverter extends ConverterAdaptor implements CustomReferenceConverter {
private PsiClassConverter delegate = new PsiClassConverter();
@Nullable
@Override
public PsiClass fromString(@Nullable @NonNls String s, ConvertContext context) {
if (StringUtil.isEmptyOrSpaces(s)) return null;
if (!s.contains(MybatisConstants.DOT_SEPARATOR)) {
return AliasFacade.getInstance(context.getProject()).findPsiClass(context.getXmlElement(), s).orElse(null);
}
return DomJavaUtil.findClass(s.trim(), context.getFile(), context.getModule(), GlobalSearchScope.allScope(context.getProject()));
}
@Nullable
@Override
public String toString(@Nullable PsiClass psiClass, ConvertContext context) {
return delegate.toString(psiClass, context);
}
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {
if (((XmlAttributeValue) element).getValue().contains(MybatisConstants.DOT_SEPARATOR)) {
return delegate.createReferences(value, element, context);
} else {
return new PsiReference[]{new AliasClassReference((XmlAttributeValue) element)};
}
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/ConverterAdaptor.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.ResolvingConverter;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
/**
* @author yanglin
*/
public abstract class ConverterAdaptor extends ResolvingConverter {
@NotNull
@Override
public Collection extends T> getVariants(ConvertContext context) {
return Collections.emptyList();
}
@Nullable
@Override
public String toString(@Nullable T t, ConvertContext context) {
// throw new UnsupportedOperationException();
return null;
}
@Nullable
@Override
public T fromString(@Nullable @NonNls String s, ConvertContext context) {
return null;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/DaoMethodConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.psi.PsiMethod;
import com.intellij.util.xml.ConvertContext;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import com.wuzhizhan.mybatis.util.JavaUtils;
import com.wuzhizhan.mybatis.util.MapperUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
/**
* @author yanglin
*/
public class DaoMethodConverter extends ConverterAdaptor {
@Nullable
@Override
public PsiMethod fromString(@Nullable @NonNls String id, ConvertContext context) {
Mapper mapper = MapperUtils.getMapper(context.getInvocationElement());
return JavaUtils.findMethod(context.getProject(), MapperUtils.getNamespace(mapper), id).orElse(null);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/IdBasedTagConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.ElementManipulators;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.xml.*;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import com.wuzhizhan.mybatis.util.MapperUtils;
import com.wuzhizhan.mybatis.util.MybatisConstants;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* @author yanglin
*/
public abstract class IdBasedTagConverter extends ConverterAdaptor implements CustomReferenceConverter {
private final boolean crossMapperSupported;
public IdBasedTagConverter() {
this(true);
}
protected IdBasedTagConverter(boolean crossMapperSupported) {
this.crossMapperSupported = crossMapperSupported;
}
@Nullable
@Override
public XmlAttributeValue fromString(@Nullable @NonNls String value, ConvertContext context) {
return matchIdDomElement(selectStrategy(context).getValue(), value, context).orElse(null);
}
@NotNull
private Optional matchIdDomElement(Collection extends IdDomElement> idDomElements, String value, ConvertContext context) {
Mapper contextMapper = MapperUtils.getMapper(context.getInvocationElement());
for (IdDomElement idDomElement : idDomElements) {
if (MapperUtils.getIdSignature(idDomElement).equals(value) ||
MapperUtils.getIdSignature(idDomElement, contextMapper).equals(value)) {
return Optional.of(idDomElement.getId().getXmlAttributeValue());
}
}
return Optional.empty();
}
@Nullable
@Override
public String toString(@Nullable XmlAttributeValue xmlAttribute, ConvertContext context) {
DomElement domElement = DomUtil.getDomElement(xmlAttribute.getParent().getParent());
if (!(domElement instanceof IdDomElement)) {
return null;
}
Mapper contextMapper = MapperUtils.getMapper(context.getInvocationElement());
return MapperUtils.getIdSignature((IdDomElement) domElement, contextMapper);
}
private TraverseStrategy selectStrategy(ConvertContext context) {
return crossMapperSupported ? new CrossMapperStrategy(context) : new InsideMapperStrategy(context);
}
/**
* @param mapper mapper in the project, null if {@link #crossMapperSupported} is false
* @param context the dom convert context
*/
@NotNull
public abstract Collection extends IdDomElement> getComparisons(@Nullable Mapper mapper, ConvertContext context);
private abstract class TraverseStrategy {
protected ConvertContext context;
public TraverseStrategy(@NotNull ConvertContext context) {
this.context = context;
}
public abstract Collection extends IdDomElement> getValue();
}
private class InsideMapperStrategy extends TraverseStrategy {
public InsideMapperStrategy(@NotNull ConvertContext context) {
super(context);
}
@Override
public Collection extends IdDomElement> getValue() {
return getComparisons(null, context);
}
}
private class CrossMapperStrategy extends TraverseStrategy {
public CrossMapperStrategy(@NotNull ConvertContext context) {
super(context);
}
@Override
public Collection extends IdDomElement> getValue() {
List result = Lists.newArrayList();
for (Mapper mapper : MapperUtils.findMappers(context.getProject())) {
result.addAll(getComparisons(mapper, context));
}
return result;
}
}
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {
return PsiClassConverter.createJavaClassReferenceProvider(value, null, new ValueReferenceProvider(context)).getReferencesByElement(element);
}
private class ValueReferenceProvider extends JavaClassReferenceProvider {
private ConvertContext context;
private ValueReferenceProvider(ConvertContext context) {
this.context = context;
}
@Nullable
@Override
public GlobalSearchScope getScope(Project project) {
return GlobalSearchScope.allScope(project);
}
/**
* It looks like hacking here, as it's a little hard to handle so many different cases as JetBrains does
*/
@NotNull
@Override
public PsiReference[] getReferencesByString(String text, @NotNull PsiElement position, int offsetInPosition) {
List refs = Lists.newArrayList(super.getReferencesByString(text, position, offsetInPosition));
ValueReference vr = new ValueReference(position, getTextRange(position), context, text);
if (!refs.isEmpty() && 0 != vr.getVariants().length) {
refs.remove(refs.size() - 1);
refs.add(vr);
}
return refs.toArray(new PsiReference[refs.size()]);
}
private TextRange getTextRange(PsiElement element) {
String text = element.getText();
int index = text.lastIndexOf(MybatisConstants.DOT_SEPARATOR);
return -1 == index ? ElementManipulators.getValueTextRange(element) : TextRange.create(text.substring(0, index).length() + 1, text.length() - 1);
}
}
private class ValueReference extends PsiReferenceBase {
private ConvertContext context;
private String text;
public ValueReference(@NotNull PsiElement element, TextRange rng, ConvertContext context, String text) {
super(element, rng, false);
this.context = context;
this.text = text;
}
@Nullable
@Override
public PsiElement resolve() {
return IdBasedTagConverter.this.fromString(text, context);
}
@NotNull
@Override
public Object[] getVariants() {
Set res = getElement().getText().contains(MybatisConstants.DOT_SEPARATOR) ? setupContextIdSignature() : setupGlobalIdSignature();
return res.toArray(new String[res.size()]);
}
private Set setupContextIdSignature() {
Set res = Sets.newHashSet();
String ns = text.substring(0, text.lastIndexOf(MybatisConstants.DOT_SEPARATOR));
for (IdDomElement ele : selectStrategy(context).getValue()) {
if (MapperUtils.getNamespace(ele).equals(ns)) {
res.add(MapperUtils.getId(ele));
}
}
return res;
}
private Set setupGlobalIdSignature() {
Mapper contextMapper = MapperUtils.getMapper(context.getInvocationElement());
Collection extends IdDomElement> idDomElements = selectStrategy(context).getValue();
Set res = new HashSet(idDomElements.size());
for (IdDomElement ele : idDomElements) {
res.add(MapperUtils.getIdSignature(ele, contextMapper));
}
return res;
}
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/ParameterMapConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.util.xml.ConvertContext;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* @author yanglin
*/
public class ParameterMapConverter extends IdBasedTagConverter {
@NotNull
@Override
public Collection extends IdDomElement> getComparisons(@Nullable Mapper mapper,
ConvertContext context) {
return mapper.getParameterMaps();
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/PropertyConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.psi.ElementManipulators;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.xml.*;
import com.wuzhizhan.mybatis.reference.ResultPropertyReferenceSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author yanglin
*/
public class PropertyConverter extends ConverterAdaptor implements CustomReferenceConverter {
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {
final String s = value.getStringValue();
if (s == null) {
return PsiReference.EMPTY_ARRAY;
}
return new ResultPropertyReferenceSet(s, element, ElementManipulators.getOffsetInElement(element)).getPsiReferences();
}
@Nullable
@Override
public XmlAttributeValue fromString(@Nullable @NonNls String s, ConvertContext context) {
DomElement ctxElement = context.getInvocationElement();
return ctxElement instanceof GenericAttributeValue ? ((GenericAttributeValue) ctxElement).getXmlAttributeValue() : null;
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/ResultMapConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.DomElement;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import com.wuzhizhan.mybatis.dom.model.ResultMap;
import com.wuzhizhan.mybatis.util.MapperUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* @author yanglin
*/
public class ResultMapConverter extends IdBasedTagConverter {
@NotNull
@Override
public Collection extends IdDomElement> getComparisons(@Nullable Mapper mapper, ConvertContext context) {
DomElement invocationElement = context.getInvocationElement();
if (isContextElementOfResultMap(mapper, invocationElement)) {
return doFilterResultMapItself(mapper, (ResultMap) invocationElement.getParent());
} else {
return mapper.getResultMaps();
}
}
private boolean isContextElementOfResultMap(Mapper mapper, DomElement invocationElement) {
return MapperUtils.isMapperWithSameNamespace(MapperUtils.getMapper(invocationElement), mapper)
&& invocationElement.getParent() instanceof ResultMap;
}
private Collection extends IdDomElement> doFilterResultMapItself(Mapper mapper, final ResultMap resultMap) {
return Collections2.filter(mapper.getResultMaps(), new Predicate() {
@Override
public boolean apply(ResultMap input) {
return !MapperUtils.getId(input).equals(MapperUtils.getId(resultMap));
}
});
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/converter/SqlConverter.java
================================================
package com.wuzhizhan.mybatis.dom.converter;
import com.intellij.util.xml.ConvertContext;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* @author yanglin
*/
public class SqlConverter extends IdBasedTagConverter {
@NotNull
@Override
public Collection extends IdDomElement> getComparisons(@Nullable Mapper mapper, ConvertContext context) {
return mapper.getSqls();
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/description/ConfigurationDescription.java
================================================
package com.wuzhizhan.mybatis.dom.description;
import com.intellij.openapi.module.Module;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.xml.DomFileDescription;
import com.wuzhizhan.mybatis.dom.model.Configuration;
import com.wuzhizhan.mybatis.util.DomUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author yanglin
*/
public class ConfigurationDescription extends DomFileDescription {
public ConfigurationDescription() {
super(Configuration.class, "configuration");
}
@Override
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
return DomUtils.isMybatisConfigurationFile(file);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/description/MapperDescription.java
================================================
package com.wuzhizhan.mybatis.dom.description;
import com.intellij.openapi.module.Module;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.xml.DomFileDescription;
import com.wuzhizhan.mybatis.dom.model.Mapper;
import com.wuzhizhan.mybatis.util.DomUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author yanglin
*/
public class MapperDescription extends DomFileDescription {
public MapperDescription() {
super(Mapper.class, "mapper");
}
@Override
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
return DomUtils.isMybatisFile(file);
}
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Arg.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
/**
* @author yanglin
*/
public interface Arg extends DomElement {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Association.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.psi.PsiClass;
import com.intellij.util.xml.Attribute;
import com.intellij.util.xml.Convert;
import com.intellij.util.xml.GenericAttributeValue;
import com.wuzhizhan.mybatis.dom.converter.AliasConverter;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public interface Association extends GroupFour, ResultMapGroup, PropertyGroup {
@NotNull
@Attribute("javaType")
@Convert(AliasConverter.class)
public GenericAttributeValue getJavaType();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Bean.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface Bean extends DomElement {
@NotNull
@SubTagList("property")
public List getBeanProperties();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/BeanProperty.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.Attribute;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.GenericAttributeValue;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public interface BeanProperty extends DomElement {
@NotNull
@Attribute("name")
public GenericAttributeValue getName();
@NotNull
@Attribute("value")
public GenericAttributeValue getValue();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Beans.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface Beans extends DomElement {
@NotNull
@SubTagList("bean")
public List getBeans();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Bind.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
/**
* @author yanglin
*/
public interface Bind extends DomElement {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Cache.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import java.util.List;
/**
* @author yanglin
*/
public interface Cache extends DomElement {
@SubTagList("property")
public List getProperties();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/CacheRef.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
/**
* @author yanglin
*/
public interface CacheRef extends DomElement {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Case.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface Case extends GroupFour {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Choose.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.Required;
import com.intellij.util.xml.SubTag;
import com.intellij.util.xml.SubTagList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface Choose extends DomElement {
@NotNull
@Required
@SubTagList("when")
public List getWhens();
@SubTag("otherwise")
public Otherwise getOtherwise();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Collection.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.psi.PsiClass;
import com.intellij.util.xml.Attribute;
import com.intellij.util.xml.Convert;
import com.intellij.util.xml.GenericAttributeValue;
import com.wuzhizhan.mybatis.dom.converter.AliasConverter;
import org.jetbrains.annotations.NotNull;
/**
* @author yanglin
*/
public interface Collection extends GroupFour, ResultMapGroup, PropertyGroup {
@NotNull
@Attribute("ofType")
@Convert(AliasConverter.class)
public GenericAttributeValue getOfType();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Configuration.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface Configuration extends DomElement {
@NotNull
@SubTagList("typeAliases")
public List getTypeAliases();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Constructor.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import java.util.List;
/**
* @author yanglin
*/
public interface Constructor extends DomElement {
@SubTagList("arg")
public List getArgs();
@SubTagList("idArg")
public List getIdArgs();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Delete.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface Delete extends GroupTwo {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Discriminator.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.Required;
import com.intellij.util.xml.SubTagList;
import java.util.List;
/**
* @author yanglin
*/
public interface Discriminator extends DomElement {
@Required
@SubTagList("case")
public List getCases();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Foreach.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface Foreach extends GroupOne {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/GroupFour.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTag;
import com.intellij.util.xml.SubTagList;
import java.util.List;
/**
* @author yanglin
*/
public interface GroupFour extends DomElement {
@SubTag("constructor")
public Constructor getConstructor();
@SubTagList("id")
public List getIds();
@SubTagList("result")
public List getResults();
@SubTagList("association")
public List getAssociations();
@SubTagList("collection")
public List getCollections();
@SubTag("discriminator")
public Discriminator getDiscriminator();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/GroupOne.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.SubTagList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface GroupOne extends DomElement {
@NotNull
@SubTagList("include")
public List getIncludes();
@NotNull
@SubTagList("trim")
public List getTrims();
@NotNull
@SubTagList("where")
public List getWheres();
@NotNull
@SubTagList("set")
public List getSets();
@NotNull
@SubTagList("foreach")
public List getForeachs();
@NotNull
@SubTagList("choose")
public List getChooses();
@NotNull
@SubTagList("if")
public List getIfs();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/GroupThree.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.SubTagList;
import java.util.List;
/**
* @author yanglin
*/
public interface GroupThree extends GroupTwo {
@SubTagList("selectKey")
public List getSelectKey();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/GroupTwo.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.psi.PsiClass;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.xml.Attribute;
import com.intellij.util.xml.Convert;
import com.intellij.util.xml.GenericAttributeValue;
import com.intellij.util.xml.SubTagList;
import com.wuzhizhan.mybatis.dom.converter.AliasConverter;
import com.wuzhizhan.mybatis.dom.converter.DaoMethodConverter;
import com.wuzhizhan.mybatis.dom.converter.ParameterMapConverter;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface GroupTwo extends GroupOne, IdDomElement {
@SubTagList("bind")
public List getBinds();
@NotNull
@Attribute("parameterMap")
@Convert(ParameterMapConverter.class)
public GenericAttributeValue getParameterMap();
@Attribute("id")
@Convert(DaoMethodConverter.class)
public GenericAttributeValue getId();
@NotNull
@Attribute("parameterType")
@Convert(AliasConverter.class)
public GenericAttributeValue getParameterType();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Id.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface Id extends PropertyGroup {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/IdArg.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.DomElement;
/**
* @author yanglin
*/
public interface IdArg extends DomElement {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/IdDomElement.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.*;
/**
* @author yanglin
*/
public interface IdDomElement extends DomElement {
@Required
@NameValue
@Attribute("id")
public GenericAttributeValue getId();
public void setValue(String content);
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/If.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface If extends GroupOne {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Include.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.xml.Attribute;
import com.intellij.util.xml.Convert;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.GenericAttributeValue;
import com.wuzhizhan.mybatis.dom.converter.SqlConverter;
/**
* @author yanglin
*/
public interface Include extends DomElement {
@Attribute("refid")
@Convert(SqlConverter.class)
public GenericAttributeValue getRefId();
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Insert.java
================================================
package com.wuzhizhan.mybatis.dom.model;
/**
* @author yanglin
*/
public interface Insert extends GroupThree {
}
================================================
FILE: src/main/java/com/wuzhizhan/mybatis/dom/model/Mapper.java
================================================
package com.wuzhizhan.mybatis.dom.model;
import com.intellij.util.xml.*;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author yanglin
*/
public interface Mapper extends DomElement {
@NotNull
@SubTagsList({"insert", "update", "delete", "select"})
public List getDaoElements();
@Required
@NameValue
@NotNull
@Attribute("namespace")
public GenericAttributeValue getNamespace();
@NotNull
@SubTagList("resultMap")
public List getResultMaps();
@NotNull
@SubTagList("parameterMap")
public List getParameterMaps();
@NotNull
@SubTagList("sql")
public List getSqls();
@NotNull
@SubTagList("insert")
public List getInserts();
@NotNull
@SubTagList("update")
public List getUpdates();
@NotNull
@SubTagList("delete")
public List getDeletes();
@NotNull
@SubTagList("select")
public List