Package org.apache.commons.jci.problems

Examples of org.apache.commons.jci.problems.CompilationProblem


        ArrayList<JavacErrorDetail> problemList = new ArrayList<JavacErrorDetail>();
        CompilationProblem[] problems = result.getErrors();
        if (problems != null) {
            try {
                for (int i = 0; i < problems.length; i++) {
                    CompilationProblem problem = problems[i];
                    problemList.add(ErrorDispatcher.createJavacError
                            (problem.getFileName(), pageNodes, new StringBuilder(problem.getMessage()),
                                    problem.getStartLine(), ctxt));
                }
            } catch (JasperException e) {
                log.error("Error visiting node", e);
            }
        }
View Full Code Here


                compilationUnits[i] = new CompilationUnit(pReader, sourceFile);
                log.debug("compiling " + sourceFile);
            } else {
                // log.error("source not found " + sourceFile);

                final CompilationProblem problem = new CompilationProblem() {

                    public int getEndColumn() {
                        return 0;
                    }

                    public int getEndLine() {
                        return 0;
                    }

                    public String getFileName() {
                        return sourceFile;
                    }

                    public String getMessage() {
                        return "Source " + sourceFile + " could not be found";
                    }

                    public int getStartColumn() {
                        return 0;
                    }

                    public int getStartLine() {
                        return 0;
                    }

                    public boolean isError() {
                        return true;
                    }

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

                if (problemHandler != null) {
                    problemHandler.handle(problem);
                }

                problems.add(problem);
            }
        }

        if (problems.size() > 0) {
            final CompilationProblem[] result = new CompilationProblem[problems.size()];
            problems.toArray(result);
            return new org.apache.commons.jci.compilers.CompilationResult(result);
        }

        final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
        final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
        final INameEnvironment nameEnvironment = new INameEnvironment() {

            public NameEnvironmentAnswer findType( final char[][] pCompoundTypeName ) {
                final StringBuilder result = new StringBuilder();
                for (int i = 0; i < pCompoundTypeName.length; i++) {
                    if (i != 0) {
                        result.append('.');
                    }
                    result.append(pCompoundTypeName[i]);
                }

                //log.debug("finding compoundTypeName=" + result.toString());

                return findType(result.toString());
            }

            public NameEnvironmentAnswer findType( final char[] pTypeName, final char[][] pPackageName ) {
                final StringBuilder result = new StringBuilder();
                for (int i = 0; i < pPackageName.length; i++) {
                    result.append(pPackageName[i]);
                    result.append('.');
                }

//                log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString());

                result.append(pTypeName);
                return findType(result.toString());
            }

            private NameEnvironmentAnswer findType( final String pClazzName ) {

                if (isPackage(pClazzName)) {
                    return null;
                }

                log.debug("finding " + pClazzName);

                final String resourceName = ConversionUtils.convertClassToResourcePath(pClazzName);

                final byte[] clazzBytes = pStore.read(resourceName);
                if (clazzBytes != null) {
                    log.debug("loading from store " + pClazzName);

                    final char[] fileName = pClazzName.toCharArray();
                    try {
                        final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true);
                        return new NameEnvironmentAnswer(classFileReader, null);
                    } catch (final ClassFormatException e) {
                        log.error("wrong class format", e);
                        return null;
                    }
                }

                log.debug("not in store " + pClazzName);

                final InputStream is = pClassLoader.getResourceAsStream(resourceName);
                if (is == null) {
                    log.debug("class " + pClazzName + " not found");
                    return null;
                }

                final byte[] buffer = new byte[8192];
                final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length);
                int count;
                try {
                    while ((count = is.read(buffer, 0, buffer.length)) > 0) {
                        baos.write(buffer, 0, count);
                    }
                    baos.flush();
                    final char[] fileName = pClazzName.toCharArray();
                    final ClassFileReader classFileReader = new ClassFileReader(baos.toByteArray(), fileName, true);
                    return new NameEnvironmentAnswer(classFileReader, null);
                } catch (final IOException e) {
                    log.error("could not read class", e);
                    return null;
                } catch (final ClassFormatException e) {
                    log.error("wrong class format", e);
                    return null;
                } finally {
                    try {
                        baos.close();
                    } catch (final IOException oe) {
                        log.error("could not close output stream", oe);
                    }
                    try {
                        is.close();
                    } catch (final IOException ie) {
                        log.error("could not close input stream", ie);
                    }
                }
            }

            private boolean isPackage( final String pClazzName ) {

                // reject this early as it is cheap
                if (pClazzName.contains("-")) { // "-" is not valid in package names
                    return false;
                }

                final InputStream is = pClassLoader.getResourceAsStream(ConversionUtils.convertClassToResourcePath(pClazzName));
                if (is != null) {
                    log.debug("found the class for " + pClazzName + "- no package");
                    try {
                        is.close();
                    } catch (final IOException ie) {
                        log.error("could not close input stream", ie);
                    }
                    return false;
                }

                // FIXME: this should not be tied to the extension
                final String source = pClazzName.replace('.', '/') + ".java";
                if (pReader.isAvailable(source)) {
                    log.debug("found the source " + source + " for " + pClazzName + " - no package ");
                    return false;
                }

                /*
                 * See https://issues.apache.org/jira/browse/JCI-59
                 * At present, the code assumes that anything else is a package name
                 * This is wrong, as for example jci.AdditionalTopLevel is not a package name.
                 * It's not clear how to fix this in general.
                 * It would seem to need access to the input classpath and/or the generated classes.
                 */
                return true;
            }

            public boolean isPackage( char[][] parentPackageName, char[] pPackageName ) {
                final StringBuilder result = new StringBuilder();
                if (parentPackageName != null) {
                    for (int i = 0; i < parentPackageName.length; i++) {
                        if (i != 0) {
                            result.append('.');
                        }
                        result.append(parentPackageName[i]);
                    }
                }

//                log.debug("isPackage parentPackageName=" + result.toString() + " packageName=" + new String(packageName));

                if (parentPackageName != null && parentPackageName.length > 0) {
                    result.append('.');
                }
                result.append(pPackageName);
                return isPackage(result.toString());
            }

            public void cleanup() {
                log.debug("cleanup");
            }
        };

        final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
            public void acceptResult( final CompilationResult pResult ) {
                if (pResult.hasProblems()) {
                    for (IProblem iproblem : pResult.getProblems()) {
                        final CompilationProblem problem = new EclipseCompilationProblem(iproblem);
                        if (problemHandler != null) {
                            problemHandler.handle(problem);
                        }
                        problems.add(problem);
                    }
View Full Code Here

            final ErrorCollector col = e.getErrorCollector();
            @SuppressWarnings("unchecked") // Groovy library is not yet generic
            final Collection<WarningMessage> warnings = col.getWarnings();
            if (warnings != null) {
                for (WarningMessage warning : warnings) {
                    final CompilationProblem problem = new GroovyCompilationProblem(warning);
                    if (problemHandler != null) {
                        problemHandler.handle(problem);
                    }
                    problems.add(problem);
                }
            }

            @SuppressWarnings("unchecked") // Groovy library is not yet generic
            final Collection<Message> errors = col.getErrors();
            if (errors != null) {
                for (Message message : errors) {
                    final CompilationProblem problem = new GroovyCompilationProblem(message);
                    if (problemHandler != null) {
                        problemHandler.handle(problem);
                    }
                    problems.add(problem);
                }
View Full Code Here

       
        private final class ProblemCollector implements ErrorReporter {

            public void error(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {

                final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, true);

                if (problemHandler != null) {
                    problemHandler.handle(problem);
                }
View Full Code Here

                problems.add(problem);
            }

            public void warning(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {

                final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, false);

                if (problemHandler != null) {
                    problemHandler.handle(problem);
                }
View Full Code Here

          pSettings.isDebug(),
                pSettings.isDebug(),
                pSettings.isDebug(),
          new FilterWarningHandler(pattern, new WarningHandler() {
            public void handleWarning( final String pHandle, final String pMessage, final Location pLocation ) {
              final CompilationProblem problem = new JaninoCompilationProblem(pLocation.getFileName(), pLocation, pMessage, false);
              if (problemHandler != null) {
                problemHandler.handle(problem);
              }
              problems.add(problem);
            }       
            })         
          );
     
     
      compiler.setCompileErrorHandler(new ErrorHandler() {
      public void handleError( final String pMessage, final Location pLocation ) throws CompileException {
        final CompilationProblem problem = new JaninoCompilationProblem(pLocation.getFileName(), pLocation, pMessage, true);
        if (problemHandler != null) {
          problemHandler.handle(problem);
        }
        problems.add(problem);
      }
View Full Code Here

                scanner = new Scanner(resourceNameFromClass, reader);
                final Java.CompilationUnit unit = new Parser(scanner).parseCompilationUnit();
                final UnitCompiler uc = new UnitCompiler(unit, this);
                uc.setCompileErrorHandler(new ErrorHandler() {
                    public void handleError(final String pMessage, final Location pOptionalLocation) throws CompileException {
                        final CompilationProblem problem = new JaninoCompilationProblem(pOptionalLocation, pMessage, true);
                        if (problemHandler != null) {
                            problemHandler.handle(problem);
                        }
                        problems.add(problem);
                    }
                });
                uc.setWarningHandler(new WarningHandler() {
                    public void handleWarning(final String pHandle, final String pMessage, final Location pOptionalLocation) {
                        final CompilationProblem problem = new JaninoCompilationProblem(pOptionalLocation, pMessage, false);
                        if (problemHandler != null) {
                            problemHandler.handle(problem);
                        }
                        problems.add(problem);
                    }
View Full Code Here

    public CompilationResult( final CompilationProblem[] pProblems ) {
        final Collection errorsColl = new ArrayList();
        final Collection warningsColl = new ArrayList();

        for (int i = 0; i < pProblems.length; i++) {
            final CompilationProblem problem = pProblems[i];
            if (problem.isError()) {
                errorsColl.add(problem);
            } else {
                warningsColl.add(problem);
            }
        }
View Full Code Here

            final ErrorCollector col = e.getErrorCollector();
            final Collection warnings = col.getWarnings();
            if (warnings != null) {
                for (final Iterator it = warnings.iterator(); it.hasNext();) {
                    final WarningMessage warning = (WarningMessage) it.next();
                    final CompilationProblem problem = new GroovyCompilationProblem(warning);
                    if (problemHandler != null) {
                        problemHandler.handle(problem);
                    }
                    problems.add(problem);
                }
            }

            final Collection errors = col.getErrors();
            if (errors != null) {
                for (final Iterator it = errors.iterator(); it.hasNext();) {
                    final Message message = (Message) it.next();
                    final CompilationProblem problem = new GroovyCompilationProblem(message);
                    if (problemHandler != null) {
                        problemHandler.handle(problem);
                    }
                    problems.add(problem);
                }
View Full Code Here

    public final String toString( final CompilationProblem[] pProblems ) {
        final StringBuffer sb = new StringBuffer();

        for (int i = 0; i < pProblems.length; i++) {
            final CompilationProblem problem = pProblems[i];
            sb.append(problem.getMessage()).append(", ");
        }

        return sb.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jci.problems.CompilationProblem

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.