OSDN Git Service

ステージ名の自動命名
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / parser / ParseStage.java
index 859e038..3814cba 100644 (file)
@@ -11,25 +11,41 @@ package jp.sourceforge.mikutoga.parser;
  * パース処理の進行ステージ種別を表す。
  * ループ構造の識別に用いられる。
  */
-public class ParseStage {
+public abstract class ParseStage {
 
     private final String name;
 
     /**
      * コンストラクタ。
-     * 進行ステージ名は空文字列が指定される。
+     * 進行ステージ名は実行時クラス名(パッケージ名抜き)が指定される。
      */
-    public ParseStage(){
-        this("");
+    protected ParseStage(){
+        super();
+
+        Class<?> klass = getClass();
+        String fullName = klass.getName();
+        int idx = fullName.lastIndexOf('.');
+
+        String stripName;
+        if(idx >= 0){
+            stripName = fullName.substring(idx + 1);
+        }else{
+            stripName = fullName;
+        }
+
+        this.name = stripName;
+
         return;
     }
 
     /**
      * コンストラクタ。
      * @param name 進行ステージ名
+     * @throws NullPointerException 引数がnull
      */
-    public ParseStage(String name){
+    protected ParseStage(String name) throws NullPointerException{
         super();
+        if(name == null) throw new NullPointerException();
         this.name = name;
         return;
     }