Package com.github.tadukoo.java.parsing
Class AbstractJavaParser
java.lang.Object
com.github.tadukoo.java.parsing.AbstractJavaParser
- All Implemented Interfaces:
JavaTokens
- Direct Known Subclasses:
FullJavaParser,JavaAnnotationParser,JavaClassParser,JavadocParser,JavaFieldParser,JavaImportStatementParser,JavaMethodParser,JavaMultiLineCommentParser,JavaPackageDeclarationParser,JavaSingleLineCommentParser,JavaTypeWithModifiersParser
A base parser for Java parsing that contains any shared logic
- Version:
- Beta v.0.5
- Author:
- Logan Ferree (Tadukoo)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringA regular expression used for all the modifiersprotected static final StringA regular expression used for tokens to match on when splitting tokens from a content Stringprotected static final MatcherA matcher to use to find whitespace (usually to skip it)Fields inherited from interface com.github.tadukoo.java.JavaTokens
ABSTRACT_MODIFIER, ANNOTATION_START_TOKEN, ASSIGNMENT_OPERATOR_TOKEN, BLOCK_CLOSE_TOKEN, BLOCK_OPEN_TOKEN, CLASS_TOKEN, EXTENDS_TOKEN, FINAL_MODIFIER, IMPLEMENTS_TOKEN, IMPORT_TOKEN, JAVADOC_AUTHOR_TOKEN, JAVADOC_LINE_TOKEN, JAVADOC_PARAM_TOKEN, JAVADOC_RETURN_TOKEN, JAVADOC_SINCE_TOKEN, JAVADOC_START_TOKEN, JAVADOC_VERSION_TOKEN, LIST_SEPARATOR_TOKEN, MODIFIERS, MULTI_LINE_COMMENT_CLOSE_TOKEN, MULTI_LINE_COMMENT_START_TOKEN, PACKAGE_TOKEN, PARAMETER_CLOSE_TOKEN, PARAMETER_OPEN_TOKEN, PRIVATE_MODIFIER, PROTECTED_MODIFIER, PUBLIC_MODIFIER, SEMICOLON, SINGLE_LINE_COMMENT_TOKEN, STATIC_MODIFIER, THROWS_TOKEN, VISIBILITY_MODIFIERS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static JavaCodeTypesdetermineFieldOrMethod(List<String> tokens, int currentToken) Used to determine if we have a field or method based on the token we're looking at in parsing.protected static intskipLeadingWhitespace(List<String> tokens) Determines the token index to start at for the given tokens List, skipping any leading newlinessplitContentIntoTokens(String content) Takes the given String content and splits it into a List of tokens to be parsedprotected static voidverifyEndOfTokens(List<String> tokens, ParsingPojo result, JavaCodeTypes type) Checks that we've made it to the end of the tokens during parsing (to verify we're really done).
-
Field Details
-
MODIFIERS_REGEX
A regular expression used for all the modifiers- See Also:
-
TOKEN_REGEX
A regular expression used for tokens to match on when splitting tokens from a content String- See Also:
-
WHITESPACE_MATCHER
A matcher to use to find whitespace (usually to skip it)
-
-
Constructor Details
-
AbstractJavaParser
protected AbstractJavaParser()Not allowed to instantiateAbstractJavaParser
-
-
Method Details
-
splitContentIntoTokens
Takes the given String content and splits it into a List of tokens to be parsed- Parameters:
content- The content to be split into tokens- Returns:
- The List of tokens to be parsed
-
skipLeadingWhitespace
Determines the token index to start at for the given tokens List, skipping any leading newlines- Parameters:
tokens- The List of tokens to be parsed- Returns:
- The token to start at (skipping leading newlines)
-
verifyEndOfTokens
protected static void verifyEndOfTokens(List<String> tokens, ParsingPojo result, JavaCodeTypes type) throws JavaParsingException Checks that we've made it to the end of the tokens during parsing (to verify we're really done). This handles any trailing newlines by ignoring them, but any other remaining tokens will cause aJavaParsingExceptionto be thrown- Parameters:
tokens- The List of tokens being parsedresult- TheParsingPojofrom what we've finished parsingtype- Thetypebeing parsed- Throws:
JavaParsingException- If we're not at the end of the tokens
-
determineFieldOrMethod
Used to determine if we have a field or method based on the token we're looking at in parsing. This is used in several places to determine which we're looking at, hence the need for a method to reduce repeated code :P- Parameters:
tokens- The tokens we're parsingcurrentToken- The current token being looked at- Returns:
- Either
JavaCodeTypes.FIELD,JavaCodeTypes.METHOD, orJavaCodeTypes.UNKNOWN
-