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
- Since:
- Beta v.0.5
- Version:
- Beta v.0.6
- Author:
- Logan Ferree (Tadukoo)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringA regular expression used for all the modifiersprotected static final PatternAPatternto use for parsing aJavaParameterprotected static final StringA regular expression for aJavaParameterprotected static final StringA regular expression used for tokens to match on when splitting tokens from a content Stringprotected static final PatternAPatternto use for parsingtype parametersprotected static final StringA regular expression for aJavaTypeParameterprotected static final Patternprotected static final StringA regular expression for aJavaTypeprotected 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, TYPE_PARAMETER_CLOSE_TOKEN, TYPE_PARAMETER_OPEN_TOKEN, VARARGS_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.static JavaParameterparseJavaParameter(String parameterContent) Parses aJavaParameterfrom the given Stringstatic JavaTypeparseJavaType(String typeContent) Parses aJavaTypefrom the given Stringstatic List<JavaTypeParameter>parseJavaTypeParameters(String typeParametersContent) Parses the given String into a List ofJava Type ParametersparseOutType(List<String> tokens, int currentToken) Parse the tokens fromcurrentTokenonward to get aJavaTypestring, where we have all the type parameters in the String for it.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) -
TYPE_PARAMETER_REGEX
A regular expression for aJavaTypeParameter- See Also:
-
TYPE_PARAMETER_PATTERN
APatternto use for parsingtype parameters -
TYPE_REGEX
A regular expression for aJavaType -
TYPE_PATTERN
-
PARAMETER_REGEX
A regular expression for aJavaParameter -
PARAMETER_PATTERN
APatternto use for parsing aJavaParameter
-
-
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
-
parseOutType
protected static com.github.tadukoo.util.tuple.Pair<String,Integer> parseOutType(List<String> tokens, int currentToken) Parse the tokens fromcurrentTokenonward to get aJavaTypestring, where we have all the type parameters in the String for it. We leave the parsing of that type to the caller, but return the next token index (after the type string) as well.- Parameters:
tokens- The List of tokens to parse a type string fromcurrentToken- The current token index to start at to get a type- Returns:
- A Pair of the type string and the next token index
-
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
-
parseJavaParameter
Parses aJavaParameterfrom the given String- Parameters:
parameterContent- The String to parse- Returns:
- The
JavaParameterthat was parsed
-
parseJavaType
Parses aJavaTypefrom the given String- Parameters:
typeContent- The String to parse- Returns:
- The
JavaTypethat was parsed
-
parseJavaTypeParameters
Parses the given String into a List ofJava Type Parameters- Parameters:
typeParametersContent- The String to be parsed- Returns:
- The List of
Java Type Parametersthat were parsed from the String
-