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 errorsColl = new ArrayList();
39          final Collection warningsColl = new ArrayList();
40  
41          for (int i = 0; i < pProblems.length; i++) {
42              final CompilationProblem problem = pProblems[i];
43              if (problem.isError()) {
44                  errorsColl.add(problem);
45              } else {
46                  warningsColl.add(problem);
47              }
48          }
49          
50          errors = new CompilationProblem[errorsColl.size()];
51          errorsColl.toArray(errors);
52  
53          warnings = new CompilationProblem[warningsColl.size()];
54          warningsColl.toArray(warnings);
55      }
56      
57      public CompilationProblem[] getErrors() {
58      	final CompilationProblem[] res = new CompilationProblem[errors.length];
59      	System.arraycopy(errors, 0, res, 0, res.length);
60          return res;
61      }
62  
63      public CompilationProblem[] getWarnings() {
64      	final CompilationProblem[] res = new CompilationProblem[warnings.length];
65      	System.arraycopy(warnings, 0, res, 0, res.length);
66          return res;
67      }
68  }