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.groovy.control.messages.ExceptionMessage;
022: import org.codehaus.groovy.control.messages.Message;
023: import org.codehaus.groovy.control.messages.SimpleMessage;
024: import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
025: import org.codehaus.groovy.syntax.SyntaxException;
026:
027: /**
028: * Groovy version of a CompilationProblem
029: *
030: * @author tcurdt
031: */
032: public final class GroovyCompilationProblem implements
033: CompilationProblem {
034:
035: private final String fileName;
036: private final String message;
037: private final boolean error;
038: private final int startLine;
039: private final int startColumn;
040: private final int endLine;
041: private final int endColumn;
042:
043: public GroovyCompilationProblem(final Message pMessage) {
044: if (pMessage instanceof SimpleMessage) {
045: error = false;
046: } else {
047: error = true;
048: }
049: if (pMessage instanceof SyntaxErrorMessage) {
050: SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) pMessage;
051: SyntaxException syntaxException = syntaxErrorMessage
052: .getCause();
053: message = syntaxException.getMessage();
054: fileName = syntaxException.getSourceLocator();
055: // FIXME: getStartLine() vs. getLine()
056: startLine = syntaxException.getStartLine();
057: startColumn = syntaxException.getStartColumn();
058: endLine = syntaxException.getLine();
059: endColumn = syntaxException.getEndColumn();
060: } else {
061: fileName = "";
062: startLine = 0;
063: startColumn = 0;
064: endLine = 0;
065: endColumn = 0;
066: if (pMessage instanceof ExceptionMessage) {
067: message = ((ExceptionMessage) pMessage).getCause()
068: .getMessage();
069: } else if (pMessage instanceof SimpleMessage) {
070: message = ((SimpleMessage) pMessage).getMessage();
071: } else {
072: message = pMessage.toString();
073: }
074: }
075: }
076:
077: public boolean isError() {
078: return error;
079: }
080:
081: public String getFileName() {
082: return fileName;
083: }
084:
085: public int getStartLine() {
086: return startLine;
087: }
088:
089: public int getStartColumn() {
090: return startColumn;
091: }
092:
093: public int getEndLine() {
094: return endLine;
095: }
096:
097: public int getEndColumn() {
098: return endColumn;
099: }
100:
101: public String getMessage() {
102: return message;
103: }
104:
105: public String toString() {
106: return getMessage();
107: }
108:
109: }
|