コード例 #1
0
        void OnFinishGame()
        {
            isVerify     = false;
            isFinishInit = false;
            isGame       = false;
            isLaunchGame = false;
            isPlay       = false;
            isStartGame  = false;

            if (JavaInterface.Java())
            {
                if (JavaInterface.GetScorePlayer() >= 10)
                {
                    JavaInterface.AddScorePlayer(-10);
                    isResetGame = true;
                }
                else
                {
                    isResetGame = false;
                }
            }
            else
            {
                isResetGame = true;
            }
            if (isResetGame)
            {
                SwitchScene(true);
            }
            else
            {
                SwitchScene(false);
            }
        }
コード例 #2
0
    void OnKeyEvent(int id)
    {
        if (JavaInterface.getKey(id) == true)
        {
            KeyEventNew[id] = true;
            //检查按键是否被持续按住
            if (hold[id] != 0)
            {
                hold[id] += 1;
                OnKeyHoldTimerEvent(id);
                //if (hold[id] > 10 && hold[id] % 3 == 0) OnKeyHoldEvent(id);
                if (hold[id] > 3)
                {
                    OnKeyHoldEvent(id);
                }
            }
        }
        else
        {
            KeyEventNew[id] = false;
        }
        //按键被按下时触发事件
        if ((KeyEventNew[id] == true) && (KeyEventOld[id] == false))
        {
            //Debug.Log("key " + id + " is click!!!");
            OnKeyDownEvent();
            OnKeyDownEvent(id);
            switch (id)
            {
            case 0: OnKeyDown0Event(); break;

            case 1: OnKeyDown1Event(); break;

            case 2: OnKeyDown2Event(); break;

            case 3: OnKeyDown3Event(); break;

            default: break;
            }
        }
        //按键被释放时触发事件
        if ((KeyEventNew[id] == false) && (KeyEventOld[id] == true))
        {
            OnKeyUpEvent();
            OnKeyUpEvent(id);
            switch (id)
            {
            case 0: OnKeyUp0Event(); break;

            case 1: OnKeyUp1Event(); break;

            case 2: OnKeyUp2Event(); break;

            case 3: OnKeyUp3Event(); break;

            default: break;
            }
        }
        KeyEventOld[id] = KeyEventNew[id];
    }
コード例 #3
0
 void Start()
 {
     if (JavaInterface.Java())
     {
         InputPort.onChangeScoreEvent += (int value) =>
         {
             Debug.Log(value);
         };
         InputPort.onKeyDownEventList[0] += () =>
         {
             Debug.Log("0 键被按下");
         };
         InputPort.onKeyDownEvent += () =>
         {
             Debug.Log("按键被按下");
         };
         //获取玩家分数
         Debug.Log(JavaInterface.GetScorePlayer());
         //设置玩家分数
         JavaInterface.SetInt("ScorePlayer", 100);
         Debug.Log(JavaInterface.GetScorePlayer());
         //添加玩家分数
         JavaInterface.AddScorePlayer(100);
         Debug.Log(JavaInterface.GetScorePlayer());
         //JavaInterface.PlayVideo();
         Debug.Log(JavaInterface.GetInt("ScorePlayer"));
     }
 }
コード例 #4
0
        public override void RunCommand(object sender)
        {
            //get variable path or URL to source file
            var vSourceFilePath = v_FilePath.ConvertToUserVariable(sender);
            // get source type of file either from a physical file or from a URL
            var vSourceFileType = v_FileSourceType.ConvertToUserVariable(sender);

            if (vSourceFileType == "File URL")
            {
                //create temp directory
                var tempDir  = Core.IO.Folders.GetFolder(Folders.FolderType.TempFolder);
                var tempFile = System.IO.Path.Combine(tempDir, $"{ Guid.NewGuid()}.pdf");

                //check if directory does not exist then create directory
                if (!System.IO.Directory.Exists(tempDir))
                {
                    System.IO.Directory.CreateDirectory(tempDir);
                }

                // Create webClient to download the file for extraction
                var webclient = new System.Net.WebClient();
                var uri       = new Uri(vSourceFilePath);
                webclient.DownloadFile(uri, tempFile);

                // check if file is downloaded successfully
                if (System.IO.File.Exists(tempFile))
                {
                    vSourceFilePath = tempFile;
                }

                // Free not needed resources
                uri = null;
                if (webclient != null)
                {
                    webclient.Dispose();
                    webclient = null;
                }
            }

            // Check if file exists before proceeding
            if (!System.IO.File.Exists(vSourceFilePath))
            {
                throw new System.IO.FileNotFoundException("Could not find file: " + vSourceFilePath);
            }

            //create process interface
            JavaInterface javaInterface = new JavaInterface();

            //get output from process
            var result = javaInterface.ExtractPDFText(vSourceFilePath);

            //apply to variable
            result.StoreInUserVariable(sender, v_applyToVariableName);
        }
コード例 #5
0
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;

            //get variable path or URL to source file
            var vSourceFilePath = v_FilePath.ConvertUserVariableToString(engine);

            if (v_FileSourceType == "File URL")
            {
                //create temp directory
                var tempDir  = Folders.GetFolder(FolderType.TempFolder);
                var tempFile = Path.Combine(tempDir, $"{ Guid.NewGuid()}.pdf");

                //check if directory does not exist then create directory
                if (!Directory.Exists(tempDir))
                {
                    Directory.CreateDirectory(tempDir);
                }

                // Create webClient to download the file for extraction
                var webclient = new WebClient();
                var uri       = new Uri(vSourceFilePath);
                webclient.DownloadFile(uri, tempFile);

                // check if file is downloaded successfully
                if (File.Exists(tempFile))
                {
                    vSourceFilePath = tempFile;
                }

                // Free not needed resources
                uri = null;
                if (webclient != null)
                {
                    webclient.Dispose();
                    webclient = null;
                }
            }

            // Check if file exists before proceeding
            if (!File.Exists(vSourceFilePath))
            {
                throw new FileNotFoundException("Could not find file: " + vSourceFilePath);
            }

            //create process interface
            JavaInterface javaInterface = new JavaInterface();

            //get output from process
            var result = javaInterface.ExtractPDFText(vSourceFilePath);

            //apply to variable
            result.StoreInUserVariable(engine, v_OutputUserVariableName);
        }
コード例 #6
0
 void OnReset()
 {
     if (mMainPanel != null)
     {
         lastScoreText.Display(0, 0.1f);
     }
     if (JavaInterface.Java() && playerText != null)
     {
         playerText.Display(JavaInterface.GetScorePlayer() / 10, 0.1f);
         scoreText.Display(JavaInterface.GetScorePlayer() % 10, 0.1f);
     }
 }
コード例 #7
0
        public override void RunCommand(object sender)
        {
            //get variable path to source file
            var vSourceFilePath = v_FilePath.ConvertToUserVariable(sender);

            //create process interface
            JavaInterface javaInterface = new JavaInterface();

            //get output from process
            var result = javaInterface.ExtractPDFText(vSourceFilePath);

            //apply to variable
            result.StoreInUserVariable(sender, v_applyToVariableName);
        }
コード例 #8
0
 void Start()
 {
     onAttackLeft       += GameEvent.OnAttackLeft;
     onAttackRight      += GameEvent.OnAttackRight;
     onEveryKey         += GameEvent.OnEveryKey;
     InputEvent.onPress += (GameObject obj) =>
     {
         GameEvent.OnEveryKey(PlayerController.players[0]);
     };
     if (JavaInterface.Java())
     {
         InputPort.onKeyDownEvent += () => { GameEvent.OnEveryKey(PlayerController.players[0]); };
     }
 }
コード例 #9
0
    IEnumerator GetCoinEventList(float time)
    {
        int newInCoin1  = JavaInterface.getInCoin1();
        int newInCoin2  = JavaInterface.getInCoin2();
        int newOutCoin1 = JavaInterface.getOutCoin1();
        int newOutCoin2 = JavaInterface.getOutCoin2();

        int newScorePlayer = JavaInterface.GetScorePlayer();

        int oldInCoin1     = newInCoin1;
        int oldInCoin2     = newInCoin2;
        int oldOutCoin1    = newOutCoin1;
        int oldOutCoin2    = newOutCoin2;
        int oldScorePlayer = newScorePlayer;

        while (true)
        {
            newInCoin1  = JavaInterface.getInCoin1();
            newInCoin2  = JavaInterface.getInCoin2();
            newOutCoin1 = JavaInterface.getOutCoin1();
            newOutCoin2 = JavaInterface.getOutCoin2();

            newScorePlayer = JavaInterface.GetScorePlayer();

            if (newScorePlayer != oldScorePlayer)
            {
                oldScorePlayer = newScorePlayer; OnChangeScoreEvent(newScorePlayer);
            }

            if (newInCoin1 != oldInCoin1)
            {
                oldInCoin1 = newInCoin1; OnChangeInCoin1Event();
            }
            if (newInCoin2 != oldInCoin2)
            {
                oldInCoin2 = newInCoin2; OnChangeInCoin2Event();
            }
            if (newOutCoin1 != oldOutCoin1)
            {
                oldOutCoin1 = newOutCoin1; OnChangeOutCoin1Event();
            }
            if (newOutCoin2 != oldOutCoin2)
            {
                oldOutCoin2 = newOutCoin2; OnChangeOutCoin2Event();
            }
            yield return(new WaitForSeconds(time));
        }
    }
コード例 #10
0
        public override void RunCommand(object sender)
        {
            //get variable path to source file
            var vSourceFilePath = v_FilePath.ConvertToUserVariable(sender);


            if (!System.IO.File.Exists(vSourceFilePath))
            {
                throw new System.IO.FileNotFoundException("Could not find file: " + vSourceFilePath);
            }

            //create process interface
            JavaInterface javaInterface = new JavaInterface();

            //get output from process
            var result = javaInterface.ExtractPDFText(vSourceFilePath);

            //apply to variable
            result.StoreInUserVariable(sender, v_applyToVariableName);
        }
コード例 #11
0
        void OnLaunchGame()
        {
            if (JavaInterface.Java())
            {
                if (JavaInterface.CoinOutCheck())
                {
                    Debug.Log("玩家分数为零停止退币");
                }

                JavaInterface.AddShuffleScore(10);
                JavaInterface.AddGameCounter(1);
            }
            profit += 1;
            PlayerPrefs.SetInt("Profit", profit);
            PlayerPrefs.Save();
            mScroll.gameObject.SetActive(true);
            mScrollMain.gameObject.SetActive(true);
            gameText.gameObject.SetActive(true);
            gameText.Display(gameScore);
            mScroll.valueA = PlayerController.players[0].health / PlayerController.players[0].healthMax;
            mScroll.Refresh();
            mScrollMain.valueA = 0;
            mScrollMain.Refresh();
            if (mWelcome != null)
            {
                mWelcome.Hide();
                mWelcome.gameObject.GetComponent <Collider>().enabled = false;
            }
            if (mChopLeft != null)
            {
                mChopLeft.Display();
            }
            if (mChopRight != null)
            {
                mChopRight.Display();
            }
        }
コード例 #12
0
 private string TraverseInterface(JavaInterface javaInterface)
 {
     return(TraverseClassOrInterface(javaInterface, false));
 }
コード例 #13
0
        IEnumerator UpdateStatus()
        {
            //临时变量
            int temp;

            WaitForSeconds wait = new WaitForSeconds(0.1f);

            //判断循环
            while (true)
            {
                //Debug.Log("启动游戏周期");
                //等待直到游戏初始化完成
                while (!isFinishInit)
                {
                    yield return(wait);
                }
                //Debug.Log("完成初始化");
                //等待直到游戏进程启动
                while (!isLaunchGame)
                {
                    //街机模式下自动启动游戏进程
                    if (JavaInterface.Java())
                    {
                        //退币完成才能开始游戏
                        while (isOutCoin)
                        {
                            isOutCoin = JavaInterface.GetCoinOutFlag();
                            //Debug.Log(isOutCoin);
                            yield return(wait);
                        }
                        if (JavaInterface.GetScorePlayer() >= 10)
                        {
                            JavaInterface.AddScorePlayer(-10);
                            isLaunchGame = true;
                        }
                    }
                    yield return(wait);
                }
                //Debug.Log("启动游戏进程");
                GameEvent.OnLaunchGame();
                //等待直到倒计时完毕
                temp = 4;
                while (temp-- > 0)
                {
                    GameEvent.WaitStartGame(temp);
                    yield return(new WaitForSeconds(0.375f));
                }
                GameEvent.OnPlayGame();
                //Debug.Log("完成倒计时");
                //等待直到正式开始游戏
                overtime = 100;
                while (!isPlay && overtime-- > 0)
                {
                    yield return(wait);
                }
                if (overtime <= 0)
                {
                    //Debug.Log("等待超时");
                    isPlay = true;
                }
                //Debug.Log("开始游戏进程");
                GameEvent.OnStartGame();
                //等待直到验证完成
                while (!isVerify)
                {
                    yield return(wait);
                }
                //Debug.Log("验证游戏结果");
                //等待直到完成游戏进程
                while (isGame)
                {
                    yield return(wait);
                }
                //Debug.Log("完成游戏进程");
                //完成后执行清理工作
                GameEvent.OnFinishGame();
                //检测间隔(默认0.1秒)
                yield return(wait);
                //Debug.Log("完成整个周期");
            }
        }
コード例 #14
0
        public static void CreateProject(List <JavaObject> javaObjects, string targetpath, string folderName)
        {
            //string subdir = $"C:/Users/sofia/Favorites/FolderTest";
            string subdir = $"{targetpath}/{folderName}";

            // If directory does not exist, create it.
            if (!Directory.Exists(subdir))
            {
                Directory.CreateDirectory(subdir);
            }

            foreach (var item in javaObjects)
            {        // TODO
                     // einzelne Unterpunkte!;
                     //string pathPackages = @"C:/Users/sofia/Favorites/FolderTest";
                string pathPackages = subdir;

                var splitPath = item.Package.Split('.');
                foreach (var p in splitPath)
                {
                    pathPackages = pathPackages + "/" + p;
                    if (!Directory.Exists(pathPackages))
                    {
                        Directory.CreateDirectory(pathPackages);
                    }
                }
            }
            foreach (var item in javaObjects)
            {
                string pathPackages = "";
                var    splitPath    = item.Package.Split('.');
                foreach (var p in splitPath)
                {
                    pathPackages = pathPackages + "/" + p;
                    if (!Directory.Exists(pathPackages))
                    {
                        Directory.CreateDirectory(pathPackages);
                    }
                }
                string path = $"{subdir}/{pathPackages}/{item.Name}.java";
                //string path = @"C:/Users/sofia/Favorites/FolderTest/" + pathPackages + "/" + item.Name + ".java";
                if (!File.Exists(path))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine($"package {item.Package};");
                        sw.WriteLine();
                        foreach (var impl in item.ObjectsToImport)
                        {
                            sw.WriteLine("import " + impl.Package + "." + impl.Name + ";");
                        }
                        if (item.GetType().ToString().Equals("UMJA.Utility.JavaClass"))
                        {
                            JavaClass javaClass = (JavaClass)item;
                            string    imp       = (javaClass.Implements.Count == 0) ? " " : " implements";


                            foreach (var i in javaClass.Implements)
                            {
                                imp = imp + " " + i.Name;
                            }
                            sw.WriteLine();
                            sw.WriteLine("public class " + item.Name + imp + " {");
                            foreach (var vari in javaClass.Variables)
                            {
                                var final = (vari.IsFinal) ? "final" : "";
                                var priv  = (vari.IsPrivate) ? "private" : "public";
                                var stat  = (vari.IsStatic) ? "static" : "";

                                string equalsPart = (vari.DefinedValue != null && vari.DefinedValue != string.Empty) ? $" = {vari.DefinedValue}" : "";
                                if (equalsPart.Equals("") && vari.IsFinal)
                                {
                                    equalsPart = $" = new {vari.ObjectType}()";
                                }

                                sw.WriteLine(priv + " " + stat + " " + final + " " + vari.ObjectType + " " + vari.Name + equalsPart + ";");
                            }
                            foreach (var method in javaClass.Methods)
                            {
                                var priv = (method.IsPrivate) ? "private" : "public";
                                var stat = (method.IsStatic) ? "static" : "";

                                string parameter = "";
                                foreach (var variable in method.Parameters)
                                {
                                    parameter += variable.ObjectType + " " + variable.Name + ", ";
                                }
                                if (parameter.Length > 0)
                                {
                                    parameter = parameter.Substring(0, parameter.Length - 2);
                                }

                                if (Object.Equals(method.Name, "toString"))
                                {
                                    sw.WriteLine(Environment.NewLine + "@Override");
                                    sw.WriteLine(priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "(" + parameter + ")" + " {" + Environment.NewLine + "   return \"\";" + Environment.NewLine + "}");
                                }
                                else if (method.Override)
                                {
                                    sw.WriteLine(Environment.NewLine + "@Override");
                                    sw.WriteLine(priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "(" + parameter + ")" + " {"
                                                 + Environment.NewLine
                                                 + "    throw new UnsupportedOperationException(\"Not supported yet.\"); //To change body of generated methods, choose Tools | Templates."
                                                 + Environment.NewLine
                                                 + "}");
                                }
                                else if (method.Name.StartsWith("get") && javaClass.Variables.FindAll(x => method.Name.ToLower().Contains(x.Name.ToLower())).Count != 0)
                                {
                                    sw.WriteLine(Environment.NewLine + priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "() {");
                                    sw.WriteLine($"return {javaClass.Variables.FindAll(x => method.Name.ToLower().Contains(x.Name.ToLower())).First().Name};");
                                    sw.WriteLine("}");
                                }
                                else if (method.Name.StartsWith("set") && javaClass.Variables.FindAll(x => method.Name.ToLower().Contains(x.Name.ToLower())).Count > 0)
                                {
                                    sw.WriteLine(Environment.NewLine + priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "(" + parameter + ")" + " {");
                                    sw.WriteLine($"this.{method.Parameters[0].Name} = {method.Parameters[0].Name};");
                                    sw.WriteLine("}");
                                }
                                else
                                {
                                    sw.WriteLine(Environment.NewLine + priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "(" + parameter + ")" + " {" + Environment.NewLine + Environment.NewLine + "}");
                                }
                            }

                            if (javaClass.HasConstructor)
                            {
                                var variablesForConstSB = new StringBuilder();
                                javaClass.Variables.FindAll(x => !x.IsStatic).ToList().ForEach(x => variablesForConstSB.Append($"{x.ObjectType} {x.Name}, "));

                                sw.WriteLine($"public {javaClass.Name}({variablesForConstSB.ToString().Remove(variablesForConstSB.ToString().Length - 2, 2)}) " + "{");
                                javaClass.Variables.ForEach(x => sw.WriteLine($"this.{x.Name} = {x.Name};"));
                                sw.WriteLine("}");
                                sw.WriteLine("");
                            }

                            if (javaClass.HasGetter)
                            {
                                javaClass.Variables.ForEach(x => sw.WriteLine($"public {x.ObjectType} get{x.Name.ToCharArray()[0].ToString().ToUpper()}{x.Name.Remove(0, 1)}() " + "{" + Environment.NewLine + $"    return {x.Name};" + Environment.NewLine + "}"));
                            }

                            if (javaClass.HasSetter)
                            {
                                javaClass.Variables.ForEach(x => sw.WriteLine($"public {x.ObjectType} set{x.Name.ToCharArray()[0].ToString().ToUpper()}{x.Name.Remove(0, 1)}({x.ObjectType} {x.Name}) "
                                                                              + "{"
                                                                              + Environment.NewLine
                                                                              + $"    this.{x.Name} =  {x.Name};"
                                                                              + Environment.NewLine
                                                                              + "}"));
                            }


                            sw.WriteLine("}");
                            guiLog($"Die Klasse {javaClass.Name} wurde Compiliert");
                        }

                        else if (item.GetType().ToString().Equals("UMJA.Utility.JavaEnumeration"))
                        {
                            JavaEnumeration javaEnumeration = (JavaEnumeration)item;
                            sw.WriteLine("public enum " + item.Name + "{");
                            sw.WriteLine(javaEnumeration.Values);
                            sw.WriteLine("}");
                            guiLog($"Das Enum {javaEnumeration.Name} wurde Compiliert");
                        }

                        else if (item.GetType().ToString().Equals("UMJA.Utility.JavaInterface"))
                        {
                            JavaInterface javaClass = (JavaInterface)item;
                            sw.WriteLine("public interface " + item.Name + "{");
                            foreach (var vari in javaClass.Variables)
                            {
                                var final = (vari.IsFinal) ? "final" : "";
                                var priv  = (vari.IsPrivate) ? "private" : "public";
                                var stat  = (vari.IsStatic) ? "static" : "";

                                string equalsPart = (vari.DefinedValue != null && vari.DefinedValue != string.Empty) ? $" = {vari.DefinedValue}" : "";
                                if (equalsPart.Equals("") && vari.IsFinal)
                                {
                                    equalsPart = $" = new {vari.ObjectType}()";
                                }

                                sw.WriteLine(priv + " " + stat + " " + final + " " + vari.ObjectType + " " + vari.Name + equalsPart + ";");
                            }
                            foreach (var method in javaClass.Methods)
                            {
                                var priv = (method.IsPrivate) ? "private" : "public";
                                var stat = (method.IsStatic) ? "static" : "";

                                string parameter = "";
                                foreach (var variable in method.Parameters)
                                {
                                    parameter += parameter + variable.ObjectType + " " + variable.Name + ", ";
                                }
                                if (parameter.Length > 0)
                                {
                                    parameter = parameter.Substring(0, parameter.Length - 2);
                                }


                                sw.WriteLine(priv + " " + stat + " " + " " + method.ReturnObject + " " + method.Name + "(" + parameter + ");");
                            }


                            sw.WriteLine("}");
                            guiLog($"Das Interface {javaClass.Name} wurde Compiliert");
                        }
                    }
                }
            }
            guiLog("Das Projekt wurde erfolgreich erstellt!");
        }
コード例 #15
0
        public JavaStubGrammar()
        {
            CommentTerminal single_line_comment = new CommentTerminal("SingleLineComment", "//", "\r", "\n");
            CommentTerminal delimited_comment   = new CommentTerminal("DelimitedComment", "/*", "*/");

            NonGrammarTerminals.Add(single_line_comment);
            NonGrammarTerminals.Add(delimited_comment);

            IdentifierTerminal identifier = new IdentifierTerminal("identifier");

            KeyTerm keyword_package      = Keyword("package");
            KeyTerm keyword_import       = Keyword("import");
            KeyTerm keyword_public       = Keyword("public");
            KeyTerm keyword_protected    = Keyword("protected");
            KeyTerm keyword_static       = Keyword("static");
            KeyTerm keyword_final        = Keyword("final");
            KeyTerm keyword_abstract     = Keyword("abstract");
            KeyTerm keyword_synchronized = Keyword("synchronized");
            KeyTerm keyword_default      = Keyword("default");
            KeyTerm keyword_native       = Keyword("native");
            KeyTerm keyword_volatile     = Keyword("volatile");
            KeyTerm keyword_transient    = Keyword("transient");
            KeyTerm keyword_enum         = Keyword("enum");
            KeyTerm keyword_class        = Keyword("class");
            KeyTerm keyword_interface    = Keyword("interface");
            KeyTerm keyword_at_interface = Keyword("@interface");
            KeyTerm keyword_extends      = Keyword("extends");
            KeyTerm keyword_implements   = Keyword("implements");
            KeyTerm keyword_throw        = Keyword("throw");
            KeyTerm keyword_throws       = Keyword("throws");
            KeyTerm keyword_null         = Keyword("null");
            KeyTerm keyword_super        = Keyword("super");
            KeyTerm keyword_true         = Keyword("true");
            KeyTerm keyword_false        = Keyword("false");
            KeyTerm keyword_new          = Keyword("new");

            var compile_unit                         = DefaultNonTerminal("compile_unit");
            var opt_package_decl                     = DefaultNonTerminal("opt_package_declaration");
            var package_decl                         = DefaultNonTerminal("package_declaration");
            var imports                              = DefaultNonTerminal("imports");
            var import                               = DefaultNonTerminal("import");
            var type_decls                           = DefaultNonTerminal("type_decls");
            var type_decl                            = DefaultNonTerminal("type_decl");
            var enum_decl                            = DefaultNonTerminal("enum_decl");
            var enum_body                            = DefaultNonTerminal("enum_body");
            var class_decl                           = DefaultNonTerminal("class_decl");
            var opt_generic_arg_decl                 = DefaultNonTerminal("opt_generic_arg_decl");
            var opt_extends_decl                     = DefaultNonTerminal("opt_extends_decl");
            var opt_implements_decl                  = DefaultNonTerminal("opt_implements_decl");
            var implements_decl                      = DefaultNonTerminal("implements_decl");
            var interface_decl                       = DefaultNonTerminal("interface_decl");
            var iface_or_at_iface                    = DefaultNonTerminal("iface_or_at_iface");
            var type_body                            = DefaultNonTerminal("type_body");
            var type_members                         = DefaultNonTerminal("type_members");
            var type_member                          = DefaultNonTerminal("type_member");
            var nested_type_decl                     = DefaultNonTerminal("nested_type_decl");
            var ctor_decl                            = DefaultNonTerminal("ctor_decl");
            var method_decl                          = DefaultNonTerminal("method_decl");
            var field_decl                           = DefaultNonTerminal("field_decl");
            var opt_field_assignment                 = DefaultNonTerminal("opt_field_assignment");
            var static_ctor_decl                     = DefaultNonTerminal("static_ctor_decl");
            var enum_members_decl                    = DefaultNonTerminal("enum_members_decl");
            var enum_member_initializers             = DefaultNonTerminal("enum_member_initializers");
            var enum_member_initializer              = DefaultNonTerminal("enum_member_initializer");
            var opt_enum_braces                      = DefaultNonTerminal("opt_enum_braces");
            var opt_final_field_assign               = DefaultNonTerminal("opt_final_field_assign");
            var final_field_assign                   = DefaultNonTerminal("final_field_assign");
            var terminate_decl_or_body               = DefaultNonTerminal("terminate_decl_or_body");
            var assignments                          = DefaultNonTerminal("assignments");
            var assignment                           = DefaultNonTerminal("assignment");
            var assign_expr                          = DefaultNonTerminal("assign_expr");
            var rvalue_expressions                   = DefaultNonTerminal("rvalue_expressions");
            var rvalue_expression                    = DefaultNonTerminal("rvalue_expression");
            var array_literal                        = DefaultNonTerminal("array_literal");
            var annotations                          = DefaultNonTerminal("annotations");
            var annotation                           = DefaultNonTerminal("annotation");
            var opt_annotation_args                  = DefaultNonTerminal("opt_annotation_args");
            var annotation_value_assignments         = DefaultNonTerminal("annotation_value_assignments");
            var annot_assign_expr                    = DefaultNonTerminal("annot_assign_expr");
            var modifiers_then_opt_generic_arg       = DefaultNonTerminal("modifiers_then_opt_generic_arg");
            var modifier_or_generic_arg              = DefaultNonTerminal("modifier_or_generic_arg");
            var modifiers                            = DefaultNonTerminal("modifiers");
            var modifier                             = DefaultNonTerminal("modifier");
            var argument_decls                       = DefaultNonTerminal("argument_decls");
            var argument_decl                        = DefaultNonTerminal("argument_decl");
            var comma_separated_types                = DefaultNonTerminal("comma_separated_types");
            var throws_decl                          = DefaultNonTerminal("throws_decl");
            var opt_throws_decl                      = DefaultNonTerminal("opt_throws_decl");
            var type_name                            = DefaultNonTerminal("type_name");
            var dotted_identifier                    = DefaultNonTerminal("dotted_identifier");
            var array_type                           = DefaultNonTerminal("array_type");
            var vararg_type                          = DefaultNonTerminal("vararg_type");
            var generic_type                         = DefaultNonTerminal("generic_type");
            var generic_definition_arguments         = DefaultNonTerminal("generic_definition_arguments");
            var generic_definition_argument          = DefaultNonTerminal("generic_definition_argument");
            var generic_definition_constraints       = DefaultNonTerminal("generic_definition_constraints");
            var generic_definition_arguments_spec    = DefaultNonTerminal("generic_definition_arguments_spec");
            var generic_instance_arguments_spec      = DefaultNonTerminal("generic_instance_arguments_spec");
            var generic_instance_arguments           = DefaultNonTerminal("generic_instance_arguments");
            var generic_instance_argument            = DefaultNonTerminal("generic_instance_argument");
            var generic_instance_identifier_or_q     = DefaultNonTerminal("generic_instance_identifier_or_q");
            var generic_instance_constraints         = DefaultNonTerminal("generic_instance_constraints");
            var generic_instance_constraints_extends = DefaultNonTerminal("generic_instance_constraints_extends");
            var generic_instance_constraints_super   = DefaultNonTerminal("generic_instance_constraints_super");
            var generic_instance_constraint_types    = DefaultNonTerminal("generic_instance_constraint_types");
            var impl_expressions                     = DefaultNonTerminal("impl_expressions");
            var impl_expression                      = DefaultNonTerminal("impl_expression");
            var call_super                           = DefaultNonTerminal("call_super");
            var super_args                           = DefaultNonTerminal("super_args");
            var default_value_expr                   = DefaultNonTerminal("default_value_expr");
            var default_value_casted                 = DefaultNonTerminal("default_value_casted");
            var default_value_literal                = DefaultNonTerminal("default_value_literal");
            var new_array                            = DefaultNonTerminal("new_array");
            var runtime_exception                    = DefaultNonTerminal("runtime_exception");
            var numeric_terminal                     = TerminalFactory.CreateCSharpNumber("numeric_value_literal");

            numeric_terminal.AddPrefix("-", NumberOptions.AllowSign);
            numeric_terminal.AddPrefix("+", NumberOptions.AllowSign);
            //numeric_terminal.AddSuffix ("f");
            numeric_terminal.AddSuffix("L");
            var numeric_literal = DefaultNonTerminal("numeric_literal");
            var string_literal  = TerminalFactory.CreateCSharpString("string_literal");
            var value_literal   = DefaultNonTerminal("value_literal");
            var identifier_wild = DefaultNonTerminal("identifier_wild");

            // <construction_rules>

            compile_unit.Rule     = opt_package_decl + imports + type_decls;
            opt_package_decl.Rule = package_decl | Empty;
            package_decl.Rule     = keyword_package + dotted_identifier + ";";
            imports.Rule          = MakeStarRule(imports, import);
            import.Rule           = keyword_import + dotted_identifier + ";";
            type_decls.Rule       = MakeStarRule(type_decls, type_decl);

            type_decl.Rule = class_decl | interface_decl | enum_decl;
            // FIXME: those modifiers_then_opt_generic_arg should be actually just modifiers... see modifiers_then_opt_generic_arg.Rule below.
            enum_decl.Rule         = annotations + modifiers_then_opt_generic_arg + keyword_enum + identifier + opt_implements_decl + "{" + enum_body + "}";
            enum_body.Rule         = Empty | enum_members_decl + type_members;
            class_decl.Rule        = annotations + modifiers_then_opt_generic_arg + keyword_class + identifier + opt_generic_arg_decl + opt_extends_decl + opt_implements_decl + type_body;
            interface_decl.Rule    = annotations + modifiers_then_opt_generic_arg + iface_or_at_iface + identifier + opt_generic_arg_decl + opt_extends_decl + opt_implements_decl + type_body;
            iface_or_at_iface.Rule = keyword_interface | keyword_at_interface;

            opt_generic_arg_decl.Rule         = Empty | "<" + generic_definition_arguments + ">";
            opt_extends_decl.Rule             = Empty | keyword_extends + implements_decl; // when it is used with an interface, it can be more than one...
            opt_implements_decl.Rule          = Empty | keyword_implements + implements_decl;
            implements_decl.Rule              = MakePlusRule(implements_decl, ToTerm(","), type_name);
            type_body.Rule                    = T("{") + type_members + T("}");
            annotations.Rule                  = MakeStarRule(annotations, annotation);
            annotation.Rule                   = T("@") + dotted_identifier + opt_annotation_args;
            opt_annotation_args.Rule          = Empty | T("(") + annotation_value_assignments + T(")");
            annotation_value_assignments.Rule = rvalue_expression | MakeStarRule(annotation_value_assignments, ToTerm(","), annot_assign_expr);
            annot_assign_expr.Rule            = assign_expr | T("{") + rvalue_expressions + T("}");

            // HACK: I believe this is an Irony bug that adding opt_generic_arg_decl here results in shift-reduce conflict, but it's too complicated to investigate the actual issue.
            // As a workaround I add generic arguments as part of this "modifier" so that it can be safely added to a generic method declaration.
            modifiers_then_opt_generic_arg.Rule = MakeStarRule(modifiers_then_opt_generic_arg, modifier_or_generic_arg);
            modifiers.Rule = MakeStarRule(modifiers, modifier);
            modifier_or_generic_arg.Rule = modifier | generic_definition_arguments_spec;
            modifier.Rule = keyword_public | keyword_protected | keyword_final | keyword_abstract | keyword_synchronized | keyword_default | keyword_native | keyword_volatile | keyword_transient | keyword_static;

            type_members.Rule             = MakeStarRule(type_members, type_member);
            type_member.Rule              = nested_type_decl | ctor_decl | method_decl | field_decl | static_ctor_decl;
            nested_type_decl.Rule         = type_decl;
            enum_members_decl.Rule        = enum_member_initializers + ";";
            enum_member_initializers.Rule = MakeStarRule(enum_member_initializers, ToTerm(","), enum_member_initializer);
            enum_member_initializer.Rule  = annotations + identifier + opt_enum_braces;
            opt_enum_braces.Rule          = Empty | "(" + ")";
            static_ctor_decl.Rule         = annotations + keyword_static + "{" + assignments + "}";
            assignments.Rule              = MakeStarRule(assignments, assignment);
            assignment.Rule         = assign_expr + ";";
            assign_expr.Rule        = identifier + "=" + rvalue_expression;
            rvalue_expressions.Rule = MakeStarRule(rvalue_expressions, ToTerm(","), rvalue_expression);
            rvalue_expression.Rule  = value_literal | new_array | type_name | identifier | array_literal | annotation;
            array_literal.Rule      = "{" + rvalue_expressions + "}";

            field_decl.Rule             = annotations + modifiers_then_opt_generic_arg + type_name + identifier + opt_field_assignment + ";" + opt_final_field_assign;
            opt_field_assignment.Rule   = Empty | "=" + rvalue_expression;
            opt_final_field_assign.Rule = Empty | "{" + assign_expr + ";" + "}";
            terminate_decl_or_body.Rule = ";" | ("{" + impl_expressions + "}") | (keyword_default + default_value_literal + ";");

            ctor_decl.Rule = annotations + modifiers_then_opt_generic_arg + identifier + "(" + argument_decls + ")" + opt_throws_decl + terminate_decl_or_body;             // these Empties can make the structure common to method_decl.

            method_decl.Rule = annotations + modifiers_then_opt_generic_arg + /*opt_generic_arg_decl*/ type_name + identifier + "(" + argument_decls + ")" + opt_throws_decl + terminate_decl_or_body;

            impl_expressions.Rule      = MakeStarRule(impl_expressions, impl_expression);
            impl_expression.Rule       = call_super | runtime_exception | assign_expr;
            call_super.Rule            = keyword_super + "(" + super_args + ")" + ";";
            super_args.Rule            = MakeStarRule(super_args, ToTerm(","), default_value_expr);
            default_value_expr.Rule    = keyword_null | default_value_casted | default_value_literal;
            default_value_casted.Rule  = "(" + type_name + ")" + default_value_expr;
            default_value_literal.Rule = numeric_terminal | "\"\"" | "{" + "}" | keyword_true | keyword_false;
            runtime_exception.Rule     = keyword_throw + keyword_new + identifier + "(\"Stub!\"" + ")" + ";";
            new_array.Rule             = keyword_new + dotted_identifier + "[" + numeric_literal + "]";

            argument_decls.Rule = annotations | MakeStarRule(argument_decls, ToTerm(","), argument_decl);

            argument_decl.Rule = annotations + type_name + identifier;

            throws_decl.Rule           = keyword_throws + comma_separated_types;
            comma_separated_types.Rule = MakeStarRule(comma_separated_types, ToTerm(","), type_name);
            opt_throws_decl.Rule       = Empty | throws_decl;

            type_name.Rule = dotted_identifier | array_type | vararg_type | generic_type;

            vararg_type.Rule = type_name + T("...");
            array_type.Rule  = type_name + ("[") + T("]");

            generic_definition_arguments_spec.Rule = "<" + generic_definition_arguments + ">";
            generic_type.Rule = dotted_identifier + generic_instance_arguments_spec;
            generic_instance_arguments_spec.Rule      = "<" + generic_instance_arguments + ">";
            generic_definition_arguments.Rule         = MakePlusRule(generic_definition_arguments, ToTerm(","), generic_definition_argument);
            generic_definition_argument.Rule          = identifier + generic_definition_constraints;
            generic_definition_constraints.Rule       = Empty | generic_instance_constraints_extends | generic_instance_constraints_super;
            generic_instance_arguments.Rule           = MakePlusRule(generic_instance_arguments, ToTerm(","), generic_instance_argument);
            generic_instance_argument.Rule            = generic_instance_identifier_or_q + generic_instance_constraints;
            generic_instance_identifier_or_q.Rule     = type_name | T("?");
            generic_instance_constraints.Rule         = Empty | generic_instance_constraints_extends | generic_instance_constraints_super;
            generic_instance_constraints_extends.Rule = keyword_extends + generic_instance_constraint_types;
            generic_instance_constraints_super.Rule   = keyword_super + generic_instance_constraint_types;
            generic_instance_constraint_types.Rule    = MakePlusRule(generic_instance_constraint_types, ToTerm("&"), type_name);

            dotted_identifier.Rule = MakePlusRule(dotted_identifier, ToTerm("."), identifier_wild);

            numeric_literal.Rule  = numeric_terminal;
            numeric_literal.Rule |= "(" + numeric_literal + "/" + numeric_literal + ")";
            value_literal.Rule    = string_literal | numeric_literal | keyword_null;
            identifier_wild.Rule  = identifier | "*";

            // Define AST node creators

            Func <string, string> stripGenerics = s => s.IndexOf('<') > 0 ? s.Substring(0, s.IndexOf('<')) : s;

            single_line_comment.AstConfig.NodeCreator = DoNothing;
            delimited_comment.AstConfig.NodeCreator   = DoNothing;
            identifier.AstConfig.NodeCreator          = (ctx, node) => node.AstNode = node.Token.ValueString;
            compile_unit.AstConfig.NodeCreator        = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new JavaPackage(null)
                {
                    Name = (string)node.ChildNodes [0].AstNode, Types = ((IEnumerable <JavaType>)node.ChildNodes [2].AstNode).ToList()
                };
            };
            opt_package_decl.AstConfig.NodeCreator     = SelectSingleChild;
            package_decl.AstConfig.NodeCreator         = SelectChildValueAt(1);
            imports.AstConfig.NodeCreator              = CreateArrayCreator <object> ();
            import.AstConfig.NodeCreator               = SelectChildValueAt(1);
            type_decls.AstConfig.NodeCreator           = CreateArrayCreator <JavaType> ();
            type_decl.AstConfig.NodeCreator            = SelectSingleChild;
            opt_generic_arg_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = node.ChildNodes.Count == 0 ? null : node.ChildNodes [1].AstNode;
            };
            opt_extends_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = node.ChildNodes.Count == 0 ? null : node.ChildNodes [1].AstNode;
            };
            opt_implements_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = node.ChildNodes.Count == 0 ? null : node.ChildNodes [1].AstNode;
            };
            implements_decl.AstConfig.NodeCreator = CreateArrayCreator <string> ();
            Action <ParseTreeNode, JavaType> fillType = (node, type) => {
                var  modsOrTps = (IEnumerable <object>)node.ChildNodes [1].AstNode;
                var  mods      = modsOrTps.OfType <string> ();
                bool isEnum    = node.ChildNodes [2].AstNode as string == "enum";
                type.Abstract      |= mods.Contains("abstract");
                type.Static        |= mods.Contains("static");
                type.Final         |= mods.Contains("final");
                type.Visibility     = mods.FirstOrDefault(s => s == "public" || s == "protected") ?? "";
                type.Name           = (string)node.ChildNodes [3].AstNode;
                type.Deprecated     = ((IEnumerable <string>)node.ChildNodes [0].AstNode).Any(v => v == "java.lang.Deprecated" || v == "Deprecated") ? "deprecated" : "not deprecated";
                type.TypeParameters = isEnum ? null : (JavaTypeParameters)node.ChildNodes [4].AstNode;
                type.Members        = (IList <JavaMember>)node.ChildNodes [isEnum ? 6 : 7].AstNode;
            };

            enum_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var type = new JavaClass(null)
                {
                    Extends = "java.lang.Enum", Final = true
                };
                var methods = new JavaMember [] {
                    new JavaMethod(null)
                    {
                        Deprecated = "not deprecated",
                        Name       = "valueOf",
                        // Return needs to be filled later, with full package name.
                        Static     = true,
                        Visibility = "public",
                        Parameters = new JavaParameter [] { new JavaParameter(null)
                                                            {
                                                                Name = "name", Type = "java.lang.String"
                                                            } },
                    },
                    new JavaMethod(null)
                    {
                        Deprecated = "not deprecated",
                        Name       = "values",
                        // Return needs to be filled later, with full package name.
                        Static     = true,
                        Visibility = "public",
                        Parameters = new JavaParameter [0],
                    }
                };
                fillType(node, type);
                node.AstNode = type;
            };
            class_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var exts  = ((IEnumerable <string>)node.ChildNodes [5].AstNode) ?? Enumerable.Empty <string> ();
                var impls = ((IEnumerable <string>)node.ChildNodes [6].AstNode) ?? Enumerable.Empty <string> ();
                var ext   = exts.FirstOrDefault() ?? "java.lang.Object";
                var type  = new JavaClass(null)
                {
                    Extends        = stripGenerics(ext),
                    ExtendsGeneric = ext,
                    Implements     = impls.Select(s => new JavaImplements {
                        Name = stripGenerics(s), NameGeneric = s
                    }).ToArray(),
                };
                fillType(node, type);
                node.AstNode = type;
            };
            interface_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                bool annot = node.ChildNodes [2].AstNode as string == "@interface";
                var  exts  = ((IEnumerable <string>)node.ChildNodes [5].AstNode) ?? Enumerable.Empty <string> ();
                var  impls = ((IEnumerable <string>)node.ChildNodes [6].AstNode) ?? Enumerable.Empty <string> ();
                var  type  = new JavaInterface(null)
                {
                    Implements = exts.Concat(impls).Select(s => new JavaImplements {
                        Name = stripGenerics(s), NameGeneric = s
                    }).ToList(),
                };
                if (annot)
                {
                    type.Implements.Add(new JavaImplements {
                        Name = "java.lang.annotation.Annotation", NameGeneric = "java.lang.annotation.Annotation"
                    });
                }
                fillType(node, type);
                node.AstNode = type;
            };
            iface_or_at_iface.AstConfig.NodeCreator = SelectSingleChild;
            type_body.AstConfig.NodeCreator         = SelectChildValueAt(1);
            type_members.AstConfig.NodeCreator      = CreateArrayCreator <JavaMember> ();
            type_member.AstConfig.NodeCreator       = SelectSingleChild;
            nested_type_decl.AstConfig.NodeCreator  = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new JavaNestedType(null)
                {
                    Type = (JavaType)node.ChildNodes [0].AstNode
                };
            };
            Action <ParseTreeNode, JavaMethodBase> fillMethodBase = (node, method) => {
                bool ctor      = node.ChildNodes.Count == 8;
                var  modsOrTps = (IEnumerable <object>)node.ChildNodes [1].AstNode;
                var  mods      = modsOrTps.OfType <string> ();
                method.Static            = mods.Contains("static");
                method.Visibility        = mods.FirstOrDefault(s => s == "public" || s == "protected") ?? "";
                method.Name              = (string)node.ChildNodes [ctor ? 2 : 3].AstNode;
                method.Parameters        = ((IEnumerable <JavaParameter>)node.ChildNodes [ctor ? 4 : 5].AstNode).ToArray();
                method.ExtendedSynthetic = mods.Contains("synthetic");
                // HACK: Exception "name" can be inconsistent for nested types, and this nested type detection is hacky.
                Func <string, string> stripPackage = s => {
                    var packageTokens = s.Split('.').TakeWhile(t => !t.Any(c => Char.IsUpper(c)));
                    return(s.Substring(Enumerable.Sum(packageTokens.Select(t => t.Length)) + packageTokens.Count()));
                };
                method.Exceptions = ((IEnumerable <string>)node.ChildNodes [ctor ? 6 : 7].AstNode)
                                    ?.Select(s => new JavaException {
                    Type = s, Name = stripPackage(s)
                })
                                    ?.ToArray();
                method.Deprecated     = ((IEnumerable <string>)node.ChildNodes [0].AstNode).Any(v => v == "java.lang.Deprecated" || v == "Deprecated") ? "deprecated" : "not deprecated";
                method.Final          = mods.Contains("final");
                method.TypeParameters = modsOrTps.OfType <JavaTypeParameters> ().FirstOrDefault();
            };

            ctor_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var annots    = node.ChildNodes [0].AstNode;
                var modsOrTps = (IEnumerable <object>)node.ChildNodes [1].AstNode;
                var mods      = modsOrTps.OfType <string> ();
                var ctor      = new JavaConstructor(null);
                fillMethodBase(node, ctor);
                node.AstNode = ctor;
            };
            method_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var annots    = node.ChildNodes [0].AstNode;
                var modsOrTps = (IEnumerable <object>)node.ChildNodes [1].AstNode;
                var mods      = modsOrTps.OfType <string> ();
                var method    = new JavaMethod(null)
                {
                    Return            = (string)node.ChildNodes [2].AstNode,
                    Abstract          = mods.Contains("abstract"),
                    Native            = mods.Contains("native"),
                    Synchronized      = mods.Contains("synchronized"),
                    ExtendedSynthetic = mods.Contains("synthetic"),
                };
                fillMethodBase(node, method);
                node.AstNode = method;
            };
            field_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var annots    = node.ChildNodes [0].AstNode;
                var modsOrTps = (IEnumerable <object>)node.ChildNodes [1].AstNode;
                var mods      = modsOrTps.OfType <string> ();
                var value     = node.ChildNodes [4].AstNode?.ToString();
                var type      = (string)node.ChildNodes [2].AstNode;
                node.AstNode = new JavaField(null)
                {
                    Static      = mods.Contains("static"),
                    Visibility  = mods.FirstOrDefault(s => s == "public" || s == "protected") ?? "",
                    Type        = stripGenerics(type),
                    TypeGeneric = type,
                    Name        = (string)node.ChildNodes [3].AstNode,
                    Deprecated  = ((IEnumerable <string>)node.ChildNodes [0].AstNode).Any(v => v == "java.lang.Deprecated" || v == "Deprecated") ? "deprecated" : "not deprecated",
                    Value       = value == "null" ? null : value,               // null will not be explicitly written.
                    Volatile    = mods.Contains("volatile"),
                    Final       = mods.Contains("final"),
                    Transient   = mods.Contains("transient"),
                };
            };
            opt_field_assignment.AstConfig.NodeCreator   = (ctx, node) => node.AstNode = node.ChildNodes.Count > 0 ? node.ChildNodes [1].AstNode : null;
            opt_final_field_assign.AstConfig.NodeCreator = (ctx, node) => node.AstNode = node.ChildNodes.Count > 0 ? node.ChildNodes [1].AstNode : null;
            static_ctor_decl.AstConfig.NodeCreator       = DoNothing;       // static constructors are ignorable.
            enum_body.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                var ml = new List <JavaMember> ();
                foreach (var c in node.ChildNodes)
                {
                    ml.AddRange((IEnumerable <JavaMember>)c.AstNode);
                }
                node.AstNode = ml;
            };
            enum_members_decl.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                if (node.ChildNodes.Count > 0)
                {
                    node.AstNode = ((IEnumerable <string>)node.ChildNodes [0].AstNode)
                                   .Select(s => new JavaField(null)
                    {
                        Name       = s,
                        Final      = true,
                        Deprecated = "not deprecated",
                        Static     = true,
                        // Type needs to be filled later, with full package name.
                        Visibility = "public"
                    });
                }
            };
            enum_member_initializers.AstConfig.NodeCreator = CreateArrayCreator <string> ();
            enum_member_initializer.AstConfig.NodeCreator  = SelectChildValueAt(1);
            opt_enum_braces.AstConfig.NodeCreator          = DoNothing;
            terminate_decl_or_body.AstConfig.NodeCreator   = DoNothing;           // method/ctor body doesn't matter.
            assignments.AstConfig.NodeCreator = CreateArrayCreator <object> ();
            assignment.AstConfig.NodeCreator  = SelectChildValueAt(0);
            assign_expr.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new KeyValuePair <string, string?> ((string)node.ChildNodes [0].AstNode, node.ChildNodes [2].AstNode?.ToString());
            };
            rvalue_expressions.AstConfig.NodeCreator = CreateArrayCreator <object> ();
            rvalue_expression.AstConfig.NodeCreator  = SelectSingleChild;
            array_literal.AstConfig.NodeCreator      = CreateStringFlattener();
            annotations.AstConfig.NodeCreator        = CreateArrayCreator <string> ();
            annotation.AstConfig.NodeCreator         = (ctx, node) => {
                ProcessChildren(ctx, node.ChildNodes [1]);                  // we only care about name.
                node.AstNode = node.ChildNodes [1].AstNode;
            };
            opt_annotation_args.AstConfig.NodeCreator            = DoNothing;
            annotation_value_assignments.AstConfig.NodeCreator   = DoNothing;
            annot_assign_expr.AstConfig.NodeCreator              = DoNothing;
            modifiers_then_opt_generic_arg.AstConfig.NodeCreator = CreateArrayCreator <object> ();
            modifier_or_generic_arg.AstConfig.NodeCreator        = SelectSingleChild;
            modifiers.AstConfig.NodeCreator      = CreateArrayCreator <string> ();
            modifier.AstConfig.NodeCreator       = CreateStringFlattener();
            argument_decls.AstConfig.NodeCreator = CreateArrayCreator <JavaParameter> ();
            argument_decl.AstConfig.NodeCreator  = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new JavaParameter(null)
                {
                    Type = (string)node.ChildNodes [1].AstNode, Name = (string)node.ChildNodes [2].AstNode
                };
            };
            opt_throws_decl.AstConfig.NodeCreator       = SelectSingleChild;
            throws_decl.AstConfig.NodeCreator           = SelectChildValueAt(1);
            comma_separated_types.AstConfig.NodeCreator = CreateArrayCreator <string> ();
            type_name.AstConfig.NodeCreator             = SelectSingleChild;
            dotted_identifier.AstConfig.NodeCreator     = CreateStringFlattener(".");
            array_type.AstConfig.NodeCreator            = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = node.ChildNodes [0].AstNode + "[]";
            };
            vararg_type.AstConfig.NodeCreator  = CreateStringFlattener();
            generic_type.AstConfig.NodeCreator = CreateStringFlattener();
            generic_definition_arguments_spec.AstConfig.NodeCreator = SelectChildValueAt(1);
            generic_instance_arguments_spec.AstConfig.NodeCreator   = (ctx, node) => {
                // It is distinct from generic type parameters definition.
                ProcessChildren(ctx, node);
                node.AstNode = "<" + string.Join(", ", (IEnumerable <string>)node.ChildNodes [1].AstNode) + ">";
            };
            generic_definition_arguments.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new JavaTypeParameters((JavaMethod?)null)
                {
                    TypeParameters = node.ChildNodes.Select(c => c.AstNode).Cast <JavaTypeParameter> ().ToList()
                };
            };
            generic_definition_argument.AstConfig.NodeCreator = (ctx, node) => {
                ProcessChildren(ctx, node);
                node.AstNode = new JavaTypeParameter(null)
                {
                    Name = (string)node.ChildNodes [0].AstNode,
                    GenericConstraints = (JavaGenericConstraints)node.ChildNodes [1].AstNode
                };
            };
            generic_definition_constraints.AstConfig.NodeCreator   = SelectSingleChild;
            generic_instance_arguments.AstConfig.NodeCreator       = CreateArrayCreator <string> ();
            generic_instance_argument.AstConfig.NodeCreator        = CreateStringFlattener();
            generic_instance_identifier_or_q.AstConfig.NodeCreator = SelectSingleChild;
            generic_instance_constraints.AstConfig.NodeCreator     = (ctx, node) => {
                ProcessChildren(ctx, node);
                var c = (JavaGenericConstraints?)node.ChildNodes.FirstOrDefault()?.AstNode;
                if (c != null)
                {
                    node.AstNode = " " + c.BoundsType + " " + string.Join(" & ", c.GenericConstraints.Select(cc => cc.Type));
                }
            };
            AstNodeCreator createGenericConstaints = (ctx, node) => {
                ProcessChildren(ctx, node);
                var cl = ((IEnumerable <string>)node.ChildNodes [1].AstNode).Select(s => new JavaGenericConstraint {
                    Type = s
                });
                node.AstNode = new JavaGenericConstraints()
                {
                    BoundsType         = (string)node.ChildNodes [0].AstNode,
                    GenericConstraints = cl.Any() ? cl.ToArray() : null,
                };
            };

            generic_instance_constraints_extends.AstConfig.NodeCreator = createGenericConstaints;
            generic_instance_constraints_super.AstConfig.NodeCreator   = createGenericConstaints;
            generic_instance_constraint_types.AstConfig.NodeCreator    = CreateArrayCreator <string> ();
            impl_expressions.AstConfig.NodeCreator = CreateArrayCreator <object> ();
            impl_expression.AstConfig.NodeCreator  = SelectSingleChild;
            // each expression item is not seriously processed.
            // They are insignificant except for consts, and for consts they are just string values.
            call_super.AstConfig.NodeCreator            = CreateStringFlattener();
            super_args.AstConfig.NodeCreator            = CreateStringFlattener();
            default_value_expr.AstConfig.NodeCreator    = CreateStringFlattener();
            default_value_casted.AstConfig.NodeCreator  = CreateStringFlattener();
            default_value_literal.AstConfig.NodeCreator = CreateStringFlattener();
            new_array.AstConfig.NodeCreator             = DoNothing;
            runtime_exception.AstConfig.NodeCreator     = CreateStringFlattener();
            Func <string, string, string> stripTail = (s, t) => s.EndsWith(t, StringComparison.Ordinal) ? s.Substring(0, s.Length - t.Length) : s;

            numeric_terminal.AstConfig.NodeCreator = (ctx, node) => node.AstNode = stripTail(stripTail(node.Token.Text, "L"), "f");
            numeric_literal.AstConfig.NodeCreator  = CreateStringFlattener();
            string_literal.AstConfig.NodeCreator   = (ctx, node) => node.AstNode = '"' + node.Token.ValueString + '"';
            value_literal.AstConfig.NodeCreator    = SelectSingleChild;
            identifier_wild.AstConfig.NodeCreator  = SelectSingleChild;

            this.Root = compile_unit;
        }
コード例 #16
0
        void Start()
        {
            //PlayerPrefs.SetInt("Profit", 0);
            //PlayerPrefs.SetInt("AllScore",0);
            //PlayerPrefs.SetInt("GameCounter", 0);
            //PlayerPrefs.SetInt("BestScore", Random.Range(500,1000));
            audio       = gameObject.AddComponent <AudioSource>();
            profit      = PlayerPrefs.GetInt("Profit");
            bestScore   = PlayerPrefs.GetInt("BestScore");
            allScore    = PlayerPrefs.GetInt("AllScore");
            gameCounter = PlayerPrefs.GetInt("GameCounter");
            if (allScore < 1000)
            {
                allScore = 1000;
            }
            if (gameCounter < 10)
            {
                gameCounter = 10;
            }

            if (JavaInterface.Java())
            {
                if (bestScore < 500)
                {
                    bestScore = Random.Range(500, 1000);
                }

                playerText = Instantiate(texts[5]).GetComponent <CustomText>();
                playerText.transform.parent     = transform;
                playerText.transform.position   = new Vector3(-1.125f, 0.5f);
                playerText.transform.localScale = new Vector3(0.15f, 0.15f);

                scoreText = Instantiate(texts[7]).GetComponent <CustomText>();
                scoreText.transform.parent     = transform;
                scoreText.transform.position   = new Vector3(-1.125f, 0.40f);
                scoreText.transform.localScale = new Vector3(0.075f, 0.075f);
                //scoreText.Init();
                //scoreText.Display(0);
                //playerText.gameObject.SetActive(false);
            }
            else
            {
                mAuidoOption = Instantiate(audioOption).GetComponent <OptionAnimation>();
                mAuidoOption.transform.parent     = transform;
                mAuidoOption.transform.localScale = new Vector3(1.5f, 1.5f, 1f);
                mAuidoOption.transform.position   = new Vector3(1.15f, 0.575f);

                //Debug.Log(mAuidoOption);
                EventListener.Get(mAuidoOption.gameObject).onClick += (GameObject obj) =>
                {
                    mAuidoOption.OnClick();
                };
                EventListener.Get(mAuidoOption.gameObject).onPress += (GameObject obj) =>
                {
                    mAuidoOption.OnPress();
                };
                EventListener.Get(mAuidoOption.gameObject).onFree += (GameObject obj) =>
                {
                    mAuidoOption.OnFree();
                };
            }
            mChopLeft  = Instantiate(chopLeft).GetComponent <ChopAnimation>();
            mChopRight = Instantiate(chopRight).GetComponent <ChopAnimation>();
            mChopLeft.transform.parent    = transform;
            mChopRight.transform.parent   = transform;
            mChopLeft.transform.position  = new Vector3(-0.75f, -0.125f);
            mChopRight.transform.position = new Vector3(0.75f, -0.125f);

            mChopLeft.Hide();
            mChopRight.Hide();



            gameText = Instantiate(texts[4]).GetComponent <CustomText>();
            gameText.transform.parent     = transform;
            gameText.transform.position   = new Vector3(0, 0.25f);
            gameText.transform.localScale = new Vector3(0.25f, 0.25f, 1);
            gameText.gameObject.SetActive(false);

            mMainPanel = Instantiate(mainPanel).GetComponent <PanelAnimation>();

            lastScoreText = Instantiate(texts[6]).GetComponent <CustomText>();
            lastScoreText.transform.parent     = mMainPanel.transform;
            lastScoreText.transform.localScale = new Vector3(0.1f, 0.2f);
            lastScoreText.transform.position   = mMainPanel.transform.position + new Vector3(0, -0.675f);

            bestText = Instantiate(texts[6]).GetComponent <CustomText>();
            bestText.transform.parent   = mMainPanel.transform;
            bestText.transform.position = mMainPanel.transform.position + new Vector3(0, -0.425f);
            bestText.Display(bestScore);

            mScroll = Instantiate(scroll).GetComponent <ScrollAnimation>();
            mScroll.transform.position = new Vector3(0, 0.65f);
            mScroll.transform.parent   = transform;
            mScroll.gameObject.SetActive(false);

            mScrollMain = Instantiate(scrollMain).GetComponent <ScrollAnimation>();
            mScrollMain.transform.position = new Vector3(1.2f, -0.15f);
            mScrollMain.transform.parent   = transform;

            mScrollMain.GetComponent <Renderer>().material.color = new Color(1, 1, 1, 0);
            for (int i = 0; i < mScrollMain.transform.childCount; i++)
            {
                mScrollMain.transform.GetChild(i).GetComponent <Renderer>().material.color = new Color(1, 1, 1, 0);
            }

            mAwards = mScrollMain.GetComponent <AwardsAnimation>();
            mScrollMain.gameObject.SetActive(false);

            if (JavaInterface.Java() == true)
            {
                mWelcome = Instantiate(welcomeArcade).GetComponent <WelcomeAnimation>();
            }
            else
            {
                mWelcome = Instantiate(welcomeMobile).GetComponent <WelcomeAnimation>();
            }
            mWelcome.transform.position = transform.position;
            mWelcome.transform.parent   = transform;
            //mWelcome.transform.localScale = new Vector3(2, 2);
            mWelcome.Hide();
            mWelcome.gameObject.GetComponent <Collider>().enabled = false;

            GameEvent.onGetScore    += OnGetScore;
            GameEvent.onDeath       += OnDeath;
            GameEvent.onFinishGame  += OnFinishGame;
            GameEvent.onReset       += OnReset;
            GameEvent.startReset    += StartReset;
            GameEvent.finishReset   += FinishReset;
            GameEvent.onHealth      += OnHealth;
            GameEvent.onStartGame   += OnStartGame;
            GameEvent.onWelcome     += OnWelcome;
            GameEvent.offWelcome    += OffWelcome;
            GameEvent.waitStartGame += WaitStartGame;
            GameEvent.onLaunchGame  += OnLaunchGame;

            EventListener.Get(mWelcome.gameObject).onClick += (GameObject obj) =>
            {
                GameController.isLaunchGame = true;
            };
            EventListener.Get(mChopLeft.gameObject).onPress += (GameObject obj) =>
            {
                GameController.isLaunchGame = true;
                GameEvent.OnAttackLeft(PlayerController.players[0]);
            };
            EventListener.Get(mChopRight.gameObject).onPress += (GameObject obj) =>
            {
                GameController.isLaunchGame = true;
                GameEvent.OnAttackRight(PlayerController.players[0]);
            };

            InputPort.onChangeScoreEvent += (int value) =>
            {
                playerText.Display(value / 10, 0.1f);
                scoreText.Display(value % 10, 0.1f);
            };
        }
コード例 #17
0
        void OnDeath(PlayerInfo player)
        {
            if (player.index == 0)
            {
                int award = 0;
                audio.clip = dieMarch;
                audio.Play();
                mScroll.gameObject.SetActive(false);
                mScrollMain.gameObject.SetActive(false);
                gameText.gameObject.SetActive(false);
                allScore    = allScore + gameScore;
                gameCounter = gameCounter + 1;
                switch (awards)
                {
                case 0: break;

                case 1:
                    award = 1;
                    //Debug.Log("铜奖");
                    break;

                case 2:
                    award = 2;
                    //Debug.Log("银奖");
                    break;

                case 3:
                    award       = 3;
                    allScore    = (int)(0.8f * allScore + gameScore);
                    gameCounter = (int)(0.8f * gameCounter + 1);
                    //Debug.Log("金奖");
                    break;

                case 4:
                    award       = 5;
                    allScore    = (int)(0.5f * allScore + gameScore);
                    gameCounter = (int)(0.5f * gameCounter + 1);
                    //Debug.Log("最高奖");
                    break;

                default: break;
                }
                if (gameScore > bestScore)
                {
                    bestScore = gameScore;
                    PlayerPrefs.SetInt("BestScore", bestScore);
                }
                if (JavaInterface.Java())
                {
                    if (award != 0 && JavaInterface.GetBonus() > (10 * award))
                    {
                        JavaInterface.AddScorePlayer(award * 10);
                        JavaInterface.CoinOut1Limit(award);
                        //开始退币检查
                        GameController.isOutCoin = true;
                        Debug.Log("退出" + award + "个币");
                    }
                    else
                    {
                        Debug.Log("奖金不足无法退出");
                    }
                }
                if (profit >= award)
                {
                    profit -= award;
                    PlayerPrefs.SetInt("Profit", profit);
                    //Debug.Log("退出"+ award + "个币");
                }
                else
                {
                    Debug.Log("奖金不足无法退出");
                }
                PlayerPrefs.SetInt("AllScore", allScore);
                PlayerPrefs.SetInt("GameCounter", gameCounter);
                PlayerPrefs.Save();
                lastScoreText.Display(gameScore, 0.05f);
                bestText.Display(bestScore);

                mMainPanel.Award(awards);
                mMainPanel.Display();

                SetGameScore(0);
                awards = 0;
                Debug.Log("利润:" + profit + " 第" + gameCounter + "局" + averageScore);
            }
        }