Package org.oorexx.language.directive

Examples of org.oorexx.language.directive.OORexxMethod


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

public class LinesToOORexxMethod {
  public static OORexxMethod convert(List<String> lines){
    OORexxMethod method = new OORexxMethod();
    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("::method") && method.getName() == null){
         
          method.setName(words[1]);
         
          method.setExpose(parseExposeInMethodDirective(line));
        }
        if(words[0].toLowerCase().equals("::method") && words[i].toLowerCase().equals("public")){
          method.setAccessModifier(OORexxAccessModifier.PUBLIC);
        }
       
        if(words[0].toLowerCase().equals("::method") && words[i].toLowerCase().equals("private")){
          method.setAccessModifier(OORexxAccessModifier.PRIVATE);
        }
        try{
          if(optionList.contains(OORexxDirectiveOption.valueOf(words[i].toUpperCase())))
            method.addOption(OORexxDirectiveOption.valueOf(words[i].toUpperCase()));
        }catch(IllegalArgumentException ex){
         
        }
        if(!words[0].toLowerCase().equals("::method")){
          if(i == 0)
          content.append(line + "\n");
        }
       
        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);
          }
         
          method.setExpose(expose);
        }
       
        if(words.length > 2 && words[0].toLowerCase().equals("use") && words[1].toLowerCase().equals("arg") && method.getUse() == null){
          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);
          }
         
          method.setUse(use);
        }
       
        if(words.length > 2 && words[0].toLowerCase().equals("parse") && words[1].toLowerCase().equals("args") && method.getUse() == null){
          OORexxUse use = new OORexxUse();
         
          String tmpLine = line.replaceAll("(?i)parse args", "");
          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);
          }
           
          method.setUse(use);
        }
       
      }
     
    }
    method.setName(method.getName().replace("\"", "").replace("'", ""));
    method.setContent(content);
    method.setReturnsValue(content.toString().toLowerCase().contains("return"));
 
    if(method.hasOption(OORexxDirectiveOption.EXTERNAL))
      for(String line: lines){
        if(line.toLowerCase().contains("::method")){
          method.setExternalLibrary(LibraryExtractor.extractExternalLibrary(line));
          break;
        }
      } 
   
    return method;
View Full Code Here

TOP

Related Classes of org.oorexx.language.directive.OORexxMethod

Copyright © 2018 www.massapicom. 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.