Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2b0ba4c
Prepare for new release
Dec 12, 2013
c1a7d1a
Model and primitive parameter type support
Dec 15, 2013
e2ab1a9
Change the way to show parameter in mapper xml
Dec 15, 2013
4795eb6
Fix typo
Dec 16, 2013
f5621a6
Finish switching between java type and alias
Dec 21, 2013
cf1433c
Update plugin.xml
Dec 22, 2013
27684a6
Usage
Dec 22, 2013
7da7530
Update AliasSwitchIntentionAction
Dec 22, 2013
a945710
Support jdbc type completion
Dec 22, 2013
8ca7da0
Support generating properties for result map
Dec 22, 2013
60832d8
Reformat
Dec 23, 2013
d00223b
Support according to select statement completion
Dec 23, 2013
a6ec184
Update plugin.xml
Dec 23, 2013
c84d42b
Delete useless class
Dec 23, 2013
03fb64e
Update some classes
Dec 23, 2013
66bb8ce
Repackage some classes
Dec 23, 2013
81ef04c
Update Annotation
Dec 23, 2013
3a0eae4
Update GeneratePropertyIntention
Dec 23, 2013
a5ff957
Update plugin.xml
Dec 24, 2013
8b15b27
Fix bug of saving settings
Dec 24, 2013
de42bb0
Rebuild mapper model
Dec 26, 2013
60ecb5b
Support parameter for collection of for each
Dec 26, 2013
3c89fc7
Remove 'item' for 'forEach' contributor
Dec 26, 2013
c4a0185
Add true and false converter
Dec 26, 2013
7038d8a
Rename Class::TrueOrFalseConverter
Dec 26, 2013
a6cbe4d
Update Class::JdbcGroup
Dec 26, 2013
4d2316f
Update Class::GroupFour
Dec 26, 2013
5802a34
Update some classes
Dec 26, 2013
1b4d299
Update Class::GeneratePropertyIntention
Dec 26, 2013
f231e91
Update Class::MybatisSetting
Dec 27, 2013
59b4889
Add $ as the char of popup parameter completion
Jan 7, 2014
9db8c3f
New features
Jan 10, 2014
0defee9
Fix bug of inspect ResultType
Jan 12, 2014
101dca7
More inspection for statement
Jan 12, 2014
51802ac
Task care of inner class
Jan 12, 2014
a4e14f9
Fix bug
Jan 13, 2014
11d22fb
Refactor
Jan 20, 2014
3acae13
Update Class::DomUtils
Jan 21, 2014
cd50f70
Update Class::Annotation
Jan 25, 2014
c39f1e5
Update Class::JavaUtils
Jan 25, 2014
d161f34
Refactor
Jan 25, 2014
1ae0c82
Access methods are no more required for completion
Feb 8, 2014
7e59d0b
Update Class::GenerateModel
Feb 10, 2014
4ead330
Add gson as a third-part library
Feb 21, 2014
27adcb3
Fix issue#15
Feb 21, 2014
237a9bc
Support generate columns with alias for sql element in mapper xml
Feb 23, 2014
d177512
Update plugin.xml
Feb 23, 2014
e9158ce
Update Class::ResultMapConverter
Feb 24, 2014
82a76be
Update Class::PropertyGenerator
Feb 24, 2014
a0afe83
Fix issue#17
Mar 23, 2014
e5e16b9
Fix
Mar 23, 2014
5236360
Fix issue#18
Apr 5, 2014
4288986
Merge branch 'master' of github.com:seventh7/intellij-mybatis-plugin
Apr 5, 2014
fd094f7
Release new version of 2.237
Apr 5, 2014
8dc8c88
Auto inject sql language in mapper xml
Jul 7, 2014
5b30886
Remove useless statements
Jul 8, 2014
a4c32c7
Update plugin.xml
seventh7me Jul 16, 2014
d58b82c
Fix bug: Range of injected sql in mapper xml
seventh7me Jul 18, 2014
d884509
Update README.md
seventh7me Jul 22, 2014
3a793a3
Ignored "commit unsuccessful" error
seventh7me Aug 12, 2014
574ffc8
Fix issue#25
seventh7me Aug 12, 2014
822165c
Fix issue#25 more
seventh7me Aug 12, 2014
ec2b234
New features of release 2.3
seventh7me Sep 2, 2014
06dc222
Update BeanAliasResolver.java
jannetiand Sep 19, 2014
4582596
Update BeanAliasResolver.java
jannetiand Sep 19, 2014
0037519
Merge pull request #28 from lialun/master
seventh7me Sep 21, 2014
760460b
Merge pull request #28
seventh7me Sep 29, 2014
4564e26
Improve for intellij 14
seventh7me Sep 30, 2014
d95d449
Update .gitignore
seventh7me Oct 7, 2014
7322d74
Update plugin.xml
seventh7me Oct 13, 2014
c27dc91
Fix issue#26
seventh7me Oct 13, 2014
684a081
Add the param itself as the lookup for sql
seventh7me Oct 15, 2014
1cc3160
Remove 'static', 'native', 'transient' fields from param for sql
seventh7me Oct 15, 2014
2c641fa
Update .gitignore to add built mybatis-plus.jar to resp
seventh7me Oct 15, 2014
a497fa4
Fix typo
seventh7me Oct 16, 2014
929f971
Update plugin.xml
seventh7me Oct 16, 2014
ba0414c
Fix typo
seventh7me Oct 16, 2014
2912a23
Fix typo
seventh7me Oct 17, 2014
a467c24
Fix issue#30 -- the mijor one
seventh7me Oct 17, 2014
01ca131
Put sql types together in 'SQLConstants'
seventh7me Oct 18, 2014
60ce972
Fix issue#31
seventh7me Oct 23, 2014
7fe668a
Fix typo
seventh7me Oct 27, 2014
51f0971
Improve for intellij 14
seventh7me Oct 29, 2014
6754f9f
Commit mybatis mapper as spring bean using idea api
seventh7me Nov 13, 2014
caade7e
Thanks to the support of JetBrains
seventh7me Dec 19, 2014
40c7f9c
Fix issue#35
seventh7me Dec 21, 2014
7278847
support multi package in basePackage
ksafe Dec 21, 2014
8f2c9cf
Update README.md
seventh7me Dec 29, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.iml
mybatis-plus.jar
log.roo
.idea/
out/
.DS_Store
.floo
.flooignore

META-INF/plugin.xml
58 changes: 23 additions & 35 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
<idea-plugin version="2" url="https://github.com/seventh7/intellij-mybatis-plugin">
<id>com.seventh7.plugin.mybatis</id>
<name>MyBatis plugin</name>
<version>2.01</version>
<vendor email="insist.day@gmail.com" url="https://github.com/seventh7">Yanglin</vendor>
<version>2.31</version>
<vendor email="seventh7.me@gmail.com" url="https://github.com/seventh7">Yanglin</vendor>

<description><![CDATA[
Plugin for mybatis <br/>
Feel free to feedback
]]></description>

<change-notes><![CDATA[
<h4>2.01</h4>
<h4>2.31</h4>
<ul>
<li>Improvement for intellij 13</li>
<li>Commit mybatis mapper as spring bean using idea api</li>
</ul>
<h4>1.56</h4>
<h4>2.3</h4>
<ul>
<li>Support correct result type for select statement in mapper xml</li>
<li>Support correct unresolved attribute value of mapper xml</li>
<li>Highlight conflicting element of mapper xml as errors</li>
<li>Support refactor for id based tag in mapper xml</li>
<li>Support refactor the name of mapper xml file when rename the mapper interface</li>
<li>Support find usage of mapper interface and mapper xml element</li>
<li>Support generating mapper of xml</li>
<li>Support property completion for result and id of resultMap、collection、association</li>
<li>Support parameter completion[ #{param} ] while editing sql(@Param based)</li>
<li>Support resultMap completion for collection and association of resultMap</li>
<li>Auto register mapper as spring bean(Optional)</li>
<li>Change reference strategy to support rename</li>
<li>Brace completion while editing sql</li>
<li>Support surround with CDATA section for sql</li>
<li>Support resultType</li>
<li>Parameter map support</li>
<li>Parameter type support</li>
<li>Alias support</li>
</ul>
<h4>1.46</h4>
<ul>
<li>Rewrite</li>
<li>Change the keystroke for generate @Param and new statement with Alt + Enter(Windows) | Option + Enter(Mac)</li>
<li>Improve for intellij 14</li>
<li>Fix bugs</li>
</ul>
]]>
</change-notes>

<idea-version since-build="132.947"/>
<depends optional="true">com.intellij.sql</depends>
<depends optional="true">com.intellij.spring</depends>
<idea-version since-build="139.224"/>
<depends optional="false">com.intellij.spring</depends>
<depends optional="false">com.intellij.database</depends>
<extensions defaultExtensionNs="com.intellij">
<dom.fileDescription implementation="com.seventh7.mybatis.dom.description.MapperDescription"/>
<dom.fileDescription implementation="com.seventh7.mybatis.dom.description.ConfigurationDescription"/>
Expand All @@ -57,7 +36,6 @@
<projectService serviceImplementation="com.seventh7.mybatis.locator.MapperLocator"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.seventh7.mybatis.provider.MapperLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="XML" implementationClass="com.seventh7.mybatis.provider.StatementLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.seventh7.mybatis.provider.InjectionLineMarkerProvider"/>
<applicationConfigurable instance="com.seventh7.mybatis.setting.MybatisConfigurable"/>
<applicationService serviceInterface="com.seventh7.mybatis.setting.MybatisSetting" serviceImplementation="com.seventh7.mybatis.setting.MybatisSetting"/>
<completion.contributor language="XML" implementationClass="com.seventh7.mybatis.contributor.TestParamContributor"/>
Expand All @@ -66,20 +44,30 @@
<typedHandler implementation="com.seventh7.mybatis.action.MybatisTypedHandler" id="mybatis" order="first"/>
<defaultLiveTemplatesProvider implementation="com.seventh7.mybatis.template.SqlLiveTemplateProvider"/>
<refactoring.elementListenerProvider implementation="com.seventh7.mybatis.refactoring.MapperRefactoringProvider"/>
<spring.customComponentsDiscoverer implementation="com.seventh7.mybatis.spring.model.MybatisBeanProvider"/>
<localInspection language="JAVA" shortName="MybatisMapperMethodInspection" displayName="Mapper method inspection"
groupName="Mybatis" enabledByDefault="true" level="ERROR"
implementationClass="com.seventh7.mybatis.inspection.MapperMethodInspection"/>
<localInspection language="JAVA" shortName="MybatisMapperInXmlInspection" displayName="Mapper in xml inspection"
groupName="Mybatis" enabledByDefault="true" level="ERROR"
implementationClass="com.seventh7.mybatis.inspection.MapperInXmlInspection"/>
<localInspection language="XML" shortName="MybatisMapperXmlInspection" enabledByDefault="true" level="ERROR" displayName="Mapper xml inspection"
groupName="Mybatis"
implementationClass="com.seventh7.mybatis.inspection.MapperXmlInspection"/>
<intentionAction>
<className>com.seventh7.mybatis.intention.GenerateParamAnnotationIntention</className>
</intentionAction>
<intentionAction>
<className>com.seventh7.mybatis.intention.GenerateStatementIntention</className>
</intentionAction>
<intentionAction order="first">
<className>com.seventh7.mybatis.intention.GenerateMapperIntention</className>
</intentionAction>
<intentionAction>
<className>com.seventh7.mybatis.intention.AliasSwitchIntentionAction</className>
</intentionAction>
<multiHostInjector implementation="com.seventh7.mybatis.xml.SqlLanguageInjector"/>
</extensions>
<actions>
<action id="com.seventh7.mybatis.action.hack" class="com.seventh7.mybatis.action.HackAction" text="HackerForDev" description="Hacker action for development">
<add-to-group group-id="MainToolBar" anchor="first"/>
</action>
</actions>
</idea-plugin>
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Ad - 强势推荐

翻墙利器: http://honx.in/i/VJ6-U86vD0s1XqbE

# Supported By

![Thanks to the support of JetBrains](http://www.jetbrains.com/company/docs/logo_jetbrains.png)

#Download

* http://plugins.jetbrains.com/plugin/7293
Expand All @@ -13,11 +21,17 @@
* Support refactor for id based tag in mapper xml
* Support find usage of mapper interface and mapper xml element
* Highlight conflicting element of mapper xml as errors
* Auto register mapper as spring bean</li>
* Mapper parameter auto completion in xml while editting sql
* Auto register mapper as spring bean
* Support completion of jdbc type in mapper xml
* Support completion of referencing to select statement in mapper xml
* Support switching between java type and alias in mapper xml using intention keystroke
* Auto inject sql language in mapper xml
* Mapper parameter auto completion in xml while editing sql
* \#{yourParameter}
* @Param annotation based
* Association is supported
* Support generating properties for elements of result map using intention keystroke
* DataSource of intellij is required

#Generate

Expand Down
Binary file added lib/gson-2.2.4.jar
Binary file not shown.
Binary file added mybatis-plus.jar
Binary file not shown.
16 changes: 16 additions & 0 deletions src/com/seventh7/mybatis/action/HackAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.seventh7.mybatis.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;

/**
* @author yanglin
*/
public class HackAction extends AnAction {


public void actionPerformed(AnActionEvent e) {
// NON
}

}
24 changes: 17 additions & 7 deletions src/com/seventh7/mybatis/action/MybatisTypedHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
import com.intellij.diagnostic.LogEventException;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.sql.psi.SqlFile;
Expand All @@ -30,12 +31,19 @@ public Result checkAutoPopup(char charTyped, final Project project, final Editor

@Override
public Result charTyped(char c, final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (c != '{') {
return Result.CONTINUE;
}
int index = editor.getCaretModel().getOffset() - 2;
if (index < 0) {
return Result.CONTINUE;
}
char beginningChar = editor.getDocument().getText().charAt(index);
if (beginningChar != '#' && beginningChar != '$') {
return Result.CONTINUE;
}
PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(file);
boolean parameterCase = c == '{' &&
index >= 0 &&
editor.getDocument().getText().charAt(index) == '#' &&
file instanceof SqlFile &&
boolean parameterCase = file instanceof SqlFile &&
DomUtils.isMybatisFile(topLevelFile);
if (parameterCase) {
autoPopupParameter(project, editor);
Expand All @@ -45,11 +53,13 @@ public Result charTyped(char c, final Project project, @NotNull final Editor edi
}

private static void autoPopupParameter(final Project project, final Editor editor) {
CompletionAutoPopupHandler.runLaterWithCommitted(project, editor.getDocument(), new Runnable() {
final Document document = editor.getDocument();
CompletionAutoPopupHandler.runLaterWithCommitted(project, document, new Runnable() {
@Override
public void run() {
if (PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
try {
new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor, 1);
} catch (LogEventException ignored) {
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/com/seventh7/mybatis/alias/AliasClassReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.xml.XmlAttributeValue;

Expand All @@ -29,7 +29,7 @@ public AliasClassReference(@NotNull XmlAttributeValue element) {
}

@Nullable @Override
public PsiElement resolve() {
public PsiClass resolve() {
XmlAttributeValue attributeValue = getElement();
return AliasFacade.getInstance(attributeValue.getProject()).findPsiClass(attributeValue, attributeValue.getValue()).orNull();
}
Expand Down
5 changes: 1 addition & 4 deletions src/com/seventh7/mybatis/alias/AliasDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ public boolean equals(Object o) {
if (alias != null ? !alias.equals(aliasDesc.alias) : aliasDesc.alias != null) {
return false;
}
if (clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null) {
return false;
}

return true;
return !(clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null);
}

@Override
Expand Down
20 changes: 8 additions & 12 deletions src/com/seventh7/mybatis/alias/AliasFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

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 com.seventh7.mybatis.util.JavaUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -24,26 +23,23 @@ public class AliasFacade {

private Project project;

private JavaPsiFacade javaPsiFacade;

private List<AliasResolver> resolvers;

public static final AliasFacade getInstance(@NotNull Project project) {
public static 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) {
} catch (ClassNotFoundException ignored) {
}
this.registerResolver(AliasResolverFactory.createSingleAliasResolver(project));
this.registerResolver(AliasResolverFactory.createConfigPackageResolver(project));
Expand All @@ -52,14 +48,14 @@ private void initResolvers() {
}

@NotNull
public Optional<PsiClass> findPsiClass(@Nullable PsiElement element, @NotNull String shortName) {
PsiClass clazz = javaPsiFacade.findClass(shortName, GlobalSearchScope.allScope(project));
if (null != clazz) {
return Optional.of(clazz);
public Optional<PsiClass> findPsiClass(@Nullable PsiElement element, @NotNull String clazzName) {
final Optional<PsiClass> clazz = JavaUtils.findClazz(project, clazzName);
if (clazz.isPresent()) {
return clazz;
}
for (AliasResolver resolver : resolvers) {
for (AliasDesc desc : resolver.getClassAliasDescriptions(element)) {
if (desc.getAlias().equals(shortName)) {
if (desc.getAlias().equalsIgnoreCase(clazzName)) {
return Optional.of(desc.getClazz());
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/com/seventh7/mybatis/alias/AnnotationAliasResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public AnnotationAliasResolver(Project project) {
super(project);
}

public static final AnnotationAliasResolver getInstance(@NotNull Project project) {
public static AnnotationAliasResolver getInstance(@NotNull Project project) {
return project.getComponent(AnnotationAliasResolver.class);
}

@NotNull
@Override
@SuppressWarnings("unchecked")
public Set<AliasDesc> getClassAliasDescriptions(@Nullable PsiElement element) {
Optional<PsiClass> clazz = Annotation.ALIAS.toPsiClass(project);
if (clazz.isPresent()) {
Expand Down
28 changes: 17 additions & 11 deletions src/com/seventh7/mybatis/alias/BeanAliasResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,37 @@
import com.intellij.psi.PsiElement;
import com.intellij.spring.CommonSpringModel;
import com.intellij.spring.SpringManager;
import com.intellij.spring.model.SpringBeanPointer;
import com.intellij.spring.model.utils.SpringPropertyUtils;
import com.intellij.spring.model.xml.beans.SpringPropertyDefinition;
import com.intellij.util.Processor;
import com.seventh7.mybatis.util.SpringUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
* @author yanglin
*/
public class BeanAliasResolver extends PackageAliasResolver{
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;
private SpringManager springManager;
private Project project;

public BeanAliasResolver(Project project) {
super(project);
this.moduleManager = ModuleManager.getInstance(project);
this.springManager = SpringManager.getInstance(project);
this.project = project;
}

@NotNull @Override
@NotNull
@Override
public Collection<String> getPackages(@Nullable PsiElement element) {
Set<String> res = Sets.newHashSet();
for (Module module : moduleManager.getModules()) {
Expand All @@ -45,16 +49,18 @@ public Collection<String> getPackages(@Nullable PsiElement element) {
return res;
}

private void addPackages(Set<String> res, CommonSpringModel springModel) {
for (SpringBeanPointer springBaseBeanPointer : springModel.findBeansByPsiClassWithInheritance(MAPPER_ALIAS_PACKAGE_CLASS)) {
SpringPropertyDefinition basePackages = SpringPropertyUtils.findPropertyByName(springBaseBeanPointer.getSpringBean(), MAPPER_ALIAS_PROPERTY);
if (basePackages != null) {
final String value = basePackages.getValueElement().getStringValue();
private void addPackages(final Set<String> res, CommonSpringModel springModel) {
Processor<SpringPropertyDefinition> processor = new Processor<SpringPropertyDefinition>() {
@Override
public boolean process(SpringPropertyDefinition def) {
final String value = def.getValueElement().getStringValue();
if (value != null) {
res.add(value);
Collections.addAll(res, value.split(",|;"));
}
return true;
}
}
};
SpringUtils.processSpringConfig(project, springModel, MAPPER_ALIAS_PACKAGE_CLASS, MAPPER_ALIAS_PROPERTY, processor);
}

}
Loading