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