Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ allprojects {
pom {
configureMavenCentralPom(project)
}
signPublication(project)
// signPublication(project)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Generated by msggen from CompilerMessages.xml
package org.kopi.compiler.base

import org.kopi.galite.util.base.MessageDescription

interface CompilerMessages {
companion object {
val FORMATTED_ERROR: MessageDescription = MessageDescription("{0}", null, 0)
val FORMATTED_CAUTION: MessageDescription = MessageDescription("{0}", null, 1)
val FORMATTED_WARNING: MessageDescription = MessageDescription("{0}", null, 2)
val FORMATTED_NOTICE: MessageDescription = MessageDescription("{0}", null, 3)
val FORMATTED_INFO: MessageDescription = MessageDescription("{0}", null, 4)
val NO_INPUT_FILE: MessageDescription = MessageDescription("No input file given", null, 0)
val FILE_NOT_FOUND: MessageDescription = MessageDescription("File \"{0}\" not found", null, 0)
val IO_EXCEPTION: MessageDescription = MessageDescription("I/O Exception on file \"{0}\": {1}", null, 0)
val UNSUPPORTED_ENCODING: MessageDescription = MessageDescription("Character encoding \"{0}\" is not supported on this platform", null, 0)
val CANNOT_CREATE: MessageDescription = MessageDescription("Cannot create file \"{0}\"", null, 0)
val INVALID_LIST_FILE: MessageDescription = MessageDescription("Invalid list file \"{0}\" : {1}", null, 0)
val NO_VIABLE_ALT_FOR_CHAR: MessageDescription = MessageDescription("Unexpected char \"{0}\"", null, 0)
val UNEXPECTED_EOF: MessageDescription = MessageDescription("Unexpected end of file", null, 0)
val EOF_IN_TRADITIONAL_COMMENT: MessageDescription = MessageDescription("End of file in comment", null, 0)
val EOF_IN_ENDOFLINE_COMMENT: MessageDescription = MessageDescription("End of file in comment", null, 1)
val ILLEGAL_CHAR: MessageDescription = MessageDescription("Unexpected char \"{0}\"", null, 0)
val BAD_ESCAPE_SEQUENCE: MessageDescription = MessageDescription("Illegal escape sequence \"{0}\"", null, 0)
val BAD_END_OF_LINE: MessageDescription = MessageDescription("Unexpected end of line in {0}", null, 0)
val SYNTAX_ERROR: MessageDescription = MessageDescription("Syntax error: {0}", null, 0)
val COMPILATION_STARTED: MessageDescription = MessageDescription("[ start compilation in verbose mode ]", null, 4)
val FILE_PARSED: MessageDescription = MessageDescription("[ parsed {0} in {1} ms ]", null, 4)
val INTERFACES_CHECKED: MessageDescription = MessageDescription("[ checked interfaces in {0} ms ]", null, 4)
val BODY_CHECKED: MessageDescription = MessageDescription("[ checked body of {0} in {1} ms ]", null, 4)
val CONDITION_CHECKED: MessageDescription = MessageDescription("[ checked condition of {0} in {1} ms ]", null, 4)
val CLASSFILE_GENERATED: MessageDescription = MessageDescription("[ optimized and generated {0} in {1} ms ]", null, 4)
val JAVA_CODE_GENERATED: MessageDescription = MessageDescription("[ generated {0} ]", null, 4)
val CLASS_LOADED: MessageDescription = MessageDescription("[ loaded {0} ]", null, 4)
val COMPILATION_ENDED: MessageDescription = MessageDescription("[ compilation ended ]", null, 4)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013-2024 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2024 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.galite.kopi.util.base

import org.kopi.galite.util.base.Message
import org.kopi.galite.util.base.MessageDescription

/**
* This class defines exceptions formatted using message descriptions.
*/
open class FormattedException(private val messageDetail: Message) : Exception(messageDetail.description.format) {

/**
* An exception with an arbitrary number of parameters
* @param description the message description
* @param parameters the array of parameters
*/
constructor(description: MessageDescription, vararg parameters: Any) : this(Message(description, parameters))

/**
* An exception with no parameters
* @param description the message description
*/
constructor(description: MessageDescription) : this(description, *emptyArray())

// ----------------------------------------------------------------------
// ACCESSORS
// ----------------------------------------------------------------------
/**
* Returns a string explaining the exception.
*/
fun getFormattedMessage(): String {
return messageDetail.description.format // Returning the formatted message
}
/**
* Returns the formatted message.
*/
val formattedMessage: Message
get() = messageDetail

/**
* Returns true if the error has the specified description.
*/
fun hasDescription(description: MessageDescription): Boolean {
return messageDetail.description === description
}

// ----------------------------------------------------------------------
// DATA MEMBERS
// ----------------------------------------------------------------------
override val message: String?
get() = messageDetail.description.format // Return the formatted message as String

companion object {
/**
* Comment for `serialVersionUID`
*/
private const val serialVersionUID = 6590654347028052938L
}
}
50 changes: 50 additions & 0 deletions galite-util/src/main/kotlin/org/kopi/galite/util/base/Message.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2013-2024 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2024 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.util.base

class Message(val description: MessageDescription, vararg parameters: Any?) {
/**
* An exception with an arbitrary number of parameters
* @param description the message description
* @param parameters the vararg parameters
*/
val params: Array<Any?> = arrayOf(*parameters)

/**
* An exception with no parameters
* @param description the message description
*/
constructor(description: MessageDescription) : this(description, *emptyArray())

// ----------------------------------------------------------------------
// ACCESSORS
// ----------------------------------------------------------------------
val severityLevel: Int
/**
* Returns the severity level
*/
get() = description.level

val message: String
/**
* Returns the string explaining the error
*/
get() = description.format(this.params)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2024 kopiLeft Services SARL, Tunis TN
* Copyright (c) 1990-2024 kopiRight Managed Solutions GmbH, Wien AT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.kopi.galite.util.base

import java.text.MessageFormat

/**
* This class defines message descriptions (errors, warnings, notices, ...)
*
* The message format is a text message with placeholders for its arguments
* of the form {0}, {1}, ... . Each placeholder will be replaced by the string
* representation of the corresponding argument.
*/
class MessageDescription( val format: String, val reference: String?, val level: Int) {

/**
* Returns a string explaining the error.
*
* @param parameters the array of parameters
*/
fun format(parameters: Array<Any?>): String {
val prefix = when (level) {
LVL_UNDEFINED -> "" // no qualifier
LVL_ERROR -> "error:"
LVL_CAUTION -> "caution:"
LVL_WARNING -> "warning:"
LVL_NOTICE -> "notice:"
LVL_INFO -> ""
else -> // unknown: mark as error
"error:"
} // the text for the severity level

var body = try {
MessageFormat.format(format, *parameters)
} catch (e: RuntimeException) {
// wrong number of parameters: give at least message text with placeholders
format
} // the formatted message

val suffix = if (reference == null) "" else " [$reference]" // the reference

return prefix + body + suffix
}

// ----------------------------------------------------------------------
// CONSTRUCTORS
// ----------------------------------------------------------------------

companion object {
const val LVL_UNDEFINED: Int = -1
const val LVL_ERROR: Int = 0
const val LVL_CAUTION: Int = 1
const val LVL_WARNING: Int = 2
const val LVL_NOTICE: Int = 3
const val LVL_INFO: Int = 4
}
}
Loading