Rename UnexpectedElementTypeException
This commit is contained in:
parent
a63d23a0e7
commit
1c08055637
|
@ -24,10 +24,10 @@
|
|||
package com.github.zafarkhaja.semver;
|
||||
|
||||
import com.github.zafarkhaja.semver.util.Stream;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static com.github.zafarkhaja.semver.VersionParser.Char.*;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementTypeException;
|
||||
|
||||
/**
|
||||
* A parser for the SemVer Version.
|
||||
|
@ -140,8 +140,7 @@ class VersionParser implements Parser<Version> {
|
|||
* @return a valid version object
|
||||
* @throws GrammarException when there is an error defined in
|
||||
* the SemVer or the formal grammar
|
||||
* @throws UnexpectedElementTypeException when encounters an unexpected
|
||||
* character type
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
@Override
|
||||
public Version parse(String input) {
|
||||
|
@ -155,8 +154,7 @@ class VersionParser implements Parser<Version> {
|
|||
* @return a valid version object
|
||||
* @throws GrammarException when there is an error defined in
|
||||
* the SemVer or the formal grammar
|
||||
* @throws UnexpectedElementTypeException when encounters an unexpected
|
||||
* character type
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
static Version parseValidSemVer(String version) {
|
||||
VersionParser parser = new VersionParser(version);
|
||||
|
@ -170,8 +168,7 @@ class VersionParser implements Parser<Version> {
|
|||
* @return a valid normal version object
|
||||
* @throws GrammarException when there is an error defined in
|
||||
* the SemVer or the formal grammar
|
||||
* @throws UnexpectedElementTypeException when encounters an unexpected
|
||||
* character type
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
static NormalVersion parseVersionCore(String versionCore) {
|
||||
VersionParser parser = new VersionParser(versionCore);
|
||||
|
|
|
@ -28,7 +28,7 @@ import com.github.zafarkhaja.semver.Version;
|
|||
import com.github.zafarkhaja.semver.expr.Lexer.Token;
|
||||
import com.github.zafarkhaja.semver.util.Stream;
|
||||
import com.github.zafarkhaja.semver.util.Stream.ElementType;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementTypeException;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import static com.github.zafarkhaja.semver.expr.Lexer.Token.Type.*;
|
||||
|
@ -78,8 +78,7 @@ public class ExpressionParser implements Parser<Expression> {
|
|||
* @param input a string representing the SemVer Expression
|
||||
* @return the AST for the SemVer Expressions
|
||||
* @throws LexerException when encounters an illegal character
|
||||
* @throws UnexpectedElementTypeException when consumes a token of an
|
||||
* unexpected type
|
||||
* @throws UnexpectedElementException when consumes a token of an unexpected type
|
||||
*/
|
||||
@Override
|
||||
public Expression parse(String input) {
|
||||
|
|
|
@ -103,7 +103,7 @@ public class Stream<E> implements Iterable<E> {
|
|||
* warnings
|
||||
* @param expected the types which are expected
|
||||
* @return the next element in this stream
|
||||
* @throws UnexpectedElementTypeException if the next element is of an unexpected type
|
||||
* @throws UnexpectedElementException if the next element is of an unexpected type
|
||||
*/
|
||||
public <T extends ElementType<E>> E consume(T... expected) {
|
||||
E lookahead = lookahead(1);
|
||||
|
@ -112,7 +112,7 @@ public class Stream<E> implements Iterable<E> {
|
|||
return consume();
|
||||
}
|
||||
}
|
||||
throw new UnexpectedElementTypeException(lookahead, expected);
|
||||
throw new UnexpectedElementException(lookahead, expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.Arrays;
|
|||
* @see Stream#consume(Stream.ElementType...)
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class UnexpectedElementTypeException extends RuntimeException {
|
||||
public class UnexpectedElementException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* The unexpected element in the stream.
|
||||
|
@ -46,13 +46,13 @@ public class UnexpectedElementTypeException extends RuntimeException {
|
|||
private final ElementType<?>[] expected;
|
||||
|
||||
/**
|
||||
* Constructs a {@code UnexpectedElementTypeException} instance
|
||||
* Constructs a {@code UnexpectedElementException} instance
|
||||
* with the unexpected element and the expected types.
|
||||
*
|
||||
* @param element the unexpected element in the stream
|
||||
* @param expected an array of the expected element types
|
||||
*/
|
||||
UnexpectedElementTypeException(Object element, ElementType<?>... expected) {
|
||||
UnexpectedElementException(Object element, ElementType<?>... expected) {
|
||||
unexpected = element;
|
||||
this.expected = expected;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
package com.github.zafarkhaja.semver.expr;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementTypeException;
|
||||
import com.github.zafarkhaja.semver.util.UnexpectedElementException;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class ExpressionParserTest {
|
|||
ExpressionParser parser = new ExpressionParser(new Lexer());
|
||||
try {
|
||||
parser.parse("((>=1.0.1 & < 2)");
|
||||
} catch (UnexpectedElementTypeException e) {
|
||||
} catch (UnexpectedElementException e) {
|
||||
return;
|
||||
}
|
||||
fail("Should raise error if closing parenthesis is missing");
|
||||
|
|
|
@ -85,7 +85,7 @@ public class StreamTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRaiseErrorWhenUnexpectedElementTypeConsumed() {
|
||||
public void shouldRaiseErrorWhenUnexpectedElementConsumed() {
|
||||
Stream<Character> stream = new Stream<Character>(
|
||||
new Character[] {'a', 'b', 'c'}
|
||||
);
|
||||
|
@ -96,7 +96,7 @@ public class StreamTest {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
} catch (UnexpectedElementTypeException e) {
|
||||
} catch (UnexpectedElementException e) {
|
||||
return;
|
||||
}
|
||||
fail("Should raise error when unexpected element type is consumed");
|
||||
|
|
Loading…
Reference in New Issue
Block a user