diff --git a/.gitignore b/.gitignore
index cca3574..f51de0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
*.iml
-mybatis-plus.jar
log.roo
.idea/
out/
.DS_Store
+.floo
+.flooignore
+
+META-INF/plugin.xml
\ No newline at end of file
diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml
index e2c31f1..a2f403b 100644
--- a/META-INF/plugin.xml
+++ b/META-INF/plugin.xml
@@ -1,8 +1,8 @@
com.seventh7.plugin.mybatis
MyBatis plugin
- 2.01
- Yanglin
+ 2.31
+ Yanglin
@@ -10,42 +10,21 @@
]]>
2.01
+ 2.31
- - Improvement for intellij 13
+ - Commit mybatis mapper as spring bean using idea api
- 1.56
+ 2.3
- - Support correct result type for select statement in mapper xml
- - Support correct unresolved attribute value of mapper xml
- - Highlight conflicting element of mapper xml as errors
- - Support refactor for id based tag in mapper xml
- - Support refactor the name of mapper xml file when rename the mapper interface
- - Support find usage of mapper interface and mapper xml element
- - Support generating mapper of xml
- - Support property completion for result and id of resultMap、collection、association
- - Support parameter completion[ #{param} ] while editing sql(@Param based)
- - Support resultMap completion for collection and association of resultMap
- - Auto register mapper as spring bean(Optional)
- - Change reference strategy to support rename
- - Brace completion while editing sql
- - Support surround with CDATA section for sql
- - Support resultType
- - Parameter map support
- - Parameter type support
- - Alias support
-
- 1.46
-
- - Rewrite
- - Change the keystroke for generate @Param and new statement with Alt + Enter(Windows) | Option + Enter(Mac)
+ - Improve for intellij 14
+ - Fix bugs
]]>
-
- com.intellij.sql
- com.intellij.spring
+
+ com.intellij.spring
+ com.intellij.database
@@ -57,7 +36,6 @@
-
@@ -66,20 +44,30 @@
+
+
com.seventh7.mybatis.intention.GenerateParamAnnotationIntention
-
- com.seventh7.mybatis.intention.GenerateStatementIntention
-
com.seventh7.mybatis.intention.GenerateMapperIntention
+
+ com.seventh7.mybatis.intention.AliasSwitchIntentionAction
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index c999bc3..68bbee3 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,11 @@
+# Ad - 强势推荐
+
+翻墙利器: http://honx.in/i/VJ6-U86vD0s1XqbE
+
+# Supported By
+
+
+
#Download
* http://plugins.jetbrains.com/plugin/7293
@@ -13,11 +21,17 @@
* Support refactor for id based tag in mapper xml
* Support find usage of mapper interface and mapper xml element
* Highlight conflicting element of mapper xml as errors
-* Auto register mapper as spring bean
-* Mapper parameter auto completion in xml while editting sql
+* Auto register mapper as spring bean
+* Support completion of jdbc type in mapper xml
+* Support completion of referencing to select statement in mapper xml
+* Support switching between java type and alias in mapper xml using intention keystroke
+* Auto inject sql language in mapper xml
+* Mapper parameter auto completion in xml while editing sql
* \#{yourParameter}
* @Param annotation based
* Association is supported
+* Support generating properties for elements of result map using intention keystroke
+ * DataSource of intellij is required
#Generate
diff --git a/lib/gson-2.2.4.jar b/lib/gson-2.2.4.jar
new file mode 100644
index 0000000..9478253
Binary files /dev/null and b/lib/gson-2.2.4.jar differ
diff --git a/mybatis-plus.jar b/mybatis-plus.jar
new file mode 100644
index 0000000..9ae3d09
Binary files /dev/null and b/mybatis-plus.jar differ
diff --git a/src/com/seventh7/mybatis/action/HackAction.java b/src/com/seventh7/mybatis/action/HackAction.java
new file mode 100644
index 0000000..54ea27b
--- /dev/null
+++ b/src/com/seventh7/mybatis/action/HackAction.java
@@ -0,0 +1,16 @@
+package com.seventh7.mybatis.action;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+
+/**
+ * @author yanglin
+ */
+public class HackAction extends AnAction {
+
+
+ public void actionPerformed(AnActionEvent e) {
+ // NON
+ }
+
+}
diff --git a/src/com/seventh7/mybatis/action/MybatisTypedHandler.java b/src/com/seventh7/mybatis/action/MybatisTypedHandler.java
index 34a762c..821e090 100644
--- a/src/com/seventh7/mybatis/action/MybatisTypedHandler.java
+++ b/src/com/seventh7/mybatis/action/MybatisTypedHandler.java
@@ -4,9 +4,10 @@
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
+import com.intellij.diagnostic.LogEventException;
+import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
-import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.sql.psi.SqlFile;
@@ -30,12 +31,19 @@ public Result checkAutoPopup(char charTyped, final Project project, final Editor
@Override
public Result charTyped(char c, final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
+ if (c != '{') {
+ return Result.CONTINUE;
+ }
int index = editor.getCaretModel().getOffset() - 2;
+ if (index < 0) {
+ return Result.CONTINUE;
+ }
+ char beginningChar = editor.getDocument().getText().charAt(index);
+ if (beginningChar != '#' && beginningChar != '$') {
+ return Result.CONTINUE;
+ }
PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(file);
- boolean parameterCase = c == '{' &&
- index >= 0 &&
- editor.getDocument().getText().charAt(index) == '#' &&
- file instanceof SqlFile &&
+ boolean parameterCase = file instanceof SqlFile &&
DomUtils.isMybatisFile(topLevelFile);
if (parameterCase) {
autoPopupParameter(project, editor);
@@ -45,11 +53,13 @@ public Result charTyped(char c, final Project project, @NotNull final Editor edi
}
private static void autoPopupParameter(final Project project, final Editor editor) {
- CompletionAutoPopupHandler.runLaterWithCommitted(project, editor.getDocument(), new Runnable() {
+ final Document document = editor.getDocument();
+ CompletionAutoPopupHandler.runLaterWithCommitted(project, document, new Runnable() {
@Override
public void run() {
- if (PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
+ try {
new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor, 1);
+ } catch (LogEventException ignored) {
}
}
});
diff --git a/src/com/seventh7/mybatis/alias/AliasClassReference.java b/src/com/seventh7/mybatis/alias/AliasClassReference.java
index 143ccdc..ea71113 100644
--- a/src/com/seventh7/mybatis/alias/AliasClassReference.java
+++ b/src/com/seventh7/mybatis/alias/AliasClassReference.java
@@ -3,7 +3,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
-import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.xml.XmlAttributeValue;
@@ -29,7 +29,7 @@ public AliasClassReference(@NotNull XmlAttributeValue element) {
}
@Nullable @Override
- public PsiElement resolve() {
+ public PsiClass resolve() {
XmlAttributeValue attributeValue = getElement();
return AliasFacade.getInstance(attributeValue.getProject()).findPsiClass(attributeValue, attributeValue.getValue()).orNull();
}
diff --git a/src/com/seventh7/mybatis/alias/AliasDesc.java b/src/com/seventh7/mybatis/alias/AliasDesc.java
index f55eddd..5c685a4 100644
--- a/src/com/seventh7/mybatis/alias/AliasDesc.java
+++ b/src/com/seventh7/mybatis/alias/AliasDesc.java
@@ -55,11 +55,8 @@ public boolean equals(Object o) {
if (alias != null ? !alias.equals(aliasDesc.alias) : aliasDesc.alias != null) {
return false;
}
- if (clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null) {
- return false;
- }
- return true;
+ return !(clazz != null ? !clazz.equals(aliasDesc.clazz) : aliasDesc.clazz != null);
}
@Override
diff --git a/src/com/seventh7/mybatis/alias/AliasFacade.java b/src/com/seventh7/mybatis/alias/AliasFacade.java
index fb1375c..fa50d26 100644
--- a/src/com/seventh7/mybatis/alias/AliasFacade.java
+++ b/src/com/seventh7/mybatis/alias/AliasFacade.java
@@ -5,10 +5,9 @@
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
-import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.search.GlobalSearchScope;
+import com.seventh7.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,18 +23,15 @@ public class AliasFacade {
private Project project;
- private JavaPsiFacade javaPsiFacade;
-
private List resolvers;
- public static final AliasFacade getInstance(@NotNull Project project) {
+ public static AliasFacade getInstance(@NotNull Project project) {
return ServiceManager.getService(project, AliasFacade.class);
}
public AliasFacade(Project project) {
this.project = project;
this.resolvers = Lists.newArrayList();
- this.javaPsiFacade = JavaPsiFacade.getInstance(project);
initResolvers();
}
@@ -43,7 +39,7 @@ private void initResolvers() {
try {
Class.forName("com.intellij.spring.model.utils.SpringModelUtils");
this.registerResolver(AliasResolverFactory.createBeanResolver(project));
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException ignored) {
}
this.registerResolver(AliasResolverFactory.createSingleAliasResolver(project));
this.registerResolver(AliasResolverFactory.createConfigPackageResolver(project));
@@ -52,14 +48,14 @@ private void initResolvers() {
}
@NotNull
- public Optional findPsiClass(@Nullable PsiElement element, @NotNull String shortName) {
- PsiClass clazz = javaPsiFacade.findClass(shortName, GlobalSearchScope.allScope(project));
- if (null != clazz) {
- return Optional.of(clazz);
+ public Optional findPsiClass(@Nullable PsiElement element, @NotNull String clazzName) {
+ final Optional clazz = JavaUtils.findClazz(project, clazzName);
+ if (clazz.isPresent()) {
+ return clazz;
}
for (AliasResolver resolver : resolvers) {
for (AliasDesc desc : resolver.getClassAliasDescriptions(element)) {
- if (desc.getAlias().equals(shortName)) {
+ if (desc.getAlias().equalsIgnoreCase(clazzName)) {
return Optional.of(desc.getClazz());
}
}
diff --git a/src/com/seventh7/mybatis/alias/AnnotationAliasResolver.java b/src/com/seventh7/mybatis/alias/AnnotationAliasResolver.java
index 10620de..5180bfe 100644
--- a/src/com/seventh7/mybatis/alias/AnnotationAliasResolver.java
+++ b/src/com/seventh7/mybatis/alias/AnnotationAliasResolver.java
@@ -41,12 +41,13 @@ public AnnotationAliasResolver(Project project) {
super(project);
}
- public static final AnnotationAliasResolver getInstance(@NotNull Project project) {
+ public static AnnotationAliasResolver getInstance(@NotNull Project project) {
return project.getComponent(AnnotationAliasResolver.class);
}
@NotNull
@Override
+ @SuppressWarnings("unchecked")
public Set getClassAliasDescriptions(@Nullable PsiElement element) {
Optional clazz = Annotation.ALIAS.toPsiClass(project);
if (clazz.isPresent()) {
diff --git a/src/com/seventh7/mybatis/alias/BeanAliasResolver.java b/src/com/seventh7/mybatis/alias/BeanAliasResolver.java
index 32b03be..2ab86f1 100644
--- a/src/com/seventh7/mybatis/alias/BeanAliasResolver.java
+++ b/src/com/seventh7/mybatis/alias/BeanAliasResolver.java
@@ -8,33 +8,37 @@
import com.intellij.psi.PsiElement;
import com.intellij.spring.CommonSpringModel;
import com.intellij.spring.SpringManager;
-import com.intellij.spring.model.SpringBeanPointer;
-import com.intellij.spring.model.utils.SpringPropertyUtils;
import com.intellij.spring.model.xml.beans.SpringPropertyDefinition;
+import com.intellij.util.Processor;
+import com.seventh7.mybatis.util.SpringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
+import java.util.Collections;
import java.util.Set;
/**
* @author yanglin
*/
-public class BeanAliasResolver extends PackageAliasResolver{
+public class BeanAliasResolver extends PackageAliasResolver {
private static final String MAPPER_ALIAS_PACKAGE_CLASS = "org.mybatis.spring.SqlSessionFactoryBean";
private static final String MAPPER_ALIAS_PROPERTY = "typeAliasesPackage";
private ModuleManager moduleManager;
private SpringManager springManager;
+ private Project project;
public BeanAliasResolver(Project project) {
super(project);
this.moduleManager = ModuleManager.getInstance(project);
this.springManager = SpringManager.getInstance(project);
+ this.project = project;
}
- @NotNull @Override
+ @NotNull
+ @Override
public Collection getPackages(@Nullable PsiElement element) {
Set res = Sets.newHashSet();
for (Module module : moduleManager.getModules()) {
@@ -45,16 +49,18 @@ public Collection getPackages(@Nullable PsiElement element) {
return res;
}
- private void addPackages(Set res, CommonSpringModel springModel) {
- for (SpringBeanPointer springBaseBeanPointer : springModel.findBeansByPsiClassWithInheritance(MAPPER_ALIAS_PACKAGE_CLASS)) {
- SpringPropertyDefinition basePackages = SpringPropertyUtils.findPropertyByName(springBaseBeanPointer.getSpringBean(), MAPPER_ALIAS_PROPERTY);
- if (basePackages != null) {
- final String value = basePackages.getValueElement().getStringValue();
+ private void addPackages(final Set res, CommonSpringModel springModel) {
+ Processor processor = new Processor() {
+ @Override
+ public boolean process(SpringPropertyDefinition def) {
+ final String value = def.getValueElement().getStringValue();
if (value != null) {
- res.add(value);
+ Collections.addAll(res, value.split(",|;"));
}
+ return true;
}
- }
+ };
+ SpringUtils.processSpringConfig(project, springModel, MAPPER_ALIAS_PACKAGE_CLASS, MAPPER_ALIAS_PROPERTY, processor);
}
}
diff --git a/src/com/seventh7/mybatis/annotation/Annotation.java b/src/com/seventh7/mybatis/annotation/Annotation.java
index 8569f49..eb16bc0 100644
--- a/src/com/seventh7/mybatis/annotation/Annotation.java
+++ b/src/com/seventh7/mybatis/annotation/Annotation.java
@@ -1,18 +1,16 @@
package com.seventh7.mybatis.annotation;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
import com.intellij.openapi.project.Project;
-import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
-import com.intellij.psi.search.GlobalSearchScope;
+import com.seventh7.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
-import java.util.Map;
import java.util.Set;
/**
@@ -43,7 +41,7 @@ public class Annotation implements Cloneable{
private final String qualifiedName;
- private Map attributePairs;
+ private ImmutableMap attributePairs;
public interface AnnotationValue {
}
@@ -66,18 +64,16 @@ public String toString() {
public Annotation(@NotNull String label, @NotNull String qualifiedName) {
this.label = label;
this.qualifiedName = qualifiedName;
- attributePairs = Maps.newHashMap();
- }
-
- private Annotation addAttribute(String key, AnnotationValue value) {
- this.attributePairs.put(key, value);
- return this;
+ this.attributePairs = ImmutableMap.of();
}
public Annotation withAttribute(@NotNull String key, @NotNull AnnotationValue value) {
Annotation copy = this.clone();
- copy.attributePairs = Maps.newHashMap(this.attributePairs);
- return copy.addAttribute(key, value);
+ copy.attributePairs = ImmutableMap.builder()
+ .putAll(this.attributePairs)
+ .put(key, value)
+ .build();
+ return copy;
}
public Annotation withValue(@NotNull AnnotationValue value) {
@@ -87,7 +83,7 @@ public Annotation withValue(@NotNull AnnotationValue value) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(label);
- if (!Iterables.isEmpty(attributePairs.entrySet())) {
+ if (!attributePairs.isEmpty()) {
builder.append(setupAttributeText());
}
return builder.toString();
@@ -106,24 +102,21 @@ private String getComplexValue() {
builder.append(attributePairs.get(key).toString());
builder.append(", ");
}
- builder.deleteCharAt(builder.length() - 1);
- builder.deleteCharAt(builder.length() - 1);
+ int length = builder.length();
+ builder.delete(length - 2, length);
builder.append(")");
return builder.toString();
}
@NotNull
public Optional toPsiClass(@NotNull Project project) {
- return Optional.fromNullable(JavaPsiFacade.getInstance(project).findClass(getQualifiedName(), GlobalSearchScope.allScope(project)));
+ return JavaUtils.findClazz(project, getQualifiedName());
}
private Optional getSingleValue() {
try {
String value = Iterables.getOnlyElement(attributePairs.keySet());
- StringBuilder builder = new StringBuilder("(");
- builder.append(attributePairs.get(value).toString());
- builder.append(")");
- return Optional.of(builder.toString());
+ return Optional.of("(" + attributePairs.get(value).toString() + ")");
} catch (Exception e) {
return Optional.absent();
}
diff --git a/src/com/seventh7/mybatis/contributor/SqlParamCompletionContributor.java b/src/com/seventh7/mybatis/contributor/SqlParamCompletionContributor.java
index 53047ab..c765f3c 100644
--- a/src/com/seventh7/mybatis/contributor/SqlParamCompletionContributor.java
+++ b/src/com/seventh7/mybatis/contributor/SqlParamCompletionContributor.java
@@ -14,6 +14,8 @@
import com.seventh7.mybatis.util.DomUtils;
import com.seventh7.mybatis.util.MapperUtils;
+import org.jetbrains.annotations.NotNull;
+
/**
* @author yanglin
@@ -21,7 +23,7 @@
public class SqlParamCompletionContributor extends CompletionContributor {
@Override
- public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) {
+ public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC) {
return;
}
@@ -51,7 +53,9 @@ private boolean shouldAddElement(PsiFile file, int offset) {
String text = file.getText();
for (int i = offset - 1; i > 0; i--) {
char c = text.charAt(i);
- if (c == '{' && text.charAt(i - 1) == '#') return true;
+ if (c == '{' && (text.charAt(i - 1) == '#' || text.charAt(i - 1) == '$')) {
+ return true;
+ }
}
return false;
}
diff --git a/src/com/seventh7/mybatis/contributor/TestParamContributor.java b/src/com/seventh7/mybatis/contributor/TestParamContributor.java
index 8feb444..873c351 100644
--- a/src/com/seventh7/mybatis/contributor/TestParamContributor.java
+++ b/src/com/seventh7/mybatis/contributor/TestParamContributor.java
@@ -1,6 +1,8 @@
package com.seventh7.mybatis.contributor;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionParameters;
@@ -11,11 +13,21 @@
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.XmlPatterns;
+import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiField;
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiModifier;
+import com.intellij.psi.PsiModifierList;
import com.intellij.psi.PsiParameter;
+import com.intellij.psi.PsiPrimitiveType;
+import com.intellij.psi.PsiType;
+import com.intellij.psi.impl.source.PsiClassReferenceType;
+import com.intellij.util.PlatformIcons;
import com.intellij.util.ProcessingContext;
import com.seventh7.mybatis.annotation.Annotation;
import com.seventh7.mybatis.dom.model.IdDomElement;
+import com.seventh7.mybatis.util.CollectionUtils;
import com.seventh7.mybatis.util.Icons;
import com.seventh7.mybatis.util.JavaUtils;
import com.seventh7.mybatis.util.MapperUtils;
@@ -24,34 +36,142 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
/**
* @author yanglin
*/
public class TestParamContributor extends CompletionContributor {
+ private final static Collection extends SimpleParameterLookupHandler> HANDLER_CHAIN = ImmutableSet.of(
+ new AnnotationParameterLookupHandler(),
+ new ModelParameterLookupHandler(),
+ new PrimitiveParameterLookupHandler()
+ );
+
@SuppressWarnings("unchecked")
public TestParamContributor() {
+ final CompletionProvider provider = new CompletionProvider() {
+ @Override
+ protected void addCompletions(@NotNull CompletionParameters parameters,
+ ProcessingContext context,
+ @NotNull CompletionResultSet result) {
+ PsiElement position = parameters.getPosition();
+ addElementForPsiParameter(position.getProject(), result, MapperUtils.findParentIdDomElement(position).orNull());
+ }
+ };
extend(CompletionType.BASIC,
- XmlPatterns.psiElement().inside(XmlPatterns.xmlAttributeValue().inside(XmlPatterns.xmlAttribute().withName("test"))),
- new CompletionProvider() {
- @Override
- protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
- PsiElement position = parameters.getPosition();
- addElementForPsiParameter(position.getProject(), result, MapperUtils.findParentIdDomElement(position).orNull());
- }
- });
+ XmlPatterns.psiElement().inside(XmlPatterns.xmlAttributeValue().inside(XmlPatterns.xmlAttribute().withName("test"))), provider);
+ extend(CompletionType.BASIC,
+ XmlPatterns.psiElement().inside(XmlPatterns.xmlAttributeValue().inside(XmlPatterns.xmlAttribute().withName("collection"))), provider);
}
public static void addElementForPsiParameter(@NotNull Project project, @NotNull CompletionResultSet result, @Nullable IdDomElement element) {
if (null == element) {
return;
}
- for (PsiParameter parameter : JavaUtils.findMethod(project, element).get().getParameterList().getParameters()) {
+ Optional method = JavaUtils.findMethod(project, element);
+ if (!method.isPresent()) {
+ return;
+ }
+ for (PsiParameter parameter : method.get().getParameterList().getParameters()) {
+ for (SimpleParameterLookupHandler handler : HANDLER_CHAIN) {
+ handler.handle(result, parameter);
+ }
+ }
+ }
+
+ private abstract static class SimpleParameterLookupHandler {
+
+ public void handle(@NotNull CompletionResultSet result, @NotNull PsiParameter parameter) {
+ Collection> lookupElements = getParameterLookupElements(parameter);
+ if (CollectionUtils.isEmpty(lookupElements)) {
+ return;
+ }
+ for (Object lookupElement : lookupElements) {
+ LookupElementBuilder builder = null;
+ if (lookupElement instanceof String) {
+ builder = LookupElementBuilder.create((String) lookupElement).withIcon(Icons.PARAM_COMPLETION_ICON);
+ } else if (lookupElement instanceof PsiField) {
+ builder = LookupElementBuilder.create((PsiField) lookupElement).withIcon(PlatformIcons.FIELD_ICON);
+ }
+ if (null != builder) {
+ result.addElement(PrioritizedLookupElement.withPriority(builder, MybatisConstants.PRIORITY));
+ }
+ }
+ }
+
+ @NotNull
+ public abstract Collection> getParameterLookupElements(@NotNull PsiParameter parameter);
+ }
+
+ private final static class AnnotationParameterLookupHandler extends SimpleParameterLookupHandler {
+
+ @NotNull
+ @Override
+ public Collection> getParameterLookupElements(@NotNull PsiParameter parameter) {
Optional valueText = JavaUtils.getAnnotationValueText(parameter, Annotation.PARAM);
- if (valueText.isPresent()) {
- LookupElementBuilder builder = LookupElementBuilder.create(valueText.get()).withIcon(Icons.PARAM_COMPLETION_ICON);
- result.addElement(PrioritizedLookupElement.withPriority(builder, MybatisConstants.PRIORITY));
+ return valueText.isPresent() ? Lists.newArrayList(valueText.get()) : Collections.emptyList();
+ }
+
+ }
+
+ private abstract static class NoParamAnnotationPresentParameterLookupHandler extends SimpleParameterLookupHandler {
+
+ @NotNull
+ @Override
+ public Collection> getParameterLookupElements(@NotNull PsiParameter parameter) {
+ Optional valueText = JavaUtils.getAnnotationValueText(parameter, Annotation.PARAM);
+ return valueText.isPresent() ? Collections.emptyList() : doHandle(parameter);
+ }
+
+ @NotNull
+ public abstract Collection> doHandle(@NotNull PsiParameter parameter);
+ }
+
+ private final static class PrimitiveParameterLookupHandler extends NoParamAnnotationPresentParameterLookupHandler {
+
+ @NotNull
+ @Override
+ public Collection> doHandle(@NotNull PsiParameter parameter) {
+ return parameter.getType() instanceof PsiPrimitiveType
+ ? Lists.newArrayList(parameter.getName())
+ : Collections.emptyList();
+ }
+ }
+
+ private final static class ModelParameterLookupHandler extends NoParamAnnotationPresentParameterLookupHandler {
+
+ @NotNull
+ @Override
+ public Collection> doHandle(@NotNull PsiParameter parameter) {
+ PsiType type = parameter.getType();
+ if (!(type instanceof PsiClassReferenceType)) { return Collections.emptyList(); }
+
+ PsiClass clazz = ((PsiClassReferenceType) type).resolve();
+ if (null == clazz) { return Collections.emptyList(); }
+
+ List