package org.intellij.ibatis.intention;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;

/**
 * generate statement xml code according to sql map client invocation when statement id absent
 *
 * @author Jacky
 */
public class GenerateStatementXmlCodeAction extends PsiIntentionBase {
    private static final String NAME = "GenerateStatementXmlCode";
    private static final String TEXT = "Generate statement xml code when statement id absent";

    protected void invoke(Project project, Editor editor, PsiFile file, @NotNull PsiElement element) {

    }

    protected boolean isAvailable(Project project, Editor editor, PsiFile file, @NotNull PsiElement element) {
        if (element instanceof PsiLiteralExpression) {
            PsiElement parent = element.getParent().getParent();
            if (parent == null || !(parent instanceof PsiMethodCallExpression)) {
                //method name validation simply, filter for detailed validation
                String[] path = ((PsiMethodCallExpression) parent).getMethodExpression().getText().split("\\.");
                String methodName = path[path.length - 1].trim();
            }
        }
        return false;
    }

    @NotNull public String getText() {
        return TEXT;
    }

    @NotNull public String getFamilyName() {
        return NAME;
    }
}

@@ -195,16 +195,77 @@
 otNull;%0D
+%0Aimport org.intellij.ibatis.provider.SqlClientElementFilter;%0D
 %0A%0D%0A/**%0D%0A
@@ -904,24 +904,103 @@
 ression) %7B%0D%0A
+            PsiLiteralExpression expression = (PsiLiteralExpression) element;%0D%0A
             
@@ -1080,28 +1080,8 @@
 ent 
-== null %7C%7C !(parent 
 inst
@@ -1111,17 +1111,16 @@
 ression)
-)
  %7B%0D%0A    
@@ -1166,71 +1166,65 @@
 mply
-, filter for detailed validation%0D%0A                String%5B%5D path
+%0D%0A                PsiReferenceExpression methodExpression
  = (
@@ -1278,16 +1278,67 @@
 ession()
+;%0D%0A                String%5B%5D path = methodExpression
 .getText
@@ -1418,24 +1418,347 @@
 1%5D.trim();%0D%0A
+                if (methodName.matches(SqlClientElementFilter.operationPattern)) %7B%0D%0A                    PsiReference psiReference = expression.getReference();%0D%0A                    if (psiReference != null && psiReference.resolve() == null) %7B%0D%0A                        return true;%0D%0A                    %7D%0D%0A                %7D%0D%0A
             

validate logic updated