Examples of OORexxRoutine


Examples of org.oorexx.language.directive.OORexxRoutine

import org.oorexx.language.statement.OORexxExpose;
import org.oorexx.language.statement.OORexxUse;

public class LinesToOORexxRoutine {
  public static OORexxRoutine convert(List<String> lines){
    OORexxRoutine routine = new OORexxRoutine();
    StringBuilder content = new StringBuilder();
    List<OORexxDirectiveOption> optionList = Arrays.asList(OORexxDirectiveOption.values());
   
    for(String line: lines){
      String[] words = line.replaceAll(";", "").split(" +");
     
      for(int i = 0; i < words.length ; i++){
        if(words[0].toLowerCase().equals("::routine")){
          routine.setName(words[1]);
        }
        if(words[0].toLowerCase().equals("::routine") && words[i].toLowerCase().equals("public")){
          routine.setAccessModifier(OORexxAccessModifier.PUBLIC);
        }
       
        if(words[0].toLowerCase().equals("::routine") && words[i].toLowerCase().equals("private")){
          routine.setAccessModifier(OORexxAccessModifier.PRIVATE);
        }
       
        if(!words[0].toLowerCase().equals("::routine")){
          if(i == 0)
          content.append(line + "\n");
        }
        try{
          if(optionList.contains(OORexxDirectiveOption.valueOf(words[i].toUpperCase())))
            routine.addOption(OORexxDirectiveOption.valueOf(words[i].toUpperCase()));
          }catch(IllegalArgumentException ex){
           
          }
        if(words[0].toLowerCase().equals("expose")){
          OORexxExpose expose = new OORexxExpose();
         
          for(int k = 1; k < words.length ; k++){
            OORexxVariable var = new OORexxVariable();
              var.setName(words[k]);
            expose.appendVariable(var);
          }
         
          routine.setExpose(expose);
        }
       
        if(words.length > 2 && words[0].toLowerCase().equals("use") && words[1].toLowerCase().equals("arg")){
          OORexxUse use = new OORexxUse();
         
          String tmpLine = line.replaceAll("(?i)use arg", "");
          tmpLine = tmpLine.replaceAll(" ", "");
          if(tmpLine.contains(","))
            for(String svar: tmpLine.split(",")){
              OORexxVariable var = new OORexxVariable();
                var.setName(svar);
              use.appendVariable(var);
            }
          else{
            OORexxVariable var = new OORexxVariable();
              var.setName(words[2]);
              use.appendVariable(var);
          }
           
          routine.setUse(use);
        }
       
        if(words.length > 2 && words[0].toLowerCase().equals("parse") && words[1].toLowerCase().equals("args")){
          OORexxUse use = new OORexxUse();
         
          String tmpLine = line.replaceAll("(?i)use arg", "");
          tmpLine = tmpLine.replaceAll(" ", "");
          if(tmpLine.contains(","))
            for(String svar: tmpLine.split(",")){
              OORexxVariable var = new OORexxVariable();
                var.setName(svar);
              use.appendVariable(var);
            }
          else{
            OORexxVariable var = new OORexxVariable();
              var.setName(words[2]);
              use.appendVariable(var);
          }
           
          routine.setUse(use);
        }
       
      }
     
    }
    routine.setName(routine.getName().replace("\"", "").replace("'", ""));
    routine.setContent(content);
    routine.setReturnsValue(content.toString().toLowerCase().contains("return "));
   
    if(routine.hasOption(OORexxDirectiveOption.EXTERNAL))
      for(String line: lines)
        if(line.toLowerCase().contains("::method")){
          routine.setExternalLibrary(LibraryExtractor.extractExternalLibrary(line));
          break;
        }
   
    return routine;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.