Package tool.model.grammar.proxy

Source Code of tool.model.grammar.proxy.ProxyTest

package tool.model.grammar.proxy;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import junit.framework.Assert;

import org.antlr.grammar.v3.ANTLRParser.tokensSpec_return;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.junit.BeforeClass;
import org.junit.Test;

import tool.model.ToolPlan;
import tool.model.grammar.ANTLRTest;
import tool.model.grammar.ForteLexer;
import tool.model.grammar.FortePRXParser;
import tool.model.grammar.FortePRXTree;
import tool.model.grammar.ForteParser;
import tool.model.grammar.NoCaseFileStream;

public class ProxyTest extends ANTLRTest {
 
  protected static StringTemplateGroup templates = null;
  @BeforeClass
  public static void setup() throws FileNotFoundException{
    FileReader reader = new FileReader("StringTemplates/Java/JavaProxy.stg");
    templates = new StringTemplateGroup(reader);
  }

  @Test
  public void testPEX() throws RecognitionException, IOException {
      this.testPEXFile(new File("UDSLibraries/GenericDBMS.pex"), true);
   
  }
  public int testPEXFile(File pex, boolean failOnError) throws IOException, RecognitionException {
    CharStream stream =
        new NoCaseFileStream(pex.getAbsolutePath());
    ForteLexer lexer = new ForteLexer(stream);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    ForteParser parser = new ForteParser(tokenStream);
   
    CommonTree tree = (CommonTree) parser.projectFile().getTree();
    printTree(tree);
    int errors = parser.getNumberOfSyntaxErrors();
    System.out.println(pex.getName() + " parse errors: " + errors );
    errors+= createPRXTree(tree, tokenStream, pex);
//    errors += createJavaProxy(tree, tokenStream, pex);
//    System.out.println(pex.getName() + "  tree errors: " + treeerrors);
    if (failOnError && (errors) > 0Assert.fail() ;
    return errors;
  }
 
//  private int createJavaProxy(CommonTree tree, TokenStream tokens, File cdf) throws RecognitionException{
//    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
//    nodes.setTokenStream(tokens);
//    JavaClassProxy walker = new JavaClassProxy(nodes);
//    walker.setTemplateLib(templates);
//    project_return result = walker.project();
//    StringTemplate output = (StringTemplate) result.getTemplate();
//    System.out.println(output.toString());
//    return walker.getNumberOfSyntaxErrors();
//
//  }

  private int createPRXTree(CommonTree tree, TokenStream tokens, File cdf) throws RecognitionException{
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    nodes.setTokenStream(tokens);
    FortePRXTree walker = new FortePRXTree(nodes);
    walker.project();
   
    return walker.getNumberOfSyntaxErrors();

  }


}
TOP

Related Classes of tool.model.grammar.proxy.ProxyTest

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.