LUCENE-1257: Move messages package to Java 1.5, thanks Robert Muir!

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@821447 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-10-03 23:36:23 +00:00
parent c70555f62d
commit 8dcc6d68b5
19 changed files with 43 additions and 43 deletions

View File

@ -58,7 +58,7 @@ public class QueryNodeParseException extends QueryNodeException {
public void setQuery(CharSequence query) { public void setQuery(CharSequence query) {
this.query = query; this.query = query;
this.message = new MessageImpl( this.message = new MessageImpl(
QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, new Object[] {query, ""}); QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, "");
} }
public CharSequence getQuery() { public CharSequence getQuery() {

View File

@ -175,9 +175,9 @@ public class QueryTreeBuilder implements QueryBuilder {
if (builder == null) { if (builder == null) {
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{node QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, node
.toQueryString(new EscapeQuerySyntaxImpl()), node.getClass() .toQueryString(new EscapeQuerySyntaxImpl()), node.getClass()
.getName()})); .getName()));
} }

View File

@ -51,7 +51,7 @@ public class BoostQueryNode extends QueryNodeImpl {
public BoostQueryNode(QueryNode query, float value) throws QueryNodeException { public BoostQueryNode(QueryNode query, float value) throws QueryNodeException {
if (query == null) { if (query == null) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"})); QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
} }
this.value = value; this.value = value;

View File

@ -42,7 +42,7 @@ public class GroupQueryNode extends QueryNodeImpl {
public GroupQueryNode(QueryNode query) { public GroupQueryNode(QueryNode query) {
if (query == null) { if (query == null) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"query", "null"})); QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
} }
allocate(); allocate();

View File

@ -94,7 +94,7 @@ public class ModifierQueryNode extends QueryNodeImpl {
public ModifierQueryNode(QueryNode query, Modifier mod) { public ModifierQueryNode(QueryNode query, Modifier mod) {
if (query == null) { if (query == null) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"query", "null"})); QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
} }
allocate(); allocate();

View File

@ -40,7 +40,7 @@ public class PhraseSlopQueryNode extends QueryNodeImpl implements FieldableNode
throws QueryNodeException { throws QueryNodeException {
if (query == null) { if (query == null) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"})); QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
} }
this.value = value; this.value = value;

View File

@ -109,8 +109,8 @@ public class ProximityQueryNode extends BooleanQueryNode {
if (type == Type.NUMBER) { if (type == Type.NUMBER) {
if (distance <= 0) { if (distance <= 0) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"distance", QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "distance",
distance})); distance));
} else { } else {
this.distance = distance; this.distance = distance;

View File

@ -47,7 +47,7 @@ public class SlopQueryNode extends QueryNodeImpl implements FieldableNode {
public SlopQueryNode(QueryNode query, int value) { public SlopQueryNode(QueryNode query, int value) {
if (query == null) { if (query == null) {
throw new QueryNodeError(new MessageImpl( throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"})); QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
} }
this.value = value; this.value = value;

View File

@ -67,9 +67,9 @@ public class BooleanQueryNodeBuilder implements StandardQueryBuilder {
} catch (TooManyClauses ex) { } catch (TooManyClauses ex) {
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, new Object[]{BooleanQuery QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
.getMaxClauseCount(), queryNode .getMaxClauseCount(), queryNode
.toQueryString(new EscapeQuerySyntaxImpl())}), ex); .toQueryString(new EscapeQuerySyntaxImpl())), ex);
} }

View File

@ -40,9 +40,9 @@ public class MatchAllDocsQueryNodeBuilder implements StandardQueryBuilder {
// validates node // validates node
if (!(queryNode instanceof MatchAllDocsQueryNode)) { if (!(queryNode instanceof MatchAllDocsQueryNode)) {
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{queryNode QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
.toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass() .toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass()
.getName()})); .getName()));
} }
return new MatchAllDocsQuery(); return new MatchAllDocsQuery();

View File

@ -40,9 +40,9 @@ public class MatchNoDocsQueryNodeBuilder implements StandardQueryBuilder {
// validates node // validates node
if (!(queryNode instanceof MatchNoDocsQueryNode)) { if (!(queryNode instanceof MatchNoDocsQueryNode)) {
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{queryNode QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
.toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass() .toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass()
.getName()})); .getName()));
} }
return new BooleanQuery(); return new BooleanQuery();

View File

@ -68,9 +68,9 @@ public class StandardBooleanQueryNodeBuilder implements StandardQueryBuilder {
} catch (TooManyClauses ex) { } catch (TooManyClauses ex) {
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, new Object[]{BooleanQuery QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
.getMaxClauseCount(), queryNode .getMaxClauseCount(), queryNode
.toQueryString(new EscapeQuerySyntaxImpl())}), ex); .toQueryString(new EscapeQuerySyntaxImpl())), ex);
} }

View File

@ -289,7 +289,7 @@ public class EscapeQuerySyntaxImpl implements EscapeQuerySyntax {
return c - 'A' + 10; return c - 'A' + 10;
} else { } else {
throw new ParseException(new MessageImpl( throw new ParseException(new MessageImpl(
QueryParserMessages.INVALID_SYNTAX_ESCAPE_NONE_HEX_UNICODE, new Object[]{c})); QueryParserMessages.INVALID_SYNTAX_ESCAPE_NONE_HEX_UNICODE, c));
} }
} }

View File

@ -47,8 +47,8 @@ public class ParseException extends QueryNodeParseException {
*/ */
public ParseException(Token currentTokenVal, public ParseException(Token currentTokenVal,
int[][] expectedTokenSequencesVal, String[] tokenImageVal) { int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, new Object[]{initialise( super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, initialise(
currentTokenVal, expectedTokenSequencesVal, tokenImageVal)})); currentTokenVal, expectedTokenSequencesVal, tokenImageVal)));
this.currentToken = currentTokenVal; this.currentToken = currentTokenVal;
this.expectedTokenSequences = expectedTokenSequencesVal; this.expectedTokenSequences = expectedTokenSequencesVal;
this.tokenImage = tokenImageVal; this.tokenImage = tokenImageVal;
@ -59,7 +59,7 @@ public class ParseException extends QueryNodeParseException {
} }
public ParseException() { public ParseException() {
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, new Object[]{"Error"})); super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "Error"));
} }
/** /**

View File

@ -68,7 +68,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC
throw tme; throw tme;
} }
catch (Error tme) { catch (Error tme) {
Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, new Object[]{query, tme.getMessage()}); Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, tme.getMessage());
QueryNodeParseException e = new QueryNodeParseException(tme); QueryNodeParseException e = new QueryNodeParseException(tme);
e.setQuery(query); e.setQuery(query);
e.setNonLocalizedMessage(message); e.setNonLocalizedMessage(message);

View File

@ -74,8 +74,8 @@ public class AllowLeadingWildcardProcessor extends QueryNodeProcessorImpl {
case '*': case '*':
case '?': case '?':
throw new QueryNodeException(new MessageImpl( throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, new Object[]{node QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
.toQueryString(new EscapeQuerySyntaxImpl())})); .toQueryString(new EscapeQuerySyntaxImpl())));
} }
} }

View File

@ -36,7 +36,7 @@ public class MessageImpl implements Message {
} }
public MessageImpl(String key, Object[] args) { public MessageImpl(String key, Object... args) {
this(key); this(key);
this.arguments = args; this.arguments = args;
} }

View File

@ -45,8 +45,8 @@ import java.util.ResourceBundle;
*/ */
public class NLS { public class NLS {
private static Map/*<String, Class<Object>>*/ bundles = new HashMap/*<String, Class<Object>>*/( private static Map<String, Class<Object>> bundles =
0); new HashMap<String, Class<Object>>(0);
protected NLS() { protected NLS() {
// Do not instantiate // Do not instantiate
@ -66,7 +66,7 @@ public class NLS {
} }
public static String getLocalizedMessage(String key, Locale locale, public static String getLocalizedMessage(String key, Locale locale,
Object[] args) { Object... args) {
String str = getLocalizedMessage(key, locale); String str = getLocalizedMessage(key, locale);
if (args.length > 0) { if (args.length > 0) {
@ -76,7 +76,7 @@ public class NLS {
return str; return str;
} }
public static String getLocalizedMessage(String key, Object[] args) { public static String getLocalizedMessage(String key, Object... args) {
return getLocalizedMessage(key, Locale.getDefault(), args); return getLocalizedMessage(key, Locale.getDefault(), args);
} }
@ -89,7 +89,7 @@ public class NLS {
* @param clazz * @param clazz
* where constants will reside * where constants will reside
*/ */
//@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected static void initializeMessages(String bundleName, Class clazz) { protected static void initializeMessages(String bundleName, Class clazz) {
try { try {
load(clazz); load(clazz);
@ -105,8 +105,8 @@ public class NLS {
// slow resource checking // slow resource checking
// need to loop thru all registered resource bundles // need to loop thru all registered resource bundles
for (Iterator/*<String>*/ it = bundles.keySet().iterator(); it.hasNext();) { for (Iterator<String> it = bundles.keySet().iterator(); it.hasNext();) {
Class/*<Object>*/ clazz = (Class) bundles.get((String)it.next()); Class<Object> clazz = bundles.get(it.next());
ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(), ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
locale); locale);
if (resourceBundle != null) { if (resourceBundle != null) {
@ -126,14 +126,14 @@ public class NLS {
/** /**
* @param clazz * @param clazz
*/ */
private static void load(Class/*<Object>*/ clazz) { private static void load(Class<Object> clazz) {
final Field[] fieldArray = clazz.getDeclaredFields(); final Field[] fieldArray = clazz.getDeclaredFields();
boolean isFieldAccessible = (clazz.getModifiers() & Modifier.PUBLIC) != 0; boolean isFieldAccessible = (clazz.getModifiers() & Modifier.PUBLIC) != 0;
// build a map of field names to Field objects // build a map of field names to Field objects
final int len = fieldArray.length; final int len = fieldArray.length;
Map/*<String, Field>*/ fields = new HashMap/*<String, Field>*/(len * 2); Map<String, Field> fields = new HashMap<String, Field>(len * 2);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
fields.put(fieldArray[i].getName(), fieldArray[i]); fields.put(fieldArray[i].getName(), fieldArray[i]);
loadfieldValue(fieldArray[i], isFieldAccessible, clazz); loadfieldValue(fieldArray[i], isFieldAccessible, clazz);
@ -145,7 +145,7 @@ public class NLS {
* @param isFieldAccessible * @param isFieldAccessible
*/ */
private static void loadfieldValue(Field field, boolean isFieldAccessible, private static void loadfieldValue(Field field, boolean isFieldAccessible,
Class/*<Object>*/ clazz) { Class<Object> clazz) {
int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; int MOD_MASK = MOD_EXPECTED | Modifier.FINAL;
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED)
@ -168,7 +168,7 @@ public class NLS {
* @param key * @param key
* - Message Key * - Message Key
*/ */
private static void validateMessage(String key, Class/*<Object>*/ clazz) { private static void validateMessage(String key, Class<Object> clazz) {
// Test if the message is present in the resource bundle // Test if the message is present in the resource bundle
try { try {
ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(), ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
@ -192,7 +192,7 @@ public class NLS {
/* /*
* Make a class field accessible * Make a class field accessible
*/ */
//@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static void makeAccessible(final Field field) { private static void makeAccessible(final Field field) {
if (System.getSecurityManager() == null) { if (System.getSecurityManager() == null) {
field.setAccessible(true); field.setAccessible(true);

View File

@ -26,13 +26,13 @@ import junit.framework.TestCase;
public class TestNLS extends TestCase { public class TestNLS extends TestCase {
public void testMessageLoading() { public void testMessageLoading() {
Message invalidSyntax = new MessageImpl( Message invalidSyntax = new MessageImpl(
MessagesTestBundle.Q0001E_INVALID_SYNTAX, new Object[]{"XXX"}); MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
assertEquals("Syntax Error: XXX", invalidSyntax.getLocalizedMessage()); assertEquals("Syntax Error: XXX", invalidSyntax.getLocalizedMessage());
} }
public void testMessageLoading_ja() { public void testMessageLoading_ja() {
Message invalidSyntax = new MessageImpl( Message invalidSyntax = new MessageImpl(
MessagesTestBundle.Q0001E_INVALID_SYNTAX, new Object[]{"XXX"}); MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
assertEquals("構文エラー: XXX", invalidSyntax assertEquals("構文エラー: XXX", invalidSyntax
.getLocalizedMessage(Locale.JAPANESE)); .getLocalizedMessage(Locale.JAPANESE));
} }
@ -43,7 +43,7 @@ public class TestNLS extends TestCase {
assertEquals("Truncated unicode escape sequence.", message); assertEquals("Truncated unicode escape sequence.", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
new Object[]{"XXX"}); "XXX");
assertEquals("Syntax Error: XXX", message); assertEquals("Syntax Error: XXX", message);
} }
@ -54,7 +54,7 @@ public class TestNLS extends TestCase {
assertEquals("切り捨てられたユニコード・エスケープ・シーケンス。", message); assertEquals("切り捨てられたユニコード・エスケープ・シーケンス。", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
Locale.JAPANESE, new Object[]{"XXX"}); Locale.JAPANESE, "XXX");
assertEquals("構文エラー: XXX", message); assertEquals("構文エラー: XXX", message);
} }
@ -66,7 +66,7 @@ public class TestNLS extends TestCase {
assertEquals("Truncated unicode escape sequence.", message); assertEquals("Truncated unicode escape sequence.", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
locale, new Object[]{"XXX"}); locale, "XXX");
assertEquals("Syntax Error: XXX", message); assertEquals("Syntax Error: XXX", message);
} }