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 org.apache.commons.jci.problems.CompilationProblem;
021    import org.eclipse.jdt.core.compiler.IProblem;
022    
023    /**
024     * Wrapping an Eclipse compiler problem
025     * 
026     * @author tcurdt
027     */
028    public final class EclipseCompilationProblem implements CompilationProblem {
029    
030        private final IProblem problem;
031    
032        public EclipseCompilationProblem(final IProblem pProblem) {
033            problem = pProblem;
034        }
035    
036        public boolean isError() {
037            return problem.isError();
038        }
039    
040        public String getFileName() {
041            return new String(problem.getOriginatingFileName());
042        }
043    
044        public int getStartLine() {
045            return problem.getSourceLineNumber();
046        }
047    
048        public int getStartColumn() {
049            return problem.getSourceStart();
050        }
051    
052        public int getEndLine() {
053            return getStartLine();
054        }
055    
056        public int getEndColumn() {
057            return problem.getSourceEnd();
058        }
059    
060        public String getMessage() {
061            return problem.getMessage();
062        }
063    
064        @Override
065        public String toString() {
066            final StringBuilder sb = new StringBuilder();
067            sb.append(getFileName()).append(" (");
068            sb.append(getStartLine());
069            sb.append(":");
070            sb.append(getStartColumn());
071            sb.append(") : ");
072            sb.append(getMessage());
073            return sb.toString();
074        }
075    
076        public int getId() {
077            return problem.getID();
078        }
079    
080    }