package ru.artyushov.jmhPlugin.action;

import com.intellij.codeInsight.template.Expression;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInsight.template.impl.ConstantNode;
import com.intellij.psi.PsiClass;

import static ru.artyushov.jmhPlugin.configuration.ConfigurationUtils.JMH_ANNOTATION_NAME;

/**
 * User: nikart
 * Date: 18/03/14
 * Time: 13:01
 */
public class BenchmarkMethodTemplateFactory {

    public static Template create(PsiClass psiClass) {
        Template template = TemplateManager.getInstance(psiClass.getProject()).createTemplate("", "");
        template.addTextSegment("@" + JMH_ANNOTATION_NAME + "\n");
        template.addTextSegment("public ");
        Expression typeExpr = new ConstantNode("void");
        template.addVariable("type", typeExpr, typeExpr, true);

        template.addTextSegment(" measure");
        Expression nameExpr = new ConstantNode("Name");
        template.addVariable("name", nameExpr, nameExpr, true);
        template.addTextSegment("() {\n}");

        template.setToIndent(true);
        template.setToReformat(true);
        template.setToShortenLongNames(true);

        return template;
    }
}

@@ -755,166 +755,12 @@
 lic 
-%22);%0A        Expression typeExpr = new ConstantNode(%22void%22);%0A        template.addVariable(%22type%22, typeExpr, typeExpr, true);%0A%0A        template.addTextSegment(%22
+void
  mea
@@ -921,16 +921,50 @@
 gment(%22(
+org.openjdk.jmh.infra.Blackhole bh
 ) %7B%5Cn%7D%22)

add Blackhole as argument