hlship 2004/12/30 07:18:17
Modified: framework/src/java/org/apache/hivemind/conditional
ClassNameEvaluator.java PropertyEvaluator.java
NodeImpl.java
framework/src/java/org/apache/hivemind/impl package.html
library/src/java/org/apache/hivemind/lib/factory
FactoryMessages.java
Added: framework/src/java/org/apache/hivemind/conditional
ConditionalStrings.properties TokenType.java
Parser.java Token.java Lexer.java package.html
ConditionalMessages.java
framework/src/test dummy.groovy
framework/src/test/org/apache/hivemind/conditional
TestParser.java TestToken.java TestLexer.java
Log:
Check in more support for conditional contributions.
Revision Changes Path
1.2 +7 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/ClassNameEvaluator.java
Index: ClassNameEvaluator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/ClassNameEvaluator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClassNameEvaluator.java 29 Dec 2004 21:09:17 -0000 1.1
+++ ClassNameEvaluator.java 30 Dec 2004 15:18:17 -0000 1.2
@@ -33,6 +33,13 @@
_className = className;
}
+ // For testing
+
+ String getClassName()
+ {
+ return _className;
+ }
+
public boolean evaluate(EvaluationContext context, Node node)
{
return context.doesClassExist(_className);
1.2 +7 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/PropertyEvaluator.java
Index: PropertyEvaluator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/PropertyEvaluator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PropertyEvaluator.java 29 Dec 2004 21:09:17 -0000 1.1
+++ PropertyEvaluator.java 30 Dec 2004 15:18:17 -0000 1.2
@@ -33,6 +33,13 @@
_propertyName = propertyName;
}
+ // For testing
+
+ String getPropertyName()
+ {
+ return _propertyName;
+ }
+
/**
* Invokes [EMAIL PROTECTED]
org.apache.hivemind.conditional.EvaluationContext#isPropertySet(String)}.
*/
1.2 +7 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/NodeImpl.java
Index: NodeImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/NodeImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NodeImpl.java 29 Dec 2004 21:09:17 -0000 1.1
+++ NodeImpl.java 30 Dec 2004 15:18:17 -0000 1.2
@@ -58,6 +58,13 @@
return _right;
}
+ // For testing
+
+ Evaluator getEvaluator()
+ {
+ return _evaluator;
+ }
+
public boolean evaluate(EvaluationContext context)
{
return _evaluator.evaluate(context, this);
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/ConditionalStrings.properties
Index: ConditionalStrings.properties
===================================================================
#
# Copyright 2004 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
unexpected-character=Unexpected character ''{0}'' at position {1} of input
string ''{2}''.
unexpected-end-of-input=End of input reached unexpectedly, parsing expression
''{0}''.
unexpected-token=Expected {0} (not {1}) parsing expression ''{2}''.
unparsed-token=Unexpected token {0} in expression ''{1}''.
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/TokenType.java
Index: TokenType.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
/**
* Used by [EMAIL PROTECTED] Token}to identify the type of token.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
class TokenType
{
// Each type has a code number, useful for switch statements.
static final int OPAREN_CODE = 0;
static final int CPAREN_CODE = 1;
static final int AND_CODE = 2;
static final int OR_CODE = 3;
static final int NOT_CODE = 4;
static final int PROPERTY_CODE = 5;
static final int CLASS_CODE = 6;
static final int SYMBOL_CODE = 7;
/**
* An open parenthesis.
*/
static final TokenType OPAREN = new TokenType("OPAREN", OPAREN_CODE);
/**
* A close parenthesis.
*/
static final TokenType CPAREN = new TokenType("CPAREN", CPAREN_CODE);
/**
* The keyword "and"
*/
static final TokenType AND = new TokenType("AND", AND_CODE);
/**
* The keyword "or"
*/
static final TokenType OR = new TokenType("OR", OR_CODE);
/**
* The keyword "not"
*/
static final TokenType NOT = new TokenType("NOT", NOT_CODE);
/**
* The keyword "property"
*/
static final TokenType PROPERTY = new TokenType("PROPERTY",
PROPERTY_CODE);
/**
* The keyword "class"
*/
static final TokenType CLASS = new TokenType("CLASS", CLASS_CODE);
/**
* A symbol.
*/
static final TokenType SYMBOL = new TokenType("SYMBOL", SYMBOL_CODE);
private String _name;
private int _code;
private TokenType(String name, int code)
{
_name = name;
_code = code;
}
public int getCode()
{
return _code;
}
public String toString()
{
return _name;
}
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/Parser.java
Index: Parser.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.Defense;
/**
* Parser for conditional expressions. This class is not threadsafe; it is
inexpensive to create,
* however, and can be discarded after parsing one or more expressions.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class Parser
{
private String _input;
private Lexer _lexer;
private Token _nextToken;
private boolean _onDeck;
// No reason to have multiple instances of these, since they are always
// identical (one of the advantages of the NodeImpl being purely
structural.
private static final Evaluator NOT_EVALUATOR = new NotEvaluator();
private static final Evaluator OR_EVALUATOR = new OrEvaluator();
private static final Evaluator AND_EVALUATOR = new AndEvaluator();
public Node parse(String input)
{
Defense.notNull(input, "input");
try
{
_input = input;
_lexer = new Lexer(input);
Node result = expression();
Token token = next();
if (token != null)
throw new
RuntimeException(ConditionalMessages.unparsedToken(token, _input));
return result;
}
finally
{
_input = null;
_nextToken = null;
_lexer = null;
_onDeck = false;
}
}
private Token next()
{
Token result = _onDeck ? _nextToken : _lexer.next();
_onDeck = false;
_nextToken = null;
return result;
}
private Token match(TokenType expected)
{
Token actual = next();
if (actual == null)
throw new
RuntimeException(ConditionalMessages.unexpectedEndOfInput(_input));
if (actual.getType() != expected)
throw new
RuntimeException(ConditionalMessages.unexpectedToken(expected, actual
.getType(), _input));
return actual;
}
private Token peek()
{
if (! _onDeck)
{
_nextToken = _lexer.next();
_onDeck = true;
}
return _nextToken;
}
private TokenType peekType()
{
Token next = peek();
return next == null ? null : next.getType();
}
private boolean isPeek(TokenType type)
{
return peekType() == type;
}
private Node expression()
{
Node lnode = term();
if (isPeek(TokenType.OR))
{
next();
Node rnode = expression();
return new NodeImpl(lnode, rnode, OR_EVALUATOR);
}
if (isPeek(TokenType.AND))
{
next();
Node rnode = expression();
return new NodeImpl(lnode, rnode, AND_EVALUATOR);
}
return lnode;
}
private Node term()
{
if (isPeek(TokenType.OPAREN))
{
next();
Node result = expression();
match(TokenType.CPAREN);
return result;
}
if (isPeek(TokenType.NOT))
{
next();
match(TokenType.OPAREN);
Node expression = expression();
match(TokenType.CPAREN);
return new NodeImpl(expression, null, NOT_EVALUATOR);
}
if (isPeek(TokenType.PROPERTY))
{
next();
Token symbolToken = match(TokenType.SYMBOL);
Evaluator ev = new PropertyEvaluator(symbolToken.getValue());
return new NodeImpl(ev);
}
if (isPeek(TokenType.CLASS))
{
next();
Token symbolToken = match(TokenType.SYMBOL);
Evaluator ev = new ClassNameEvaluator(symbolToken.getValue());
return new NodeImpl(ev);
}
throw new RuntimeException(ConditionalMessages.unparsedToken(next(),
_input));
}
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/Token.java
Index: Token.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.Defense;
/**
* A token recognized from a conditional expression.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
class Token
{
private TokenType _type;
private String _value;
Token(TokenType type)
{
this(type, null);
}
/**
* @param type
* a specific token type (may not be null)
* @param value
* the value for this token
*/
Token(TokenType type, String value)
{
Defense.notNull(type, "type");
_type = type;
_value = value;
}
public TokenType getType()
{
return _type;
}
/**
* Returns the specific value for this token, generally only meaningful
for the
* [EMAIL PROTECTED]
org.apache.hivemind.conditional.TokenType#SYMBOL}type.
*/
public String getValue()
{
return _value;
}
/**
* Returns either <TYPE> or <TYPE(VALUE)>, where TYPE is the
TokenType and VALUE is
* the value (if non null).
*/
public String toString()
{
StringBuffer buffer = new StringBuffer("<");
buffer.append(_type);
if (_value != null)
{
buffer.append("(");
buffer.append(_value);
buffer.append(")");
}
buffer.append(">");
return buffer.toString();
}
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/Lexer.java
Index: Lexer.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.Defense;
/**
* Parses a string into a series of [EMAIL PROTECTED]
org.apache.hivemind.conditional.Token}s.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
class Lexer
{
private char[] _input;
private int _cursor = 0;
private static final Token OPAREN = new Token(TokenType.OPAREN);
private static final Token CPAREN = new Token(TokenType.CPAREN);
private static final Token AND = new Token(TokenType.AND);
private static final Token OR = new Token(TokenType.OR);
private static final Token NOT = new Token(TokenType.NOT);
private static final Token PROPERTY = new Token(TokenType.PROPERTY);
private static final Token CLASS = new Token(TokenType.CLASS);
Lexer(String input)
{
Defense.notNull(input, "input");
_input = input.toCharArray();
}
/**
* Returns the next token from the input, or null when all tokens have
been recognized.
*/
Token next()
{
while (_cursor < _input.length)
{
char ch = _input[_cursor];
if (ch == ')')
{
_cursor++;
return CPAREN;
}
if (ch == '(')
{
_cursor++;
return OPAREN;
}
if (Character.isWhitespace(ch))
{
_cursor++;
continue;
}
if (isSymbolChar(ch))
return readSymbol();
throw new
RuntimeException(ConditionalMessages.unexpectedCharacter(_cursor, _input));
}
return null;
}
/**
* This is somewhat limited; a complete regexp would only allow dots
within the text, would not
* allow consecutive dots, and would require the string start with letter
or underscore.
*/
private boolean isSymbolChar(char ch)
{
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >=
'0' && ch <= '9')
|| (ch == '.') || (ch == '_');
}
/**
* Reads the next symbol at the cursor position, leaving the cursor on
the character after the
* symbol. Also recognizes keywords.
*/
private Token readSymbol()
{
int start = _cursor;
while (true)
{
_cursor++;
if (_cursor >= _input.length)
break;
if (!isSymbolChar(_input[_cursor]))
break;
}
String symbol = new String(_input, start, _cursor - start);
if (symbol.equalsIgnoreCase("and"))
return AND;
if (symbol.equalsIgnoreCase("or"))
return OR;
if (symbol.equalsIgnoreCase("not"))
return NOT;
if (symbol.equalsIgnoreCase("property"))
return PROPERTY;
if (symbol.equalsIgnoreCase("class"))
return CLASS;
return new Token(TokenType.SYMBOL, symbol);
}
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/package.html
Index: package.html
===================================================================
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<body>
Classes and interfaces used in the implementation of conditional
contributions.
</body>
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/conditional/ConditionalMessages.java
Index: ConditionalMessages.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.impl.MessageFormatter;
/**
* @author Howard M. Lewis Ship
* @since 1.1
*/
class ConditionalMessages
{
private static final MessageFormatter _formatter = new MessageFormatter(
ConditionalMessages.class, "ConditionalStrings");
public static String unexpectedCharacter(int position, char[] input)
{
return _formatter.format(
"unexpected-character",
new Character(input[position]),
new Integer(position + 1),
new String(input));
}
public static String unexpectedEndOfInput(String input)
{
return _formatter.format("unexpected-end-of-input", input);
}
public static String unexpectedToken(TokenType expected, TokenType
actual, String input)
{
return _formatter.format("unexpected-token", expected, actual, input);
}
public static String unparsedToken(Token token, String input)
{
return _formatter.format("unparsed-token", token, input);
}
}
1.2 +0 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/package.html
Index: package.html
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/package.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- package.html 26 Feb 2004 23:07:40 -0000 1.1
+++ package.html 30 Dec 2004 15:18:17 -0000 1.2
@@ -1,4 +1,3 @@
-<!-- $Id$ -->
<!--
Copyright 2004 The Apache Software Foundation
1.1 jakarta-hivemind/framework/src/test/dummy.groovy
Index: dummy.groovy
===================================================================
# Placeholder Groovy test script.
#
# Add -Dtest=framework/src/test/dummy.groovy to runtime options.
#
# Allows unit tests to be run from inside Eclipse IDE.
1.1
jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestParser.java
Index: TestParser.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.test.HiveMindTestCase;
/**
* Tests for [EMAIL PROTECTED] org.apache.hivemind.conditional.Parser}.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class TestParser extends HiveMindTestCase
{
public void testSingleTerm()
{
Parser p = new Parser();
Node n = p.parse("class foo");
Evaluator ev = ((NodeImpl) n).getEvaluator();
ClassNameEvaluator cne = (ClassNameEvaluator) ev;
assertEquals("foo", cne.getClassName());
}
public void testExtraToken()
{
Parser p = new Parser();
try
{
p.parse("class foo bar");
unreachable();
}
catch (RuntimeException ex)
{
assertEquals("Unexpected token <SYMBOL(bar)> in expression 'class
foo bar'.", ex
.getMessage());
}
}
public void testTermAsExpression()
{
Parser p = new Parser();
NodeImpl n = (NodeImpl) p.parse("(property foo.bar)");
PropertyEvaluator ev = (PropertyEvaluator) n.getEvaluator();
assertEquals("foo.bar", ev.getPropertyName());
}
public void testNot()
{
Parser p = new Parser();
NodeImpl n = (NodeImpl) p.parse("not (property foo)");
assertTrue(n.getEvaluator() instanceof NotEvaluator);
NodeImpl n2 = (NodeImpl) n.getLeft();
PropertyEvaluator ev = (PropertyEvaluator) n2.getEvaluator();
assertEquals("foo", ev.getPropertyName());
}
public void testMissingToken()
{
Parser p = new Parser();
try
{
p.parse("not (property foo");
unreachable();
}
catch (RuntimeException ex)
{
assertEquals(
"End of input reached unexpectedly, parsing expression
'not (property foo'.",
ex.getMessage());
}
}
public void testWrongToken()
{
Parser p = new Parser();
try
{
p.parse("not property foo");
unreachable();
}
catch (RuntimeException ex)
{
assertEquals(
"Expected OPAREN (not PROPERTY) parsing expression 'not
property foo'.",
ex.getMessage());
}
}
public void testWrongTokenInTerm()
{
Parser p = new Parser();
try
{
p.parse("and property foo");
unreachable();
}
catch (RuntimeException ex)
{
assertEquals("Unexpected token <AND> in expression 'and property
foo'.", ex
.getMessage());
}
}
public void testAnd()
{
Parser p = new Parser();
NodeImpl n = (NodeImpl) p.parse("property foo and class bar");
assertTrue(n.getEvaluator() instanceof AndEvaluator);
NodeImpl n2 = (NodeImpl) n.getLeft();
PropertyEvaluator ev1 = (PropertyEvaluator) n2.getEvaluator();
assertEquals("foo", ev1.getPropertyName());
NodeImpl n3 = (NodeImpl) n.getRight();
ClassNameEvaluator ev2 = (ClassNameEvaluator) n3.getEvaluator();
assertEquals("bar", ev2.getClassName());
}
public void testOr()
{
Parser p = new Parser();
NodeImpl n = (NodeImpl) p.parse("property foo or class bar");
assertTrue(n.getEvaluator() instanceof OrEvaluator);
NodeImpl n2 = (NodeImpl) n.getLeft();
PropertyEvaluator ev1 = (PropertyEvaluator) n2.getEvaluator();
assertEquals("foo", ev1.getPropertyName());
NodeImpl n3 = (NodeImpl) n.getRight();
ClassNameEvaluator ev2 = (ClassNameEvaluator) n3.getEvaluator();
assertEquals("bar", ev2.getClassName());
}
}
1.1
jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestToken.java
Index: TestToken.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.test.HiveMindTestCase;
/**
* Tests for [EMAIL PROTECTED] org.apache.hivemind.conditional.Token}and
* [EMAIL PROTECTED] org.apache.hivemind.conditional.TokenType}.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class TestToken extends HiveMindTestCase
{
public void testTokenTypeToString()
{
assertEquals("SYMBOL", TokenType.SYMBOL.toString());
assertEquals(TokenType.SYMBOL_CODE, TokenType.SYMBOL.getCode());
}
public void testTokenToStringNoValue()
{
Token t = new Token(TokenType.OPAREN);
assertEquals("<OPAREN>", t.toString());
}
public void testTokenToString()
{
Token t = new Token(TokenType.SYMBOL, "foo.bar.Baz");
assertEquals("<SYMBOL(foo.bar.Baz)>", t.toString());
}
}
1.1
jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestLexer.java
Index: TestLexer.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.conditional;
import org.apache.hivemind.test.HiveMindTestCase;
/**
* Tests for [EMAIL PROTECTED] org.apache.hivemind.conditional.Lexer}.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class TestLexer extends HiveMindTestCase
{
public void testKeywords()
{
Lexer l = new Lexer("and OR Not class Property");
assertSame(TokenType.AND, l.next().getType());
assertSame(TokenType.OR, l.next().getType());
assertSame(TokenType.NOT, l.next().getType());
assertSame(TokenType.CLASS, l.next().getType());
assertSame(TokenType.PROPERTY, l.next().getType());
assertNull(l.next());
}
public void testParens()
{
Lexer l = new Lexer("not (property foo)");
assertSame(TokenType.NOT, l.next().getType());
assertSame(TokenType.OPAREN, l.next().getType());
assertSame(TokenType.PROPERTY, l.next().getType());
Token t = l.next();
assertSame(TokenType.SYMBOL, t.getType());
assertEquals("foo", t.getValue());
assertSame(TokenType.CPAREN, l.next().getType());
assertNull(l.next());
}
public void testInvalidCharacter()
{
Lexer l = new Lexer("not[property foo]");
assertSame(TokenType.NOT, l.next().getType());
try
{
l.next();
unreachable();
}
catch (RuntimeException ex)
{
assertEquals(
"Unexpected character '[' at position 4 of input string
'not[property foo]'.",
ex.getMessage());
}
}
public void testSymbolAtEnd()
{
Lexer l = new Lexer("property foo.bar.Baz");
assertSame(TokenType.PROPERTY, l.next().getType());
Token t = l.next();
assertSame(TokenType.SYMBOL, t.getType());
assertEquals("foo.bar.Baz", t.getValue());
assertNull(l.next());
}
}
1.8 +1 -1
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/factory/FactoryMessages.java
Index: FactoryMessages.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/factory/FactoryMessages.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FactoryMessages.java 28 Dec 2004 22:43:15 -0000 1.7
+++ FactoryMessages.java 30 Dec 2004 15:18:17 -0000 1.8
@@ -1,4 +1,4 @@
-// Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]