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
Since:
Beta v.0.5
Version:
Beta v.0.6
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)
    • TYPE_PARAMETER_REGEX

      protected static final String TYPE_PARAMETER_REGEX
      A regular expression for a JavaTypeParameter
      See Also:
    • TYPE_PARAMETER_PATTERN

      protected static final Pattern TYPE_PARAMETER_PATTERN
      A Pattern to use for parsing type parameters
    • TYPE_REGEX

      protected static final String TYPE_REGEX
      A regular expression for a JavaType
    • TYPE_PATTERN

      protected static final Pattern TYPE_PATTERN
      A Pattern to use for parsing a JavaType
    • PARAMETER_REGEX

      protected static final String PARAMETER_REGEX
      A regular expression for a JavaParameter
    • PARAMETER_PATTERN

      protected static final Pattern PARAMETER_PATTERN
      A Pattern to use for parsing a JavaParameter
  • 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
    • parseOutType

      protected static com.github.tadukoo.util.tuple.Pair<String,Integer> parseOutType(List<String> tokens, int currentToken)
      Parse the tokens from currentToken onward to get a JavaType string, 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 from
      currentToken - The current token index to start at to get a type
      Returns:
      A Pair of the type string and the next token index
    • 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
    • parseJavaParameter

      public static JavaParameter parseJavaParameter(String parameterContent)
      Parses a JavaParameter from the given String
      Parameters:
      parameterContent - The String to parse
      Returns:
      The JavaParameter that was parsed
    • parseJavaType

      public static JavaType parseJavaType(String typeContent)
      Parses a JavaType from the given String
      Parameters:
      typeContent - The String to parse
      Returns:
      The JavaType that was parsed
    • parseJavaTypeParameters

      public static List<JavaTypeParameter> parseJavaTypeParameters(String typeParametersContent)
      Parses the given String into a List of Java Type Parameters
      Parameters:
      typeParametersContent - The String to be parsed
      Returns:
      The List of Java Type Parameters that were parsed from the String