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 org.apache.commons.jci.problems.CompilationProblem;
21  import org.eclipse.jdt.core.compiler.IProblem;
22  
23  /**
24   * Wrapping an Eclipse compiler problem
25   * 
26   * @author tcurdt
27   */
28  public final class EclipseCompilationProblem implements CompilationProblem {
29  
30      private final IProblem problem;
31  
32      public EclipseCompilationProblem(final IProblem pProblem) {
33          problem = pProblem;
34      }
35  
36      public boolean isError() {
37          return problem.isError();
38      }
39  
40      public String getFileName() {
41          return new String(problem.getOriginatingFileName());
42      }
43  
44      public int getStartLine() {
45          return problem.getSourceLineNumber();
46      }
47  
48      public int getStartColumn() {
49          return problem.getSourceStart();
50      }
51  
52      public int getEndLine() {
53          return getStartLine();
54      }
55  
56      public int getEndColumn() {
57          return problem.getSourceEnd();
58      }
59  
60      public String getMessage() {
61          return problem.getMessage();
62      }
63  
64      @Override
65      public String toString() {
66          final StringBuilder sb = new StringBuilder();
67          sb.append(getFileName()).append(" (");
68          sb.append(getStartLine());
69          sb.append(":");
70          sb.append(getStartColumn());
71          sb.append(") : ");
72          sb.append(getMessage());
73          return sb.toString();
74      }
75  
76      public int getId() {
77          return problem.getID();
78      }
79  
80  }