From c36bb542027754d394639170b96348439257103b Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 28 Jul 2013 22:05:21 +0300 Subject: [PATCH] moved string tokenizer to svjatoslav-commons --- pom.xml | 2 +- .../inspector/java/methods/Annotation.java | 6 +- .../java/methods/ClassReference.java | 4 +- .../inspector/java/methods/Clazz.java | 6 +- .../inspector/java/methods/JavaFile.java | 6 +- .../java/methods/ProjectScanner.java | 2 +- .../tokenizer/InvalidSyntaxException.java | 11 -- .../inspector/tokenizer/Terminator.java | 22 ---- .../inspector/tokenizer/Tokenizer.java | 120 ------------------ .../inspector/tokenizer/TokenizerMatch.java | 12 -- 10 files changed, 13 insertions(+), 178 deletions(-) delete mode 100644 src/main/java/eu/svjatoslav/inspector/tokenizer/InvalidSyntaxException.java delete mode 100644 src/main/java/eu/svjatoslav/inspector/tokenizer/Terminator.java delete mode 100644 src/main/java/eu/svjatoslav/inspector/tokenizer/Tokenizer.java delete mode 100644 src/main/java/eu/svjatoslav/inspector/tokenizer/TokenizerMatch.java diff --git a/pom.xml b/pom.xml index 09c54f8..c5825da 100755 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ eu.svjatoslav svjatoslavcommons - 1.1-SNAPSHOT + 1.1 diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java index d262061..96e0d20 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java @@ -1,8 +1,8 @@ package eu.svjatoslav.inspector.java.methods; -import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException; -import eu.svjatoslav.inspector.tokenizer.Tokenizer; -import eu.svjatoslav.inspector.tokenizer.TokenizerMatch; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; +import eu.svjatoslav.commons.string.tokenizer.Tokenizer; +import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; public class Annotation { diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java b/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java index 1a943f5..470a0d5 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java @@ -3,8 +3,8 @@ package eu.svjatoslav.inspector.java.methods; import java.util.ArrayList; import java.util.List; -import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException; -import eu.svjatoslav.inspector.tokenizer.Tokenizer; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; +import eu.svjatoslav.commons.string.tokenizer.Tokenizer; public class ClassReference { diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java index 29c2899..430b5f1 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java @@ -3,9 +3,9 @@ package eu.svjatoslav.inspector.java.methods; import java.util.ArrayList; import java.util.List; -import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException; -import eu.svjatoslav.inspector.tokenizer.Tokenizer; -import eu.svjatoslav.inspector.tokenizer.TokenizerMatch; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; +import eu.svjatoslav.commons.string.tokenizer.Tokenizer; +import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; public class Clazz { diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java index 3dd5557..15d5169 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java @@ -8,9 +8,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException; -import eu.svjatoslav.inspector.tokenizer.Tokenizer; -import eu.svjatoslav.inspector.tokenizer.TokenizerMatch; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; +import eu.svjatoslav.commons.string.tokenizer.Tokenizer; +import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; public class JavaFile { diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java index b37fa4f..aaeacd4 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; import eu.svjatoslav.commons.file.FilePathParser; -import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; public class ProjectScanner { diff --git a/src/main/java/eu/svjatoslav/inspector/tokenizer/InvalidSyntaxException.java b/src/main/java/eu/svjatoslav/inspector/tokenizer/InvalidSyntaxException.java deleted file mode 100644 index 1d47f4c..0000000 --- a/src/main/java/eu/svjatoslav/inspector/tokenizer/InvalidSyntaxException.java +++ /dev/null @@ -1,11 +0,0 @@ -package eu.svjatoslav.inspector.tokenizer; - -public class InvalidSyntaxException extends Exception { - - private static final long serialVersionUID = 88294980027680555L; - - public InvalidSyntaxException(final String cause) { - super(cause); - } - -} diff --git a/src/main/java/eu/svjatoslav/inspector/tokenizer/Terminator.java b/src/main/java/eu/svjatoslav/inspector/tokenizer/Terminator.java deleted file mode 100644 index 8848775..0000000 --- a/src/main/java/eu/svjatoslav/inspector/tokenizer/Terminator.java +++ /dev/null @@ -1,22 +0,0 @@ -package eu.svjatoslav.inspector.tokenizer; - -public class Terminator { - - String startSequence; - String endSequence; - boolean ignoreTerminator; - - public Terminator(final String startPattern, final boolean ignoreTerminator) { - this.startSequence = startPattern; - this.ignoreTerminator = ignoreTerminator; - } - - public Terminator(final String startSequence, final String endSequence, - final boolean ignoreTerminator) { - - this.startSequence = startSequence; - this.endSequence = endSequence; - this.ignoreTerminator = ignoreTerminator; - } - -} diff --git a/src/main/java/eu/svjatoslav/inspector/tokenizer/Tokenizer.java b/src/main/java/eu/svjatoslav/inspector/tokenizer/Tokenizer.java deleted file mode 100644 index ec13b1a..0000000 --- a/src/main/java/eu/svjatoslav/inspector/tokenizer/Tokenizer.java +++ /dev/null @@ -1,120 +0,0 @@ -package eu.svjatoslav.inspector.tokenizer; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -public class Tokenizer { - - private final List terminators = new ArrayList(); - private final String source; - - Stack tokenIndexes = new Stack(); - - private int currentIndex = 0; - - public Tokenizer(final String source) { - this.source = source; - } - - public void addTerminator(final String startSequence, - final boolean ignoreTerminator) { - terminators.add(new Terminator(startSequence, ignoreTerminator)); - } - - public void addTerminator(final String startSequence, - final String endSequence, final boolean ignoreTerminator) { - terminators.add(new Terminator(startSequence, endSequence, - ignoreTerminator)); - } - - public void expectNextToken(final String value) - throws InvalidSyntaxException { - final TokenizerMatch match = getNextToken(); - if (!value.equals(match.token)) - throw new InvalidSyntaxException("Expected \"" + value - + "\" but got \"" + match.token + "\" instead."); - } - - public TokenizerMatch getNextToken() { - tokenIndexes.push(currentIndex); - final StringBuffer result = new StringBuffer(); - - while (true) { - if (currentIndex >= source.length()) - return null; - - boolean accumulateCurrentChar = true; - - findTerminator: for (final Terminator terminator : terminators) - if (sequenceMatches(terminator.startSequence)) - - if (terminator.ignoreTerminator) { - currentIndex += terminator.startSequence.length(); - - if (terminator.endSequence != null) - skipUntilSequence(terminator.endSequence); - - if (result.length() > 0) - return new TokenizerMatch(result.toString(), - terminator); - else { - accumulateCurrentChar = false; - break findTerminator; - } - } else if (result.length() > 0) - return new TokenizerMatch(result.toString(), terminator); - else { - currentIndex += terminator.startSequence.length(); - return new TokenizerMatch(terminator.startSequence, - terminator); - } - - if (accumulateCurrentChar) { - result.append(source.charAt(currentIndex)); - currentIndex++; - } - } - - } - - public boolean probeNextToken(final String token) { - if (token.equals(getNextToken().token)) - return true; - - unreadToken(); - return false; - } - - public boolean sequenceMatches(final String sequence) { - if ((currentIndex + sequence.length()) > source.length()) - return false; - - for (int i = 0; i < sequence.length(); i++) - if (sequence.charAt(i) != source.charAt(i + currentIndex)) - return false; - - return true; - } - - public void skipUntilDataEnd() { - tokenIndexes.push(currentIndex); - currentIndex = source.length(); - } - - public void skipUntilSequence(final String sequence) { - while (currentIndex < source.length()) { - if (sequenceMatches(sequence)) { - currentIndex += sequence.length(); - return; - } - - currentIndex++; - } - } - - public void unreadToken() { - currentIndex = tokenIndexes.pop(); - } - -} diff --git a/src/main/java/eu/svjatoslav/inspector/tokenizer/TokenizerMatch.java b/src/main/java/eu/svjatoslav/inspector/tokenizer/TokenizerMatch.java deleted file mode 100644 index 158a9d9..0000000 --- a/src/main/java/eu/svjatoslav/inspector/tokenizer/TokenizerMatch.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.svjatoslav.inspector.tokenizer; - -public class TokenizerMatch { - - public String token; - public Terminator terminator; - - public TokenizerMatch(final String token, final Terminator terminator) { - this.token = token; - this.terminator = terminator; - } -} -- 2.20.1