Example usage for org.apache.commons.jci.problems CompilationProblem toString

List of usage examples for org.apache.commons.jci.problems CompilationProblem toString

Introduction

In this page you can find the example usage for org.apache.commons.jci.problems CompilationProblem toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:me.jaimegarza.syntax.test.java.TestJavaLexerModes.java

@Test
public void testJavaLexerModes() throws ParsingException, AnalysisException, OutputException,
        MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException,
        NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
    generateLanguageFile(args);/*  ww w  .j  a  v a  2s .  c  om*/
    File source = new File(tmpLanguageFile);
    File sourceDir = source.getParentFile();
    CompilationResult result = compileJavaFile(source, sourceDir);

    if (result.getErrors().length > 0) {
        for (CompilationProblem problemo : result.getErrors()) {
            if (problemo.isError()) {
                System.err.println(problemo.toString());
            }
        }
        Assert.fail("Errors during the compilation of the output java file");
    }

    URL urls[] = new URL[1];
    urls[0] = sourceDir.toURI().toURL();
    URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader());
    String className = FilenameUtils.getBaseName(tmpLanguageFile);
    Class<?> clazz = classLoader.loadClass(className);
    Object parser = clazz.newInstance();
    //Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class);
    Method parse = parser.getClass().getMethod("parse");
    Method getOutput = parser.getClass().getMethod("getOutput");
    //setVerbose.invoke(parser, true);
    Object o = parse.invoke(parser);
    Assert.assertTrue(o instanceof Integer);
    int rc = (Integer) o;
    Assert.assertEquals(rc, 1, "Parse did not succeed");
    o = getOutput.invoke(parser);
    Assert.assertTrue(o instanceof String);
    String s = (String) o;
    Assert.assertEquals(s, "bacaab", "string does not match");
}

From source file:me.jaimegarza.syntax.test.java.TestJavaExpandedParser.java

@Test
public void test02Compile() throws ParsingException, AnalysisException, OutputException {
    generateLanguageFile(expandedArgs);//w  ww  .j  a v  a2s.  c o  m

    File source = new File(tmpLanguageFile);
    File sourceDir = source.getParentFile();
    CompilationResult result = compileJavaFile(source, sourceDir);

    if (result.getErrors().length > 0) {
        for (CompilationProblem problemo : result.getErrors()) {
            if (problemo.isError()) {
                System.err.println(problemo.toString());
            }
        }
        Assert.fail("Errors during the compilation of the output java file");
    }
}

From source file:me.jaimegarza.syntax.test.java.TestJavaExpandedScanner.java

@Test
public void test02Compile() throws ParsingException, AnalysisException, OutputException {
    generateLanguageFile(packedArgs);//from  w  w w. ja v  a  2s  .co m

    File source = new File(tmpLanguageFile);
    File sourceDir = source.getParentFile();
    CompilationResult result = compileJavaFile(source, sourceDir);

    if (result.getErrors().length > 0) {
        for (CompilationProblem problemo : result.getErrors()) {
            if (problemo.isError()) {
                System.err.println(problemo.toString());
            }
        }
        Assert.fail("Errors during the compilation of the output java file");
    }
}

From source file:org.apache.commons.jci.examples.serverpages.ServerPageServlet.java

protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log("Request " + request.getRequestURI());

    final CompilationResult result = jspListener.getCompilationResult();
    final CompilationProblem[] errors = result.getErrors();

    if (errors.length > 0) {

        // if there are errors we provide the compilation errors instead of the jsp page

        final PrintWriter out = response.getWriter();

        out.append("<html><body>");

        for (CompilationProblem problem : errors) {
            out.append(problem.toString()).append("<br/>").append('\n');
        }/*from w  ww  .j  a v a  2 s.  c  om*/

        out.append("</body></html>");

        out.flush();
        out.close();
        return;
    }

    final String servletClassname = convertRequestToServletClassname(request);

    log("Checking for serverpage " + servletClassname);

    final HttpServlet servlet = servletsByClassname.get(servletClassname);

    if (servlet == null) {
        log("No servlet  for " + request.getRequestURI());
        response.sendError(404);
        return;
    }

    log("Delegating request to " + servletClassname);

    servlet.service(request, response);
}