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

public abstract class AbstractJavaParser extends Object implements JavaTokens
A base parser for Java parsing that contains any shared logic
Version:
Beta v.0.5
Author:
Logan Ferree (Tadukoo)
  • Field Details

    • MODIFIERS_REGEX

      protected static final String MODIFIERS_REGEX
      A regular expression used for all the modifiers
      See Also:
    • TOKEN_REGEX

      protected static final String TOKEN_REGEX
      A regular expression used for tokens to match on when splitting tokens from a content String
      See Also:
    • WHITESPACE_MATCHER

      protected static final Matcher WHITESPACE_MATCHER
      A matcher to use to find whitespace (usually to skip it)
  • Constructor Details

    • AbstractJavaParser

      protected AbstractJavaParser()
      Not allowed to instantiate AbstractJavaParser
  • Method Details

    • splitContentIntoTokens

      protected static List<String> splitContentIntoTokens(String content)
      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

      protected static int skipLeadingWhitespace(List<String> tokens)
      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 a JavaParsingException to be thrown
      Parameters:
      tokens - The List of tokens being parsed
      result - The ParsingPojo from what we've finished parsing
      type - The type being parsed
      Throws:
      JavaParsingException - If we're not at the end of the tokens
    • determineFieldOrMethod

      protected static JavaCodeTypes determineFieldOrMethod(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. 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 parsing
      currentToken - The current token being looked at
      Returns:
      Either JavaCodeTypes.FIELD, JavaCodeTypes.METHOD, or JavaCodeTypes.UNKNOWN