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.codehaus.commons.compiler.LocatedException;
022 import org.codehaus.commons.compiler.Location;
023
024 /**
025 * Janino version of a CompilationProblem
026 *
027 * @author tcurdt
028 */
029 public final class JaninoCompilationProblem implements CompilationProblem {
030
031 private final Location location;
032 private final String fileName;
033 private final String message;
034 private final boolean error;
035
036 public JaninoCompilationProblem(final LocatedException pLocatedException) {
037 this(pLocatedException.getLocation(), pLocatedException.getMessage(), true);
038 }
039
040 public JaninoCompilationProblem(final Location pLocation, final String pMessage, final boolean pError) {
041 this(pLocation.getFileName(), pLocation, pMessage, pError);
042 }
043
044 public JaninoCompilationProblem(final String pFilename, final String pMessage, final boolean pError) {
045 this(pFilename, null, pMessage, pError);
046 }
047
048 public JaninoCompilationProblem(final String pFilename, final Location pLocation, final String pMessage, final boolean pError) {
049 location = pLocation;
050 fileName = pFilename;
051 message = pMessage;
052 error = pError;
053 }
054
055 public boolean isError() {
056 return error;
057 }
058
059 public String getFileName() {
060 return fileName;
061 }
062
063 public int getStartLine() {
064 if (location == null) {
065 return 0;
066 }
067 return location.getLineNumber();
068 }
069
070 public int getStartColumn() {
071 if (location == null) {
072 return 0;
073 }
074 return location.getColumnNumber();
075 }
076
077 public int getEndLine() {
078 return getStartLine();
079 }
080
081 public int getEndColumn() {
082 return getStartColumn();
083 }
084
085 public String getMessage() {
086 return message;
087 }
088
089 @Override
090 public String toString() {
091 final StringBuilder sb = new StringBuilder();
092 sb.append(getFileName()).append(" (");
093 sb.append(getStartLine());
094 sb.append(":");
095 sb.append(getStartColumn());
096 sb.append(") : ");
097 sb.append(getMessage());
098 return sb.toString();
099 }
100
101 }