View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.jci.compilers;
19  
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import org.apache.commons.jci.problems.CompilationProblem;
23  
24  /**
25   * A CompilationResult represents the result of a compilation.
26   * It includes errors (which failed the compilation) or warnings
27   * (that can be ignored and do not affect the creation of the
28   * class files)
29   * 
30   * @author tcurdt
31   */
32  public final class CompilationResult {
33      
34      private final CompilationProblem[] errors;
35      private final CompilationProblem[] warnings;
36          
37      public CompilationResult( final CompilationProblem[] pProblems ) {
38          final Collection<CompilationProblem> errorsColl = new ArrayList<CompilationProblem>();
39          final Collection<CompilationProblem> warningsColl = new ArrayList<CompilationProblem>();
40  
41          for (CompilationProblem problem : pProblems) {
42              if (problem.isError()) {
43                  errorsColl.add(problem);
44              } else {
45                  warningsColl.add(problem);
46              }
47          }
48          
49          errors = new CompilationProblem[errorsColl.size()];
50          errorsColl.toArray(errors);
51  
52          warnings = new CompilationProblem[warningsColl.size()];
53          warningsColl.toArray(warnings);
54      }
55      
56      public CompilationProblem[] getErrors() {
57      	final CompilationProblem[] res = new CompilationProblem[errors.length];
58      	System.arraycopy(errors, 0, res, 0, res.length);
59          return res;
60      }
61  
62      public CompilationProblem[] getWarnings() {
63      	final CompilationProblem[] res = new CompilationProblem[warnings.length];
64      	System.arraycopy(warnings, 0, res, 0, res.length);
65          return res;
66      }
67  }