├── lib └── gson-2.2.4.jar ├── mybatis-plus.jar ├── .gitignore ├── resources ├── images │ ├── logo.png │ ├── injection.png │ └── logo_icon.png ├── fileTemplates │ └── j2ee │ │ └── Mybatis Mapper.xml.ft └── liveTemplates │ └── sql.xml ├── intellij-mybatis-plugin.jar ├── src └── com │ └── seventh7 │ └── mybatis │ ├── dom │ ├── model │ │ ├── If.java │ │ ├── IdArg.java │ │ ├── Set.java │ │ ├── Trim.java │ │ ├── When.java │ │ ├── Delete.java │ │ ├── Id.java │ │ ├── Insert.java │ │ ├── Otherwise.java │ │ ├── Update.java │ │ ├── Where.java │ │ ├── Bind.java │ │ ├── Property.java │ │ ├── Result.java │ │ ├── Parameter.java │ │ ├── Sql.java │ │ ├── Select.java │ │ ├── Arg.java │ │ ├── Association.java │ │ ├── GroupThree.java │ │ ├── SelectKey.java │ │ ├── Beans.java │ │ ├── Constructor.java │ │ ├── Discriminator.java │ │ ├── Bean.java │ │ ├── Configuration.java │ │ ├── MyBatisElement.java │ │ ├── Package.java │ │ ├── TypeAliases.java │ │ ├── IdDomElement.java │ │ ├── BeanProperty.java │ │ ├── Include.java │ │ ├── Choose.java │ │ ├── TypeAlias.java │ │ ├── JdbcGroup.java │ │ ├── Collection.java │ │ ├── JavaTypeGroup.java │ │ ├── ResultMapGroup.java │ │ ├── ResultTypeGroup.java │ │ ├── CacheRef.java │ │ ├── Case.java │ │ ├── ReferenceToSelectGroup.java │ │ ├── PropertyGroup.java │ │ ├── ParameterMap.java │ │ ├── GroupFour.java │ │ ├── ResultMap.java │ │ ├── GroupOne.java │ │ ├── LangGroup.java │ │ ├── Foreach.java │ │ ├── GroupTwo.java │ │ ├── Cache.java │ │ └── Mapper.java │ ├── converter │ │ ├── PlainTextConverter.java │ │ ├── TrueOrFalseConverter.java │ │ ├── SqlConverter.java │ │ ├── StatementTypeConverter.java │ │ ├── ReferenceToSelectConverter.java │ │ ├── ResultSetTypeConverter.java │ │ ├── ParameterMapConverter.java │ │ ├── JdbcTypeConverter.java │ │ ├── DaoMethodConverter.java │ │ ├── ConverterAdaptor.java │ │ ├── PropertyConverter.java │ │ ├── CacheRefNamespaceConverter.java │ │ ├── ResultMapConverter.java │ │ └── AliasConverter.java │ ├── description │ │ ├── MapperDescription.java │ │ └── ConfigurationDescription.java │ └── MapperBacktrackingUtils.java │ ├── ui │ ├── ClickableListener.java │ ├── ExecutableListener.java │ ├── ListSelectionListener.java │ ├── ListSelectionItemListener.java │ └── UiComponentFacade.java │ ├── locator │ ├── LocateStrategy.java │ ├── PackageProvider.java │ ├── PackageLocateStrategy.java │ ├── MapperLocator.java │ └── MapperXmlPackageProvider.java │ ├── action │ ├── HackAction.java │ └── MybatisTypedHandler.java │ ├── inspection │ ├── GenericQuickFix.java │ ├── MapperInspection.java │ ├── StatementNotExistsQuickFix.java │ ├── ResultTypeQuickFix.java │ ├── MapperInXmlInspection.java │ ├── MapperXmlInspection.java │ └── MapperMethodInspection.java │ ├── intention │ ├── chooser │ │ ├── IntentionChooser.java │ │ ├── GenerateMapperChooser.java │ │ ├── AliasSwitchChooser.java │ │ ├── GenerateParamChooser.java │ │ ├── ColumnIntentionChooser.java │ │ └── JavaFileIntentionChooser.java │ ├── GenericIntention.java │ ├── GenerateMapperIntention.java │ ├── GenerateParamAnnotationIntention.java │ └── AliasSwitchIntentionAction.java │ ├── util │ ├── MybatisConstants.java │ ├── CollectionUtils.java │ ├── Icons.java │ ├── SpringUtils.java │ ├── DomUtils.java │ └── SQLConstants.java │ ├── setting │ ├── MybatisSettingForm.java │ ├── MybatisSetting.java │ ├── MybatisConfigurable.java │ └── MybatisSettingForm.form │ ├── reference │ ├── ReferenceSetResolverFactory.java │ ├── ResultPropertyReferenceSet.java │ ├── PsiFieldReferenceSetResolver.java │ ├── ContextPsiFieldReference.java │ └── ContextReferenceSetResolver.java │ ├── template │ ├── SqlLiveTemplateProvider.java │ └── MybatisFileTemplateDescriptorFactory.java │ ├── provider │ ├── MarkerProviderAdaptor.java │ ├── SimpleLineMarkerProvider.java │ ├── MapperLineMarkerProvider.java │ ├── StatementLineMarkerProvider.java │ └── InjectionLineMarkerProvider.java │ ├── generate │ ├── InsertGenerator.java │ ├── DeleteGenerator.java │ ├── UpdateGenerator.java │ ├── SelectGenerator.java │ ├── GenerateModel.java │ └── PropertyGenerator.java │ ├── alias │ ├── AliasResolverFactory.java │ ├── SingleAliasResolver.java │ ├── ConfigPackageAliasResolver.java │ ├── AliasResolver.java │ ├── AliasClassReference.java │ ├── AliasDesc.java │ ├── PackageAliasResolver.java │ ├── AnnotationAliasResolver.java │ ├── BeanAliasResolver.java │ ├── InnerAliasResolver.java │ └── AliasFacade.java │ ├── definitionsearch │ └── MapperDefinitionSearch.java │ ├── service │ ├── EditorService.java │ ├── AnnotationService.java │ └── JavaService.java │ ├── refactoring │ └── MapperRefactoringProvider.java │ ├── xml │ └── SqlLanguageInjector.java │ ├── contributor │ └── SqlParamCompletionContributor.java │ ├── spring │ └── model │ │ └── MybatisBeanProvider.java │ └── annotation │ └── Annotation.java ├── README.md └── META-INF └── plugin.xml /lib/gson-2.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/lib/gson-2.2.4.jar -------------------------------------------------------------------------------- /mybatis-plus.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/mybatis-plus.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | log.roo 3 | .idea/ 4 | out/ 5 | .DS_Store 6 | .floo 7 | .flooignore 8 | 9 | META-INF/plugin.xml -------------------------------------------------------------------------------- /resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/resources/images/logo.png -------------------------------------------------------------------------------- /intellij-mybatis-plugin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/intellij-mybatis-plugin.jar -------------------------------------------------------------------------------- /resources/images/injection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/resources/images/injection.png -------------------------------------------------------------------------------- /resources/images/logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenix/intellij-mybatis-plugin/HEAD/resources/images/logo_icon.png -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/If.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface If extends GroupOne { 7 | } 8 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/IdArg.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface IdArg extends Arg { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Set.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Set extends GroupOne { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Trim.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Trim extends GroupOne { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/When.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface When extends GroupOne { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Delete.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Delete extends GroupTwo{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Id.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Id extends PropertyGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Insert.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Insert extends GroupThree{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Otherwise.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Otherwise extends GroupOne { 7 | } 8 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Update.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Update extends GroupTwo{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Where.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Where extends GroupOne { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Bind.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Bind extends MyBatisElement { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Property.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Property extends MyBatisElement { 7 | } 8 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Result.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Result extends PropertyGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Parameter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Parameter extends PropertyGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Sql.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Sql extends GroupOne, IdDomElement, LangGroup{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Select.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Select extends GroupTwo, ResultMapGroup, ResultTypeGroup{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Arg.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Arg extends ReferenceToSelectGroup, JavaTypeGroup, JdbcGroup, ResultMapGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /resources/fileTemplates/j2ee/Mybatis Mapper.xml.ft: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Association.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public interface Association extends GroupFour, ResultMapGroup, PropertyGroup, ReferenceToSelectGroup, JavaTypeGroup { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/ui/ClickableListener.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.ui; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public abstract class ClickableListener extends ExecutableListener { 7 | 8 | public void clicked() { 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/ui/ExecutableListener.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.ui; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public abstract class ExecutableListener { 7 | 8 | public boolean isWriteAction() { 9 | return false; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/ui/ListSelectionListener.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.ui; 2 | 3 | /** 4 | * @author yanglin 5 | */ 6 | public abstract class ListSelectionListener extends ExecutableListener { 7 | 8 | public void selected(int index) { 9 | } 10 | 11 | public void selected(int[] indexes) { 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/locator/LocateStrategy.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.locator; 2 | 3 | import com.intellij.psi.PsiClass; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public abstract class LocateStrategy { 11 | 12 | public abstract boolean apply(@NotNull PsiClass clazz); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/GroupThree.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public interface GroupThree extends GroupTwo{ 11 | 12 | @SubTagList("selectKey") 13 | public List getSelectKey(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/ui/ListSelectionItemListener.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.ui; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public abstract class ListSelectionItemListener extends ExecutableListener { 9 | 10 | public void apply(T t) { 11 | } 12 | 13 | public void apply(Collection ts) { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/action/HackAction.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnAction; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | 6 | /** 7 | * @author yanglin 8 | */ 9 | public class HackAction extends AnAction { 10 | 11 | 12 | public void actionPerformed(AnActionEvent e) { 13 | // NON 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/SelectKey.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.GenericAttributeValue; 4 | import com.intellij.util.xml.Required; 5 | 6 | /** 7 | * @author yanglin 8 | */ 9 | public interface SelectKey extends GroupTwo, ResultTypeGroup { 10 | 11 | @Required(value = false) 12 | public GenericAttributeValue getId(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Beans.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Beans extends MyBatisElement { 13 | 14 | @NotNull 15 | @SubTagList("bean") 16 | public List getBeans(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Constructor.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public interface Constructor extends MyBatisElement { 11 | 12 | @SubTagList("arg") 13 | public List getArgs(); 14 | 15 | @SubTagList("idArg") 16 | public List getIdArgs(); 17 | } 18 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Discriminator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Required; 4 | import com.intellij.util.xml.SubTagList; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface Discriminator extends JavaTypeGroup, JdbcGroup { 12 | 13 | @Required 14 | @SubTagList("case") 15 | public List getCases(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Bean.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Bean extends MyBatisElement { 13 | 14 | @NotNull 15 | @SubTagList("property") 16 | public List getBeanProperties(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/inspection/GenericQuickFix.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.inspection; 2 | 3 | import com.intellij.codeInspection.LocalQuickFix; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public abstract class GenericQuickFix implements LocalQuickFix { 11 | 12 | @NotNull @Override 13 | public String getFamilyName() { 14 | return getName(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Configuration extends MyBatisElement { 13 | 14 | @NotNull 15 | @SubTagList("typeAliases") 16 | public List getTypeAliases(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/MyBatisElement.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.DomElement; 5 | import com.intellij.util.xml.GenericAttributeValue; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public interface MyBatisElement extends DomElement { 11 | 12 | @Attribute("databaseId") 13 | public GenericAttributeValue getDatabaseId(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Package.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.GenericAttributeValue; 5 | 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface Package extends MyBatisElement { 12 | 13 | @NotNull 14 | @Attribute("name") 15 | public GenericAttributeValue getName(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/inspection/MapperInspection.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.inspection; 2 | 3 | import com.intellij.codeInspection.BaseJavaLocalInspectionTool; 4 | import com.intellij.codeInspection.ProblemDescriptor; 5 | 6 | /** 7 | * @author yanglin 8 | */ 9 | public abstract class MapperInspection extends BaseJavaLocalInspectionTool { 10 | 11 | public static final ProblemDescriptor[] EMPTY_ARRAY = new ProblemDescriptor[0]; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/locator/PackageProvider.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.locator; 2 | 3 | import com.intellij.openapi.project.Project; 4 | import com.intellij.psi.PsiPackage; 5 | 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.Set; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public abstract class PackageProvider { 14 | 15 | @NotNull 16 | public abstract Set getPackages(@NotNull Project project); 17 | 18 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/IntentionChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiFile; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface IntentionChooser { 13 | 14 | public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/util/MybatisConstants.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.util; 2 | 3 | import com.intellij.psi.util.ReferenceSetBase; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public final class MybatisConstants { 9 | 10 | private MybatisConstants() { 11 | throw new UnsupportedOperationException(); 12 | } 13 | 14 | public static final String DOT_SEPARATOR = String.valueOf(ReferenceSetBase.DOT_SEPARATOR); 15 | 16 | public static final double PRIORITY = 400.0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/TypeAliases.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface TypeAliases extends MyBatisElement { 13 | 14 | @NotNull 15 | @SubTagList("typeAlias") 16 | public List getTypeAlias(); 17 | 18 | @NotNull 19 | @SubTagList("package") 20 | public List getPackages(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/IdDomElement.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.GenericAttributeValue; 5 | import com.intellij.util.xml.NameValue; 6 | import com.intellij.util.xml.Required; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface IdDomElement extends MyBatisElement{ 12 | 13 | @Required 14 | @NameValue 15 | @Attribute("id") 16 | public GenericAttributeValue getId(); 17 | 18 | public void setValue(String content); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/BeanProperty.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.GenericAttributeValue; 5 | 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public interface BeanProperty extends MyBatisElement { 12 | 13 | @NotNull 14 | @Attribute("name") 15 | public GenericAttributeValue getName(); 16 | 17 | @NotNull 18 | @Attribute("value") 19 | public GenericAttributeValue getValue(); 20 | } 21 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Include.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlTag; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.SqlConverter; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Include extends MyBatisElement { 13 | 14 | @Attribute("refid") 15 | @Convert(SqlConverter.class) 16 | public GenericAttributeValue getRefId(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /resources/liveTemplates/sql.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/util/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.util; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public final class CollectionUtils { 9 | 10 | private CollectionUtils() { 11 | throw new UnsupportedOperationException(); 12 | } 13 | 14 | public static boolean isEmpty(Collection collection) { 15 | return null == collection || 0 == collection.size(); 16 | } 17 | 18 | public static boolean isNotEmpty(Collection collection) { 19 | return !isEmpty(collection); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/setting/MybatisSettingForm.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.setting; 2 | 3 | import javax.swing.*; 4 | 5 | /** 6 | * @author yanglin 7 | */ 8 | public class MybatisSettingForm { 9 | 10 | public JTextField insertPatternTextField; 11 | 12 | public JTextField deletePatternTextField; 13 | 14 | public JTextField updatePatternTextField; 15 | 16 | public JTextField selectPatternTextField; 17 | 18 | public JPanel mainPanel; 19 | 20 | public JComboBox modelComboBox; 21 | 22 | public JButton clearDefaultDataSourceButton; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Choose.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Required; 4 | import com.intellij.util.xml.SubTag; 5 | import com.intellij.util.xml.SubTagList; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface Choose extends MyBatisElement { 15 | 16 | @NotNull 17 | @Required 18 | @SubTagList("when") 19 | public List getWhens(); 20 | 21 | @SubTag("otherwise") 22 | public Otherwise getOtherwise(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/TypeAlias.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.GenericAttributeValue; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface TypeAlias extends MyBatisElement { 13 | 14 | @NotNull 15 | @Attribute("type") 16 | public GenericAttributeValue getType(); 17 | 18 | @NotNull 19 | @Attribute("alias") 20 | public GenericAttributeValue getAlias(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/JdbcGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.Convert; 5 | import com.intellij.util.xml.GenericAttributeValue; 6 | import com.seventh7.mybatis.dom.converter.JdbcTypeConverter; 7 | 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public interface JdbcGroup extends MyBatisElement { 14 | 15 | @NotNull 16 | @Attribute("jdbcType") 17 | @Convert(JdbcTypeConverter.class) 18 | public GenericAttributeValue getJdbcType(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/reference/ReferenceSetResolverFactory.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.reference; 2 | 3 | import com.intellij.psi.xml.XmlAttributeValue; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public final class ReferenceSetResolverFactory { 11 | 12 | private ReferenceSetResolverFactory() { 13 | throw new UnsupportedOperationException(); 14 | } 15 | 16 | public static ContextReferenceSetResolver createPsiFieldResolver(@NotNull F target) { 17 | return new PsiFieldReferenceSetResolver(target); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Collection.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.AliasConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface Collection extends Association { 15 | 16 | @NotNull 17 | @Attribute("ofType") 18 | @Convert(AliasConverter.class) 19 | public GenericAttributeValue getOfType(); 20 | 21 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/JavaTypeGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.AliasConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface JavaTypeGroup extends MyBatisElement { 15 | 16 | @NotNull 17 | @Attribute("javaType") 18 | @Convert(AliasConverter.class) 19 | public GenericAttributeValue getJavaType(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/PlainTextConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | 5 | import org.jetbrains.annotations.NonNls; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public abstract class PlainTextConverter extends ConverterAdaptor { 12 | 13 | @Nullable @Override 14 | public String toString(@Nullable String s, ConvertContext context) { 15 | return s; 16 | } 17 | 18 | @Nullable @Override 19 | public String fromString(@Nullable @NonNls String s, ConvertContext context) { 20 | return s; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/ResultMapGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlTag; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.ResultMapConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface ResultMapGroup extends MyBatisElement { 15 | 16 | @NotNull 17 | @Attribute("resultMap") 18 | @Convert(ResultMapConverter.class) 19 | public GenericAttributeValue getResultMap(); 20 | } 21 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/ResultTypeGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.AliasConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface ResultTypeGroup extends MyBatisElement { 15 | 16 | @NotNull 17 | @Attribute("resultType") 18 | @Convert(AliasConverter.class) 19 | public GenericAttributeValue getResultType(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/CacheRef.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.CacheRefNamespaceConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface CacheRef extends MyBatisElement { 15 | 16 | @NotNull 17 | @Attribute("namespace") 18 | @Convert(CacheRefNamespaceConverter.class) 19 | public GenericAttributeValue getNamespace(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Case.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlAttributeValue; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.ResultMapConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface Case extends GroupFour, ResultTypeGroup{ 15 | 16 | @NotNull 17 | @Attribute("resultMap") 18 | @Convert(ResultMapConverter.class) 19 | public GenericAttributeValue getResultMap(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/TrueOrFalseConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.ConvertContext; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.Collection; 10 | import java.util.Set; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class TrueOrFalseConverter extends PlainTextConverter { 16 | 17 | private static final Set RESULTS = ImmutableSet.of("true", "false"); 18 | 19 | @NotNull @Override 20 | public Collection getVariants(ConvertContext context) { 21 | return RESULTS; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/template/SqlLiveTemplateProvider.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.template; 2 | 3 | import com.intellij.codeInsight.template.impl.DefaultLiveTemplatesProvider; 4 | 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public class SqlLiveTemplateProvider implements DefaultLiveTemplatesProvider { 11 | 12 | public static final String[] TEMPLATE_FILES = { "liveTemplates/sql" }; 13 | 14 | @Override 15 | public String[] getDefaultLiveTemplateFiles() { 16 | return TEMPLATE_FILES; 17 | } 18 | 19 | @Nullable @Override 20 | public String[] getHiddenLiveTemplateFiles() { 21 | return null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/SqlConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.seventh7.mybatis.dom.model.IdDomElement; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Collection; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class SqlConverter extends IdBasedTagConverter{ 16 | 17 | @NotNull @Override 18 | public Collection getComparisons(@Nullable Mapper mapper, ConvertContext context) { 19 | return mapper.getSqls(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/util/Icons.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.util; 2 | 3 | import javax.swing.Icon; 4 | 5 | import com.intellij.icons.AllIcons.Gutter; 6 | import com.intellij.openapi.util.IconLoader; 7 | import com.intellij.util.PlatformIcons; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface Icons { 13 | 14 | Icon MYBATIS_LOGO = IconLoader.getIcon("/images/logo_icon.png"); 15 | 16 | Icon PARAM_COMPLETION_ICON = PlatformIcons.PARAMETER_ICON; 17 | 18 | Icon MAPPER_LINE_MARKER_ICON = Gutter.ImplementingMethod; 19 | 20 | Icon STATEMENT_LINE_MARKER_ICON = Gutter.ImplementedMethod; 21 | 22 | Icon SPRING_INJECTION_ICON = IconLoader.getIcon("/images/injection.png"); 23 | } 24 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/StatementTypeConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.ConvertContext; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.Collection; 10 | import java.util.Set; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class StatementTypeConverter extends PlainTextConverter { 16 | 17 | private static final Set TYPES = ImmutableSet.of("STATEMENT", "PREPARED", "CALLABLE"); 18 | 19 | @NotNull @Override 20 | public Collection getVariants(ConvertContext context) { 21 | return TYPES; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/ReferenceToSelectGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlAttributeValue; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.ReferenceToSelectConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface ReferenceToSelectGroup extends MyBatisElement{ 15 | 16 | @NotNull 17 | @Attribute("select") 18 | @Convert(ReferenceToSelectConverter.class) 19 | public GenericAttributeValue getExtends(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/ReferenceToSelectConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.seventh7.mybatis.dom.model.IdDomElement; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Collection; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class ReferenceToSelectConverter extends IdBasedTagConverter { 16 | 17 | @NotNull @Override 18 | public Collection getComparisons(@Nullable Mapper mapper, ConvertContext context) { 19 | return mapper.getSelects(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/ResultSetTypeConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.ConvertContext; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.Collection; 10 | import java.util.Set; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class ResultSetTypeConverter extends PlainTextConverter { 16 | 17 | private static final Set TYPES = ImmutableSet.of("FORWARD_ONLY", "SCROLL_SENSITIVE", "SCROLL_INSENSITIVE"); 18 | 19 | @NotNull @Override 20 | public Collection getVariants(ConvertContext context) { 21 | return TYPES; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/PropertyGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.xml.XmlAttributeValue; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.converter.PropertyConverter; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public interface PropertyGroup extends JdbcGroup, JavaTypeGroup { 15 | 16 | @Attribute("property") 17 | @Convert(PropertyConverter.class) 18 | GenericAttributeValue getProperty(); 19 | 20 | @NotNull 21 | @Attribute("column") 22 | public GenericAttributeValue getColumn(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/ParameterMapConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.seventh7.mybatis.dom.model.IdDomElement; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Collection; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class ParameterMapConverter extends IdBasedTagConverter{ 16 | 17 | @NotNull @Override 18 | public Collection getComparisons(@Nullable Mapper mapper, 19 | ConvertContext context) { 20 | return mapper.getParameterMaps(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/ParameterMap.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.util.xml.Attribute; 5 | import com.intellij.util.xml.Convert; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.intellij.util.xml.SubTagList; 8 | import com.seventh7.mybatis.dom.converter.AliasConverter; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author yanglin 16 | */ 17 | public interface ParameterMap extends IdDomElement{ 18 | 19 | @NotNull 20 | @Attribute("type") 21 | @Convert(AliasConverter.class) 22 | public GenericAttributeValue getType(); 23 | 24 | @SubTagList("parameter") 25 | public List getParameters(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/description/MapperDescription.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.description; 2 | 3 | import com.intellij.openapi.module.Module; 4 | import com.intellij.psi.xml.XmlFile; 5 | import com.intellij.util.xml.DomFileDescription; 6 | import com.seventh7.mybatis.dom.model.Mapper; 7 | import com.seventh7.mybatis.util.DomUtils; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class MapperDescription extends DomFileDescription { 16 | 17 | public MapperDescription() { 18 | super(Mapper.class, "mapper"); 19 | } 20 | 21 | @Override 22 | public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) { 23 | return DomUtils.isMybatisFile(file); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/provider/MarkerProviderAdaptor.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.provider; 2 | 3 | import com.intellij.codeInsight.daemon.LineMarkerInfo; 4 | import com.intellij.codeInsight.daemon.LineMarkerProvider; 5 | import com.intellij.psi.PsiElement; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Collection; 11 | import java.util.List; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public abstract class MarkerProviderAdaptor implements LineMarkerProvider { 17 | 18 | @Override 19 | public void collectSlowLineMarkers(@NotNull List elements, @NotNull Collection result) { 20 | } 21 | 22 | @Nullable @Override 23 | public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { 24 | return null; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/JdbcTypeConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.collect.Sets; 4 | 5 | import com.intellij.util.xml.ConvertContext; 6 | import com.seventh7.mybatis.util.SQLConstants; 7 | 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.Collection; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class JdbcTypeConverter extends PlainTextConverter { 17 | 18 | private static final Set TYPE_NAMES = Sets.newHashSet(); 19 | 20 | static { 21 | for (int type : SQLConstants.sqlTypes()) { 22 | TYPE_NAMES.add(SQLConstants.getJdbcTypeName(type)); 23 | } 24 | } 25 | 26 | @NotNull @Override 27 | public Collection getVariants(ConvertContext context) { 28 | return TYPE_NAMES; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/DaoMethodConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.psi.PsiMethod; 4 | import com.intellij.util.xml.ConvertContext; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | import com.seventh7.mybatis.util.JavaUtils; 7 | import com.seventh7.mybatis.util.MapperUtils; 8 | 9 | import org.jetbrains.annotations.NonNls; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class DaoMethodConverter extends ConverterAdaptor { 16 | 17 | @Nullable @Override 18 | public PsiMethod fromString(@Nullable @NonNls String id, ConvertContext context) { 19 | Mapper mapper = MapperUtils.getMapper(context.getInvocationElement()); 20 | return JavaUtils.findMethod(context.getProject(), MapperUtils.getNamespace(mapper), id).orNull(); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/description/ConfigurationDescription.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.description; 2 | 3 | import com.intellij.openapi.module.Module; 4 | import com.intellij.psi.xml.XmlFile; 5 | import com.intellij.util.xml.DomFileDescription; 6 | import com.seventh7.mybatis.dom.model.Configuration; 7 | import com.seventh7.mybatis.util.DomUtils; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class ConfigurationDescription extends DomFileDescription{ 16 | 17 | public ConfigurationDescription() { 18 | super(Configuration.class, "configuration"); 19 | } 20 | 21 | @Override 22 | public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) { 23 | return DomUtils.isMybatisConfigurationFile(file); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/GroupFour.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public interface GroupFour extends MyBatisElement { 11 | 12 | @SubTagList("constructor") 13 | public Constructor getConstructor(); 14 | 15 | @SubTagList("id") 16 | public List getIds(); 17 | 18 | @SubTagList("result") 19 | public List getResults(); 20 | 21 | @SubTagList("association") 22 | public List getAssociations(); 23 | 24 | @SubTagList("collection") 25 | public List getCollections(); 26 | 27 | @SubTagList("discriminator") 28 | public Discriminator getDiscriminator(); 29 | 30 | @SubTagList("id") 31 | public Id addId(); 32 | 33 | @SubTagList("result") 34 | public Result addResult(); 35 | } 36 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/GenerateMapperChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.util.PsiTreeUtil; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public class GenerateMapperChooser extends JavaFileIntentionChooser { 13 | 14 | public static final JavaFileIntentionChooser INSTANCE = new GenerateMapperChooser(); 15 | 16 | @Override 17 | public boolean isAvailable(@NotNull PsiElement element) { 18 | if (isPositionOfInterfaceDeclaration(element)) { 19 | PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class); 20 | if (null != clazz) { 21 | return !isTargetPresentInXml(clazz); 22 | } 23 | } 24 | return false; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/generate/InsertGenerator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.generate; 2 | 3 | import com.intellij.psi.PsiMethod; 4 | import com.seventh7.mybatis.dom.model.GroupTwo; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public class InsertGenerator extends StatementGenerator{ 13 | 14 | public InsertGenerator(@NotNull String... patterns) { 15 | super(patterns); 16 | } 17 | 18 | @NotNull @Override 19 | protected GroupTwo getComparableTarget(@NotNull Mapper mapper, @NotNull PsiMethod method) { 20 | return mapper.addInsert(); 21 | } 22 | 23 | @NotNull @Override 24 | public String getId() { 25 | return "InsertGenerator"; 26 | } 27 | 28 | @NotNull @Override 29 | public String getDisplayText() { 30 | return "Insert Statement"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/generate/DeleteGenerator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.generate; 2 | 3 | import com.intellij.psi.PsiMethod; 4 | import com.seventh7.mybatis.dom.model.GroupTwo; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public class DeleteGenerator extends StatementGenerator{ 13 | 14 | public DeleteGenerator(@NotNull String... patterns) { 15 | super(patterns); 16 | } 17 | 18 | @NotNull @Override 19 | protected GroupTwo getComparableTarget(@NotNull Mapper mapper, @NotNull PsiMethod method) { 20 | return mapper.addDelete(); 21 | } 22 | 23 | @NotNull @Override 24 | public String getId() { 25 | return "DeleteGenerator"; 26 | } 27 | 28 | @NotNull @Override 29 | public String getDisplayText() { 30 | return "Delete Statement"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/generate/UpdateGenerator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.generate; 2 | 3 | import com.intellij.psi.PsiMethod; 4 | import com.seventh7.mybatis.dom.model.GroupTwo; 5 | import com.seventh7.mybatis.dom.model.Mapper; 6 | 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public class UpdateGenerator extends StatementGenerator{ 13 | 14 | public UpdateGenerator(@NotNull String... patterns) { 15 | super(patterns); 16 | } 17 | 18 | @NotNull @Override 19 | protected GroupTwo getComparableTarget(@NotNull Mapper mapper, @NotNull PsiMethod method) { 20 | return mapper.addUpdate(); 21 | } 22 | 23 | @NotNull @Override 24 | public String getId() { 25 | return "UpdateGenerator"; 26 | } 27 | 28 | @NotNull @Override 29 | public String getDisplayText() { 30 | return "Update Statement"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/ResultMap.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.xml.XmlAttributeValue; 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.GenericAttributeValue; 8 | import com.seventh7.mybatis.dom.converter.AliasConverter; 9 | import com.seventh7.mybatis.dom.converter.ResultMapConverter; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public interface ResultMap extends GroupFour, IdDomElement{ 17 | 18 | @NotNull 19 | @Attribute("extends") 20 | @Convert(ResultMapConverter.class) 21 | public GenericAttributeValue getExtends(); 22 | 23 | @NotNull 24 | @Attribute("type") 25 | @Convert(AliasConverter.class) 26 | public GenericAttributeValue getType(); 27 | 28 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/GroupOne.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.SubTagList; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author yanglin 11 | */ 12 | public interface GroupOne extends MyBatisElement{ 13 | 14 | @NotNull 15 | @SubTagList("include") 16 | public List getIncludes(); 17 | 18 | @NotNull 19 | @SubTagList("trim") 20 | public List getTrims(); 21 | 22 | @NotNull 23 | @SubTagList("where") 24 | public List getWheres(); 25 | 26 | @NotNull 27 | @SubTagList("set") 28 | public List getSets(); 29 | 30 | @NotNull 31 | @SubTagList("foreach") 32 | public List getForeachs(); 33 | 34 | @NotNull 35 | @SubTagList("choose") 36 | public List getChooses(); 37 | 38 | @NotNull 39 | @SubTagList("if") 40 | public List getIfs(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/template/MybatisFileTemplateDescriptorFactory.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.template; 2 | 3 | import com.intellij.ide.fileTemplates.FileTemplateDescriptor; 4 | import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor; 5 | import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptorFactory; 6 | import com.seventh7.mybatis.util.Icons; 7 | 8 | /** 9 | * @author yanglin 10 | */ 11 | public class MybatisFileTemplateDescriptorFactory implements FileTemplateGroupDescriptorFactory { 12 | 13 | public static final String MYBATIS_MAPPER_XML_TEMPLATE = "Mybatis Mapper.xml"; 14 | 15 | @Override 16 | public FileTemplateGroupDescriptor getFileTemplatesDescriptor() { 17 | FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor("Mybatis", Icons.MYBATIS_LOGO); 18 | group.addTemplate(new FileTemplateDescriptor(MYBATIS_MAPPER_XML_TEMPLATE, Icons.MYBATIS_LOGO)); 19 | return group; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/locator/PackageLocateStrategy.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.locator; 2 | 3 | import com.intellij.psi.JavaPsiFacade; 4 | import com.intellij.psi.PsiClass; 5 | import com.intellij.psi.PsiJavaFile; 6 | import com.intellij.psi.PsiPackage; 7 | 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public class PackageLocateStrategy extends LocateStrategy{ 14 | 15 | private PackageProvider provider = new MapperXmlPackageProvider(); 16 | 17 | @Override 18 | public boolean apply(@NotNull PsiClass clazz) { 19 | String packageName = ((PsiJavaFile) clazz.getContainingFile()).getPackageName(); 20 | PsiPackage pkg = JavaPsiFacade.getInstance(clazz.getProject()).findPackage(packageName); 21 | for (PsiPackage tmp : provider.getPackages(clazz.getProject())) { 22 | if (tmp.equals(pkg)) { 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/AliasSwitchChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiFile; 6 | import com.intellij.psi.PsiReference; 7 | import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference; 8 | import com.seventh7.mybatis.alias.AliasClassReference; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class AliasSwitchChooser implements IntentionChooser{ 16 | 17 | public static final AliasSwitchChooser INSTANCE = new AliasSwitchChooser(); 18 | 19 | @Override 20 | public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { 21 | PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset()); 22 | return reference instanceof JavaClassReference || reference instanceof AliasClassReference; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/ConverterAdaptor.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.util.xml.ConvertContext; 4 | import com.intellij.util.xml.ResolvingConverter; 5 | 6 | import org.jetbrains.annotations.NonNls; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Collection; 11 | import java.util.Collections; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public abstract class ConverterAdaptor extends ResolvingConverter { 17 | 18 | @NotNull @Override 19 | public Collection getVariants(ConvertContext context) { 20 | return Collections.emptyList(); 21 | } 22 | 23 | @Nullable @Override 24 | public String toString(@Nullable T t, ConvertContext context) { 25 | // throw new UnsupportedOperationException(); 26 | return null; 27 | } 28 | 29 | @Nullable @Override 30 | public T fromString(@Nullable @NonNls String s, ConvertContext context) { 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/reference/ResultPropertyReferenceSet.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.reference; 2 | 3 | import com.intellij.openapi.util.TextRange; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiReference; 6 | import com.intellij.psi.util.ReferenceSetBase; 7 | import com.intellij.psi.xml.XmlAttributeValue; 8 | 9 | import org.jetbrains.annotations.NonNls; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class ResultPropertyReferenceSet extends ReferenceSetBase{ 17 | 18 | public ResultPropertyReferenceSet(String text, @NotNull PsiElement element, int offset) { 19 | super(text, element, offset, DOT_SEPARATOR); 20 | } 21 | 22 | @Nullable @NonNls @Override 23 | protected PsiReference createReference(TextRange range, int index) { 24 | XmlAttributeValue element = (XmlAttributeValue)getElement(); 25 | return null == element ? null : new ContextPsiFieldReference(element, range, index); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/LangGroup.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.ConvertContext; 8 | import com.intellij.util.xml.GenericAttributeValue; 9 | import com.seventh7.mybatis.dom.converter.PlainTextConverter; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.Collection; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public interface LangGroup extends MyBatisElement { 19 | 20 | @NotNull 21 | @Attribute("lang") 22 | @Convert(LangConverter.class) 23 | public GenericAttributeValue getLang(); 24 | 25 | public static class LangConverter extends PlainTextConverter { 26 | 27 | private static final java.util.Set RAW_KNOWN = ImmutableSet.of("xml", "raw"); 28 | 29 | @NotNull @Override 30 | public Collection getVariants(ConvertContext context) { 31 | return RAW_KNOWN; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/GenericIntention.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention; 2 | 3 | import com.intellij.codeInsight.intention.IntentionAction; 4 | import com.intellij.openapi.editor.Editor; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiFile; 7 | import com.seventh7.mybatis.intention.chooser.IntentionChooser; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public abstract class GenericIntention implements IntentionAction{ 15 | 16 | protected IntentionChooser chooser; 17 | 18 | public GenericIntention(@NotNull IntentionChooser chooser) { 19 | this.chooser = chooser; 20 | } 21 | 22 | @NotNull @Override 23 | public String getFamilyName() { 24 | return getText(); 25 | } 26 | 27 | @Override 28 | public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { 29 | return chooser.isAvailable(project, editor, file); 30 | } 31 | 32 | @Override 33 | public boolean startInWriteAction() { 34 | return true; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/locator/MapperLocator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.locator; 2 | 3 | import com.intellij.openapi.components.ServiceManager; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.psi.PsiMethod; 7 | import com.seventh7.mybatis.util.JavaUtils; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class MapperLocator { 16 | 17 | public static LocateStrategy dfltLocateStrategy = new PackageLocateStrategy(); 18 | 19 | public static MapperLocator getInstance(@NotNull Project project) { 20 | return ServiceManager.getService(project, MapperLocator.class); 21 | } 22 | 23 | public boolean process(@Nullable PsiMethod method) { 24 | return null != method && process(method.getContainingClass()); 25 | } 26 | 27 | public boolean process(@Nullable PsiClass clazz) { 28 | return null != clazz && JavaUtils.isElementWithinInterface(clazz) && dfltLocateStrategy.apply(clazz); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Foreach.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.ConvertContext; 8 | import com.intellij.util.xml.GenericAttributeValue; 9 | import com.seventh7.mybatis.dom.converter.PlainTextConverter; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.Collection; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public interface Foreach extends GroupOne { 19 | 20 | @NotNull 21 | @Attribute("collection") 22 | @Convert(ForEachCollectionConverter.class) 23 | public GenericAttributeValue getCollection(); 24 | 25 | public static class ForEachCollectionConverter extends PlainTextConverter { 26 | 27 | private static final java.util.Set TYPES_KNOWN = ImmutableSet.of("list", "array"); 28 | 29 | @NotNull @Override 30 | public Collection getVariants(ConvertContext context) { 31 | return TYPES_KNOWN; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/AliasResolverFactory.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.intellij.openapi.project.Project; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public class AliasResolverFactory { 11 | 12 | @NotNull 13 | public static AliasResolver createInnerAliasResolver(@NotNull Project project) { 14 | return new InnerAliasResolver(project); 15 | } 16 | 17 | @NotNull 18 | public static AliasResolver createAnnotationResolver(@NotNull Project project) { 19 | return new AnnotationAliasResolver(project); 20 | } 21 | 22 | @NotNull 23 | public static AliasResolver createBeanResolver(@NotNull Project project) { 24 | return new BeanAliasResolver(project); 25 | } 26 | 27 | @NotNull 28 | public static AliasResolver createConfigPackageResolver(@NotNull Project project) { 29 | return new ConfigPackageAliasResolver(project); 30 | } 31 | 32 | @NotNull 33 | public static AliasResolver createSingleAliasResolver(@NotNull Project project) { 34 | return new SingleAliasResolver(project); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/GenerateParamChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.psi.PsiElement; 4 | import com.intellij.psi.PsiMethod; 5 | import com.intellij.psi.PsiParameter; 6 | import com.intellij.psi.util.PsiTreeUtil; 7 | import com.seventh7.mybatis.annotation.Annotation; 8 | import com.seventh7.mybatis.util.JavaUtils; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | /** 13 | * @author yanglin 14 | */ 15 | public class GenerateParamChooser extends JavaFileIntentionChooser { 16 | 17 | public static final JavaFileIntentionChooser INSTANCE = new GenerateParamChooser(); 18 | 19 | @Override 20 | public boolean isAvailable(@NotNull PsiElement element) { 21 | PsiParameter parameter = PsiTreeUtil.getParentOfType(element, PsiParameter.class); 22 | PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class); 23 | return (null != parameter && !JavaUtils.isAnnotationPresent(parameter, Annotation.PARAM)) || 24 | (null != method && !JavaUtils.isAllParameterWithAnnotation(method, Annotation.PARAM)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/inspection/StatementNotExistsQuickFix.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.inspection; 2 | 3 | import com.intellij.codeInspection.ProblemDescriptor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiMethod; 6 | import com.seventh7.mybatis.generate.StatementGenerator; 7 | 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author yanglin 12 | */ 13 | public class StatementNotExistsQuickFix extends GenericQuickFix { 14 | 15 | private PsiMethod method; 16 | 17 | public StatementNotExistsQuickFix(@NotNull PsiMethod method) { 18 | this.method = method; 19 | } 20 | 21 | @NotNull @Override 22 | public String getName() { 23 | return "Generate statement"; 24 | } 25 | 26 | @Override 27 | public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { 28 | StatementGenerator.applyGenerate(method, true); 29 | } 30 | 31 | @NotNull 32 | public PsiMethod getMethod() { 33 | return method; 34 | } 35 | 36 | public void setMethod(@NotNull PsiMethod method) { 37 | this.method = method; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/SingleAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.google.common.collect.Sets; 4 | 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.util.Processor; 8 | import com.seventh7.mybatis.dom.model.TypeAlias; 9 | import com.seventh7.mybatis.util.MapperUtils; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.Set; 15 | 16 | /** 17 | * @author yanglin 18 | */ 19 | public class SingleAliasResolver extends AliasResolver{ 20 | 21 | public SingleAliasResolver(Project project) { 22 | super(project); 23 | } 24 | 25 | @NotNull @Override 26 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 27 | final Set result = Sets.newHashSet(); 28 | MapperUtils.processConfiguredTypeAliases(project, new Processor() { 29 | @Override 30 | public boolean process(TypeAlias typeAlias) { 31 | addAliasDesc(result, typeAlias.getType().getValue(), typeAlias.getAlias().getStringValue()); 32 | return true; 33 | } 34 | }); 35 | return result; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/ConfigPackageAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.util.Processor; 8 | import com.seventh7.mybatis.dom.model.Package; 9 | import com.seventh7.mybatis.util.MapperUtils; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Collection; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public class ConfigPackageAliasResolver extends PackageAliasResolver{ 21 | 22 | public ConfigPackageAliasResolver(Project project) { 23 | super(project); 24 | } 25 | 26 | @NotNull @Override 27 | public Collection getPackages(@Nullable PsiElement element) { 28 | final ArrayList result = Lists.newArrayList(); 29 | MapperUtils.processConfiguredPackage(project, new Processor() { 30 | @Override 31 | public boolean process(Package pkg) { 32 | result.add(pkg.getName().getStringValue()); 33 | return true; 34 | } 35 | }); 36 | return result; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/GroupTwo.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.psi.PsiClass; 4 | import com.intellij.psi.xml.XmlTag; 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.GenericAttributeValue; 8 | import com.intellij.util.xml.SubTagList; 9 | import com.seventh7.mybatis.dom.converter.AliasConverter; 10 | import com.seventh7.mybatis.dom.converter.DaoMethodConverter; 11 | import com.seventh7.mybatis.dom.converter.ParameterMapConverter; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public interface GroupTwo extends GroupOne, IdDomElement, LangGroup{ 21 | 22 | @SubTagList("bind") 23 | public List getBinds(); 24 | 25 | @NotNull 26 | @Attribute("parameterMap") 27 | @Convert(ParameterMapConverter.class) 28 | public GenericAttributeValue getParameterMap(); 29 | 30 | @Attribute("id") 31 | @Convert(DaoMethodConverter.class) 32 | public GenericAttributeValue getId(); 33 | 34 | @NotNull 35 | @Attribute("parameterType") 36 | @Convert(AliasConverter.class) 37 | public GenericAttributeValue getParameterType(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/definitionsearch/MapperDefinitionSearch.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.definitionsearch; 2 | 3 | import com.intellij.openapi.application.QueryExecutorBase; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiTypeParameterListOwner; 6 | import com.intellij.psi.xml.XmlElement; 7 | import com.intellij.util.Processor; 8 | import com.intellij.util.xml.DomElement; 9 | import com.seventh7.mybatis.service.JavaService; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | 14 | /** 15 | * @author yanglin 16 | */ 17 | public class MapperDefinitionSearch extends QueryExecutorBase { 18 | 19 | public MapperDefinitionSearch() { 20 | super(true); 21 | } 22 | 23 | @Override 24 | public void processQuery(@NotNull PsiElement element, @NotNull final Processor consumer) { 25 | 26 | if (!(element instanceof PsiTypeParameterListOwner)) return; 27 | 28 | Processor processor = new Processor() { 29 | @Override 30 | public boolean process(DomElement domElement) { 31 | return consumer.process(domElement.getXmlElement()); 32 | } 33 | }; 34 | 35 | JavaService.getInstance(element.getProject()).processMapperInterfaceElements(element, processor); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/generate/SelectGenerator.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.generate; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.psi.PsiMethod; 7 | import com.seventh7.mybatis.dom.model.GroupTwo; 8 | import com.seventh7.mybatis.dom.model.Mapper; 9 | import com.seventh7.mybatis.dom.model.Select; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | /** 14 | * @author yanglin 15 | */ 16 | public class SelectGenerator extends StatementGenerator { 17 | 18 | public SelectGenerator(@NotNull String... patterns) { 19 | super(patterns); 20 | } 21 | 22 | @NotNull @Override 23 | protected GroupTwo getComparableTarget(@NotNull Mapper mapper, @NotNull PsiMethod method) { 24 | Select select = mapper.addSelect(); 25 | setupResultType(method, select); 26 | return select; 27 | } 28 | 29 | private void setupResultType(PsiMethod method, Select select) { 30 | Optional clazz = StatementGenerator.getSelectResultType(method); 31 | if (clazz.isPresent()) { 32 | select.getResultType().setValue(clazz.get()); 33 | } 34 | } 35 | 36 | @NotNull @Override 37 | public String getId() { 38 | return "SelectGenerator"; 39 | } 40 | 41 | @NotNull @Override 42 | public String getDisplayText() { 43 | return "Select Statement"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/AliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiClass; 7 | import com.intellij.psi.PsiElement; 8 | import com.seventh7.mybatis.util.JavaUtils; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | import java.util.Set; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public abstract class AliasResolver { 19 | 20 | protected Project project; 21 | 22 | public AliasResolver(Project project) { 23 | this.project = project; 24 | } 25 | 26 | @NotNull 27 | protected Optional addAliasDesc(@NotNull Set descs, @Nullable PsiClass clazz, @Nullable String alias) { 28 | if (null == alias || !JavaUtils.isModelClazz(clazz)) { 29 | return Optional.absent(); 30 | } 31 | AliasDesc desc = new AliasDesc(); 32 | descs.add(desc); 33 | desc.setClazz(clazz); 34 | desc.setAlias(alias); 35 | return Optional.of(desc); 36 | } 37 | 38 | @NotNull 39 | public abstract Set getClassAliasDescriptions(@Nullable PsiElement element); 40 | 41 | public Project getProject() { 42 | return project; 43 | } 44 | 45 | public void setProject(Project project) { 46 | this.project = project; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Cache.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | 5 | import com.intellij.util.xml.Attribute; 6 | import com.intellij.util.xml.Convert; 7 | import com.intellij.util.xml.ConvertContext; 8 | import com.intellij.util.xml.GenericAttributeValue; 9 | import com.intellij.util.xml.SubTagList; 10 | import com.seventh7.mybatis.dom.converter.PlainTextConverter; 11 | import com.seventh7.mybatis.dom.converter.TrueOrFalseConverter; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public interface Cache extends MyBatisElement { 21 | 22 | @SubTagList("property") 23 | public List getProperties(); 24 | 25 | @NotNull 26 | @Attribute("eviction") 27 | @Convert(CacheEvictionConverter.class) 28 | public GenericAttributeValue getEviction(); 29 | 30 | @NotNull 31 | @Attribute("readOnly") 32 | @Convert(TrueOrFalseConverter.class) 33 | public GenericAttributeValue getReadOnly(); 34 | 35 | public static class CacheEvictionConverter extends PlainTextConverter{ 36 | 37 | private static final java.util.Set EVICTIONS = ImmutableSet.of("LRU", "FIFO", "SOFT", "WEAK"); 38 | 39 | @NotNull @Override 40 | public java.util.Collection getVariants(ConvertContext context) { 41 | return EVICTIONS; 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/inspection/ResultTypeQuickFix.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.inspection; 2 | 3 | import com.intellij.codeInspection.ProblemDescriptor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.util.xml.GenericAttributeValue; 7 | import com.seventh7.mybatis.dom.model.Select; 8 | 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author yanglin 13 | */ 14 | public class ResultTypeQuickFix extends GenericQuickFix { 15 | 16 | private Select select; 17 | private PsiClass target; 18 | 19 | public ResultTypeQuickFix(@NotNull Select select, @NotNull PsiClass target) { 20 | this.select = select; 21 | this.target = target; 22 | } 23 | 24 | @NotNull @Override 25 | public String getName() { 26 | return "Correct resultType"; 27 | } 28 | 29 | @Override 30 | public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { 31 | GenericAttributeValue resultType = select.getResultType(); 32 | resultType.setValue(target); 33 | } 34 | 35 | @NotNull 36 | public PsiClass getTarget() { 37 | return target; 38 | } 39 | 40 | public void setTarget(@NotNull PsiClass target) { 41 | this.target = target; 42 | } 43 | 44 | @NotNull 45 | public Select getSelect() { 46 | return select; 47 | } 48 | 49 | public void setSelect(@NotNull Select select) { 50 | this.select = select; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/GenerateMapperIntention.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.PsiFile; 8 | import com.intellij.psi.util.PsiTreeUtil; 9 | import com.intellij.util.IncorrectOperationException; 10 | import com.seventh7.mybatis.generate.MapperXmlGenerator; 11 | import com.seventh7.mybatis.intention.chooser.GenerateMapperChooser; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public class GenerateMapperIntention extends GenericIntention { 19 | 20 | public GenerateMapperIntention() { 21 | super(GenerateMapperChooser.INSTANCE); 22 | } 23 | 24 | @NotNull @Override 25 | public String getText() { 26 | return "[Mybatis] Generate mapper of xml"; 27 | } 28 | 29 | @Override 30 | public boolean startInWriteAction() { 31 | return true; 32 | } 33 | 34 | @Override 35 | public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { 36 | PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); 37 | PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class); 38 | if (clazz == null) { 39 | return; 40 | } 41 | MapperXmlGenerator.getInstance().generate(clazz); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/AliasClassReference.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.Collections2; 5 | 6 | import com.intellij.psi.PsiClass; 7 | import com.intellij.psi.PsiReferenceBase; 8 | import com.intellij.psi.xml.XmlAttributeValue; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | import java.util.Collection; 14 | 15 | /** 16 | * @author yanglin 17 | */ 18 | public class AliasClassReference extends PsiReferenceBase { 19 | 20 | private Function function = new Function() { 21 | @Override 22 | public String apply(AliasDesc input) { 23 | return input.getAlias(); 24 | } 25 | }; 26 | 27 | public AliasClassReference(@NotNull XmlAttributeValue element) { 28 | super(element, true); 29 | } 30 | 31 | @Nullable @Override 32 | public PsiClass resolve() { 33 | XmlAttributeValue attributeValue = getElement(); 34 | return AliasFacade.getInstance(attributeValue.getProject()).findPsiClass(attributeValue, attributeValue.getValue()).orNull(); 35 | } 36 | 37 | @NotNull @Override 38 | public Object[] getVariants() { 39 | AliasFacade aliasFacade = AliasFacade.getInstance(getElement().getProject()); 40 | Collection result = Collections2.transform(aliasFacade.getAliasDescs(getElement()), function); 41 | return result.toArray(new String[result.size()]); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/AliasDesc.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.intellij.psi.PsiClass; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | /** 8 | * @author yanglin 9 | */ 10 | public class AliasDesc { 11 | 12 | private PsiClass clazz; 13 | 14 | private String alias; 15 | 16 | public AliasDesc() { 17 | } 18 | 19 | public static AliasDesc create(@NotNull PsiClass psiClass, @NotNull String alias) { 20 | return new AliasDesc(psiClass, alias); 21 | } 22 | 23 | public AliasDesc(PsiClass clazz, String alias) { 24 | this.clazz = clazz; 25 | this.alias = alias; 26 | } 27 | 28 | public PsiClass getClazz() { 29 | return clazz; 30 | } 31 | 32 | public void setClazz(PsiClass clazz) { 33 | this.clazz = clazz; 34 | } 35 | 36 | public String getAlias() { 37 | return alias; 38 | } 39 | 40 | public void setAlias(String alias) { 41 | this.alias = alias; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) { 47 | return true; 48 | } 49 | if (o == null || getClass() != o.getClass()) { 50 | return false; 51 | } 52 | 53 | AliasDesc aliasDesc = (AliasDesc) o; 54 | 55 | if (alias != null ? !alias.equals(aliasDesc.alias) : aliasDesc.alias != null) { 56 | return false; 57 | } 58 | 59 | return !(clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null); 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | int result = clazz != null ? clazz.hashCode() : 0; 65 | result = 31 * result + (alias != null ? alias.hashCode() : 0); 66 | return result; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/locator/MapperXmlPackageProvider.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.locator; 2 | 3 | import com.google.common.base.Optional; 4 | import com.google.common.collect.Sets; 5 | 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.JavaPsiFacade; 8 | import com.intellij.psi.PsiClass; 9 | import com.intellij.psi.PsiFile; 10 | import com.intellij.psi.PsiJavaFile; 11 | import com.intellij.psi.PsiPackage; 12 | import com.seventh7.mybatis.dom.model.Mapper; 13 | import com.seventh7.mybatis.util.JavaUtils; 14 | import com.seventh7.mybatis.util.MapperUtils; 15 | 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | import java.util.Collection; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | /** 23 | * @author yanglin 24 | */ 25 | public class MapperXmlPackageProvider extends PackageProvider{ 26 | 27 | @NotNull @Override 28 | public Set getPackages(@NotNull Project project) { 29 | HashSet res = Sets.newHashSet(); 30 | Collection mappers = MapperUtils.findMappers(project); 31 | JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); 32 | for (Mapper mapper : mappers) { 33 | final Optional clazz = JavaUtils.findClazz(project, MapperUtils.getNamespace(mapper)); 34 | if (clazz.isPresent()) { 35 | PsiFile file = clazz.get().getContainingFile(); 36 | if (file instanceof PsiJavaFile) { 37 | PsiPackage pkg = javaPsiFacade.findPackage(((PsiJavaFile) file).getPackageName()); 38 | if (null != pkg) { 39 | res.add(pkg); 40 | } 41 | } 42 | } 43 | } 44 | return res; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/ColumnIntentionChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.psi.PsiFile; 7 | import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; 8 | import com.intellij.psi.util.PsiTreeUtil; 9 | import com.intellij.psi.xml.XmlText; 10 | import com.intellij.sql.psi.SqlFile; 11 | import com.intellij.util.xml.DomElement; 12 | import com.intellij.util.xml.DomUtil; 13 | import com.seventh7.mybatis.dom.model.Sql; 14 | import com.seventh7.mybatis.util.DomUtils; 15 | 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public class ColumnIntentionChooser implements IntentionChooser { 22 | 23 | public static final IntentionChooser INSTANCE = new ColumnIntentionChooser(); 24 | 25 | @Override 26 | public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { 27 | boolean sqlFileCase = file instanceof SqlFile && DomUtils.isMybatisFile(InjectedLanguageUtil.getTopLevelFile(file)); 28 | if (sqlFileCase) { 29 | return true; 30 | } 31 | 32 | PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); 33 | XmlText text = PsiTreeUtil.getParentOfType(element, XmlText.class); 34 | if (text == null) { 35 | return false; 36 | } 37 | 38 | DomElement domElement = DomUtil.getDomElement(element); 39 | if (domElement == null) { 40 | return false; 41 | } 42 | return DomUtil.getParentOfType(domElement, Sql.class, true) != null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/PropertyConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.intellij.psi.ElementManipulators; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiReference; 6 | import com.intellij.psi.xml.XmlAttributeValue; 7 | import com.intellij.util.xml.ConvertContext; 8 | import com.intellij.util.xml.CustomReferenceConverter; 9 | import com.intellij.util.xml.DomElement; 10 | import com.intellij.util.xml.GenericAttributeValue; 11 | import com.intellij.util.xml.GenericDomValue; 12 | import com.seventh7.mybatis.reference.ResultPropertyReferenceSet; 13 | 14 | import org.jetbrains.annotations.NonNls; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public class PropertyConverter extends ConverterAdaptor implements CustomReferenceConverter { 22 | 23 | @NotNull @Override 24 | public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) { 25 | final String s = value.getStringValue(); 26 | if (s == null) { 27 | return PsiReference.EMPTY_ARRAY; 28 | } 29 | return new ResultPropertyReferenceSet(s, element, ElementManipulators.getOffsetInElement(element)).getPsiReferences(); 30 | } 31 | 32 | @Nullable @Override 33 | public XmlAttributeValue fromString(@Nullable @NonNls String s, ConvertContext context) { 34 | DomElement ctxElement = context.getInvocationElement(); 35 | return ctxElement instanceof GenericAttributeValue ? ((GenericAttributeValue)ctxElement).getXmlAttributeValue() : null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/CacheRefNamespaceConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.Collections2; 5 | 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.util.xml.ConvertContext; 9 | import com.seventh7.mybatis.dom.model.Mapper; 10 | import com.seventh7.mybatis.util.JavaUtils; 11 | import com.seventh7.mybatis.util.MapperUtils; 12 | 13 | import org.jetbrains.annotations.NonNls; 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.Nullable; 16 | 17 | import java.util.Collection; 18 | 19 | /** 20 | * @author yanglin 21 | */ 22 | public class CacheRefNamespaceConverter extends ConverterAdaptor { 23 | 24 | @NotNull @Override 25 | public Collection getVariants(ConvertContext context) { 26 | final Project project = context.getProject(); 27 | final Collection mappers = MapperUtils.findMappers(project); 28 | return Collections2.transform(mappers, new Function() { 29 | @Override 30 | public PsiClass apply(Mapper input) { 31 | return JavaUtils.findClazz(project, input.getNamespace().getStringValue()).orNull(); 32 | } 33 | }); 34 | } 35 | 36 | @Nullable @Override 37 | public String toString(@Nullable PsiClass psiClass, ConvertContext context) { 38 | return psiClass == null ? null : psiClass.getQualifiedName(); 39 | } 40 | 41 | @Nullable @Override 42 | public PsiClass fromString(@Nullable @NonNls String s, ConvertContext context) { 43 | return JavaUtils.findClazz(context.getProject(), s).orNull(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/alias/PackageAliasResolver.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.alias; 2 | 3 | import com.google.common.collect.Sets; 4 | 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.JavaPsiFacade; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.PsiPackage; 10 | 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.Collection; 15 | import java.util.Set; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public abstract class PackageAliasResolver extends AliasResolver{ 21 | 22 | private JavaPsiFacade javaPsiFacade; 23 | 24 | public PackageAliasResolver(Project project) { 25 | super(project); 26 | this.javaPsiFacade = JavaPsiFacade.getInstance(project); 27 | } 28 | 29 | @NotNull @Override 30 | public Set getClassAliasDescriptions(@Nullable PsiElement element) { 31 | Set result = Sets.newHashSet(); 32 | for (String pkgName : getPackages(element)) { 33 | if (null == pkgName) { 34 | continue; 35 | } 36 | PsiPackage pkg = javaPsiFacade.findPackage(pkgName); 37 | if (null != pkg) { 38 | addAliasDesc(result, pkg); 39 | for (PsiPackage tmp : pkg.getSubPackages()) { 40 | addAliasDesc(result, tmp); 41 | } 42 | } 43 | } 44 | return result; 45 | } 46 | 47 | private void addAliasDesc(Set result, PsiPackage pkg) { 48 | for (PsiClass clazz : pkg.getClasses()) { 49 | addAliasDesc(result, clazz, clazz.getName()); 50 | } 51 | } 52 | 53 | @NotNull 54 | public abstract Collection getPackages(@Nullable PsiElement element); 55 | } 56 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/GenerateParamAnnotationIntention.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.psi.PsiFile; 7 | import com.intellij.psi.PsiMethod; 8 | import com.intellij.psi.PsiParameter; 9 | import com.intellij.psi.util.PsiTreeUtil; 10 | import com.intellij.util.IncorrectOperationException; 11 | import com.seventh7.mybatis.intention.chooser.GenerateParamChooser; 12 | import com.seventh7.mybatis.service.AnnotationService; 13 | 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | /** 17 | * @author yanglin 18 | */ 19 | public class GenerateParamAnnotationIntention extends GenericIntention { 20 | 21 | public GenerateParamAnnotationIntention() { 22 | super(GenerateParamChooser.INSTANCE); 23 | } 24 | 25 | @NotNull @Override 26 | public String getText() { 27 | return "[Mybatis] Generate @Param"; 28 | } 29 | 30 | @Override 31 | public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { 32 | PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); 33 | PsiParameter parameter = PsiTreeUtil.getParentOfType(element, PsiParameter.class); 34 | AnnotationService annotationService = AnnotationService.getInstance(project); 35 | if (null != parameter) { 36 | annotationService.addAnnotationWithParameterName(parameter); 37 | } else { 38 | PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class); 39 | if (null != method) { 40 | annotationService.addAnnotationWithParameterNameForMethodParameters(method); 41 | } 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/intention/chooser/JavaFileIntentionChooser.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.intention.chooser; 2 | 3 | import com.intellij.openapi.editor.Editor; 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.PsiFile; 8 | import com.intellij.psi.PsiJavaFile; 9 | import com.intellij.psi.PsiMethod; 10 | import com.intellij.psi.PsiParameter; 11 | import com.seventh7.mybatis.util.JavaUtils; 12 | import com.seventh7.mybatis.util.MapperUtils; 13 | 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | /** 17 | * @author yanglin 18 | */ 19 | public abstract class JavaFileIntentionChooser implements IntentionChooser { 20 | 21 | @Override 22 | public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { 23 | if (!(file instanceof PsiJavaFile)) 24 | return false; 25 | PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); 26 | return null != element && JavaUtils.isElementWithinInterface(element) && isAvailable(element); 27 | } 28 | 29 | public abstract boolean isAvailable(@NotNull PsiElement element); 30 | 31 | public boolean isPositionOfParameterDeclaration(@NotNull PsiElement element) { 32 | return element.getParent() instanceof PsiParameter; 33 | } 34 | 35 | public boolean isPositionOfMethodDeclaration(@NotNull PsiElement element) { 36 | return element.getParent() instanceof PsiMethod; 37 | } 38 | 39 | public boolean isPositionOfInterfaceDeclaration(@NotNull PsiElement element) { 40 | return element.getParent() instanceof PsiClass; 41 | } 42 | 43 | public boolean isTargetPresentInXml(@NotNull PsiElement element) { 44 | return MapperUtils.isTargetPresentInMapperXml(element); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/util/SpringUtils.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.util; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiClass; 7 | import com.intellij.spring.CommonSpringModel; 8 | import com.intellij.spring.model.SpringBeanPointer; 9 | import com.intellij.spring.model.utils.SpringPropertyUtils; 10 | import com.intellij.spring.model.xml.beans.SpringPropertyDefinition; 11 | import com.intellij.util.Processor; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import java.util.Collection; 16 | 17 | /** 18 | * @author yanglin 19 | */ 20 | public final class SpringUtils { 21 | 22 | private SpringUtils() { 23 | throw new UnsupportedOperationException(); 24 | } 25 | 26 | public static void processSpringConfig(@NotNull Project project, 27 | @NotNull CommonSpringModel model, 28 | @NotNull String clazzName, 29 | @NotNull String prop, 30 | @NotNull Processor processor) { 31 | Optional clazzOpt = JavaUtils.findClazz(project, clazzName); 32 | if (!clazzOpt.isPresent()) { 33 | return; 34 | } 35 | Collection domBeans = model.getAllDomBeans(); 36 | PsiClass clazz = clazzOpt.get(); 37 | for (SpringBeanPointer pointer : domBeans) { 38 | PsiClass beanClass = pointer.getBeanClass(); 39 | if (beanClass == null || !beanClass.equals(clazz)) { 40 | continue; 41 | } 42 | SpringPropertyDefinition def = SpringPropertyUtils.findPropertyByName(pointer.getSpringBean(), prop); 43 | if (def != null) { 44 | if (!processor.process(def)) { 45 | break; 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/converter/ResultMapConverter.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.converter; 2 | 3 | import com.google.common.base.Predicate; 4 | import com.google.common.collect.Collections2; 5 | 6 | import com.intellij.util.xml.ConvertContext; 7 | import com.intellij.util.xml.DomElement; 8 | import com.seventh7.mybatis.dom.model.IdDomElement; 9 | import com.seventh7.mybatis.dom.model.Mapper; 10 | import com.seventh7.mybatis.dom.model.ResultMap; 11 | import com.seventh7.mybatis.util.MapperUtils; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | 16 | import java.util.Collection; 17 | 18 | /** 19 | * @author yanglin 20 | */ 21 | public class ResultMapConverter extends IdBasedTagConverter{ 22 | 23 | @NotNull @Override 24 | public Collection getComparisons(@Nullable Mapper mapper, ConvertContext context) { 25 | DomElement invocationElement = context.getInvocationElement(); 26 | if (isContextElementOfResultMap(mapper, invocationElement)) { 27 | return doFilterResultMapItself(mapper, (ResultMap)invocationElement.getParent()); 28 | } else { 29 | return mapper.getResultMaps(); 30 | } 31 | } 32 | 33 | private boolean isContextElementOfResultMap(Mapper mapper, DomElement invocationElement) { 34 | return MapperUtils.isMapperWithSameNamespace(MapperUtils.getMapper(invocationElement), mapper) 35 | && invocationElement.getParent() instanceof ResultMap; 36 | } 37 | 38 | private Collection doFilterResultMapItself(Mapper mapper, final ResultMap resultMap) { 39 | return Collections2.filter(mapper.getResultMaps(), new Predicate() { 40 | @Override 41 | public boolean apply(ResultMap input) { 42 | return !MapperUtils.getId(input).equals(MapperUtils.getId(resultMap)); 43 | } 44 | }); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/seventh7/mybatis/dom/model/Mapper.java: -------------------------------------------------------------------------------- 1 | package com.seventh7.mybatis.dom.model; 2 | 3 | import com.intellij.util.xml.Attribute; 4 | import com.intellij.util.xml.GenericAttributeValue; 5 | import com.intellij.util.xml.NameValue; 6 | import com.intellij.util.xml.Required; 7 | import com.intellij.util.xml.SubTagList; 8 | import com.intellij.util.xml.SubTagsList; 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author yanglin 16 | */ 17 | public interface Mapper extends MyBatisElement { 18 | 19 | @NotNull 20 | @SubTagsList({"insert", "update", "delete", "select"}) 21 | public List getDaoElements(); 22 | 23 | @Required 24 | @NameValue 25 | @NotNull 26 | @Attribute("namespace") 27 | public GenericAttributeValue getNamespace(); 28 | 29 | @NotNull 30 | @SubTagList("resultMap") 31 | public List getResultMaps(); 32 | 33 | @NotNull 34 | @SubTagList("parameterMap") 35 | public List getParameterMaps(); 36 | 37 | @NotNull 38 | @SubTagList("sql") 39 | public List getSqls(); 40 | 41 | @NotNull 42 | @SubTagList("insert") 43 | public List getInserts(); 44 | 45 | @NotNull 46 | @SubTagList("update") 47 | public List getUpdates(); 48 | 49 | @NotNull 50 | @SubTagList("delete") 51 | public List getDeletes(); 52 | 53 | @NotNull 54 | @SubTagList("select") 55 | public List