001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.jci.compilers;
019    
020    import java.util.ArrayList;
021    import java.util.Collection;
022    import org.apache.commons.jci.problems.CompilationProblem;
023    
024    /**
025     * A CompilationResult represents the result of a compilation.
026     * It includes errors (which failed the compilation) or warnings
027     * (that can be ignored and do not affect the creation of the
028     * class files)
029     * 
030     * @author tcurdt
031     */
032    public final class CompilationResult {
033        
034        private final CompilationProblem[] errors;
035        private final CompilationProblem[] warnings;
036            
037        public CompilationResult( final CompilationProblem[] pProblems ) {
038            final Collection<CompilationProblem> errorsColl = new ArrayList<CompilationProblem>();
039            final Collection<CompilationProblem> warningsColl = new ArrayList<CompilationProblem>();
040    
041            for (CompilationProblem problem : pProblems) {
042                if (problem.isError()) {
043                    errorsColl.add(problem);
044                } else {
045                    warningsColl.add(problem);
046                }
047            }
048            
049            errors = new CompilationProblem[errorsColl.size()];
050            errorsColl.toArray(errors);
051    
052            warnings = new CompilationProblem[warningsColl.size()];
053            warningsColl.toArray(warnings);
054        }
055        
056        public CompilationProblem[] getErrors() {
057            final CompilationProblem[] res = new CompilationProblem[errors.length];
058            System.arraycopy(errors, 0, res, 0, res.length);
059            return res;
060        }
061    
062        public CompilationProblem[] getWarnings() {
063            final CompilationProblem[] res = new CompilationProblem[warnings.length];
064            System.arraycopy(warnings, 0, res, 0, res.length);
065            return res;
066        }
067    }