public class RESNode {
	
	public boolean deadStatement;
	@SuppressWarnings("unchecked")
	public ArrayList ref;
	@SuppressWarnings("unchecked")
	public ArrayList mod;
	
	public SymbolProperties props;
	
	public int line;
	
	public String sourceFile;
	public RESNode() {
		sourceFile=Main.getContext().getCharStream().getLastSourceFileName();
		if(CobolParserTokenManager.lastToken!=null)
			line=CobolParserTokenManager.lastToken.beginLine;
		else
			line=Main.getContext().getCharStream().getRESBeginLine();
		if(sourceFile!=null)
			sourceFile=sourceFile.substring(Math.max(sourceFile.lastIndexOf('\\'),
				sourceFile.lastIndexOf('/'))+1);
	}
}
 public class TreeToCommentFormatter extends DepthFirstVisitor {
   protected ClassFileWriter out;
   private int curLine = 1;
   private int curColumn = 1;
   private boolean startAtNextToken = false;
   private boolean printSpecials = true;
   private boolean isOutputToTrackClassFiles=false;
   private int classFileCommentLines=0;
   private int firstCommentLineColumnNum=0;
   /**
    * The default constructor uses System.out as its output location.
    * You may specify your own Writer or OutputStream using one of the
    * other constructors.
    */
   public TreeToCommentFormatter()       { 
		   out = new ClassFileWriter(System.out);
   	}

   public TreeToCommentFormatter(OutputStream o)  { 
		out = new ClassFileWriter(new PrintStream(o));
   }
   
   public TreeToCommentFormatter(ClassFileWriter o)  { 
		out = o;
  }
   
   public TreeToCommentFormatter(boolean b)  { out=null;isOutputToTrackClassFiles=true;printSpecials(b);}

   /**
    * Flushes the OutputStream or Writer that this TreeDumper is using.
    */
   public void flushWriter()        { out.flush(); }

   /**
    * Allows you to specify whether or not to print special tokens.
    */
   public void printSpecials(boolean b)   { printSpecials = b; }

   /**
    * Starts the tree dumper on the line containing the next token
    * visited.  For example, if the next token begins on line 50 and the
    * dumper is currently on line 1 of the file, it will set its current
    * line to 50 and continue printing from there, as opposed to
    * printing 49 blank lines and then printing the token.
    */
   public void startAtNextToken()   { 
	   startAtNextToken = true;
	   classFileCommentLines=0;
	   if(isOutputToTrackClassFiles) {
			 out=ClassFile.current;
	   }
   }

   /**
    * Resets the position of the output "cursor" to the first line and
    * column.  When using a dumper on a syntax tree more than once, you
    * either need to call this method or startAtNextToken() between each
    * dump.
    */
   public void resetPosition()      { curLine = curColumn = 1; }

   @Override
   public void visit(Statement n) {
	   if(startAtNextToken)
		   super.visit(n);
   }
   
   @Override
   public void visit(DataDescriptionEntry n) {
	   if(startAtNextToken)
		   super.visit(n);
   }
/**
    * Dumps the current NodeToken to the output stream being used.
    *
    * @throws  IllegalStateException   if the token position is invalid
    *   relative to the current position, i.e. its location places it
    *   before the previous token.
    */
   public void visit(NodeToken n) {
	
     if(out==null)
		return;
	 if(RESConfig.getInstance().isRetainCobolComments()&&
			 startAtNextToken) {
    	 printCobolComments(n.beginLine);
    	 if(!RESConfig.getInstance().isPrintCobolStatementsAsComments())
    		 return;
	 }

      if ( n.beginLine == -1 || n.beginColumn == -1 ) {
         printToken(n.tokenImage);
         return;
      }

      //
      // Handle special tokens
      //
      if ( printSpecials && n.numSpecials() > 0 )
         for ( Enumeration<NodeToken> e = n.specialTokens.elements(); e.hasMoreElements(); )
            visit(e.nextElement());

      //
      // Handle startAtNextToken option
      //
      if ( startAtNextToken ) {
         curLine = n.beginLine;
         curColumn = n.beginColumn;
         startAtNextToken = false;

        
    	 if(isOutputToTrackClassFiles) {
    		 if(n.sourceFile!=null&&n.sourceFile.length()>0)
    			 out.println("//@CobolSourceFile(\""+n.sourceFile+"\","+String.valueOf(n.beginLine)+
    					 ","+String.valueOf(n.beginColumn)+") ");
    		 out.print("//");
    		 toPrintSlashes=false;
             classFileCommentLines=0;
             firstCommentLineColumnNum=n.beginColumn;
    	 }
    	 else
    		 if ( n.beginColumn < curColumn )
    			 out.println();
      }

      //
      // Check for invalid token position relative to current position.
      //
      if ( n.beginLine < curLine ) {
    	  if(isOutputToTrackClassFiles) {
              classFileCommentLines++;
     	 }
     	 else { 
     		 //out.print("#"+ String.valueOf(n.beginLine)+ " "+String.valueOf(curLine));
     		 //out.println(" \"<source-file-name-here>\"");
     	 }
         //throw new IllegalStateException("at token \"" + n.tokenImage +
           // "\", n.beginLine = " + Integer.toString(n.beginLine) +
           // ", curLine = " + Integer.toString(curLine));
      }
      else if ( n.beginLine == curLine && n.beginColumn < curColumn ) {
         //throw new IllegalStateException("at token \"" + n.tokenImage +
            //"\", n.beginColumn = " +
           // Integer.toString(n.beginColumn) + ", curColumn = " +
            //Integer.toString(curColumn));
      }

      //
      // Move output "cursor" to proper location, then print the token
      //
      boolean first=true,second=false,third=false;
      if ( curLine < n.beginLine ) {
    	 if(isOutputToTrackClassFiles)
             curColumn = firstCommentLineColumnNum;
    	 else
    		 curColumn = 1;
         for ( ; curLine < n.beginLine; ++curLine ) {
        	 if(isOutputToTrackClassFiles) {
        		 if(first) {
            		 ClassFile.println("");
            		 toPrintSlashes=true;
        			 first=false;
        			 second=true;
        		 } else if(second) 
        		 {
        			 ClassFile.print("//");
        			 toPrintSlashes=false;
        			 second=false;
        			 third=true;
        		 } else if(third){
        			 ClassFile.printPlain("...");
        			 toPrintSlashes=false;
        			 third=false;
        		 } else
        			 toPrintSlashes=false;
                 classFileCommentLines++;
        	 }
        	 else out.println("");
         }
      }
	   if(isOutputToTrackClassFiles) {
		   if(toPrintSlashes){
			 ClassFile.print("//");
			 toPrintSlashes=false;
		   }
	   }

      for ( ; curColumn < n.beginColumn; ++curColumn ){
          out.printPlain(' ');
      }

      printToken(n.tokenImage);
   }
   boolean toPrintSlashes=false,entering=false;
   private void printToken(String s) {

	   entering=true;
	   boolean prevCRLF=false;
      for ( int i = 0; i < s.length(); ++i ) { 
         if ( s.charAt(i) == '\n' ) {
            ++curLine;
            curColumn = 1;
         }
         else
            curColumn++;
         
         if(prevCRLF)
        	 if(RunTimeUtil.getInstance().isWhiteSpaces(s.charAt(i)))
        		 continue;
        	 else 
        	 if( !entering ){ ClassFile.print("//"); prevCRLF=false;toPrintSlashes=false;}
         
         if(s.charAt(i)=='\r'||s.charAt(i)=='\n'){
        	 prevCRLF=true;
        	 toPrintSlashes=true;
         } 
         out.printPlain(s.charAt(i));
         entering=false;
      }

      out.flush();
   }
   
   public void printCobolComments(int currLineNo) {
       if(RESConfig.getInstance().isRetainCobolComments()) {
      	 if(CobolParserTokenManager.commentLines!=null) {
      		 int i=0;
	        	 while(CobolParserTokenManager.commentLines.size()>i) {
	        		 Token cmt_t=(Token)CobolParserTokenManager.commentLines.get(i);
	        		 if(cmt_t==null||cmt_t.image==null) continue;
	        		 if(cmt_t.beginLine<=currLineNo) {
        				 out.println("//"+cmt_t.image.replace("*>", "*"));
	            		 CobolParserTokenManager.commentLines.remove(i);
	        		 } 
	        		 else 
	        			 break;
	        	 }
      	 }
       }
	   
   }
} public class RESConfig implements Cloneable {

	public final String versionString = " alpha1.9(08/05/2010) ";
	private String programPackage;
	private String dataPackage ;
	private String outputDir=null;
	private String configFile="."+File.separatorChar+"Config.properties";
	private boolean longDataPackageName ;
	private boolean doListDir ;
	private boolean printCobolStatementsAsComments;
	private boolean retainCobolComments;
	private int optimizeAlgorithm=0;
	private boolean isEbcdicMachine=false;
	private boolean isFixedFormat=true;
	private boolean isBigEndian=true;
	private byte procedureFormat;//0-Use CobolMethod/Paragraph/Section classes;1-Switch-Case-Loop;2-Java Native Recursive
	private byte dataNameFormat;//0-first char upper for classes and lower for objects and fields, methods
	private boolean toMigrateVSAMISAM=false;
	private boolean toGenVSAMISAMDb=false;
	private boolean isOverwriteJavaFiles=false;
	private boolean isRenameJavaFiles=false;
	private boolean isInError=false;
	private boolean allSymbols=false;
	private boolean generateBeanInfo=false;
	private boolean exception_PrintStackTrace_On=false;
	private int inlineStatement=0;
	private int tabLength = 4;
	private int sqlDatabaseType = 0;
	private String tabSpaces = "    ";

	private static Properties config=null;
	
	public void loadDefaults() {
		try {
			config=new Properties();
			FileInputStream fis = new FileInputStream(new File(configFile));
			config.load(fis);
			programPackage =(String) config.getProperty("programPackage");
			dataPackage =(String) config.getProperty("dataPackage");
			outputDir = (String) config.getProperty("outputDir","");
			String s = (String)config.getProperty("printCobolStatementsAsComments","false");
			printCobolStatementsAsComments=false;
			s = (String)config.getProperty("retainCobolComments","false");
			retainCobolComments=false;
			s=config.getProperty("isEbcdicMachine","false");
			isEbcdicMachine=false;
			s=config.getProperty("isFixedFormat","true");
			isFixedFormat=true;
			s=config.getProperty("isBigEndian","true");
			isBigEndian=true;
			procedureFormat=0;
			s = (String)config.getProperty("dataNameFormat","0");
			dataNameFormat=new Byte(s.trim()).byteValue();
			s = (String)config.getProperty("isOverwriteJavaFiles","false");
			isOverwriteJavaFiles=new Boolean(s.trim()).booleanValue();
			s = config.getProperty("optimizeAlgorithm","0");
			optimizeAlgorithm=Integer.parseInt(s);
			s = config.getProperty("generateBeanInfo","false");
			generateBeanInfo=new Boolean(s.trim()).booleanValue();
			s = config.getProperty("exceptionPrintStackTraceOn","false");
			setExceptionPrintStackTraceOn(new Boolean(s.trim()).booleanValue());
			s = config.getProperty("tabLength","4");
			tabLength=Integer.parseInt(s);
			s = config.getProperty("sqlDatabaseType","1");
			sqlDatabaseType=Integer.parseInt(s);
			programPackage=applyNameValidation(programPackage);
			dataPackage=applyNameValidation(dataPackage);
		} catch(Exception e) {
			programPackage ="cobolprogramclasses";
			dataPackage ="coboldataclasses";
			outputDir="";
		}
		tabSpaces="";
		for(int i=0;i<tabLength;++i)
			tabSpaces+=' ';
	}
	
	private String applyNameValidation(String pkg) {
		StringBuffer pkgBuff=new StringBuffer(pkg);
		int i=0,j=0;
		while((j=pkgBuff.indexOf(".",i))>i) {
			pkgBuff.replace(i, j, NameUtil.convertCobolNameToJava(
					pkgBuff.substring(i, j), false).toLowerCase());
			i=j;
		}
		return pkgBuff.toString();
	}
	
	private static RESConfig resConfig=null;
	
	private RESConfig() {
	}
	
	public static RESConfig getInstance()  {
		if(resConfig==null){
			resConfig=new RESConfig();
			resConfig.loadDefaults();
		} 		
		return resConfig;
	}
	
	public void setDoListDir(boolean doListDir) {
		this.doListDir = doListDir;
	}

	public boolean isDoListDir() {
		return doListDir;
	}

	public boolean isFixedFormat() {
		return isFixedFormat;
	}

	public void setFixedFormat(boolean isFixedFormat) {
		this.isFixedFormat = isFixedFormat;
	}

	public boolean isEbcdicMachine() {
		return isEbcdicMachine;
	}
	public void setEbcdicMachine(boolean isEbcdicMachine) {
		this.isEbcdicMachine = isEbcdicMachine;
	}
	public String getProgramPackage() {
		return programPackage;
	}
	public void setProgramPackage(String programPackage) {
		this.programPackage = programPackage;
	}
	public String getDataPackage() {
		return dataPackage;
	}
	public void setDataPackage(String dataPackage) {
		this.dataPackage = dataPackage;
	}
	public boolean isPrintCobolStatementsAsComments() {
		return printCobolStatementsAsComments;
	}
	public void setPrintCobolStatementsAsComments(
			boolean printCobolStatementsAsComments) {
		this.printCobolStatementsAsComments = printCobolStatementsAsComments;
	}
	public boolean isRetainCobolComments() {
		return retainCobolComments;
	}
	public void setRetainCobolComments(boolean retainCobolComments) {
		this.retainCobolComments = retainCobolComments;
	}
	public byte getDataNameFormat() {
		return dataNameFormat;
	}
	public void setDataNameFormat(byte dataNameFormat) {
		this.dataNameFormat = dataNameFormat;
	}
	
	public void setBigEndian(boolean isBigEndian) {
		this.isBigEndian = isBigEndian;
	}

	public boolean isBigEndian() {
		return isBigEndian;
	}

	public void setProcedureFormat(byte procedureFormat) {
		this.procedureFormat = procedureFormat;
	}

	public byte getProcedureFormat() {
		return this.procedureFormat;
	}

	public void setInError(boolean isInError) {
		this.isInError = isInError;
	}

	public boolean isInError() {
		return isInError;
	}
	
	public boolean isOverwriteJavaFiles() {
		return isOverwriteJavaFiles;
	}

	public void setOverwriteJavaFiles(boolean isOverwriteJavaFiles) {
		this.isOverwriteJavaFiles = isOverwriteJavaFiles;
	}

	public boolean isRenameJavaFiles() {
		return isRenameJavaFiles;
	}

	public void setRenameJavaFiles(boolean isRenameJavaFiles) {
		this.isRenameJavaFiles = isRenameJavaFiles;
	}

	public void setOptimizeAlgorithm(int optimizeAlgorithm) {
		this.optimizeAlgorithm = optimizeAlgorithm;
	}

	public int getOptimizeAlgorithm() {
		return optimizeAlgorithm;
	}

	public void setLongDataPackageName(boolean longDataPackageName) {
		this.longDataPackageName = longDataPackageName;
	}

	public boolean isLongDataPackageName() {
		return longDataPackageName;
	}

	public void setToMigrateVSAMISAM(boolean toMigrateVSAMISAM) {
		this.toMigrateVSAMISAM = toMigrateVSAMISAM;
	}

	public boolean isToMigrateVSAMISAM() {
		return toMigrateVSAMISAM;
	}

	public void setToGenVSAMISAMDb(boolean toGenVSAMISAMDb) {
		this.toGenVSAMISAMDb = toGenVSAMISAMDb;
	}

	public boolean isToGenVSAMISAMDb() {
		return toGenVSAMISAMDb;
	}

	public void setAllSymbols(boolean allSymbols) {
		this.allSymbols = allSymbols;
	}

	public boolean isAllSymbols() {
		return allSymbols;
	}

	public void setInlineStatement(int inlineStatement) {
		this.inlineStatement = inlineStatement;
	}

	public int getInlineStatement() {
		return inlineStatement;
	}

	public void setTabLength(int tabLength) {
		this.tabLength = tabLength;
	}

	public int getTabLength() {
		return tabLength;
	}
	public String getTabSpaces() {
		return tabSpaces;
	}

	public void setTabSpaces(String tabSpaces) {
		this.tabSpaces = tabSpaces;
	}

	public void setGenerateBeanInfo(boolean generateBeanInfo) {
		this.generateBeanInfo = generateBeanInfo;
	}

	public boolean isGenerateBeanInfo() {
		return generateBeanInfo;
	}

	public void setOutputDir(String outputDir) {
		this.outputDir = outputDir;
	}

	public String getOutputDir() {
		return outputDir;
	}

	public boolean isUsePointers() {
		return false;
	}

	public void setExceptionPrintStackTraceOn(boolean exception_PrintStackTrace_On) {
		this.exception_PrintStackTrace_On = exception_PrintStackTrace_On;
	}

	public boolean isExceptionPrintStackTraceOn() {
		return exception_PrintStackTrace_On;
	}

	public void setConfigFile(String configFile) {
		this.configFile = configFile;
		loadDefaults();
	}

	public String getConfigFile() {
		return configFile;
	}

	public void setSqlDatabaseType(int sqlDatabaseType) {
		this.sqlDatabaseType = sqlDatabaseType;
	}

	public int getSqlDatabaseType() {
		return sqlDatabaseType;
	}

}
 public class RESContext {

	//Run related
	private String sourceFileName;
	private CobolParser parser=null;
	private RESCharStream charStream=null;
        private CobolFillTable cobolFillTable = null;
        private CobolRecode cobolRecode = null;
        private Cobol2Java cobol2Java = null;
	private Reader srcIn=null;
	private boolean sqlTranslated=false;
	private StringBuffer optionsVerbose=new StringBuffer();
	private boolean processVerbose=false;
	private boolean processPreprocessOnly=false;
	private boolean processParseOnly=false;
	private boolean traceOn=false;
	private int traceLevel=0;
	
	private String currencySign=null;
	private boolean decimalPointIsComma = false;
	
	public void setParser(CobolParser parser) {
		this.parser = parser;
	}
	public CobolParser getParser() {
		return parser;
	}
	public void setCharStream(RESCharStream charStream) {
		this.charStream = charStream;
	}
	public RESCharStream getCharStream() {
		return charStream;
	}
	public void setSourceFileName(String sourceFileName) {
		this.sourceFileName = sourceFileName;
	}
	public String getSourceFileName() {
		return sourceFileName;
	}
	public Reader getSourceFile() {
		return srcIn;
	}
	public void setSourceFile(Reader srcIn) {
		this.srcIn=srcIn;
	}
	public void setSqlTranslated(boolean sqlTranslated) {
		this.sqlTranslated = sqlTranslated;
	}
	public boolean isSqlTranslated() {
		return sqlTranslated;
	}
	public void setOptionsVerbose(StringBuffer optionsVerbose) {
		this.optionsVerbose = optionsVerbose;
	}
	public StringBuffer getOptionsVerbose() {
		return optionsVerbose;
	}
	public void setProcessVerbose(boolean processVerbose) {
		this.processVerbose = processVerbose;
	}
	public boolean isProcessVerbose() {
		return processVerbose;
	}
	public void setProcessPreprocessOnly(boolean processPreprocessOnly) {
		this.processPreprocessOnly = processPreprocessOnly;
	}
	public boolean isProcessPreprocessOnly() {
		return processPreprocessOnly;
	}
	public void setProcessParseOnly(boolean processParseOnly) {
		this.processParseOnly = processParseOnly;
	}
	public boolean isProcessParseOnly() {
		return processParseOnly;
	}
	public void setTraceOn(boolean traceOn) {
		this.traceOn = traceOn;
	}
	public boolean isTraceOn() {
		return traceOn;
	}
	public void setTraceLevel(int traceLevel) {
		this.traceLevel = traceLevel;
	}
	public int getTraceLevel() {
		return traceLevel;
	}
	public void setDecimalPointIsComma(boolean decimalPointIsComma) {
		this.decimalPointIsComma = decimalPointIsComma;
	}
	public boolean isDecimalPointIsComma() {
		return decimalPointIsComma;
	}
	public void setCurrencySign(String currencySign) {
		this.currencySign = currencySign;
	}
	public String getCurrencySign() {
		return currencySign;
	}

    public Cobol2Java getCobol2Java() {
        return cobol2Java;
    }

    public void setCobol2Java(Cobol2Java cobol2Java) {
        this.cobol2Java = cobol2Java;
    }

    public CobolFillTable getCobolFillTable() {
        return cobolFillTable;
    }

    public void setCobolFillTable(CobolFillTable cobolFillTable) {
        this.cobolFillTable = cobolFillTable;
    }

    public CobolRecode getCobolRecode() {
        return cobolRecode;
    }

    public void setCobolRecode(CobolRecode cobolRecode) {
        this.cobolRecode = cobolRecode;
    }
}
 public class Constants {

	//Java  types
	public static final int BYTE=0;
	public static final int CHAR=1;
	public static final int SHORT=2;
	public static final int INTEGER=3;
	public static final int LONG=4;
	public static final int FLOAT=5;
	public static final int DOUBLE=6;
	public static final int BIGDECIMAL=7;
	public static final int STRING=8;
	public static final int GROUP=9;
	public static final int OBJECT=10;
	public static final int MAX_TYPES=11;
	public static final int UNKNOWN=MAX_TYPES;
	
	//Basic Cobol Usage Types
	public static final int BINARY=0;
	public static final int PACKED_DECIMAL=1;
	public static final int DISPLAY=2;
	public static final int COMPUTATIONAL1=3;
	public static final int COMPUTATIONAL2=4;
	public static final int FLOATING_POINT=5;
	public static final int COMPUTATIONAL5=6;
	public static final int DISPLAY_1=7;
	public static final int INDEX=8;
	public static final int NATIONAL_U=9;
	public static final int POINTER=10;
	public static final int PROCEDURE_POINTER=11;
	public static final int FUNCTION_POINTER=12;
	
	//Basic Cobol Data Categories
	public static final int ALPHABETIC=0;
	public static final int NUMERIC=1;
	public static final int NUMERIC_EDITED=2;
	public static final int ALPHANUMERIC=3;
	public static final int ALPHANUMERIC_EDITED=3;
	public static final int EXTERNAL_FLOATING_POINT=4;
	public static final int NATIONAL=5;
	public static final int NATIONAL_EDITED=6;
	
	//File Organization Codes
	public static final int SEQUENTIAL = 0;
	public static final int INDEXED = 1;
	public static final int RELATIVE = 2;
	public static final int LINE_SEQUENTIAL = 3;
	
	//Access Mode Codes
	public static final int SEQUENTIAL_ACCESS = 0;
	public static final int RANDOM_ACCESS = 1;
	public static final int DYNAMIC_ACCESS = 2;
	
}
 public class RunTimeUtil {

    private static RunTimeUtil runTimeUtil = null;

    private RunTimeUtil() {
    }

    public static RunTimeUtil getInstance() {
        if (runTimeUtil == null) {
            runTimeUtil = new RunTimeUtil();
        }
        return runTimeUtil;
    }

    public String stripQuotes(String in) {
        return stripQuotes(in, true);
    }

    public String stripQuotes(String in, boolean trim) {
        if ((in = in.trim()).length() > 0 && (in.charAt(0) == '\'' || in.charAt(0) == '\"')) {
            if (in.lastIndexOf(in.charAt(0)) > 0) {
                in = in.substring(1, in.lastIndexOf(in.charAt(0)));
            }
            if (trim) {
                return in.trim();
            }
        }
        return in;
    }

    public boolean isWhiteSpaces(char c) {
        return (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f');
    }

    public String stripTrailingBlanks(String in) {
        if (in == null) {
            return "";
        }
        String s;
        return (in.substring(0, (in.indexOf(s = in.trim()) + s.length())));
    }

    public void reportError(String s, boolean exit) {
        System.out.println(s);
        if (exit) {
            System.out.println("Done.");
            System.exit(1);
        }
    }
    
    private static final java.util.regex.Pattern ZERO_PATTERN = java.util.regex.Pattern.compile("[-+]?[0]*(\\.[0]+)?");

    //Input is a valid number literal
    public String stripLeadingZeros(String lit) {

        lit = lit.replaceAll("[, ]", "");

        if (ZERO_PATTERN.matcher(lit).matches()) {
            return "0";
        }

        int i = 0;
        int sign = 0;
        if (lit.charAt(0) == '+') {
            i = 1;
        } else if (lit.charAt(0) == '-') {
            i = 1;
            sign = -1;
        }

        do {
            if (lit.charAt(i) != '0') {
                break;
            }
            ++i;
        } while (i < lit.length());

        lit = lit.substring(i);

        if (lit.charAt(0) == '.') {
            lit = '0' + lit;
        }

        if (sign < 0) {
            lit = '-' + lit;
        }

        return lit;

    }
}
 public class CobolSymbol {

    private String name;
    private String pic;
    private int type;
    private byte usage;
    private byte dataCategory;
    private short maxIntLength;
    private short maxFractionLength;
    private short maxScalingLength;
    private int maxStringLength;
    private boolean isBlankWhenZero;
    private boolean isCurrency;
    private boolean isSigned;
    private boolean isSignLeading;
    private boolean isSignSeparate;
    private boolean isJustifiedRight;
    private boolean isExternal;
    private boolean isGlobal;

    public byte getDataCategory() {
        return dataCategory;
    }

    public void setDataCategory(byte dataCategory) {
        this.dataCategory = dataCategory;
    }

    public boolean isIsBlankWhenZero() {
        return isBlankWhenZero;
    }

    public void setIsBlankWhenZero(boolean isBlankWhenZero) {
        this.isBlankWhenZero = isBlankWhenZero;
    }

    public boolean isIsCurrency() {
        return isCurrency;
    }

    public void setIsCurrency(boolean isCurrency) {
        this.isCurrency = isCurrency;
    }

    public boolean isIsExternal() {
        return isExternal;
    }

    public void setIsExternal(boolean isExternal) {
        this.isExternal = isExternal;
    }

    public boolean isIsGlobal() {
        return isGlobal;
    }

    public void setIsGlobal(boolean isGlobal) {
        this.isGlobal = isGlobal;
    }

    public boolean isIsJustifiedRight() {
        return isJustifiedRight;
    }

    public void setIsJustifiedRight(boolean isJustifiedRight) {
        this.isJustifiedRight = isJustifiedRight;
    }

    public boolean isIsSignLeading() {
        return isSignLeading;
    }

    public void setIsSignLeading(boolean isSignLeading) {
        this.isSignLeading = isSignLeading;
    }

    public boolean isIsSignSeparate() {
        return isSignSeparate;
    }

    public void setIsSignSeparate(boolean isSignSeparate) {
        this.isSignSeparate = isSignSeparate;
    }

    public boolean isIsSigned() {
        return isSigned;
    }

    public void setIsSigned(boolean isSigned) {
        this.isSigned = isSigned;
    }

    public short getMaxFractionLength() {
        return maxFractionLength;
    }

    public void setMaxFractionLength(short maxFractionLength) {
        this.maxFractionLength = maxFractionLength;
    }

    public short getMaxIntLength() {
        return maxIntLength;
    }

    public void setMaxIntLength(short maxIntLength) {
        this.maxIntLength = maxIntLength;
    }

    public short getMaxScalingLength() {
        return maxScalingLength;
    }

    public void setMaxScalingLength(short maxScalingLength) {
        this.maxScalingLength = maxScalingLength;
    }

    public int getMaxStringLength() {
        return maxStringLength;
    }

    public void setMaxStringLength(int maxStringLength) {
        this.maxStringLength = maxStringLength;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public byte getType() {
        return (byte)type;
    }

    public void setType(int type) {
        setIdentifierType(type);
        this.type = type;
    }

    public byte getUsage() {
        return usage;
    }

    public void setUsage(byte usage) {
        this.usage = usage;
    }

    public CobolSymbol() {
    }

    public CobolSymbol(int t) {
        type = (byte) t;
    }
}
 public class SymbolConstants {

	//Type keys
	public static final short PROGRAM = 0;
	public static final short DATA = 1;
	public static final short PARAGRAPH = 2;
	public static final short SECTION = 3;
	public static final short FILE = 4;
	public static final short DUMMY = 5;
	

	private static final String[] TYPES = {"byte","char","short","int","long","float","double",
		"BigDecimal","String","byte[]","Object","Object"};
	private static final String[] TYPES_O = {"Byte","Char","Short","Integer","Long","Float","Double",
		"BigDecimal","String","byte[]","Object","Object"};
	private static final String[] SQL_TYPES = {"Byte","Char","Short","Int","Long","Float","Double",
		"BigDecimal","String","Bytes","Object","Object"};
	private static final String[] SQL_TYPES_LONG = {"java.sql.Types.INTEGER",
		"java.sql.Types.INTEGER","java.sql.Types.INTEGER",
		"java.sql.Types.INTEGER","java.sql.Types.LONGVARBINARY",
		"java.sql.Types.DECIMAL","java.sql.Types.DECIMAL","java.sql.Types.DECIMAL",
		"java.sql.Types.VARCHAR","java.sql.Types.JAVA_OBJECT",
		"java.sql.Types.JAVA_OBJECT","java.sql.Types.JAVA_OBJECT"};
	
	private static final String[] FUNCTION_NAMES = new String[]{
			"aCos","annuity","aSin","aTan","_char",
			"cos","currentDate","dateOfInteger","dateToYYYYMMDD","dateVal",	
			"dayOfInteger","dayToYYYYDDD","displayOf","factorial","integer",
			"integerOfDate","integerOfDay","integerPart","length","log",
			"log10","lowerCase","max","mean","median",
			"midrange","min","mod",	"nationalOf","numVal",
			"numValC","ord","ordMax","ordMin","presentValue",
			"random","range","rem","reverse","sin",
			"sqrt","standardDeviation","sum","tan","undate",
			"upperCase","variance","whenCompiled","yearToYYYY","yearWindow",
			"MAX_VALUE","MIN_VALUE"};

	private static final int[][] FUNCTION_ARG_TYPES = new int[][]{
		{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE},{Constants.CHAR,Constants.INTEGER},
		{Constants.DOUBLE,Constants.DOUBLE},{Constants.STRING,Constants.STRING},{Constants.LONG,Constants.LONG},{Constants.STRING,Constants.INTEGER},{Constants.STRING,Constants.OBJECT},	
		{Constants.LONG,Constants.LONG},{Constants.STRING,Constants.INTEGER},{Constants.STRING,Constants.OBJECT},{Constants.INTEGER,Constants.INTEGER},{Constants.INTEGER,Constants.DOUBLE,Constants.BIGDECIMAL},
		{Constants.LONG,Constants.LONG},{Constants.INTEGER,Constants.INTEGER},{Constants.INTEGER,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.INTEGER,Constants.CHAR,Constants.STRING},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},
		{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.STRING,Constants.CHAR,Constants.STRING},{-Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL,Constants.STRING},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},
		{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{-Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL,Constants.STRING},{Constants.LONG,Constants.LONG},{Constants.STRING,Constants.OBJECT},{Constants.DOUBLE,Constants.STRING},
		{Constants.DOUBLE,Constants.STRING},{Constants.INTEGER,Constants.CHAR,Constants.INTEGER,Constants.STRING},{Constants.INTEGER,Constants.CHAR,Constants.INTEGER,Constants.STRING},{Constants.INTEGER,Constants.CHAR,Constants.INTEGER,Constants.STRING},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},
		{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.STRING,Constants.STRING},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},
		{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.DOUBLE,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.DOUBLE,Constants.DOUBLE,Constants.BIGDECIMAL},{Constants.INTEGER,Constants.OBJECT},
		{Constants.STRING,Constants.CHAR,Constants.STRING},{Constants.DOUBLE,Constants.DOUBLE},{Constants.STRING,Constants.STRING},{Constants.DOUBLE,Constants.LONG,Constants.DOUBLE},{Constants.DOUBLE,Constants.DOUBLE},
		{Constants.CHAR},{Constants.CHAR}};
	
	
	public static String get(int t) {
		if(t<0||t>=Constants.MAX_TYPES) t=Constants.INTEGER;
		return TYPES[t];
	}
	
	public static String get_O(int t) {
		if(t<0||t>=Constants.MAX_TYPES) t=Constants.INTEGER;
		return TYPES_O[t];
	}
	
	
	public static String getSQL(int t) {
		if(t<0||t>=SQL_TYPES.length)return "Int";
		return SQL_TYPES[t];
	}
	
	public static String getSQL2(int t) {
		if(t<0||t>=SQL_TYPES_LONG.length) t=0;
		return SQL_TYPES_LONG[t];
	}
	
	
	public static String getFunction(int f) {
		if(f<0||f>=FUNCTION_NAMES.length) return "integer";
		return FUNCTION_NAMES[f];
	}

	public static int[] getFunctionArgTypes(int f) {
		if(f<0||f>=FUNCTION_NAMES.length) return FUNCTION_ARG_TYPES[Constants.INTEGER];
		return FUNCTION_ARG_TYPES[f];
	}
	
}
 public class SymbolProperties implements Cloneable {

    public String getDataName() {
        return dataName;
    }

    public void setDataName(String dataName) {
        this.dataName = dataName;
    }

    public short getLevelNumber() {
        return levelNumber;
    }

    public void setLevelNumber(short levelNumber) {
        this.levelNumber = levelNumber;
    }

    public String getPictureString() {
        return pictureString;
    }

    public void setPictureString(String pictureString) {
        this.pictureString = pictureString;
    }

    public short getDataUsage() {
        return dataUsage;
    }

    public void setDataUsage(short dataUsage) {
        getJavaType().setUsage((byte)dataUsage);
        this.dataUsage = dataUsage;
    }

    public CobolSymbol getJavaType() {
        if(javaType==null) javaType = new CobolSymbol();
        return javaType;
    }

    public void setJavaType(CobolSymbol javaType) {
        if (javaType != null) {
            javaType.usage = (byte) this.dataUsage;
        }
        this.javaType = javaType;
        this.identifierType = javaType.type;
    }

    public short getType() {
        return type;
    }

    public void setType(short type) {
        this.type = type;
    }

    public SymbolProperties getParent() {
        return parent;
    }

    public void setParent(SymbolProperties parent) {
        this.parent = parent;
    }

    public ArrayList<SymbolProperties> getChildren() {
        return children;
    }

    public void setChildren(ArrayList<SymbolProperties> children) {
        this.children = children;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public SymbolProperties getMajorIndex() {
        return majorIndex;
    }

    public void setMajorIndex(SymbolProperties fallThruPara) {
        this.majorIndex = fallThruPara;
    }

    public String getValue1() {
        return value1;
    }

    public void setValue1(String value1) {
        this.value1 = value1;
    }

    public String getValue2() {
        return value2;
    }

    public void setValue2(String value2) {
        this.value2 = value2;
    }

    public boolean getIsFiller() {
        return isFiller;
    }

    public void setIsFiller(boolean isFiller) {
        this.isFiller = isFiller;
    }

    public ArrayList<String> getGroupDictionary() {
        return groupDictionary;
    }

    public void setGroupDictionary(ArrayList<String> groupDictionary) {
        this.groupDictionary = groupDictionary;
    }

    public ArrayList<SymbolProperties> getParagraphList() {
        return paragraphList;
    }

    public void setParagraphList(ArrayList<SymbolProperties> paragraphList) {
        this.paragraphList = paragraphList;
    }

    public int getParagraphMark() {
        return paragraphMark;
    }

    public void setParagraphMark(int paragraphMark) {
        this.paragraphMark = paragraphMark;
    }

    public boolean getIsFormat() {
        return isFormat;
    }

    public void setIsFormat(boolean isFormat) {
        this.isFormat = isFormat;
    }

    public boolean getRef() {
        return ref;
    }

    public void setRef(boolean ref) {
        this.ref = ref;
    }

    public boolean getMod() {
        return mod;
    }

    public void setMod(boolean mod) {
        this.mod = mod;
    }

    public boolean getIsSuppressed() {
        return isSuppressed;
    }

    public void setIsSuppressed(boolean isSuppressed) {
        this.isSuppressed = isSuppressed;
    }

    public String getJavaName1() {
        return javaName1;
    }

    public void setJavaName1(String javaName1) {
        this.javaName1 = javaName1;
    }

    public String getJavaName2() {
        return javaName2;
    }

    public void setJavaName2(String javaName2) {
        this.javaName2 = javaName2;
    }

    public boolean getImportLib() {
        return importLib;
    }

    public void setImportLib(boolean importLib) {
        this.importLib = importLib;
    }

    public boolean getImportBigDecimal() {
        return importBigDecimal;
    }

    public void setImportBigDecimal(boolean importBigDecimal) {
        this.importBigDecimal = importBigDecimal;
    }

    public boolean isUsedNativeJavaTypes() {
        return usedNativeJavaTypes;
    }

    public void setUsedNativeJavaTypes(boolean usedNativeJavaTypes) {
        this.usedNativeJavaTypes = usedNativeJavaTypes;
    }

    public boolean isNumericTested() {
        return isNumericTested;
    }

    public void setNumericTested(boolean isNumericTested) {
        this.isNumericTested = isNumericTested;
    }

    public boolean isAlphabeticTested() {
        return isAlphabeticTested;
    }

    public void setAlphabeticTested(boolean isAlphabeticTested) {
        this.isAlphabeticTested = isAlphabeticTested;
    }

    public boolean isAlphabeticLowerTested() {
        return isAlphabeticLowerTested;
    }

    public void setAlphabeticLowerTested(boolean isAlphabeticLowerTested) {
        this.isAlphabeticLowerTested = isAlphabeticLowerTested;
    }

    public boolean isAlphabeticUpperTested() {
        return isAlphabeticUpperTested;
    }

    public void setAlphabeticUpperTested(boolean isAlphabeticUpperTested) {
        this.isAlphabeticUpperTested = isAlphabeticUpperTested;
    }

    public void setFiller(boolean isFiller) {
        this.isFiller = isFiller;
    }

    public void setFormat(boolean isFormat) {
        this.isFormat = isFormat;
    }

    public void setSuppressed(boolean isSuppressed) {
        this.isSuppressed = isSuppressed;
    }

    public int getMinOccurs() {
        return minOccurs;
    }

    public void setMinOccurs(int minOccurs) {
        this.minOccurs = minOccurs;
    }

    public String getMaxOccurs() {
        if (dependingOnOccurs != null) {
            return NameUtil.getJavaName(dependingOnOccurs, false);
        }
        return String.valueOf(maxOccurs);
    }

    public int getMaxOccursInt() {
        return maxOccurs;
    }

    public void setMaxOccurs(int maxOccurs) {
        this.maxOccurs = maxOccurs;
    }

    public ArrayList<SymbolProperties> getFileStatus() {
        return fileStatus;
    }

    public void setFileStatus(ArrayList<SymbolProperties> fs) {
        this.fileStatus = fs;
    }

    public ArrayList<String> getIndexesWorkSpace() {
        return indexesWorkSpace;
    }

    public void setIndexesWorkSpace(ArrayList<String> indexesWorkSpace) {
        this.indexesWorkSpace = indexesWorkSpace;
    }

    public boolean isOccurs() {
        return isOccurs;
    }

    public void setOccurs(boolean isOccurs) {
        this.isOccurs = isOccurs;
    }

    public boolean isVaryingOccurs() {
        return isVaryingOccurs;
    }

    public void setVaryingOccurs(boolean isVaryingOccurs) {
        this.isVaryingOccurs = isVaryingOccurs;
    }

    public ArrayList<SymbolProperties> getIndexedByOccurs() {
        return indexedByOccurs;
    }

    public void setIndexedByOccurs(ArrayList<SymbolProperties> indexedByOccurs) {
        this.indexedByOccurs = indexedByOccurs;
    }

    public int getNoOccursSubscripts() {
        return noOccursSubscripts;
    }

    public void setNoOccursSubscripts(int noOccursSubscripts) {
        this.noOccursSubscripts = noOccursSubscripts;
    }

    public void setMaxMaxLen(int maxMaxLen) {
        this.maxMaxLen = maxMaxLen;
    }

    public int getMaxMaxLen() {
        return maxMaxLen;
    }

    public void setUnAdjustedOffset(int unAdjustedOffset) {
        this.unAdjustedOffset = unAdjustedOffset;
    }

    public int getUnAdjustedOffset() {
        return unAdjustedOffset;
    }

    public boolean isAParentInOccurs() {
        return isAParentInOccurs;
    }

    public void setAParentInOccurs(boolean isAParentInOccurs) {
        this.isAParentInOccurs = isAParentInOccurs;
    }

    public void setOccursParents(ArrayList<SymbolProperties> occursParents) {
        OccursParents = occursParents;
    }

    public SymbolProperties getRedefines() {
        return redefines;
    }

    public void setRedefines(SymbolProperties redefines) {
        this.redefines = redefines;
    }

    public ArrayList<SymbolProperties> getOccursParents() {
        return OccursParents;
    }

    public void setRedefinedBy(ArrayList<SymbolProperties> redefinedBy) {
        this.redefinedBy = redefinedBy;
    }

    public ArrayList<SymbolProperties> getRedefinedBy() {
        return redefinedBy;
    }

    public ArrayList<CoupleValue> getValues() {
        return values;
    }

    public void setValues(ArrayList<CoupleValue> values) {
        this.values = values;
    }

    public boolean isSigned() {
        return isSigned;
    }

    public void setSigned(boolean isSigned) {
        this.isSigned = isSigned;
    }

    public boolean isBlankWhenZero() {
        return isBlankWhenZero;
    }

    public void setBlankWhenZero(boolean isBlankWhenZero) {
        this.isBlankWhenZero = isBlankWhenZero;
    }

    public boolean isCurrency() {
        return isCurrency;
    }

    public void setCurrency(boolean isCurrency) {
        this.isCurrency = isCurrency;
    }

    public boolean isSignLeading() {
        return isSignLeading;
    }

    public void setSignLeading(boolean isSignLeading) {
        this.isSignLeading = isSignLeading;
    }

    public boolean isSignSeparate() {
        return isSignSeparate;
    }

    public void setSignSeparate(boolean isSignSeparate) {
        this.isSignSeparate = isSignSeparate;
    }

    public boolean isJustifiedRight() {
        return isJustifiedRight;
    }

    public void setJustifiedRight(boolean isJustifiedRight) {
        this.isJustifiedRight = isJustifiedRight;
    }

    public boolean isExternal() {
        return isExternal;
    }

    public void setExternal(boolean isExternal) {
        this.isExternal = isExternal;
    }

    public boolean isGlobal() {
        return isGlobal;
    }

    public void setGlobal(boolean isGlobal) {
        this.isGlobal = isGlobal;
    }

    public void setNoSingleParagraph(boolean noSingleParagraph) {
        this.noSingleParagraph = noSingleParagraph;
    }

    public boolean isNoSingleParagraph() {
        return noSingleParagraph;
    }

    public void setSubstringWorkSpace(ArrayList<String> substringWorkSpace) {
        this.substringWorkSpace = substringWorkSpace;
    }

    public ArrayList<String> getSubstringWorkSpace() {
        return substringWorkSpace;
    }

    public void setAChildHasRedefines(boolean isAChildHasRedefines) {
        this.isAChildHasRedefines = isAChildHasRedefines;
    }

    public boolean isAChildHasRedefines() {
        return isAChildHasRedefines;
    }

    public void setDataDescriptionEntry(DataDescriptionEntry dataDescriptionEntry) {
        this.dataDescriptionEntry = dataDescriptionEntry;
    }

    public DataDescriptionEntry getDataDescriptionEntry() {
        return dataDescriptionEntry;
    }

    public void setOtherData1(int otherData1) {
        this.otherData1 = otherData1;
    }

    public int getOtherData1() {
        return otherData1;
    }

    public void setDoWriteClassFile(boolean doWriteClassFile) {
        this.doWriteClassFile = doWriteClassFile;
    }

    public boolean isDoWriteClassFile() {
        return doWriteClassFile;
    }
    private String dataName;
    private String pictureString;
    private String javaName1;
    private String javaName2;
    private CobolSymbol javaType;
    private SymbolProperties parent;
    private ArrayList<SymbolProperties> children;
    private short levelNumber;
    private short dataUsage;
    private short dataCategory;
    private short type;
    private int offset;
    private int length;
    private int adjustedLength;
    private int identifierType;

    public int getIdentifierType() {
        return identifierType;
    }

    public void setIdentifierType(int identifierType) {
        this.identifierType = identifierType;
    }

    public int getAdjustedLength() {
        return adjustedLength;
    }

    public void setAdjustedLength(int adjustedLength) {
        this.adjustedLength = adjustedLength;
    }
    private int paragraphMark;
    private SymbolProperties majorIndex;
    private String value1;
    private String value2;
    private ArrayList<String> groupDictionary;
    private ArrayList<SymbolProperties> paragraphList;
    private int minOccurs;
    private int maxOccurs;
    private SymbolProperties dependingOnOccurs = null;
    private ArrayList<SymbolProperties> fileStatus;
    private ArrayList<SymbolProperties> indexedByOccurs;
    private ArrayList<SymbolProperties> OccursParents;
    private int noOccursSubscripts;
    private int maxMaxLen;
    private int otherData1;
    private int unAdjustedOffset;
    private String otherName;
    private Object otherData2;
    private ArrayList<Object> otherData;

    public String getOtherName() {
        return otherName;
    }

    public void setOtherName(String otherName) {
        this.otherName = otherName;
    }

    public void setOtherData2(Object otherData2) {
        this.otherData2 = otherData2;
    }

    public Object getOtherData2() {
        return otherData2;
    }
    private SymbolProperties redefines;
    private ArrayList<SymbolProperties> redefinedBy;
    private ArrayList<CoupleValue> values;
    private boolean hasRenames;
    private SymbolProperties inCopyBook;

    public SymbolProperties getInCopyBook() {
        return inCopyBook;
    }

    public void setInCopyBook(SymbolProperties isInCopyBook) {
        this.inCopyBook = isInCopyBook;
    }

    public boolean hasRenames() {
        return this.hasRenames;
    }

    public void setHasRenames(boolean hr) {
        this.hasRenames = hr;
    }

    public void setOtherData(ArrayList<Object> otherData) {
        this.otherData = otherData;
    }

    public ArrayList<Object> getOtherData() {
        return otherData;
    }

    public boolean isFileOpenedInput() {
        return isFileInput;
    }

    public void setFileOpenedInput(boolean isFileInput) {
        this.isFileInput = isFileInput;
    }

    public boolean isFileOpenedOutput() {
        return isFileOutput;
    }

    public void setFileOpenedOutput(boolean isFileOutput) {
        this.isFileOutput = isFileOutput;
    }

    public boolean isFileOpenedIO() {
        return isFileInputOutput;
    }

    public void setFileOpenedIO(boolean isFileIO) {
        this.isFileInputOutput = isFileIO;
    }

    public void setFileOpenedExtend(boolean isFileExtend) {
        this.isFileExtend = isFileExtend;
    }

    public boolean isFileOpenedExtend() {
        return isFileExtend;
    }

    public void setVarying(boolean isVarying) {
        this.isVarying = isVarying;
    }

    public boolean isVarying() {
        return isVarying;
    }

    public void setVaryingLen(boolean isVaryingLen) {
        this.isVaryingLen = isVaryingLen;
    }

    public boolean isVaryingLen() {
        return isVaryingLen;
    }

    public void setVaryingArray(boolean isVaryingArray) {
        this.isVaryingArray = isVaryingArray;
    }

    public boolean isVaryingArray() {
        return isVaryingArray;
    }
    private boolean isOccurs;
    private boolean isVaryingOccurs;
    private boolean isFiller;
    private boolean isFormat;
    private boolean ref;
    private boolean mod;
    private boolean isSuppressed;
    private boolean importLib;
    private boolean importBigDecimal;
    private boolean usedNativeJavaTypes;
    private boolean isAChildHasRedefines;
    private boolean isAChildHasDependingOn;
    private boolean isNumericTested;
    private boolean isAlphabeticTested;
    private boolean isAlphabeticLowerTested;
    private boolean isAlphabeticUpperTested;
    private boolean isSpacesTested;
    private boolean isAParentInOccurs;
    private boolean isSigned;//These are duplicated here with Constants.
    //May have to re-factor out the duplications
    private boolean isBlankWhenZero;
    private boolean isCurrency;
    private boolean isSignLeading;
    private boolean isSignSeparate;
    private boolean isJustifiedRight;
    private boolean isExternal;
    private boolean isGlobal;
    private boolean doWriteClassFile;
    private boolean noSingleParagraph;
    private boolean isFileInput;
    private boolean isFileOutput;
    private boolean isFileInputOutput;
    private boolean isFileExtend;
    private boolean isVarying;
    private boolean isVaryingArray;
    private boolean isVaryingLen;
    private boolean consolidatePara;
    private boolean fromRESLibrary;
    private boolean isGotoTarget;
    private boolean isIndexRedefines;
    private boolean isAsBytesAccessor;
    private boolean isLinkageSection;
    private boolean isIndexedFileRecord;
    private boolean isAllIndexes = true;
    private boolean isAlteredParagraph = false;
    private boolean isDuplicateKey = false;
    private boolean forceCobolBytes = false;
    private ArrayList<String> indexesWorkSpace;
    private ArrayList<String> substringWorkSpace;
    private DataDescriptionEntry dataDescriptionEntry;
    private SymbolProperties sibling;

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public boolean isData() {
        return (this.getType() == SymbolConstants.DATA && this.getDataUsage() < Constants.POINTER);
    }

    public boolean isElementData() {
        return (isData() && this.getPictureString() != null);
    }

    public boolean isGroupData() {
        return (isData() && this.getPictureString() == null && this.getLevelNumber() != 88);
    }

    public boolean is01Group() {
        return (isData() && this.getPictureString() == null && this.getLevelNumber() == 1);
    }

    public boolean isProgram() {
        return (this.getType() == SymbolConstants.PROGRAM);
    }

    public boolean isTopFiller() {
        if (!getIsFiller() || isElementData()) {
            return false;
        }
        SymbolProperties par = getParent();
        while (par != null && par.getIsFiller()) {
            par = par.getParent();
        }
        return !par.is01Group();
    }

    public boolean isFile() {
        return this.type == SymbolConstants.FILE && this.getParent().type == SymbolConstants.PROGRAM;
    }

    public boolean isSequentialFile() {
        return isFile() && this.getDataUsage() == com.res.java.lib.Constants.SEQUENTIAL;
    }

    public boolean isIndexedFile() {
        return isFile() && this.getDataUsage() == com.res.java.lib.Constants.INDEXED;
    }

    public boolean isRandomFile() {
        return isFile() && this.getDataUsage() == com.res.java.lib.Constants.RELATIVE;
    }

    public boolean isLineSequentialFile() {
        return isFile() && this.getDataUsage() == com.res.java.lib.Constants.LINE_SEQUENTIAL;
    }

    public boolean isSequentialAccess() {
        return isFile() && this.getOtherData1() == com.res.java.lib.Constants.SEQUENTIAL_ACCESS;
    }

    public boolean isRandomAccess() {
        return isFile() && this.getOtherData1() == com.res.java.lib.Constants.RANDOM_ACCESS;
    }

    public boolean isDynamicAccess() {
        return isFile() && this.getOtherData1() == com.res.java.lib.Constants.DYNAMIC_ACCESS;
    }

    public boolean hasChildren() {
        return this.children != null && this.children.size() > 0;
    }

    @Override
    public String toString() {
        return dataName;
    }

    public void setSibling(SymbolProperties sibling) {
        this.sibling = sibling;
    }

    public SymbolProperties getSibling() {
        return sibling;
    }

    public void setConsolidateParagraph(boolean consolidatePara) {
        this.consolidatePara = consolidatePara;
    }

    public boolean isConsolidateParagraph() {
        return consolidatePara;
    }

    public void setFromRESLibrary(boolean fromRESLibrary) {
        this.fromRESLibrary = fromRESLibrary;
    }

    public boolean isFromRESLibrary() {
        return fromRESLibrary;
    }

    public void setGotoTarget(boolean isGotoTarget) {
        this.isGotoTarget = isGotoTarget;
    }

    public boolean isGotoTarget() {
        return isGotoTarget;
    }

    public SymbolProperties() {
        otherData2 = null;
    }

    public class CoupleValue {

        public Cobol2Java.ExpressionString value1;
        public Cobol2Java.ExpressionString value2;

        public CoupleValue(String v1, String v2) {
            value1 = Main.getContext().getCobol2Java().new ExpressionString(v1);
            value2 = Main.getContext().getCobol2Java().new ExpressionString(v2);
        }

        public CoupleValue(Cobol2Java.ExpressionString v1, Cobol2Java.ExpressionString v2) {
            value1 = v1;
            value2 = v2;
        }
    }

    public boolean isFloatingPoint() {
        return dataUsage == Constants.COMPUTATIONAL1 || dataUsage == Constants.COMPUTATIONAL2;
    }

    public void setSpacesTested(boolean isSpacesTested) {
        this.isSpacesTested = isSpacesTested;
    }

    public boolean isSpacesTested() {
        return isSpacesTested;
    }

    public void setIndexRedefines(boolean isIndexRedefines) {
        this.isIndexRedefines = isIndexRedefines;
    }

    public boolean isIndexRedefines() {
        return isIndexRedefines;
    }

    public void setAllIndexes(boolean isAllIndexes) {
        this.isAllIndexes = isAllIndexes;
    }

    public boolean isAllIndexes() {
        return isAllIndexes;
    }

    public void setAsBytesAccessor(boolean isAsBytesAccessor) {
        this.isAsBytesAccessor = isAsBytesAccessor;
    }

    public boolean isAsBytesAccessor() {
        return isAsBytesAccessor;
    }

    public SymbolProperties findNearestCobolBean() {
        if (this.is01Group()) {
            return this;
        }
        if (this.isData()) {
            SymbolProperties par = this;
            do {
                par = par.getParent();
            } while (par != null && par.getLevelNumber() != 1 && !par.isProgram());
            return par;
        }
        return null;
    }

    public void setLinkageSection(boolean isLinkageSection) {
        this.isLinkageSection = isLinkageSection;
    }

    public boolean isLinkageSection() {
        return isLinkageSection;
    }

    public boolean isTopLevelData() {
        return levelNumber == 01 || levelNumber == 77;
    }

    public void setDependingOnOccurs(SymbolProperties dependingOnOccurs) {
        this.dependingOnOccurs = dependingOnOccurs;
    }

    public SymbolProperties getDependingOnOccurs() {
        return dependingOnOccurs;
    }

    public String getCobolBeanName() {
        if (this.isProgram()) {
            return "this";
        } else {
            return this.getJavaName1();
        }
    }

    public boolean equals(SymbolProperties to) {
        return this.dataName.equalsIgnoreCase(to.dataName);
    }

    public void setAChildHasDependingOn(boolean isAChildHasDependingOn) {
        this.isAChildHasDependingOn = isAChildHasDependingOn;
    }

    public boolean isAChildHasDependingOn() {
        return isAChildHasDependingOn;
    }

    public void setIndexedFileRecord(boolean isIndexedFileRecord) {
        this.isIndexedFileRecord = isIndexedFileRecord;
    }

    public boolean isIndexedFileRecord() {
        return isIndexedFileRecord;
    }

    public void setAlteredParagraph(boolean isAlteredParagraph) {
        this.isAlteredParagraph = isAlteredParagraph;
    }

    public boolean isAlteredParagraph() {
        return isAlteredParagraph;
    }

    public void setDuplicateKey(boolean isDuplicateKey) {
        this.isDuplicateKey = isDuplicateKey;
    }

    public boolean isDuplicateKey() {
        return isDuplicateKey;
    }

    public void setForceCobolBytes(boolean forceCobolBytes) {
        this.forceCobolBytes = forceCobolBytes;
    }

    public boolean isForceCobolBytes() {
        return forceCobolBytes;
    }

    public void setDataCategory(short dataCategory) {
        this.dataCategory = dataCategory;
    }

    public short getDataCategory() {
        return dataCategory;
    }

    public class CobolSymbol {

        private String name;
        private String pic;
        private int type;
        private byte usage;
        private byte dataCategory;
        private short maxIntLength;
        private short maxFractionLength;
        private short maxScalingLength;
        private int maxStringLength;
        private boolean isBlankWhenZero;
        private boolean isCurrency;
        private boolean isSigned;
        private boolean isSignLeading;
        private boolean isSignSeparate;
        private boolean isJustifiedRight;
        private boolean isExternal;
        private boolean isGlobal;

        public byte getDataCategory() {
            return dataCategory;
        }

        public void setDataCategory(byte dataCategory) {
            this.dataCategory = dataCategory;
        }

        public boolean isIsBlankWhenZero() {
            return isBlankWhenZero;
        }

        public void setIsBlankWhenZero(boolean isBlankWhenZero) {
            this.isBlankWhenZero = isBlankWhenZero;
        }

        public boolean isIsCurrency() {
            return isCurrency;
        }

        public void setIsCurrency(boolean isCurrency) {
            this.isCurrency = isCurrency;
        }

        public boolean isIsExternal() {
            return isExternal;
        }

        public void setIsExternal(boolean isExternal) {
            this.isExternal = isExternal;
        }

        public boolean isIsGlobal() {
            return isGlobal;
        }

        public void setIsGlobal(boolean isGlobal) {
            this.isGlobal = isGlobal;
        }

        public boolean isIsJustifiedRight() {
            return isJustifiedRight;
        }

        public void setIsJustifiedRight(boolean isJustifiedRight) {
            this.isJustifiedRight = isJustifiedRight;
        }

        public boolean isIsSignLeading() {
            return isSignLeading;
        }

        public void setIsSignLeading(boolean isSignLeading) {
            this.isSignLeading = isSignLeading;
        }

        public boolean isIsSignSeparate() {
            return isSignSeparate;
        }

        public void setIsSignSeparate(boolean isSignSeparate) {
            this.isSignSeparate = isSignSeparate;
        }

        public boolean isIsSigned() {
            return isSigned;
        }

        public void setIsSigned(boolean isSigned) {
            this.isSigned = isSigned;
        }

        public short getMaxFractionLength() {
            return maxFractionLength;
        }

        public void setMaxFractionLength(short maxFractionLength) {
            this.maxFractionLength = maxFractionLength;
        }

        public short getMaxIntLength() {
            return maxIntLength;
        }

        public void setMaxIntLength(short maxIntLength) {
            this.maxIntLength = maxIntLength;
        }

        public short getMaxScalingLength() {
            return maxScalingLength;
        }

        public void setMaxScalingLength(short maxScalingLength) {
            this.maxScalingLength = maxScalingLength;
        }

        public int getMaxStringLength() {
            return maxStringLength;
        }

        public void setMaxStringLength(int maxStringLength) {
            this.maxStringLength = maxStringLength;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getPic() {
            return pic;
        }

        public void setPic(String pic) {
            this.pic = pic;
        }

        public byte getType() {
            return (byte)type;
        }

        public void setType(int type) {
            setIdentifierType(type);
            this.type = type;
        }

        public byte getUsage() {
            return usage;
        }

        public void setUsage(byte usage) {
            this.usage = usage;
        }

        public CobolSymbol() {
        }

        public CobolSymbol(int t) {
            type = (byte) t;
        }
    }

    public boolean isANumber() {
        if (this.getJavaType().type <= Constants.BIGDECIMAL && this.getJavaType().type > Constants.CHAR) {
            return true;
        }
        return false;
    }

    public boolean isADisplayNumber() {
        if (isANumber() && dataUsage == Constants.DISPLAY) {
            return true;
        }
        return false;
    }

    private long internalMark;

    public long getInternalMark() {
        return internalMark;
    }

    public void setInternalMark(long internalMark) {
        this.internalMark = internalMark;
    }
}
 public class SymbolTable {

	final int symbol_table_size = 4096;
    SymbolCell[] symbol_table = new SymbolCell[symbol_table_size];

    //final int scope_stack_length = 1024;

    int scope_stack_top = 0;

    int[] scope_stack = new int[symbol_table_size];
    
	public static int paragraphMark = 0;
	public static int tempVariablesMark = 0;
	public static int duplicateJavaNameMark = 0;
        private static long symbolInternalMark=0;
         private boolean cloneOnLookup = false;
	private static SymbolTable table = null;
	
	private static Stack<SymbolProperties> programs=null;
	
	public SymbolProperties getCurrentProgram() {
		if(programs==null||programs.size()<=0) return null;
		return programs.peek();
	}

	public SymbolProperties getFirstProgram() {
		if(programs==null||programs.size()<=0) return null;
		return programs.get(0);
	}

	public boolean isCurrentProgramTopLevel() {
		if(programs==null||programs.size()!=1) return false;
		return true;
	}
	
	public boolean isTopLevePrograml(SymbolProperties props) {
		if(programs==null||programs.size()!=1) return false;
		return programs.peek().getDataName().equalsIgnoreCase(props.getDataName());
	}
	
	public boolean isCurrentProgram(SymbolProperties props) {
		if(programs==null||programs.size()<=0) return false;
		return programs.peek().getDataName().equalsIgnoreCase(props.getDataName());
	}
	
	//public static Cobol2Java cobol2Java = new Cobol2Java();
	   
    public void setCloneOnLookup(boolean cloneOnLookup) {
		this.cloneOnLookup = cloneOnLookup;
	}

	public boolean isCloneOnLookup() {
		return cloneOnLookup;
	}

	static final String TOSTRING_REF_STRING_="bytes_";
    
    private SymbolTable () {
		scope_stack_top = 0;
		for (int i = 0; i<symbol_table_size; i++)
		    symbol_table[i] = null;
    }

    public void startProgram(SymbolProperties program) {
    	if(programs==null) programs = new Stack<SymbolProperties>();
    	programs.push(program);
    }
    
    public void endProgram() {
    	if(programs==null||programs.size()<=0)
    		RunTimeUtil.getInstance().reportError("FatalError: Program Stack empty",true);
    	programs.pop();
    }
    
    public static SymbolTable getScope() {
    	if(table==null) table=new SymbolTable();
    	return table;
    }
    
    public static void clear() {
    	table=null;
    	programs=null;
        paragraphMark = 0;
	tempVariablesMark = 0;
	duplicateJavaNameMark = 0;
        symbolInternalMark=0;
    }
    
    
    static void fatal_error ( String msg, Node x ) {
    	throw new Error("*** Fatal error: " + msg + x);
    }

    /* a hashing function for strings */
    int hash ( String s ) {
    	if(s==null) {
    		System.out.println("*** Fatal error: ERROR IN NULL STRING BEING HASHED");
    		System.exit(-1);
    		return -1;
    	}
    	else
    		return Math.abs(s.hashCode()) % symbol_table_size;
    }

    /* a hashing function for strings */
    int hash ( String s, int table_size ) {
    	if(s==null) {
    		System.out.println("*** Fatal error: ERROR IN NULL STRING BEING HASHED");
    		System.exit(-1);
    		return -1;
    	}
    	else
    		return Math.abs(s.hashCode()) % table_size;
    }
    
    /* insert a new item in the symbol table */
    public void insert ( String key, SymbolProperties binding ) {
    	
    key=key.toUpperCase();
	int loc = hash(key);
        binding.setInternalMark(symbolInternalMark++);
	SymbolCell o=symbol_table[loc];
	//if(symbol_table[loc]!=null)
		//for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
		  //  o=s;
	symbol_table[loc] = new SymbolCell(key,binding,o);
	if (scope_stack_top >= symbol_table_size)
	   RunTimeUtil.getInstance().reportError("Fatal Error: Symbol Table Stack Overflow.Exiting",true);
	else scope_stack[scope_stack_top++] = loc;
    }

    /* replace an item with a given name in the symbol table */
    public void replace ( String key, SymbolProperties binding ) {
    key=key.toUpperCase();
	int loc = hash(key);
	for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
	    if (s.name.equals(key))
		s.binding = binding;
    }

    private SymbolProperties cloneSymbol(SymbolProperties props) {
        if(props.getJavaType()!=null)
            props.setIdentifierType(props.getJavaType().getType());
    	if(isCloneOnLookup()) {
    		props.setIndexesWorkSpace(null);
    		props.setSubstringWorkSpace(null);
			try {
				return (SymbolProperties)props.clone();
			} catch (CloneNotSupportedException e) {
				RunTimeUtil.getInstance().reportError(e.getMessage(),false);
			}
    	}
    	return props;
    }
    
    SymbolProperties ret=null;
    /* lookup for an item in the symbol table */
    public SymbolProperties lookup ( String key ) {
    	if((getCurrentProgram()!=null&&
    			(ret=lookup(key,getCurrentProgram().getDataName()))!=null))
    			return cloneSymbol(ret);
	    key=key.toUpperCase();
		int loc = hash(key);
		for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
		    if (s.name.equalsIgnoreCase(key)) {
	    		return cloneSymbol(s.binding);
		    }
		return null;      // if not found
    }

    /* lookup for an item and parent in the symbol table */
    public SymbolProperties lookup ( String key, String par ) {
        key=key.toUpperCase();
        par=par.toUpperCase();
	int loc = hash(key);
	boolean passedAProgram=false;
	for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
	    if (s.name.equalsIgnoreCase(key)) {
	    	SymbolProperties props =s.binding;
	    	boolean first=true;
	    	do {
		    	if(!first) {
			    	if(props==null&&(par==null||par.length()==0))
			    		return cloneSymbol(s.binding);
			    	String name = (String) props.getDataName();	
			    	if (name.equalsIgnoreCase(par)&&(!passedAProgram||s.binding.isExternal()))
			    		return cloneSymbol(s.binding);
			    	else 
			    		if(props.isProgram()) {
			    			break;
			    		}
		    	}
		    	first = false;
		    	props = props.getParent();
	    	} while(props!=null);
	    }
	return null;       // if not found
    }
    
    /* lookup for an item and parent in the symbol table */
    public SymbolProperties lookup ( String key, int type ) {
       	if((getCurrentProgram()!=null&&
    			(ret=lookup(key,getCurrentProgram().getDataName()))!=null))
       		if(ret.getType()==type)
    			return cloneSymbol(ret);
       		else return null;
    key=key.toUpperCase();
	int loc = hash(key);
	for (SymbolCell s = symbol_table[loc]; s != null; s=s.next) {
	    if (s.name.equalsIgnoreCase(key)&&s.binding.getType()==type) {
    		return cloneSymbol(s.binding);
	    }
	}
	return null;       // if not found
    }
    
    /* start a new environment */
    public void begin_scope () {
	if (scope_stack_top >= symbol_table_size)
		RunTimeUtil.getInstance().reportError("Fatal Error: Symbol Table Stack Overflow.Exiting",true);
	else scope_stack[scope_stack_top++] = -1;
    }

    /* pop the last environment */
    public void end_scope () {
	int i = scope_stack_top-1;
	for (; scope_stack[i]>=0 && i>0; i--) {
	    int loc = scope_stack[i];
	    symbol_table[loc] = symbol_table[loc].next;
	};
	scope_stack_top = i;
    }

    /* display the content of the symbol table */
	public void display () {
	SymbolCell[] s = new SymbolCell[symbol_table_size];
	for (int i = 0; i<symbol_table_size; i++)
	    s[i] = symbol_table[i];
	for (int i = scope_stack_top-1; i>=0; i--)
	    if (scope_stack[i] == -1)
	       System.out.println("----------------");
	    else { SymbolCell c = s[scope_stack[i]];
	           s[scope_stack[i]] = c.next;
	       SymbolProperties o1=null,o2=null;
	       o1= c.binding;
	       o2= (SymbolProperties) c.binding.getParent();
	       if (o1==null)
	    	   System.out.println("***ERROR IN SYMBOL TABLE"+c.name);
	       else {
	    	   System.out.print("DATA="+c.name);
	    	   if(o2!=null)
	    		  System.out.print(" Parent=" + 
				   (String)o2.getDataName());
	    	   int i1 ;
	    	   i1=o1.getLevelNumber();
	    	   System.out.print(" LEVEL="+i1);
	    	   i1=o1.getOffset();
    		   System.out.print(" Offset="+i1);
	    	   i1=o1.getLength();
    		   System.out.print(" Length="+i1);
	    	   i1=o1.getDataUsage();
    		   System.out.print(" USAGE="+i1);
	    	   String p1 = null;
	    	   if((p1=(String)o1.getPictureString())!=null)
	    		   System.out.print(" PICTURE="+p1);
	    	   p1 = null;
	    	   if((p1=(String)o1.getValue1())!=null)
	    		   System.out.print(" VALUE="+p1);
	    	   p1 = null;
	    	   if((p1=(String)o1.getValue2())!=null)
	    		   System.out.print(" THROUGH"+p1);
	    	   boolean b1 =  o1.getRef();
    		   System.out.print("Ref="+b1);
	    	   b1 = o1.getMod();
    		   System.out.print("Mod="+b1);
	    	   b1 = o1.getIsSuppressed();
    		   System.out.print("IS_SUPRESSED="+b1);
	    	   b1 = o1.getIsFormat();
    		   System.out.print("IsFormat(="+b1);
	       }
	       System.out.println();
	       if(o1!=null&&o1.getChildren()!=null) {
	    	   for (Iterator<SymbolProperties> ite=o1.getChildren().iterator();
	    	   		ite.hasNext();) {
	    		   o2=ite.next();
	    		   System.out.println("\t\t"+((o2==null)?"NullChild":((o2.getDataName())!=null)?
	    				   ((String)o2.getDataName()):"NullName"));
	    	   }
	       }
	    }
    }
    

    public static void visit(SymbolProperties props,Visitor visitor) {
    	if(props.isProgram()&&
    			!SymbolTable.getScope().isCurrentProgram(props)
    			||props.getType()==SymbolConstants.PARAGRAPH
    			||props.getType()==SymbolConstants.SECTION)
    		return;
    	//Preprocess
    	visitor.visitPreprocess(props);
       	
    	//Body
       	if(props.isFile())
    		visitor.visitFile(props);
    	else
    	if(props.getLevelNumber()==1&&props.getPictureString()==null)
    		visitor.visit01Group(props);
    	else
	    	if(props.getLevelNumber()==1&&props.getPictureString()!=null)
	    		visitor.visit01Element(props);
	    	else
		    	if(props.getLevelNumber()==77&&props.getPictureString()!=null)
		    		visitor.visit77Element(props);
		    	else
	    	    	if(props.getLevelNumber()==88)
	    	    		visitor.visit88Element(props);
	    	    	else
		        	if(props.getPictureString()==null)
		        		visitor.visitInnerGroup(props);
		    	    	else
		    	    	if(props.getPictureString()!=null)
		    	    		visitor.visitInnerElement(props);
			        	
    	
    	//Postprocess
    	visitor.visitPostprocess(props);
    	
    }
    
    public static void visit(ArrayList<SymbolProperties> children,Visitor visitor) {
    	//visit children
    	if(children!=null){
    		for(SymbolProperties child:children){
    			
    			visitor.visitChildPreprocess(child);
    			visit(child,visitor);
    			visitor.visitChildPostprocess(child);
    		}
    	} 
    		
    }
    
    public static boolean convert2Java() {
    	visit(SymbolTable.getScope().getCurrentProgram(), new PrintSymbol());
    	TranUtil.get().saveDatabaseProperties();
    	return true;
    }

}
 public class SymbolUtil {

    private static SymbolUtil symbolUtil = null;

    private SymbolUtil() {
    }

    public static SymbolUtil getInstance() {
        if (symbolUtil == null) {
            symbolUtil = new SymbolUtil();
        }
        return symbolUtil;
    }

    public static void clear() {
        symbolUtil = null;
    }

    public void doClassBegin(SymbolProperties props, String name, boolean programScope) {
        if (programScope) {
            props.setIsFormat(false);
            ClassFile.doProgramScope(props, true);
            if (name == null || name.length() <= 0) {
                name = props.getJavaName2();
            }
            ClassFile.println("");
            ClassFile.println("import com.res.java.lib.*;");
            ClassFile.println("import java.math.BigDecimal;");
            ClassFile.println("import java.beans.*;", true);
            ClassFile.println("import com.res.java.lib.*;", true);
            ClassFile.println("");
            ClassFile.println("@SuppressWarnings(\"unused\")");
            if (props.isIndexedFileRecord()) {
                ClassFile.println("public class " + name + " extends CobolBean implements CobolFileBean {");
            } else {
                ClassFile.println("public class " + name + " extends CobolBean {");
            }
            ClassFile.println("public class " + name + "BeanInfo extends RESBeanInfo {", true);
            ClassFile.tab();
        } else {
            ClassFile.println("public class " + name + " extends CobolBean {");
            ClassFile.tab();
        }
        if (RESConfig.getInstance().isUsePointers()) {
            ClassFile.println("public BytesField " + props.getJavaName1() + "Fld_ = new BytesField(this,"
                    + String.valueOf(props.getUnAdjustedOffset()) + ','
                    + String.valueOf(props.getLength()) + ");");
        }

    }

    public void doClassEnding(SymbolProperties props, boolean programScope) {
        String name1 = props.getJavaName1();
        String name2 = props.getJavaName2();

        int adjLen = props.getAdjustedLength();

        if (props.getType() != SymbolConstants.PROGRAM) {

            printInitialize(props);

            printConstructors(props, adjLen);

            printStringAccessors(props);

            printGroupAccessors(props, true, getGroupOccursIdx(props));
            if (props.isIndexedFileRecord()) {
                TranUtil.get().printSetSQLProperties(props);
                TranUtil.get().printgetSQLResults(props);
                TranUtil.get().printSetStartSQLProperties(props);
            }
        }

        if (props.getType() != SymbolConstants.PROGRAM) {

            ClassFile.backTab();
            if (programScope) {
                ClassFile.endProgramScope();
            } else {
                ClassFile.doMethodScope("}");
            }

            printClassAccessors(props, name1, name2);

            printClass88s(props);

        }

    }
    private static String modifier0 = "";
    private static String modifier1 = "";
    private static String getSubscripts = "";
    private static String modifier2 = "";
    private static String modifier3 = "";
    private static String modifier4 = "";
    private static String setSubscripts = "";

    private void printGroupAccessors(SymbolProperties props,
            boolean isTopLevel, int idx) {

        if (!props.getRef() && !props.getMod()) {
            return;
        }
        int relOff = -1;
        if (isTopLevel) {
            ClassFile.doMethodScope("public byte[] getBytes(" + getGroupOccursSignature(props)
                    + ") {");
            idx = 0;
            if (RESConfig.getInstance().getOptimizeAlgorithm() == 2 && props.isUsedNativeJavaTypes()) {
                relOff = 0;
            }
            //else
            // idx = -2;
        } else {
            ClassFile.doMethodScope("public byte[] get"
                    + props.getJavaName2()
                    + "(" + getGroupOccursSignature(props)
                    + ") {");
            if (RESConfig.getInstance().getOptimizeAlgorithm() == 2 && props.isUsedNativeJavaTypes()) {
                relOff = props.getUnAdjustedOffset();
            }
        }
        ClassFile.tab();

        if (isSingleTopLevel(props) && !props.isUsedNativeJavaTypes()) {
            printGroupGetClassString(props);
        } else if (props.hasChildren()) {
            ClassFile.println("CobolBytes " + SymbolTable.TOSTRING_REF_STRING_
                    + "=new CobolBytes(" + String.valueOf(props.getLength()) + ",true);");
            for (Iterator<SymbolProperties> ite = props.getChildren().iterator(); ite.hasNext();) {
                SymbolProperties child = ite.next();
                if (child.getRedefines() != null || child.getLevelNumber() == 88 || child.getLevelNumber() == 66 || child.getLength()==0) {
                    continue;
                }
                child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                printGroupGetBytesOccursLoop(child, idx, relOff);
            }
            ClassFile.println("return "
                    + SymbolTable.TOSTRING_REF_STRING_
                    + ".getBytes();");
        } else {
            ClassFile.println("return new b[0];");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
        if (isTopLevel) {
            ClassFile.doMethodScope("public void valueOf(byte[] val"
                    + (((getSubscripts = getGroupOccursSignature(props)).length() > 0) ? ("," + getSubscripts) : "")
                    + ") {");
            /*
            if(RESConfig.getInstance().getOptimizeAlgorithm()==2&&props.isUsedNativeJavaTypes())
            idx = -1;
            else idx = -2;
             */
        } else {
            ClassFile.doMethodScope("public void set"
                    + props.getJavaName2()
                    + "(byte[] val" + (((getSubscripts = getGroupOccursSignature(props)).length() > 0) ? ("," + getSubscripts) : "")
                    + ") {");
            relOff = props.getUnAdjustedOffset();
        }
        ClassFile.tab();
        if (isSingleTopLevel(props) && !props.isUsedNativeJavaTypes()) {
            printGroupSetClassString(props);
        } else if (props.hasChildren()) {
            ClassFile.println("CobolBytes "
                    + SymbolTable.TOSTRING_REF_STRING_
                    + "=new CobolBytes(val,Math.max(val.length," + String.valueOf(props.getLength())
                    + "));");
            for (Iterator<SymbolProperties> ite = props.getChildren().iterator(); ite.hasNext();) {
                SymbolProperties child = ite.next();
                if (child.getRedefines() != null || child.getLevelNumber() == 88 || child.getLevelNumber() == 66||child.getLength()==0) {
                    continue;
                }
                child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                printGroupSetBytesOccursLoop(child, "val", idx, relOff);
            }
        } else {
            ClassFile.println("return;");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
    }

    private boolean isSingleTopLevel(SymbolProperties props) {
        if (!props.isUsedNativeJavaTypes()) {
            return true;
        }
        while (props.hasChildren()
                && !(props = props.getChildren().get(0)).isUsedNativeJavaTypes()
                && props.getIsFiller()) {
            continue;
        }
        return props.getChildren() != null && props.getChildren().size() == 1 && !props.getChildren().get(0).isUsedNativeJavaTypes();
    }

    private void printGroupGetClassString(SymbolProperties props) {
        props.setIndexesWorkSpace(null);
        ClassFile.println("return "
                + getGetterString(props, -2, -1) + ";");
    }

    private void printGroupSetClassString(SymbolProperties props) {
        props.setIndexesWorkSpace(null);
        ClassFile.println(getSetterString(props, -2, -1) + ";");
    }
    private boolean forceDisplayAccessor = false;
    //Of the form...
    //super.setDisplayLong(0,13,bytes_.getDisplayLong(0,13,false,false,false),false,false,false);

    private void printGroupSetCobolBytesString(SymbolProperties props, int modifiedIdx, int relativeUnadjustedOffset) {
        int i = 0;
        String s;
        forceDisplayString = forceDisplayAccessor = true;
        s = getGetterString(props, modifiedIdx, (RESConfig.getInstance().getOptimizeAlgorithm() == 1)
                ? -1 : relativeUnadjustedOffset);
        forceDisplayString = false;
        ClassFile.println(getSetterString(props, modifiedIdx, -1).replace(",val", "," + SymbolTable.TOSTRING_REF_STRING_
                + s.substring(((i = s.indexOf('.')) < 0) ? 0 : i).replace(",val", ",")) + ";");
        forceDisplayAccessor = false;
    }

    //Of the form...
    //bytes_.setDisplayLong(0,13,super.getDisplayLong(0,13,false,false,false),false,false,false);
    private void printGroupGetCobolBytesString(SymbolProperties props, int modifiedIdx, int relativeUnadjustedOffset) {
        int i = 0;
        String s;
        forceDisplayString = forceDisplayAccessor = true;
        s = getSetterString(props, modifiedIdx, relativeUnadjustedOffset);
        forceDisplayString = false;
        ClassFile.println(SymbolTable.TOSTRING_REF_STRING_ + s.substring(((i = s.indexOf('.')) < 0) ? 0 : i).replace(",val", ","
                + getGetterString(props, modifiedIdx, -1)) + ";");
        forceDisplayAccessor = false;
    }

    // Of the form...
    // setName(bytes_.getDisplayLong(0,13,false,false,false));
    String getGroupSetterString(SymbolProperties props, String value, int modifiedIdx, int relativeUnadjustedOffset) {
        int i = 0;
        forceDisplayString = forceDisplayAccessor = true;
        String s = getSetterString(props, modifiedIdx, relativeUnadjustedOffset);
        forceDisplayString = false;
        s = SymbolTable.TOSTRING_REF_STRING_ + s.substring(((i = s.indexOf('.')) < 0) ? 0 : i).replace(",val", "," + value);
        forceDisplayAccessor = false;
        return s;
    }

    //Of the form...
    //bytes_.setDisplayLong(0,13,getName(),false,false,false);
    String getGroupGetterString(SymbolProperties props, int modifiedIdx, int relativeUnadjustedOffset) {
        int i = 0;
        forceDisplayString = forceDisplayAccessor = true;
        String s = getGetterString(props, modifiedIdx, relativeUnadjustedOffset);
        forceDisplayString = false;
        s = SymbolTable.TOSTRING_REF_STRING_ + s.substring(((i = s.indexOf('.')) < 0) ? 0 : i);
        forceDisplayAccessor = false;
        return s;
    }

    //Of the form...
    //for(int idx_=0;idx_<10240;++idx_) {
    //   bytes_.setDisplayLong(0+13*idx_,13,getName(idx_+1),false,false,false);
    //   bytes_.setDisplayLong(13*idx_,13,getName2(idx_+1),false,false,false);
    //   bytes_.setDisplayLong(26*idx_,16,getName3(idx_+1),false,false,false);
    //}
    public void printGroupGetBytesOccursLoop(SymbolProperties props, int modifiedIdx, int relOff) {
        if (props.isOccurs()) {
            //Of form... for(int idx1=0;idx1<10240;++idx_) {
            ClassFile.println("for(int idx" + String.valueOf(props.getNoOccursSubscripts())
                    + "=" + String.valueOf(props.getMaxOccursInt())
                    + ";idx" + String.valueOf(props.getNoOccursSubscripts())
                    + ">=1"
                    + ";--"
                    + "idx" + String.valueOf(props.getNoOccursSubscripts())
                    + ") {");
            ClassFile.tab();
            if (props.getIndexesWorkSpace() == null) {
                props.setIndexesWorkSpace(new ArrayList<String>());
            }
            props.getIndexesWorkSpace().add("idx" + String.valueOf(props.getNoOccursSubscripts()));
        }

        if ((!props.getRef() && !props.getMod()) || (props.getIsFiller() && props.isGroupData())) {
            if (props.hasChildren()) {
                for (SymbolProperties child : props.getChildren()) {
                    child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                    //Of the form... bytes_.setDisplayLong(0+13*--idx1,13,getName(++idx1),false,false,false);
                    printGroupGetBytesOccursLoop(child, modifiedIdx, relOff);
                }
            }

        } else if (!props.isUsedNativeJavaTypes()) {
            printGroupGetCobolBytesString(props, modifiedIdx, relOff);
        } else if (props.isOccurs()) {
            if (props.isGroupData() && props.getIsFiller()) {
                for (SymbolProperties child : props.getChildren()) {
                    child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                    if (child.getIsFiller() && child.isElementData()) {
                        printGroupGetBytesString(child, modifiedIdx, relOff);
                    } else //Recursion
                    {
                        printGroupGetBytesOccursLoop(child, modifiedIdx, relOff);
                    }
                }

            } else {
                //Of the form... bytes_.setDisplayLong(0+13*idx_,13,getName(idx_+1),false,false,false);
                printGroupGetBytesString(props, modifiedIdx, relOff);
            }
        } //Of the form... bytes_.setDisplayLong(0+13*idx_,13,getName(idx_+1),false,false,false);
        else {
            printGroupGetBytesString(props, modifiedIdx, relOff);
        }
        if (props.isOccurs()) {
            ClassFile.backTab();
            ClassFile.println("}");
            if (props.getIndexesWorkSpace() != null) {
                props.getIndexesWorkSpace().remove(props.getIndexesWorkSpace().size() - 1);
            }
        }
    }

    //Of the form...
    //bytes_.setDisplayLong(0+13*--idx1,13,getName(++idx1),false,false,false);
    void printGroupGetBytesString(SymbolProperties props, int modifiedIdx, int relOff) {
        forceDisplayString = forceDisplayAccessor = true;
        ClassFile.println(getGroupSetterString(props, SymbolUtil.getLocalName(NameUtil.getJavaName(props, false, props.isADisplayNumber())), modifiedIdx, relOff) + ";");
        forceDisplayString = forceDisplayAccessor = false;
    }
    //Of the form...
    //for(int idx1=0;idx1<10240;++idx1) {
    // setName1(bytes_.getDisplayLong(0+13*--idx1,13,false,false,false),++idx1);
    // setName2(bytes_.getDisplayLong(0+13*--idx1+13,13,false,false,false),++idx1);
    // setName3(bytes_.toString(0+13*--idx1+26,19),++idx1);
    //}

    void printGroupSetBytesOccursLoop(SymbolProperties props, String value, int modifiedIdx, int relOff) {
        if (props.isOccurs()) {
            ClassFile.println("for(int idx" + String.valueOf(props.getNoOccursSubscripts())
                    + "=" + String.valueOf(props.getMaxOccursInt())
                    + ";idx" + String.valueOf(props.getNoOccursSubscripts())
                    + ">=1"
                    + ";--"
                    + "idx" + String.valueOf(props.getNoOccursSubscripts())
                    + ") {");
            ClassFile.tab();
            if (props.getIndexesWorkSpace() == null) {
                props.setIndexesWorkSpace(new ArrayList<String>());
            }
            props.getIndexesWorkSpace().add("idx" + String.valueOf(props.getNoOccursSubscripts()));
        }
        if (!props.getRef() && !props.getMod() || (props.getIsFiller() && props.isGroupData())) {
            if (props.hasChildren()) {
                for (SymbolProperties child : props.getChildren()) {
                    child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                    printGroupSetBytesOccursLoop(child, value, modifiedIdx, relOff);
                }
            }
        } else if (!props.isUsedNativeJavaTypes()) {
            printGroupSetCobolBytesString(props, modifiedIdx, relOff);
        } else {
            if (props.isOccurs()) {
                if (props.getPictureString() == null && props.getIsFiller()) {
                    for (SymbolProperties child : props.getChildren()) {
                        child.setIndexesWorkSpace(props.getIndexesWorkSpace());
                        printGroupSetBytesOccursLoop(child, value, modifiedIdx, relOff);
                    }
                } else {
                    printGroupSetBytesString(props, value, modifiedIdx, relOff);
                }
            } else {
                printGroupSetBytesString(props, value, modifiedIdx, relOff);
            }
        }
        if (props.isOccurs()) {
            ClassFile.backTab();
            ClassFile.println("}");
            if (props.getIndexesWorkSpace() != null) {
                props.getIndexesWorkSpace().remove((int) (props.getIndexesWorkSpace().size() - 1));
            }
        }
    }

    //Of the form...
    //setName1(bytes_.getDisplayLong(0,13,false,false,false));
    public void printGroupSetBytesString(SymbolProperties props, String value, int modifiedIdx, int relOff) {
        forceDisplayString = forceDisplayAccessor = true;
        ClassFile.println(getLocalName(NameUtil.getJavaName(props, true, props.isADisplayNumber())).replace("%0", getGroupGetterString(props, modifiedIdx, relOff)) + ";");
        forceDisplayString = forceDisplayAccessor = false;
    }

    static String getLocalName(String fullName) {
        int i = ((i = fullName.indexOf('(')) < 0) ? fullName.length() : ++i;
        return fullName.substring(fullName.substring(0, i).lastIndexOf('.') + 1);
    }

    public static boolean setCheckUseNativeJavaTypes(SymbolProperties props, boolean forceCobolBytes) {
        if (props.isFloatingPoint()) {
            props.setUsedNativeJavaTypes(true);
            return true;
        }
        props.setUsedNativeJavaTypes(false);
        if (props.getIsFiller() || props.getIsSuppressed() || props.isConsolidateParagraph() || props.isForceCobolBytes()) {
            return false;
        }
        if (RESConfig.getInstance().getOptimizeAlgorithm() == 0 || forceCobolBytes) {
            return false;
        }
        SymbolProperties props2 = props;
        if (RESConfig.getInstance().getOptimizeAlgorithm() == 1) {
            boolean ret = true;
            while ((props2 = props2.getParent()) != null) {
                ret &= (props2.isUsedNativeJavaTypes() || props2.isProgram());
            }
            if (!ret) {
                return false;
            }
        }

        props2 = props;
        if (!(props2.getRedefines() != null
                && props2.getRedefines().getDataUsage() == Constants.INDEX
                && props2.getRedefines().is01Group())) {
            while (props2 != null) {
                if (props2.getRedefines() != null || (props2.getRedefinedBy() != null && props2.getRedefinedBy().size() > 0)) {
                    return false;
                }
                if ((props2.getLevelNumber() == 1 || props2.getLevelNumber() == 77) && props2.isAChildHasRedefines()) {
                    return false;
                }

                props2 = props2.getParent();
            }
        }
        props.setUsedNativeJavaTypes(true);
        return true;
    }

    public void printJavaTypesAccessors(SymbolProperties props) {

        if (props.getIsSuppressed()) {
            return;
        }
        if (!props.isUsedNativeJavaTypes() && !props.isFloatingPoint()) {
            return;
        }
        if (props.getIsFiller()) {
            return;
        }
        if (!(props.getRef() || props.getMod())) {
            return;
        }

        CobolSymbol sym = (SymbolProperties.CobolSymbol) props.getJavaType();
        String name1 = (String) props.getJavaName1();
        String name2 = (String) props.getJavaName2();

        String s = "";
        modifier0 = "";
        modifier1 = "";
        getSubscripts = "";
        modifier2 = "";
        modifier3 = "";
        modifier4 = "";
        setSubscripts = "";

        if (props.isGroupData() || sym.getType() == Constants.GROUP) {
            props.setIsFormat(false);
            if (RESConfig.getInstance().getOptimizeAlgorithm() == 2) {
                printGroupAccessors(props, false, getGroupOccursIdx(props));
            } else {
                props.setUsedNativeJavaTypes(false);
                printCobolByteAccessors(props);
            }
            return;
        }

        if (props.isOccurs() || props.isAParentInOccurs()) {
            ArrayList<SymbolProperties> a = props.getOccursParents();
            int i = 0;
            //offsetCalc=String.valueOf(a.get(0).getOffset());
            if (a != null && a.size() > 0) {
                for (Iterator<SymbolProperties> ite = a.iterator(); ite.hasNext();) {
                    SymbolProperties curr = ite.next();
                    ++i;
                    modifier0 += "[]";
                    modifier1 += "[" + String.valueOf(curr.getMaxOccursInt()) + "]";
                    getSubscripts += "int idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                    setSubscripts += ",int idx" + String.valueOf(i);
                    modifier2 += "[--idx" + String.valueOf(i) + "]";
                    modifier3 += "idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                    modifier4 += ",idx" + String.valueOf(i);
                }

            }
        }

        if (FieldFormat.isPlainString(props.getPictureString())) {
            props.setIsFormat(false);
        }

        if (props.getIsFormat()) {
            printFieldFormat(props);
        }
        boolean isADisplayNumber = false;
        switch (sym.getType()) {
            case Constants.CHAR:
                s = "private " + SymbolConstants.get(sym.getType()) + modifier0 + " " + name1;
                if (modifier1.length() > 0) {
                    s += "= new " + SymbolConstants.get(sym.getType()) + modifier1 + ";";
                }
                s += ";";
                break;
            case Constants.BIGDECIMAL:
                if (props.getDataUsage() == Constants.DISPLAY) {
                    isADisplayNumber = true;
                    if (modifier1.length() <= 0) {
                        modifier1 = "()";
                    }
                    s = "private String" + modifier0 + " " + name1
                            + "= new String" + modifier1 + ";";
                } else {
                    s = "private " + SymbolConstants.get(sym.getType()) + modifier0 + " " + name1 + " = ";
                    if (modifier1.length() <= 0) {
                        s += SymbolConstants.get(sym.getType()) + ".ZERO;";
                    } else {
                        s += "new " + SymbolConstants.get(sym.getType()) + modifier1 + ";";
                    }
                }
                break;
            case Constants.BYTE:
            case Constants.SHORT:
            case Constants.INTEGER:
            case Constants.FLOAT:
            case Constants.DOUBLE:
            case Constants.LONG:
                if (props.getDataUsage() != Constants.DISPLAY) {
                    s = "private " + SymbolConstants.get(sym.getType()) + modifier0 + " " + name1;
                    if (modifier1.length() > 0) {
                        s += "= new " + SymbolConstants.get(sym.getType()) + modifier1 + ";";
                    }
                    s += ";";
                    break;
                }
                isADisplayNumber = true;
            case Constants.STRING:
                if (modifier1.length() <= 0) {
                    modifier1 = "()";
                }
                s = "private String" + modifier0 + " " + name1
                        + "= new String" + modifier1 + ";";
                break;
            case Constants.GROUP:
            //TODO for group moves
            default:
                if (modifier1.length() <= 0) {
                    modifier1 = "()";
                }
                s = "private " + SymbolConstants.get(sym.getType()) + modifier0 + " " + name1
                        + "= new " + SymbolConstants.get(sym.getType()) + modifier1 + ";";
        }

        if (s.length() > 0) {
            ClassFile.println(s);
        }
        if (isADisplayNumber) {
            printDisplayNumberAccessor(props);
        } else {
            ClassFile.doMethodScope("public " + SymbolConstants.get(sym.getType())
                    + " get" + props.getJavaName2() + "(" + getSubscripts + ") {");
            ClassFile.tab();
            ClassFile.println("return " + props.getJavaName1() + modifier2 + ";");
            ClassFile.backTab();
            ClassFile.endMethodScope();
            ClassFile.doMethodScope("public "
                    + " void set" + name2
                    + "("
                    + SymbolConstants.get(sym.getType())
                    + " val" + setSubscripts + ") {");
            ClassFile.tab();
            s = getJavaTypeSetterString(props);
            ClassFile.println(name1 + modifier2 + "=" + s.replace("%0", "val") + ";");
            ClassFile.backTab();
            ClassFile.endMethodScope();
        }
        if (props.isAsBytesAccessor()) {
            ClassFile.doMethodScope("public " + SymbolConstants.get(sym.getType())
                    + " get" + name2 + "AsBytes(" + getSubscripts + ") {");
            ClassFile.tab();
            ClassFile.println("CobolBytes " + SymbolTable.TOSTRING_REF_STRING_
                    + "=new CobolBytes(" + String.valueOf(props.getLength()) + ");");
            printGroupGetBytesOccursLoop(props, -1, props.getUnAdjustedOffset());
            ClassFile.println("return " + SymbolTable.TOSTRING_REF_STRING_ + ".getBytes();");
            ClassFile.backTab();
            ClassFile.endMethodScope();
        }

        printJavaTypeClassConditionTail(props);
        return;
    }

    private void printDisplayNumberAccessor(SymbolProperties props) {
        int len = props.getAdjustedLength();//+Math.abs(props.getJavaType().maxScalingLength);
        String s;
        ClassFile.doMethodScope("public " + SymbolConstants.get(props.getJavaType().getType())
                + " get" + props.getJavaName2() + "(" + getSubscripts + ") {");
        ClassFile.tab();
        switch (props.getJavaType().getType()) {
            case Constants.BIGDECIMAL:
                ClassFile.println("return super.normalizeDisplay(" + props.getJavaName1() + modifier2 + ","
                        + len + ","
                        + +props.getJavaType().getMaxFractionLength() + "," + props.getJavaType().isIsSigned() + ");");
                break;
            case Constants.BYTE:
                ClassFile.println("return (byte) super.normalizeDisplay(" + props.getJavaName1() + modifier2 + ","
                        + len + ","
                        + props.getJavaType().isIsSigned() + ");");
                break;
            case Constants.SHORT:
                ClassFile.println("return (short) super.normalizeDisplay("
                        + props.getJavaName1() + modifier2 + ","
                        + len + ","
                        + props.getJavaType().isIsSigned() + ");");
                break;
            case Constants.INTEGER:
                ClassFile.println("return (int) super.normalizeDisplay("
                        + props.getJavaName1() + modifier2 + ","
                        + len + ","
                        + props.getJavaType().isIsSigned() + ");");
                break;
            case Constants.FLOAT:
            case Constants.DOUBLE:
                reportError("Invalid JavaType for data-name: Float or Double");
            case Constants.LONG:
                ClassFile.println("return super.normalizeDisplay("
                        + props.getJavaName1() + modifier2 + ","
                        + len + ","
                        + props.getJavaType().isIsSigned() + ");");
                break;
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
        ClassFile.doMethodScope("public String get" + props.getJavaName2() + "AsString(" + getSubscripts + ") {");
        ClassFile.tab();
            switch (props.getJavaType().getType()) {
            case Constants.BYTE:
            case Constants.SHORT:
            case Constants.INTEGER:
            case Constants.LONG:
                s = "super.asDottedSignedString("
                        + props.getJavaName1() + modifier2  +","+ len
                         + ((props.getJavaType().getMaxScalingLength()==0)?
                         (""):
                         (","+String.valueOf(props.getJavaType().getMaxFractionLength()))+","+
                          String.valueOf(props.getJavaType().getMaxScalingLength()))
                        + "," + String.valueOf(props.isSigned()) + "," + props.isSignLeading() + "," + props.isSignSeparate() + ")";
                break;
            case Constants.BIGDECIMAL:
                s = "super.asDottedSignedString("
                        + props.getJavaName1() + modifier2  + ","+ len + ","
                        + ((props.getJavaType().getMaxScalingLength()==0)?
                         (String.valueOf(props.getJavaType().getMaxFractionLength())):
                         (String.valueOf(props.getJavaType().getMaxFractionLength()))+","+
                          String.valueOf(props.getJavaType().getMaxScalingLength()))+ ","
                        + String.valueOf(props.getJavaType().isIsSigned()) + "," + props.isSignLeading() + "," + props.isSignSeparate() + ")";
                break;
            default:
                s = "";
        }
        ClassFile.println("return "+s+';');
        ClassFile.backTab();
        ClassFile.endMethodScope();

        ClassFile.doMethodScope("public " + " void set" + props.getJavaName2() + "("
                + SymbolConstants.get(props.getJavaType().getType()) + " val" + setSubscripts + ") {");
        ClassFile.tab();
        switch (props.getJavaType().getType()) {
            case Constants.BYTE:
            case Constants.SHORT:
            case Constants.INTEGER:
            case Constants.LONG:
                s = "super.toDisplayString(%0," + len
                        + "," + String.valueOf(props.isSigned()) + "," + props.isSignLeading() + "," + props.isSignSeparate() + ")";
                break;
            case Constants.BIGDECIMAL:
                s = "super.toDisplayString(%0," + len + ","
                        + String.valueOf(props.getJavaType().getMaxFractionLength())
                        //               -props.getJavaType().maxScalingLength)
                        + ","+ String.valueOf(props.getJavaType().isIsSigned()) +
                        "," + props.isSignLeading() + "," + props.isSignSeparate() + ")";
                break;
            default:
                s = "";
        }
        ClassFile.println("this." + props.getJavaName1() + modifier2 + "=" + s.replace("%0", "val") + ";");
        ClassFile.backTab();
        ClassFile.endMethodScope();

        ClassFile.doMethodScope("public " + " void set" + props.getJavaName2() + "("
                + "String val" + setSubscripts + ") {");
        ClassFile.tab();
        //s="super.normalizeString(%0,"+String.valueOf(props.getAdjustedLength())+","+
        //String.valueOf(props.getJavaType().getMaxFractionLength())+","+
        //String.valueOf(props.getJavaType().isIsSigned())+")";
        //ClassFile.println("this."+props.getJavaName1()+modifier2+"="+s.replace("%0","val")+";");
        if (props.getJavaType().getType() == Constants.CHAR) {
            ClassFile.println("this." + props.getJavaName1() + modifier2 + "=super.normalizeString(val,"
                    + (len+1) + ",true,true,false).charAt(0);");
        } else {
            ClassFile.println("this." + props.getJavaName1() + modifier2 + "=super.normalizeString(val,"
                    + (len+1) + ",true,true,false);");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
    }

    private void printDisplayNumberAccessor2(SymbolProperties props) {
        String s;
        //Now getters
        ClassFile.doMethodScope("public " + SymbolConstants.get(props.getJavaType().getType())
                + " get" + props.getJavaName2() + "(" + getSubscripts + ") {");
        ClassFile.tab();
        forceDisplayAccessor = false;
        s = getGetterString(props, -1, 0);
        //props.setFillerGetter(s);
        s = "return " + s + ";";
        ClassFile.println(s);
        ClassFile.backTab();
        ClassFile.endMethodScope();
        ClassFile.doMethodScope("public String get" + props.getJavaName2() + "AsString(" + getSubscripts + ") {");
        ClassFile.tab();
        forceDisplayAccessor = true;
        s = getGetterString(props, -1, 0);
        String dottedSignedParms =
                "," + props.getJavaType().isIsSigned() + "," + props.getJavaType().isIsSignLeading() + ","
                + props.getJavaType().isIsSignSeparate();
        s = "return " + s + ";";
        ClassFile.println(s);
        ClassFile.backTab();
        ClassFile.endMethodScope();

        //Now setters
        ClassFile.doMethodScope("public " + " void set" + props.getJavaName2()
                + "(" + SymbolConstants.get(props.getJavaType().getType()) + " val"
                + setSubscripts + ") {");
        ClassFile.tab();
        forceDisplayAccessor = false;
        s = getSetterString(props, -1, 0);
        s += ";";
        ClassFile.println(s);
        ClassFile.backTab();
        ClassFile.endMethodScope();
        ClassFile.doMethodScope("public "
                + " void set" + props.getJavaName2() + "(String val" + setSubscripts + ") {");
        ClassFile.tab();
        forceDisplayAccessor = true;
        s = getSetterString(props, -1, 0).replace(props.getJavaName1() + "=", "fromDottedSignedString(val,"
                + props.getAdjustedLength() + "," + props.getJavaType().getMaxFractionLength()
                + dottedSignedParms + ",");
        s += ";";
        ClassFile.println(s);
        ClassFile.backTab();
        ClassFile.endMethodScope();
        forceDisplayAccessor = false;
    }

    private void printFieldFormat(SymbolProperties props) {
        ClassFile.println("public "
                + ((SymbolTable.getScope().isCurrentProgramTopLevel() || ClassFile.current.isData()) ? "static " : "")
                + "final FieldFormat " + props.getJavaName1() + "Fmt_ = new FieldFormat(\""
                + props.getJavaName1() + "\",\"" + props.getJavaType().getPic() + "\""
                + (props.isBlankWhenZero() ? ",true" : "")
                + ");");
    }

    private void printJavaTypeClassConditionTail(SymbolProperties props) {
        if (props.getJavaType().getUsage() == Constants.DISPLAY || props.getJavaType().getUsage() == Constants.PACKED_DECIMAL) {
            String isNumeric = "";
            String isAlphabetic = "";
            String isAlphabeticLower = "";
            String isAlphabeticUpper = "";

            switch (props.getJavaType().getType()) {
                case Constants.STRING:
                    isNumeric = "return " + props.getJavaName1() + ".matches(\"[0-9+-]*\");";
                    isAlphabetic = "return " + props.getJavaName1() + ".matches(\"[a-zA-Z ]*\");";
                    isAlphabeticLower = "return " + props.getJavaName1() + ".matches(\"[a-z ]*\");";
                    isAlphabeticUpper = "return " + props.getJavaName1() + ".matches(\"[A-Z ]*\");";
                    break;
                case Constants.BIGDECIMAL:
                case Constants.SHORT:
                case Constants.INTEGER:
                case Constants.LONG:
                case Constants.FLOAT:
                case Constants.DOUBLE:
                case Constants.CHAR:
                case Constants.BYTE:
                    isNumeric = "return true;";
                    isAlphabetic = "return false";
                    isAlphabeticLower = "return false";
                    isAlphabeticUpper = "return false";
                    break;
                case Constants.GROUP:
                    isNumeric = "return " + "new String(get" + props.getJavaName2() + "())" + ".matches(\"[0-9+-]*\");";
                    isAlphabetic = "return " + "new String(get" + props.getJavaName2() + "())" + ".matches(\"[a-zA-Z ]*\");";
                    isAlphabeticLower = "return " + "new String(get" + props.getJavaName2() + "())" + ".matches(\"[a-z ]*\");";
                    isAlphabeticUpper = "return " + "new String(get" + props.getJavaName2() + "())" + ".matches(\"[A-Z ]*\");";
                    break;
                default:
                    isNumeric = "return false;";
                    isAlphabetic = "return false";
                    isAlphabeticLower = "return false";
                    isAlphabeticUpper = "return false";
                    break;
            }

            if (props.isNumericTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "Numeric(" + getSubscripts + ") {");
                ClassFile.tab();
                ClassFile.println(isNumeric);
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "Alphabetic(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println(isAlphabetic);
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticLowerTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "AlphabeticLower(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println(isAlphabeticLower);
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticUpperTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "AlphabeticUpper(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println(isAlphabeticUpper);
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
        }
    }
    private String refString = null;
    private String offsetCalc = null;

    public void printCobolByteAccessors(SymbolProperties props) {

        if (props.getIsSuppressed()) {
            return;
        }
        if (props.getIsFiller()) {
            return;
        }
        if (props.isUsedNativeJavaTypes() || props.isFloatingPoint()) {
            printJavaTypesAccessors(props);
            return;
        }
        if (!(props.getRef() || props.getMod() || props.getIsFiller())) {
            return;
        }
        if ((props.getLength() == 0 || props.getJavaType() == null)) {
            return;
        }


        String s;
        preparePrintCobolBytesAccessors(props);
        //String name1=(String) props.getJavaName1();
        String name2 = (String) props.getJavaName2();
        boolean isADisplayNumber = props.isANumber() && props.getDataUsage() == Constants.DISPLAY;
        if (props.isGroupData()) {
            props.setIsFormat(false);
            if (!props.getIsFiller()) {
                ClassFile.doMethodScope("public byte[]"
                        + " get" + name2 + "(" + getSubscripts + ") {");
                ClassFile.tab();
                ClassFile.println("return " + getGetterString(props, -1, 0) + ";");
                ClassFile.backTab();
                ClassFile.endMethodScope();

                ClassFile.doMethodScope("public "
                        + " void set" + name2
                        + "(byte[] val"
                        + setSubscripts + ") {");
                ClassFile.tab();
                ClassFile.println(getSetterString(props, -1, 0) + ";");
                ClassFile.backTab();
                ClassFile.endMethodScope();

                props.setIsFormat(Boolean.FALSE);
            }
            return;
        } else {

            if (FieldFormat.isPlainString(props.getPictureString())) {
                props.setIsFormat(false);
            }

            if (props.getIsFormat()) {
                printFieldFormat(props);
            }
            if (isADisplayNumber) {
                printDisplayNumberAccessor2(props);
            } else {
                //Now getters
                ClassFile.doMethodScope("public " + SymbolConstants.get(props.getJavaType().getType())
                        + " get" + name2 + "(" + getSubscripts + ") {");
                ClassFile.tab();
                s = getGetterString(props, -1, 0);
                //props.setFillerGetter(s);
                s = "return " + s + ";";
                ClassFile.println(s);
                ClassFile.backTab();
                ClassFile.endMethodScope();

                //Now setters
                ClassFile.doMethodScope("public "
                        + " void set" + name2
                        + "(" + SymbolConstants.get(props.getJavaType().getType()) + " val"
                        + setSubscripts + ") {");
                ClassFile.tab();
                s = getSetterString(props, -1, 0);
                //props.setFillerSetter(s);
                s += ";";
                ClassFile.println(s);
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
        }
        if (props.isAsBytesAccessor()) {
            ClassFile.doMethodScope("public " + SymbolConstants.get(props.getJavaType().getType())
                    + " get" + name2 + "AsBytes(" + getSubscripts + ") {");
            ClassFile.tab();
            ClassFile.println("CobolBytes " + SymbolTable.TOSTRING_REF_STRING_
                    + "=new CobolBytes(" + String.valueOf(props.getLength()) + ");");
            printGroupGetBytesOccursLoop(props, -1, props.getUnAdjustedOffset());
            ClassFile.println("return " + SymbolTable.TOSTRING_REF_STRING_ + ".getBytes();");
            ClassFile.backTab();
            ClassFile.endMethodScope();
        }
        printCobolBytesClassConditionTail(props);
        return;
    }

    private void preparePrintCobolBytesAccessors(SymbolProperties props) {
        if ((props.getLevelNumber() == 1 || props.getLevelNumber() == 77)
                && props.getRedefines() != null && props.getPictureString() != null
                && props.getRedefines().getPictureString() == null) {
            refString = props.getRedefines().getJavaName1();
        } else {
            refString = "super";
        }

        getSubscripts = "";
        setSubscripts = "";

        Integer offset = props.getOffset();
        offsetCalc = offset.toString().trim();

        if (props.isOccurs() || props.isAParentInOccurs()) {
            ArrayList<SymbolProperties> a = props.getOccursParents();
            if (a != null && a.size() > 0) {
                //   offsetCalc="";
                int i = 0;
                for (Iterator<SymbolProperties> ite = a.iterator(); ite.hasNext();) {
                    ite.next();
                    ++i;
                    getSubscripts += "int idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                    setSubscripts += ",int idx" + String.valueOf(i);


                }
            }
            offsetCalc = getOccursString(props, -1, 0, offset);
        }
    }

    private void printCobolBytesClassConditionTail(SymbolProperties props) {

        if (props.getJavaType().getUsage() == Constants.DISPLAY || props.getJavaType().getUsage() == Constants.PACKED_DECIMAL) {
            if (props.isNumericTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "Numeric(" + getSubscripts + ") {");
                ClassFile.tab();
                ClassFile.println("return "
                        + refString
                        + ".isNumeric(" + offsetCalc + "," + String.valueOf(props.getLength()) + ");");
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "Alphabetic(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println("return "
                        + refString
                        + ".isAlphabetic(" + offsetCalc + "," + String.valueOf(props.getLength()) + ");");
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticLowerTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "AlphabeticLower(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println("return "
                        + refString
                        + ".isAlphabeticLower(" + offsetCalc + "," + String.valueOf(props.getLength()) + ");");
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
            if (props.isAlphabeticUpperTested()) {
                ClassFile.doMethodScope("public boolean is" + props.getJavaName2() + "AlphabeticUpper(" + getSubscripts
                        + ") {");
                ClassFile.tab();
                ClassFile.println("return "
                        + refString
                        + ".isAlphabeticUpper(" + offsetCalc + "," + String.valueOf(props.getLength()) + ");");
                ClassFile.backTab();
                ClassFile.endMethodScope();
            }
        }
    }

    public String getGetterString(SymbolProperties props, int modifiedIdx, int relativeToUnAdjustedOffset) {

        int offset = getOffset(props, relativeToUnAdjustedOffset);
        int len = props.getLength();
        if ((len == 0 || props.getJavaType() == null)) {
            return "";
        }
        //String refString;

        if ((props.getLevelNumber() == 1 || props.getLevelNumber() == 77)
                && props.getRedefines() != null && !props.isGroupData()
                && props.getRedefines().getPictureString() == null) {
            refString = props.getRedefines().getJavaName1();
        } else {
            refString = "super";
        }

        //String offsetCalc;
        if (modifiedIdx == -2) {
            len = getMaxLen(props);
            offsetCalc = String.valueOf(offset);
        } else {
            offsetCalc = getOccursString(props, modifiedIdx,
                    relativeToUnAdjustedOffset, offset);
        }


        if (props.isGroupData()) {
            return refString + ".getBytes(" + offsetCalc + "," + String.valueOf(len) + ")";
        }

        switch (props.getJavaType().getType()) {
            case Constants.BYTE:
            case Constants.CHAR:
                return getSingleByteGetterString(props, refString, offsetCalc);
            case Constants.SHORT:
            case Constants.INTEGER:
                return getIntegerGetterString(props, refString, offsetCalc);
            case Constants.LONG:
                return getLongGetterString(props, refString, offsetCalc);
            case Constants.FLOAT:
            case Constants.DOUBLE:
            case Constants.BIGDECIMAL:
                return getBigDecimalGetterString(props, refString, offsetCalc);
            case Constants.STRING:
                if (props.getDataUsage() == Constants.DISPLAY) {
                    return refString + ".toString(" + offsetCalc + "," + len + ")";
                } else {
                    return "notAvailable";
                }
            default:
        }
        return "";
    }
    private boolean forceDisplayString = false;

    private int getOffset(SymbolProperties props, int relativeToUnAdjustedOffset) {
        if (forceDisplayString) {
            if (relativeToUnAdjustedOffset > 0) {
                return props.getUnAdjustedOffset() - relativeToUnAdjustedOffset;
            } else {
                return props.getUnAdjustedOffset();
            }
        }
        if (props.isAParentInOccurs()) {
            return props.getUnAdjustedOffset() - props.getOccursParents().get(props.getOccursParents().size() - 1).getUnAdjustedOffset();
        }
        boolean test = (relativeToUnAdjustedOffset <= 0);
        if (RESConfig.getInstance().getOptimizeAlgorithm() == 2
                && (props.isUsedNativeJavaTypes() || props.getIsFiller())) {
            test = (relativeToUnAdjustedOffset < 0);
        }
        return (test) ? props.getOffset() : (props.getUnAdjustedOffset() - relativeToUnAdjustedOffset);
    }

    public String getSetterString(SymbolProperties props, int modifiedIdx, int relativeToUnAdjustedOffset) {

        Integer offset = 0;
        offset = getOffset(props, relativeToUnAdjustedOffset);
        Integer len = props.getLength();
        int usage = props.getDataUsage();
        CobolSymbol sym = (CobolSymbol) props.getJavaType();
        String s = null;
        if ((len == 0 || sym == null)) {
            return "";
        }

        //String refString;
        if ((props.getLevelNumber() == 1 || props.getLevelNumber() == 77)
                && props.getRedefines() != null && props.getPictureString() != null
                && props.getRedefines().getPictureString() == null) {
            refString = props.getRedefines().getJavaName1();
        } else {
            refString = "super";
        }

        // String offsetCalc;
        if (modifiedIdx == -2) {
            len = getMaxLen(props);
            offsetCalc = String.valueOf(offset);
        } else {
            offsetCalc = getOccursString(props, modifiedIdx,
                    relativeToUnAdjustedOffset, offset);
        }

        if (props.isGroupData()) {
            return refString
                    + ".valueOf(" + offsetCalc + ","
                    + len.toString() + ",val"
                    + ",0)";
        }

        switch (sym.getType()) {
            case Constants.BYTE:
            case Constants.CHAR: {
                s = getSingleByteSetterString(props, refString, offsetCalc);
                break;
            }
            case Constants.SHORT:
            case Constants.INTEGER: {
                s = getIntegerSetterString(props, refString, offsetCalc);
                break;
            }
            case Constants.LONG: {
                s = getLongSetterString(props, refString, offsetCalc);
                break;
            }
            case Constants.FLOAT:
            case Constants.DOUBLE:
            case Constants.BIGDECIMAL: {
                {
                    s = getBigDecimalSetterString(props, refString, offsetCalc);
                    break;
                }
            }
            case Constants.STRING: {
                switch (usage) {
                    case Constants.DISPLAY:
                        s = refString
                                + ".valueOf(" + offsetCalc + ","
                                + len.toString().trim() + ","
                                + "val"
                                + ")";
                        break;
                    case Constants.BINARY:
                    case Constants.PACKED_DECIMAL:
                    case Constants.COMPUTATIONAL1:
                    default:
                        s = "notAvailable";
                }
                break;
            }
        }
        return s;
    }

    public String getPointerSetterString(SymbolProperties props) {

        Integer len = props.getLength();
        int usage = props.getDataUsage();
        CobolSymbol sym = (CobolSymbol) props.getJavaType();
        String s = null;
        if ((len == 0 || sym == null)) {
            return "";
        }

        // String refString;
        if ((props.getLevelNumber() == 1 || props.getLevelNumber() == 77)
                && props.getRedefines() != null && props.getPictureString() != null
                && props.getRedefines().getPictureString() == null) {
            refString = props.getRedefines().getJavaName1();
        } else {
            refString = "super";
        }

        if (props.isGroupData()) {
            return refString
                    + ".valueOf(" + offsetCalc + ","
                    + len.toString() + ",val"
                    + ",0);";
        }

        switch (sym.getType()) {
            case Constants.BYTE:
                s = refString + ".setByte(val)";
                break;
            case Constants.CHAR:
                s = refString + ".setChar(val)";
                break;
            case Constants.SHORT:
            case Constants.INTEGER:
                s = refString + ".setInteger(val)";
                break;
            case Constants.LONG:
                s = refString + ".setLong(val)";
                break;
            case Constants.FLOAT:
            case Constants.DOUBLE:
            case Constants.BIGDECIMAL:
                s = refString + ".setBigDecimal(val)";
                break;
            case Constants.STRING:
                switch (usage) {
                    case Constants.DISPLAY:
                        s = refString + ".setString(val)";
                        break;
                    case Constants.BINARY:
                    case Constants.PACKED_DECIMAL:
                    case Constants.COMPUTATIONAL1:
                    default:
                        s = "notAvailable";
                }
                break;
        }
        return s;
    }

    private int getMaxLen(SymbolProperties props) {
        int maxlen = 0;
        if (props.isOccurs() || props.isAParentInOccurs()) {
            ArrayList<SymbolProperties> a = props.getOccursParents();
            if (a != null && a.size() > 0) {
                for (ListIterator<SymbolProperties> ite = a.listIterator(a.size()); ite.hasPrevious();) {
                    props = ite.previous();
                    maxlen += ((props.getMaxOccursInt() > 0) ? props.getLength() * (props.getMaxOccursInt()) : props.getLength());
                }
            }
        } else {
            maxlen = props.getLength();
        }
        return maxlen;
    }

    private int getGroupOccursIdx(SymbolProperties props) {
        return props.getNoOccursSubscripts();
    }

    private String getGroupOccursSignature(SymbolProperties props) {
        String signature = "";
        String subscripts = "";
        int i = 0;
        if (props.isOccurs() || props.isAParentInOccurs()) {
            ArrayList<SymbolProperties> a = props.getOccursParents();
            if (a != null && a.size() > 0) {
                for (Iterator<SymbolProperties> ite = a.iterator(); ite.hasNext();) {
                    ite.next();
                    ++i;
                    signature += "int idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                    subscripts += "idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                }

            }
            props.setIndexesWorkSpace(new ArrayList<String>());
            props.getIndexesWorkSpace().add(subscripts);
        }
        return signature;
    }

    public String getOccursString(SymbolProperties props, int modifiedIdx,
            int relativeToUnAdjustedOffset, Integer offset) {
        return getOccursString(props, modifiedIdx, relativeToUnAdjustedOffset, offset,
                RESConfig.getInstance().getOptimizeAlgorithm() == 0);
    }

    public String getOccursString(SymbolProperties props, int modifiedIdx,
            int relativeToUnAdjustedOffset, Integer offset, boolean hideIndexes) {
        getSubscripts = "";
        setSubscripts = "";
        String offsetCalcLocal = null;
        if (props.isOccurs() || props.isAParentInOccurs()) {
            ArrayList<SymbolProperties> a = props.getOccursParents();
            int i = 1;
            if (a != null && a.size() > 0) {
                for (Iterator<SymbolProperties> ite = a.iterator(); ite.hasNext(); i++) {
                    SymbolProperties curr = ite.next();
                    if (i > modifiedIdx) {
                        if (offsetCalcLocal == null) {
                            if (!hideIndexes) {
                                offsetCalcLocal = "super.__offset(";
                            } else {
                                offsetCalcLocal = "";
                            }
                        } else if (!hideIndexes) {
                            offsetCalcLocal += ',';
                        } else {
                            offsetCalcLocal += '+';
                        }
                        getSubscripts += "int idx" + String.valueOf(i) + ((ite.hasNext()) ? "," : "");
                        setSubscripts += ",int idx" + String.valueOf(i);
                        if (hideIndexes) {
                            if ((offset = getOffset(curr, relativeToUnAdjustedOffset)) == 0) {
                                if (curr.getLength() == 1) {
                                    offsetCalcLocal += "--" + "idx" + String.valueOf(i);
                                } else {
                                    offsetCalcLocal += String.valueOf(curr.getLength()) + "*--" + "idx" + String.valueOf(i);
                                }
                            } else {
                                if (curr.getLength() == 1) {
                                    offsetCalcLocal += String.valueOf(getOffset(curr, relativeToUnAdjustedOffset))
                                            + '+' + "--" + "idx" + String.valueOf(i);
                                } else {
                                    offsetCalcLocal += String.valueOf(getOffset(curr, relativeToUnAdjustedOffset))
                                            + '+' + String.valueOf(curr.getLength()) + "*--" + "idx" + String.valueOf(i);
                                }
                            }
                        } else {
                            offsetCalcLocal += String.valueOf(getOffset(curr, relativeToUnAdjustedOffset))
                                    + ',' + String.valueOf(curr.getLength()) + ',' + "idx" + String.valueOf(i);
                        }

                    }
                }
                if (offsetCalcLocal != null) {
                    if (!hideIndexes) {
                        offsetCalcLocal += ')';
                    }
                    if (props.isAParentInOccurs() && (offset = getOffset(props, relativeToUnAdjustedOffset)) > 0) {
                        offsetCalcLocal += "+" + String.valueOf(offset);
                    }
                    return offsetCalcLocal;
                }
            }
        }
        return offset.toString().trim();
    }

    private String getBigDecimalSetterString(SymbolProperties props, String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".valueOf(" + offsetCalc + ","
                            + String.valueOf(props.getLength()) + ",val,true)";
                } else {
                    return refString + ".setDisplayBigDecimal(" + offsetCalc + ","
                            + props.getLength() + ",val," + String.valueOf(props.getJavaType().getMaxFractionLength()) + ","
                            + String.valueOf(props.isSigned()) + "," + String.valueOf(props.isSignLeading()) + ","
                            + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".setBinaryBigDecimal(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + ",val,"
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + ","
                        + String.valueOf(props.isSigned()) + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".setPackedDecimalBigDecimal(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + ",val,"
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + ","
                        + String.valueOf(props.isSigned()) + ")";
            case Constants.COMPUTATIONAL1:
            case Constants.COMPUTATIONAL2:
                return refString + ".setBinaryBigDecimal(" + offsetCalc + ","
                        + props.getAdjustedLength() + ",new BigDecimal(val)," + String.valueOf(props.getJavaType().getMaxFractionLength());
            default:
                SymbolUtil.reportError();
        }
        return "";
    }

    private String getLongSetterString(SymbolProperties props,
            String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".valueOf(" + offsetCalc + ","
                            + String.valueOf(props.getLength()) + ",val,true)";
                } else {
                    return refString + ".setDisplayLong(" + offsetCalc + ","
                            + props.getLength() + "," + "val" + "," + String.valueOf(props.isSigned()) + ","
                            + String.valueOf(props.isSignLeading()) + "," + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".setBinaryLong(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength()) + ","
                        + "val" + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".setPackedDecimalLong(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + "," + "val" + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.COMPUTATIONAL1:
                return refString + ".setBinaryBigDecimal(" + offsetCalc + "," + props.getAdjustedLength() + ","
                        + "super.normalizeDecimal(val," + props.getAdjustedLength() + "," + props.getJavaType().getMaxFractionLength() + ")" + ","
                        + props.getJavaType().getMaxFractionLength() + ")";
            default:
                SymbolUtil.reportError();
        }
        return "";
    }

    private String getIntegerSetterString(SymbolProperties props, String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".valueOf(" + offsetCalc + ","
                            + String.valueOf(props.getLength()) + ",val,true)";
                } else {
                    return refString + ".setDisplayInt(" + offsetCalc + "," + String.valueOf(props.getLength()) + ",val"
                            + "," + String.valueOf(props.isSigned()) + "," + String.valueOf(props.isSignLeading()) + ","
                            + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".setBinaryInt(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + ",val" + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".setPackedDecimalInt(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength())
                        + ",val" + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.COMPUTATIONAL1:
                return refString + ".setBinaryBigDecimal(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength()) + ","
                        + "super.normalizeDecimal(val," + props.getAdjustedLength() + ","
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + ")" + ","
                        + props.getJavaType().getMaxFractionLength() + ")";
            default:
                SymbolUtil.reportError();
        }
        return "";
    }

    private String getBigDecimalGetterString(SymbolProperties props, String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".toString(" + offsetCalc + ","
                            + String.valueOf(props.getLength())+')';// + "," + String.valueOf(props.getJavaType().getMaxFractionLength()) + "," + props.getJavaType().isIsSigned() + ","
                            //+ props.getJavaType().isIsSignLeading() + "," + props.getJavaType().isIsSignSeparate() + ")";
                } else {
                    return refString + ".getDisplayBigDecimal(" + offsetCalc + ","
                            + String.valueOf(props.getLength()) + "," + String.valueOf(props.getJavaType().getMaxFractionLength()) + ","
                            + String.valueOf(props.isSigned()) + "," + String.valueOf(props.isSignLeading()) + ","
                            + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".getBinaryBigDecimal(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength())
                        + "," + new Integer(props.getJavaType().getMaxFractionLength()).toString().trim() + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".getPackedDecimalBigDecimal(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + ","
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + ")";
            case Constants.COMPUTATIONAL1:
            case Constants.COMPUTATIONAL2:
                return refString + ".getBinaryBigDecimal(" + offsetCalc + "," + String.valueOf(props.getLength()) + ","
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + ").floatValue()";
            default:
                SymbolUtil.reportError();
        }
        return "";
    }

    private String getLongGetterString(SymbolProperties props, String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".toString(" + offsetCalc + ","
                            + String.valueOf(props.getLength())+')' ;//+ "," + props.getJavaType().isIsSigned() + ","
                            //+ props.getJavaType().isIsSignLeading() + "," + props.getJavaType().isIsSignSeparate() + ")";
                } else {
                    return refString + ".getDisplayLong(" + offsetCalc + "," + String.valueOf(props.getLength()) + ","
                            + String.valueOf(props.isSigned()) + "," + String.valueOf(props.isSignLeading()) + ","
                            + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".getBinaryLong(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength()) + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".getPackedDecimalLong(" + offsetCalc + ","
                        + String.valueOf(props.getAdjustedLength()) + ")";
            case Constants.COMPUTATIONAL1:
                return refString + ".getBinaryBigDecimal(" + offsetCalc + "," + String.valueOf(props.getLength()) + ","
                        + new Integer(props.getJavaType().getMaxFractionLength()).toString().trim() + ")";
            default:
                SymbolUtil.reportError();
        }
        return "";
    }

    private String getSingleByteGetterString(SymbolProperties props, String refString, String offsetCalc) {
        if (props.getJavaType().getType() == Constants.CHAR) {
            return refString + ".getChar(" + offsetCalc + ")";
        } else {
            return refString + ".getByte(" + offsetCalc + ")";
        }
    }

    private String getSingleByteSetterString(SymbolProperties props, String refString, String offsetCalc) {
        if (props.getJavaType().getType() == Constants.CHAR) {
            return refString + ".setChar(" + offsetCalc + ",val)";
        } else {
            return refString + ".setByte(" + offsetCalc + ",val)";
        }
    }

    private String getIntegerGetterString(SymbolProperties props, String refString, String offsetCalc) {
        switch (props.getDataUsage()) {
            case Constants.DISPLAY:
                if (forceDisplayAccessor) {
                    return refString + ".toString(" + offsetCalc + ","
                            + String.valueOf(props.getLength())+')';// + "," + props.getJavaType().isIsSigned() + ","
                            //+ props.getJavaType().isIsSignLeading() + "," + props.getJavaType().isIsSignSeparate() + ")";
                } else {
                    return refString + ".getDisplayInt(" + offsetCalc + "," + String.valueOf(props.getLength()) + ","
                            + String.valueOf(props.isSigned()) + "," + String.valueOf(props.isSignLeading()) + ","
                            + String.valueOf(props.isSignLeading()) + ")";
                }
            case Constants.BINARY:
                return refString + ".getBinaryInt(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength()) + ")";
            case Constants.PACKED_DECIMAL:
                return refString + ".getPackedDecimalInt(" + offsetCalc + "," + String.valueOf(props.getAdjustedLength()) + ")";
            case Constants.COMPUTATIONAL1:
                return refString + ".getBinaryBigDecimal(" + offsetCalc + "," + String.valueOf(props.getLength()) + ","
                        + new Integer(props.getJavaType().getMaxFractionLength()).toString().trim() + ")";
            default:
                SymbolUtil.reportError();
                return "";
        }
    }

    private String getJavaTypeSetterString(SymbolProperties props) {
        CobolSymbol sym = (CobolSymbol) props.getJavaType();
        if (sym == null) {
            return "%0";
        }

        switch (sym.getType()) {
            case Constants.SHORT:
            case Constants.INTEGER:
                return "(int) super.normalizeBinary(%0," + String.valueOf(props.getAdjustedLength())
                        + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.LONG:
                return "super.normalizeBinary(%0," + String.valueOf(props.getAdjustedLength())
                        + "," + String.valueOf(props.isSigned()) + ")";
            case Constants.BIGDECIMAL:
                return "super.normalizeDecimal(%0," + String.valueOf(props.getAdjustedLength()) + ","
                        + String.valueOf(props.getJavaType().getMaxFractionLength()) + "," + String.valueOf(props.getJavaType().isIsSigned()) + ")";
            case Constants.STRING:
                return "super.normalizeString(%0," + String.valueOf(props.getLength()) + ","
                        + String.valueOf(props.isJustifiedRight())
                        + ")";
            case Constants.CHAR:
            default:
                return "%0";
        }
    }

    public String getLocalFillerSetter(SymbolProperties props, String fillerVal) {
        return getSetterString(props, -1, -1).replace(",val", "," + fillerVal);
    }

    public String getLocalFillerGetter(SymbolProperties props) {
        return getGetterString(props, -1, -1);
    }

    public String getFillerSetter(SymbolProperties props, String fillerVal) {
        String level01Name = getLevel01Name(props);
        return getLocalFillerSetter(props, fillerVal).replace("super.", ((level01Name == null) ? "" : (level01Name + '.')));
    }
/*
    public String getToStringOrGroupMove(SymbolProperties propsFrom) {
        String level01Name = getLevel01Name(propsFrom);
        return ((level01Name == null) ? ("getProgram().toStringWithoutSign(") : (level01Name + ".toStringWithoutSign("))
                + getOccursString(propsFrom, -1, 0, propsFrom.getOffset(), false)
                + "," + propsFrom.getLength() + "," + propsFrom.isSigned()
                + "," + propsFrom.isSignLeading() + "," + propsFrom.isSignSeparate() + ")";
    }

    public String getFromStringOrGroupMove(SymbolProperties props, String fillerVal) {
        String level01Name = getLevel01Name(props);
        return ((level01Name == null) ? "valueOf(" : (level01Name + ".valueOf(")) + getOccursString(props, -1, 0, props.getOffset(), false) + ","
                + props.getLength() + "," + fillerVal + ")";
    }

 * 
 */
    public String getFillerGetter(SymbolProperties props) {
        String level01Name = getLevel01Name(props);
        return getGetterString(props, -1, -1).
                replace("super.", ((level01Name == null) ? "" : (level01Name + '.')));
    }

    private String getLevel01Name(SymbolProperties props) {
        while ((props = props.getParent()) != null && !props.is01Group()) {
            continue;
        }
        if (props == null) {
            return null;
        } else {
            return props.getJavaName1();
        }
    }

    private void printClass88s(SymbolProperties props) {
        ArrayList<SymbolProperties> a = (ArrayList<SymbolProperties>) props.getChildren();
        if (a != null) {
            //boolean isNativeJavaType=RESConfig.getInstance().isUseNativeJavaTypes();
            for (SymbolProperties child : a) {
                if (child.getLevelNumber() != 88) {
                    break;
                }
                Main.getContext().getCobol2Java().doOne88(child);
            }
        }
    }

    public void printClassAccessors(SymbolProperties props,
            String name1, String name2) {

        if (name1.equals("sqlca")) {
            ClassFile.println("public " + name2 + " " + name1 + " = new " + name2 + "();");
        } else if (props.getRedefines() == null) {
            ClassFile.println("private " + name2 + " " + name1 + " = new " + name2 + "();");
        } else {
            if (props.getRedefines().is01Group()) {
                ClassFile.println("private " + name2 + " " + name1 + " = new " + name2 + "("
                        + props.getRedefines().getJavaName1()
                        + ");");
            } else {
                String exprString = "this," + String.valueOf(props.getRedefines().getOffset()) + ","
                        + String.valueOf(props.getLength());
                ClassFile.println("private " + name2 + " " + name1 + " = new " + name2 + "(" + exprString
                        + ");");
            }
        }
        if (!RESConfig.getInstance().isUsePointers()) {
            ClassFile.println("public byte[] get" + name2 + "() {");
            ClassFile.println("\treturn " + name1 + ".getBytes();");
            ClassFile.println("}");
            ClassFile.println("public void set" + name2 + "(byte[] val) {");
            ClassFile.println("\t" + name1 + ".valueOf(val);");
            ClassFile.println("}");
        } else {
            ClassFile.println("public BytesField get" + name2 + "() {");
            ClassFile.println("\treturn " + name1 + "." + name1 + "Fld_;");
            ClassFile.println("}");
            ClassFile.println("public void set" + name2 + "(byte[] val) {");
            ClassFile.println("\t" + name1 + ".valueOf(val);");
            ClassFile.println("}");
        }

        printClassConditionTail(props);
    }

    private void printClassConditionTail(SymbolProperties props) {
        if (props.isUsedNativeJavaTypes()) {
            printJavaTypeClassConditionTail(props);
        } else {
            preparePrintCobolBytesAccessors(props);
            printCobolBytesClassConditionTail(props);
        }
    }

    private void printStringAccessors(SymbolProperties props) {
        ClassFile.doMethodScope("public String toString() {");
        ClassFile.tab();
        if (props.hasChildren()) {
            ClassFile.println("return new String(getBytes());");
        } else {
            ClassFile.println("return \"\";");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
        ClassFile.doMethodScope("public void valueOf(String val) {//Bytes Vs. Chars");
        ClassFile.tab();
        if (props.hasChildren()) {
            ClassFile.println("valueOf(val.getBytes());");
        } else {
            ClassFile.println("return;");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
    }

    private void printConstructors(SymbolProperties props, Integer adjLen) {
        ClassFile.doMethodScope("public " + props.getJavaName2() + "() {");
        ClassFile.tab();
        if (//(!props.isUsedNativeJavaTypes()||RESConfig.getInstance().getOptimizeAlgorithm()==2)
                //&&
                adjLen > 0) {
            ClassFile.println("super(new CobolBytes(" + String.valueOf(adjLen) + "));");
        } else {
            ClassFile.println("super();");
        }
        ClassFile.backTab();
        ClassFile.endMethodScope();
        ClassFile.doMethodScope("public " + props.getJavaName2() + "(CobolBytes b) {//For redefines");
        ClassFile.println("\tsuper(b); }");
        ClassFile.doMethodScope("public " + props.getJavaName2() + "(CobolBytes b,int off,int len) {//For redefines");
        ClassFile.println("\tsuper(b,off,len); }");
    }

    private void printInitialize(SymbolProperties props) {
        ClassFile.doMethodScope("public void initialize(Program p) {");
        ClassFile.tab();
        ClassFile.println("__setProgram(p);");
        printInit(props);
        ClassFile.backTab();
        ClassFile.endMethodScope();
    }

    private void printInit(SymbolProperties props) {
        if (props.hasChildren()) {
            for (SymbolProperties child : props.getChildren()) {
                Main.getContext().getCobol2Java().initializeOneSymbol(child);
                if (child != null && child.getChildren() != null) {
                    printInit(child);
                }
            }
        }
    }

    public static void reportError() {
        try {
            throw new InvalidCobolFormatException("");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    public void reportError(SymbolProperties props, String msg) {
        System.out.println("@CobolSourceFile(\"" + props.getDataDescriptionEntry().sourceFile + "\","
                + props.getDataDescriptionEntry().line
                + "):" + msg);
        System.exit(0);
    }

    public void reportError(String msg) {
        System.out.println("@CobolSourceFile(\"" + Main.getContext().getSourceFileName() + "):" + msg);
        System.exit(0);
    }
}
 public class ClassFile {
	
	public static ClassFileWriter current=null;
	public static Stack<ClassFileWriter> files=new Stack<ClassFileWriter>();
	
	public PrintWriter out = null;
	public boolean importJavaUtil = false;
	public boolean importJavaIo = false;
	
	public static void doProgramScope(SymbolProperties props, boolean dataLevel) {
		if (files==null)
			files=new Stack<ClassFileWriter>();
		if(dataLevel)
			current=new DataClassFileWriter(props);
		else  {
			if(SymbolTable.getScope().isCurrentProgramTopLevel()) {			
			current=new ProgramClassFileWriter(props);
			} else
				((ProgramClassFileWriter)current).printHeader(props,true);
		}
		files.push(current);
	}

	public static void doProgramScope(ClassFileWriter gen) {
		current=gen;
		files.push(current);
	}

	public static void endProgramScope() {
		if(current==null)
			return;
		current.println("}");
		current.println("}",true);
		if(files.peek().isData()||SymbolTable.getScope().isCurrentProgramTopLevel()) {			
		current.close();
		
		} else 
			current.backTab();
		files.pop();
		if(files.size()>0) {
			current=files.peek();
		} else {
			current=null;
		}
	}

	public static void doMethodScope(String line,boolean bi) {
		if(current==null)
			return;
		current.println(line,bi);
	}

	public static void endMethodScope(boolean bi) {
		if(current==null)
			return;
		current.println("}",bi);
	}

	public static void println(String line,boolean bi) {
		if(current==null)
			return;
		current.println(line,bi);
	}
	
	public static void print(String line,boolean bi) {
		if(current==null)
			return;
		current.print(line,bi);
	}
	
	public static void printPlainln(String line,boolean bi) {
		if(current==null)
			return;
		current.println(line,bi);
	}
	
	public static void printPlain(String line,boolean bi) {
		if(current==null)
			return;
		current.print(line,bi);
	}
	
	public static void printPlain(char c,boolean bi) {
		if(current==null)
			return;
		current.printPlain(c,bi);
	}

	public static void tab(boolean bi) {
		if(current==null)
			return;
		current.tab(bi);
	}
	
	public static void backTab(boolean bi) {
		if(current==null)
			return;
		current.backTab(bi);
	}
	
	////
	
	public static void doMethodScope(String line) {
		if(current==null)
			return;
		current.println(line);
	}

	public static void endMethodScope() {
		if(current==null)
			return;
		current.println("}");
	}

	public static void println(String line) {
		if(current==null)
			return;
		current.println(line);
	}
	
	public static void print(String line) {
		if(current==null)
			return;
		current.print(line);
	}
	
	public static void printPlainln(String line) {
		if(current==null)
			return;
		current.println(line);
	}
	
	public static void printPlain(String line) {
		if(current==null)
			return;
		current.print(line);
	}
	
	public static void printPlain(char c) {
		if(current==null)
			return;
		current.printPlain(c);
	}

	public static void tab() {
		if(current==null)
			return;
		current.tab();
	}
	
	public static void backTab() {
		if(current==null)
			return;
		current.backTab();
	}


	
	
}
 public class NameUtil {

 public static String convertCobolNameToJava(String cobolName,boolean firstUpper) {
  
  if(cobolName==null) return "";
  
  cobolName = cobolName.toUpperCase();
 
  StringBuilder javaName=new StringBuilder(cobolName.length()+5);
  
  int i=0;
  int j=0;
  
  while(i<cobolName.length()) {
   if(i==0) {
    if(cobolName.charAt(i)>='A'&&cobolName.charAt(i)<='Z') {
     if(firstUpper)
      javaName.append(cobolName.charAt(i));
     else
      javaName.append((char)NameUtil.lowerCase[cobolName.charAt(i)-'A']);
    }
    else {
     javaName.append("_").append(cobolName.charAt(i));
    }
   } else
    if(cobolName.charAt(i)=='-'||cobolName.charAt(i)=='.') {
     i++;
     if(cobolName.charAt(i)>='A'&&cobolName.charAt(i)<='Z') {
      javaName.append(cobolName.charAt(i));
     } else { 
      javaName.append('_');
      if(cobolName.charAt(i)>='0'&&cobolName.charAt(i)<='9') 
       javaName.append(cobolName.charAt(i));
     }
    } else {
     if(cobolName.charAt(i)>='A'&&cobolName.charAt(i)<='Z') {
      javaName.append((char)NameUtil.lowerCase[cobolName.charAt(i)-'A']);
     }
     else if(cobolName.charAt(i)>='0'&&cobolName.charAt(i)<='9'||cobolName.charAt(i)=='_')
      javaName.append(cobolName.charAt(i));
     else;
    }
   i++;
   j++;
  }
  String name=javaName.toString().trim();
  if(JAVA_RESERVED_WORDS.contains(name.toLowerCase()))
   name+=String.valueOf(nameMark++)+"_";
  return name;
 }

 private static byte[] lowerCase =
 {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
  's','t','u','v','w','x','y','z'};

 public static String getJavaName(SymbolProperties props2,boolean lastSet) {
  return getJavaName(props2,lastSet,false);
 }
 @SuppressWarnings("unchecked")
 public static String getJavaName(SymbolProperties props2,boolean lastSet,boolean asString) {
  if(props2.getType()==SymbolConstants.DUMMY)
   if(!lastSet)return "getNull()";
   else return "setNull(%0)";
  if(props2.getIsFiller())
   if(!lastSet) return SymbolUtil.getInstance().getFillerGetter(props2);
   else return SymbolUtil.getInstance().getFillerSetter(props2, "%0");
  
  SymbolProperties props;
  String s = ""; 
  
  if(props2.isVaryingArray()&&props2.getParent().isVarying()) {
   props2=props2.getParent();
  }
  else 
   if(props2.isVaryingLen()&&props2.getParent().isVarying()){
    if(!lastSet) return getJavaName(props2.getParent(),false)+".length()";
    else { 
     RunTimeUtil.getInstance().reportError("Warning: Setting Varying Length Ignored.",false);
     return "setNull(%0)";
    }
   }
  
  if(props2.getLevelNumber()==1&&props2.getPictureString()==null||
    (props2.getLevelNumber()==88&&
      (props2.getParent().getLevelNumber()==1||props2.getParent().getLevelNumber()==77)&&
    props2.getPictureString()==null)) {
   if(RESConfig.getInstance().isUsePointers()) {
     s="get"+getJavaName2(props2)+(asString?"AsString":"")+"()";
    if(lastSet) {
     s+="set"+"(%0)";
    }
   } else {
    if(!lastSet) {
     s="get"+getJavaName2(props2)+(asString?"AsString":"")+"()";
    } else {
     s="set"+getJavaName2(props2)+"(%0)";
    }
   }
   if(!lastSet&&asString) {
       props2.setIdentifierType(Main.getContext().getCobol2Java().expressionType=Constants.STRING);
      }
   if(NameUtil.appendInstance)
    return "instance_." +s;
   else
    return s;
  }
  
  props=props2;
  
  @SuppressWarnings("rawtypes")
  Stack st = new Stack();
  boolean isFirst=true;
  while(props!=null) {
   if(!props.getIsSuppressed()&&!(props.getIsFiller()&&!props.is01Group()))
    if(props.getType()==SymbolConstants.DATA)
     if(props.getLevelNumber()==1||
       props.getLevelNumber()==77||isFirst)
      st.push(props);
   props=(SymbolProperties)props.getParent();
   isFirst=false;
  }
  
  boolean doRefModSet=false;
  String refModSet = "";
  if(lastSet&&!(props2.getSubstringWorkSpace()==null||props2.getSubstringWorkSpace().size()<=0)) {
   doRefModSet=true;
  }
  boolean first=true;
  while(st!=null&&st.size()>0) {
   props = (SymbolProperties) st.pop();
   if(!first) {
    s+=".";
    if(doRefModSet) 
     refModSet+=".";
   }
   
   if(st.size()>0) {
    s+=getJavaName1(props);
    if(doRefModSet) refModSet+=getJavaName1(props);
   }
   else
   if(!lastSet){
    s+="get"+getJavaName2(props)+(asString?"AsString":"");
   }
   else {
    if(doRefModSet) refModSet+="get"+getJavaName2(props)+(asString?"AsString":"");
    s+="set"+getJavaName2(props);
   }
   first=false;
  }
  if(!lastSet){
    s+="("+NameUtil.getJavaIndexes(props2)+")";
  }
   else {
    if(RESConfig.getInstance().isUsePointers()) {
     s="get"+getJavaName2(props2)+(asString?"AsString":"")+"()";
     if(lastSet) {
      s+="set"+"(%0)";
     }
    } else {
     String ind;
     if((ind=NameUtil.getJavaIndexes(props2)).length()<=0) {
      s+="(%0)";
      if(doRefModSet) {
       refModSet+="()";
      }
     }
     else {
      s+="(%0," +ind+ ")";
      if(doRefModSet) {
       refModSet+="("+ind+")";
      }
     }
    }
   }
  
  if(!lastSet)
   s=NameUtil.doRefMod(props2,s);
  else
   if(doRefModSet)
    s=NameUtil.doRefMod2(props2,s,refModSet);
  
  if(NameUtil.appendInstance)
   return "instance_."+s;
  else
   return s;
 }

 public static String getJavaIndexes(SymbolProperties props) {
  if (props.getIndexesWorkSpace()==null||props.getIndexesWorkSpace().size()<=0) return "";
  String s="";
  if(props.getIndexesWorkSpace()!=null&&props.getIndexesWorkSpace().size()>0) {
   for(Iterator<String> ite=props.getIndexesWorkSpace().iterator();ite.hasNext();) {
    s+=ite.next();
    if(ite.hasNext())
     s+=",";
   }
  }
  return s;
 }

 static String doRefMod(SymbolProperties props,String s){

     if (props.getSubstringWorkSpace() == null || props.getSubstringWorkSpace().size() <= 0) {
         return s;

     }
     if (props.getIsFormat()) {
         s = NameUtil.getFormatName2(props, true).replace("%0", s);

     }
     s = "new CobolString(" + s + ").substring(" + NameUtil.simplify(props.getSubstringWorkSpace().get(0));
     if (props.getSubstringWorkSpace().size() > 1) {
         s += "," + NameUtil.simplify(props.getSubstringWorkSpace().get(1));

     }
     s += ")";

     //s = TranslationTable.getInstance().convertType(s, props.getJavaType().type, Constants.STRING);
     props.setIdentifierType(Constants.STRING);
     return s;

 }
 static String doRefMod2(SymbolProperties props,String s,String g){//Set RefMod
     if (props.getSubstringWorkSpace() == null || props.getSubstringWorkSpace().size() <= 0) {
         return s;


     }
     String refMod = "new CobolString(" + g + ")";

     refMod = refMod + ".refMod(%0," + props.getSubstringWorkSpace().get(0);
     if (props.getSubstringWorkSpace().size() > 1) {
         refMod += "," + props.getSubstringWorkSpace().get(1);

     }
     refMod += ")";
     s = s.replace("%0", TranslationTable.getInstance().convertType(refMod, props.getJavaType().getType(), Constants.STRING));
     return s;
 }

 static String simplify(String expr) {
  return expr;//simply.simplify(expr);
 }

 @SuppressWarnings("unchecked")
 @Deprecated
 public static String getFormatName(final SymbolProperties props2,boolean force) {
  if(!props2.getIsFormat())
   return "";
  SymbolProperties props=props2;
  String s = "";
  @SuppressWarnings("rawtypes")
  Stack st = new Stack();
  while(props!=null) {
   if(!props.getIsSuppressed())
    if(props.getType()==SymbolConstants.DATA)
     if(props.getLevelNumber()==1||
       props.getLevelNumber()==77||props.getPictureString()!=null)
      st.push(props);
   
   props=(SymbolProperties)props.getParent();
  }
  boolean first=true;
  while(st!=null&&st.size()>0) {
   props = (SymbolProperties) st.pop();
   String name1=(String)getJavaName1(props);
   String name2=(String)getJavaName2(props);
   if(!first)
    s+=".";
   if(st.size()==0){
    s+=name1+"Fmt_";
   }
   else 
    s+=name2;
   first=false;
  }
  return s+".format";
 }

 public static String getSetName(SymbolProperties props2) {
  return "set"+getJavaName2(props2);
 }

 public static String getFileName(SymbolProperties props2, boolean isData) {
  String s=getJavaName2(props2)+".java";
  return s;
 }

 public static String getBeanInfoFileName(SymbolProperties props2, boolean isData) {
  String s=getJavaName2(props2)+"BeanInfo.java";
  return s;
 }

 public static String getPackageName(SymbolProperties props2, boolean programPackage) {
 
  RESConfig config = RESConfig.getInstance();
  
  if(programPackage)
    return config.getProgramPackage().replace('\\', '.');
  else {
   
   SymbolProperties props=props2;

   props=SymbolTable.getScope().getFirstProgram();
   
   if(props!=null&&!props.isProgram()) props=null;
   
   return config.getDataPackage().replace('\\', '.')+
    ((RESConfig.getInstance().isLongDataPackageName()&&props!=null)?
      ('.'+props.getJavaName1().toLowerCase()):"");

  }
 }

 public static String getPathName(String fileName,String suffix,boolean isData) {
  String p=null;
  if(isData) 
   p=RESConfig.getInstance().getDataPackage();
  else
   p=RESConfig.getInstance().getProgramPackage();
  p=p.toLowerCase().replace('.', '\\')+'\\';
  if(suffix!=null&&suffix.trim().length()>0) 
   p+=suffix.toLowerCase().replace('.','\\');
  p+='\\'+NameUtil.getClassName(fileName,suffix,isData);
  p+=".java" ;
  
  return p;
 }
 
 public static String getPackageName(String suffix,boolean isData) {
  String p=null;
  if(isData) 
   p=RESConfig.getInstance().getDataPackage();
  else
   p=RESConfig.getInstance().getProgramPackage();
  if(suffix!=null&&suffix.trim().length()>0) 
   p+='.'+suffix.toLowerCase();
  return p;
 }

 public static String getClassName(String fileName,String suffix,boolean isData) {
  String c=convertCobolNameToJava(fileName, true);
  if(suffix!=null&&suffix.trim().length()>0) {
   c+=convertCobolNameToJava(suffix, true);
  } 
  return c;
 }

 public static String getLongClassName(String fileName,String suffix,boolean isData) {
  String lc=getPackageName(suffix,isData)+"."+convertCobolNameToJava(fileName, true);
  if(suffix!=null&&suffix.trim().length()>0) {
   lc+=convertCobolNameToJava(suffix, true);
  } 
  return lc;
 }

 public static String getProgramName(SymbolProperties props) {
  while(props!=null&&props.getType()!=SymbolConstants.PROGRAM)
   props=props.getParent();
  if(props!=null)
   return props.getDataName();
  return "";
 }

 private static boolean appendInstance=false;

 private static final TreeSet<String> JAVA_RESERVED_WORDS= new TreeSet<String>();

 static {
  ((Collection)JAVA_RESERVED_WORDS).addAll(Arrays.asList(new String[]{
    "abstract","continue","for","new","switch","assert",
    "default","goto","package","synchronized","boolean",
    "do","if","private","this","break","double","implements",
    "protected","throw","byte","else","import","public",
    "throws","case","enum","instanceof","return","transient",
    "catch","extends","int","short","try","char","final",
    "interface","static","void","class","finally","long",
    "strictfp","volatile","const","float","native","super","while"
    }))
   ;
  
 }
 
 public static long nameMark=1;
 
 public static String getJavaName1(SymbolProperties props) {
  if(props.getJavaName1()!=null)
   return props.getJavaName1();
  RunTimeUtil.getInstance().reportError("Error: Java name for " +props.getDataName()+
    " is null. Contact RES support.", true);
  return "nullName";

 }
 
 public static String getJavaName2(SymbolProperties props) {
  if(props.getJavaName2()!=null)
   return props.getJavaName2();
  RunTimeUtil.getInstance().reportError("Error: Java name for " +props.getDataName()+
    " is null. Contact RES support.", true);
  return "NullName";
 }
 
 public static String convertCobolNameToSQL(String name) {
  return convertCobolNameToJava(RunTimeUtil.getInstance().stripQuotes(name.toUpperCase()).replace('.', '_'),true);
 }

 public static String getFormatName2(SymbolProperties lhs, boolean b) {
  
  if(!lhs.getIsFormat()||lhs.getType()==SymbolConstants.DUMMY){
   lhs.setIsFormat(false);
   return "%0";
  }
  
  SymbolProperties props=lhs;
  String s = "";
  Stack<SymbolProperties> st = new Stack<SymbolProperties>();
  while(props!=null) {
   if(!props.getIsSuppressed())
    if(props.getType()==SymbolConstants.DATA)
     if(props.getLevelNumber()==1||
       props.getLevelNumber()==77||props.getPictureString()!=null)
      st.push(props);
   
   props=(SymbolProperties)props.getParent();
  }
  
  boolean first=true;
  
  while(st!=null&&st.size()>0) {
   props = (SymbolProperties) st.pop();
   String name1=(String)getJavaName1(props);
   String name2=(String)getJavaName2(props);
   if(!first)
    s+=".";
   if(st.size()==0){
    s+=name1+"Fmt_";
   }
   else 
    s+=name2;
   first=false;
  }
  /*
  if(Main.getContext().isDecimalPointIsComma()) 
   if(Main.getContext().getCurrencySign()!=null)
    return s+".format(%0,"+Main.getContext().getCurrencySign()+",true"+")";
   else 
    return s+".format(%0"+",true"+")";
  else
   if(Main.getContext().getCurrencySign()!=null)
    return s+".format(%0,"+Main.getContext().getCurrencySign()+",false)";
   else */
    return s+".format(%0)";
 
 }
}

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import com.res.cobol.RESNode;
import com.res.cobol.TreeToCommentFormatter;
import com.res.cobol.parser.CobolParserConstants;
import com.res.cobol.syntaxtree.*;
import com.res.cobol.visitor.DepthFirstVisitor;
import com.res.common.RESConfig;
import com.res.common.RESContext;
import com.res.java.lib.Constants;
import com.res.java.lib.RunTimeUtil;
import com.res.java.translation.symbol.SymbolProperties.CobolSymbol;
import com.res.java.translation.symbol.SymbolConstants;
import com.res.java.translation.symbol.SymbolProperties;
import com.res.java.translation.symbol.SymbolTable;
import com.res.java.translation.symbol.SymbolUtil;
import com.res.java.util.ClassFile;
import com.res.java.util.NameUtil;
import java.math.BigDecimal;

    private ArrayList<Node> delayedStatements = null;

    @Override
    public void visit(DataDescriptionEntry n) {

        if (n.nodeChoice.which == 5) {
            NodeChoice nodech = (NodeChoice) ((NodeSequence) n.nodeChoice.choice).elementAt(2);
            if (nodech.which == 3) {
                //DECLARE CURSOR
                if (delayedStatements == null) {
                    delayedStatements = new ArrayList<Node>();
                }
                delayedStatements.add(n);
            }
        }
        //super.visit(n);
    }
    private String returnLine = null;

    @Override
    public void visit(ProcedureDivision n) {

        if (SymbolTable.getScope().getCurrentProgram() == null) {
            return;
        }
        aLine.push(new StringBuilder());
        returnLine = null;
        isLastGotoStatement = false;
        ClassFile.doProgramScope(SymbolTable.getScope().getCurrentProgram(), false);
        ClassFile.tab();

        //Create Symbols and Accessors.
        SymbolTable.convert2Java();

        String className = (String) SymbolTable.getScope().getCurrentProgram().getJavaName2();
        if (SymbolTable.getScope().isCurrentProgramTopLevel()) {
            ClassFile.println("public static void main(String[] args) {");
            ClassFile.tab();
            ClassFile.println("__processCmdLineArgs(args);");
            ClassFile.println(className + " instance_ = new " + className + "();");
            ClassFile.println("instance_.execute(null); ");
            ClassFile.println("System.exit(instance_.__getReturnCode());");
            ClassFile.backTab();
            ClassFile.endMethodScope();
        }

        ClassFile.println("public void execute(ProgramEnv __env) {");
        ClassFile.tab();
        ClassFile.println("initialize(this); ");
        if (n.nodeOptional.present()) {
            NodeList nodelist = ((UsingArgs) ((NodeSequence) n.nodeOptional.node).elementAt(1)).nodeList;
            processUsingArgs1(nodelist);
        }
        if (delayedStatements != null) {
            for (Node nd : delayedStatements) {
                nd.accept(execSql2Java);
            }
        }
        if (n.procedureBody.paragraphs.nodeListOptional.present()) {
            n.procedureBody.paragraphs.nodeListOptional.accept(this);
        }
        if (!isLastGotoStatement) {
            ClassFile.println("doCobolGotoStart();");
        }
        if (n.nodeOptional.present()) {
            NodeList nodelist = ((UsingArgs) ((NodeSequence) n.nodeOptional.node).elementAt(1)).nodeList;
            processUsingArgs2(nodelist);
        }

        ClassFile.backTab();
        ClassFile.endMethodScope();

        aLine.pop();
        if (n.nodeOptional1.present()) {
            dumper.startAtNextToken();
            dumper.visit(n.nodeOptional1);
            n.nodeOptional1.accept(this);
        }
        if (n.procedureBody.paragraphs.nodeListOptional1.present()) {
            n.procedureBody.paragraphs.nodeListOptional1.accept(this);
        }
        if (n.procedureBody.nodeListOptional.present()) {
            n.procedureBody.nodeListOptional.accept(this);
        }
        doTail();

    }

    private void processUsingArgs2(NodeList nodelist) {
        aLine.peek().setLength(0);
        bLine.push(new StringBuilder());
        for (Enumeration<Node> e = nodelist.elements(); e.hasMoreElements();) {
            e.nextElement().accept(this);
            if (aLine.peek().length() > 0) {
                aLine.peek().append(',');
            }
            if (props != null) {
                // if (props.getIsFormat()) {
                //   line = NameUtil.getFormatName2(props, false).replace("%0", NameUtil.getJavaName(props, false));
                //} else {
                line = new ExpressionString(props).toString();
                //}
                aLine.peek().append(line);
            }
        }
        aLine.peek().append(bLine.peek());
        ClassFile.println(aLine.peek().insert(0, "doCobolReturn(").append(");").toString());
        returnLine = aLine.peek().toString();
        bLine.pop();
    }

    private void processUsingArgs1(NodeList nodelist) {
        ClassFile.println("__initializeCall(__env," + String.valueOf(nodelist.size())
                + ");");
        int i = 0;
        for (Enumeration<Node> e = nodelist.elements(); e.hasMoreElements();) {
            e.nextElement().accept(this);
            if (props != null) {
                if (props.isAChildHasDependingOn() || (props.isOccurs() && props.getDependingOnOccurs() != null)) {
                    aLine.peek().append(ClassFile.current.getTabs()).append(NameUtil.getJavaName(props, true).replace("%0",

                            ("__get" + SymbolConstants.getSQL(props.getIdentifierType()) + "Arg("
