// Path: src/main/java/yk/senjin/shaders/gshader/ShaderTranslator.java
// public static boolean isPrimitive(String oglType) {
//     return PRIMITIVES.contains(oglType);
// }
// 
// Path: src/main/java/yk/senjin/shaders/gshader/ShaderTranslator.java
// public static String translateType(String groovyType) {
//     String t = al(groovyType.split("\\.")).last();
//     if (!convertions.containsKey(t)) return groovyType;
//     return convertions.get(t);
// }


import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.builder.AstBuilder;
import org.codehaus.groovy.ast.expr.*;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.IfStatement;
import org.codehaus.groovy.ast.stmt.ReturnStatement;
import org.codehaus.groovy.control.CompilePhase;
import org.junit.Test;
import yk.jcommon.collections.*;
import yk.jcommon.match2.*;
import yk.jcommon.probe.Probe;
import yk.jcommon.probe.State;
import yk.jcommon.search.SSearch;
import yk.jcommon.utils.IO;
import static org.junit.Assert.assertEquals;
import static yk.jcommon.collections.YArrayList.al;
import static yk.jcommon.collections.YHashMap.hm;
import static yk.jcommon.collections.YHashSet.hs;
import static yk.jcommon.match2.MatcherShortNames.*;
import static yk.senjin.shaders.gshader.ShaderTranslator.isPrimitive;
import static yk.senjin.shaders.gshader.ShaderTranslator.translateType;

        Object refReadPattern2 = stairs(
                deeper(G_BODY_ACCESSORS),
                p(ReturnStatement.class, "getExpression"),
                deeper(G_BODY_ACCESSORS),
                p(VariableExpression.class, "variable", var("name")));

        Object fieldReadPattern = new MatchDeeper(G_BODY_ACCESSORS,
                p("operation", p("text", "="), "rightExpression", new MatchDeeper(G_BODY_ACCESSORS,
                        p("objectExpression", p("variable", var("name"))))));

        return null;
    }

    public static YList<String> gAsserts(Object mainClass, YMap<String, YSet<String>> modifiers) {
        YList<String> errors = al();

        Object varWritePattern = stairs(
                deeper(G_BODY_ACCESSORS),
                p(BinaryExpression.class, "operation", p("text", "="), "leftExpression"),
                p(VariableExpression.class, "variable", var("VAR_NAME")));

        Object varReturnPattern = stairs(
                deeper(G_BODY_ACCESSORS),
                p(ReturnStatement.class, "getExpression"),
                p(VariableExpression.class, "variable", var("VAR_NAME")));

        for (YMap<String, Object> m : new Matcher().match(mainClass, stairs(deeper(G_METHOD_ACCESSORS), var("method"), p(MethodNode.class, "name"), var("methodName")))) {
            Object methodName = m.get("methodName");
            String prefix = "(method " + methodName + ") ";
// Path: src/main/java/yk/senjin/shaders/gshader/ShaderTranslator.java
// public static boolean isPrimitive(String oglType) {
//     return PRIMITIVES.contains(oglType);
// }
// 
// Path: src/main/java/yk/senjin/shaders/gshader/ShaderTranslator.java
// public static String translateType(String groovyType) {
//     String t = al(groovyType.split("\\.")).last();
//     if (!convertions.containsKey(t)) return groovyType;
//     return convertions.get(t);
// }


// Path: src/main/java/yk/senjin/shaders/gshader/analysis/GglslAnalyzer.java
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.builder.AstBuilder;
import org.codehaus.groovy.ast.expr.*;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.IfStatement;
import org.codehaus.groovy.ast.stmt.ReturnStatement;
import org.codehaus.groovy.control.CompilePhase;
import org.junit.Test;
import yk.jcommon.collections.*;
import yk.jcommon.match2.*;
import yk.jcommon.probe.Probe;
import yk.jcommon.probe.State;
import yk.jcommon.search.SSearch;
import yk.jcommon.utils.IO;
import static org.junit.Assert.assertEquals;
import static yk.jcommon.collections.YArrayList.al;
import static yk.jcommon.collections.YHashMap.hm;
import static yk.jcommon.collections.YHashSet.hs;
import static yk.jcommon.match2.MatcherShortNames.*;
import static yk.senjin.shaders.gshader.ShaderTranslator.isPrimitive;
import static yk.senjin.shaders.gshader.ShaderTranslator.translateType;


        Object refReadPattern2 = stairs(
                deeper(G_BODY_ACCESSORS),
                p(ReturnStatement.class, "getExpression"),
                deeper(G_BODY_ACCESSORS),
                p(VariableExpression.class, "variable", var("name")));

        Object fieldReadPattern = new MatchDeeper(G_BODY_ACCESSORS,
                p("operation", p("text", "="), "rightExpression", new MatchDeeper(G_BODY_ACCESSORS,
                        p("objectExpression", p("variable", var("name"))))));

        return null;
    }

    public static YList<String> gAsserts(Object mainClass, YMap<String, YSet<String>> modifiers) {
        YList<String> errors = al();

        Object varWritePattern = stairs(
                deeper(G_BODY_ACCESSORS),
                p(BinaryExpression.class, "operation", p("text", "="), "leftExpression"),
                p(VariableExpression.class, "variable", var("VAR_NAME")));

        Object varReturnPattern = stairs(
                deeper(G_BODY_ACCESSORS),
                p(ReturnStatement.class, "getExpression"),
                p(VariableExpression.class, "variable", var("VAR_NAME")));

        for (YMap<String, Object> m : new Matcher().match(mainClass, stairs(deeper(G_METHOD_ACCESSORS), var("method"), p(MethodNode.class, "name"), var("methodName")))) {
            Object methodName = m.get("methodName");
            String prefix = "(method " + methodName + ") ";
            for (Parameter parameter : ((MethodNode)m.get("method")).getParameters()) if (!isPrimitive(translateType(parameter.getType().getName()))) {//TODO match type