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