Class ASTPos

java.lang.Object
de.hsh.graja.modules.junit.api.ASTPos

public class ASTPos extends Object
This class represents the source code position of a node in an abstract syntax tree (AST).
It can be used to throw a PositionAssertionError.

  • Method Details

    • getScope

      public ASTPos.Scope getScope()
    • getName

      public String getName()
    • getSubmission

      public String getSubmission()
    • getType

      public String getType()
    • getParams

      public List<String> getParams()
    • setType

      public void setType(String type)
    • setParams

      public void setParams(String... params)
    • ofClass

      public static ASTPos ofClass(String submission)
      Parameters:
      submission - Compilation unit class name's "simple name" (this is the name of the submitted file - .java stripped of). This one also defines the name of the class, so it is assumed that the class is inside a compilation unit of the same name as the class.
    • ofFullyQualifiedClass

      public static ASTPos ofFullyQualifiedClass(String fqnSubmission)
      Parameters:
      submission - Compilation unit class name's "simple name" (this is the name of the submitted file - .java stripped of). This one also defines the name of the class, so it is assumed that the class is inside a compilation unit of the same name as the class.
    • ofClass

      public static ASTPos ofClass(Class<?> submission)
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of). This one also defines the name of the class, so it is assumed that the class is inside a compilation unit of the same name as the class.
    • ofConstructor

      public static ASTPos ofConstructor(String submission, String... params)
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of). This one also defines the name of the class of which a constructor is declared. It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      params -
      Returns:
    • ofConstructor

      public static ASTPos ofConstructor(Class<?> submission, Class<?>... params)
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of). This one also defines the name of the class of which a constructor is declared.
      params -
      Returns:
    • ofConstructor

      public static ASTPos ofConstructor(Class<?> submission, Object... params)
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of). This one also defines the name of the class of which a constructor is declared.
      params -
      Returns:
    • ofMethod

      public static ASTPos ofMethod(String submission, String methodName)
      Declares a method by name and leaves parameters and returntype undeclared.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      methodName -
      Returns:
    • ofFullyQualifiedMethod

      public static ASTPos ofFullyQualifiedMethod(String fqnSubmission, String methodName)
      Declares a method by name and leaves parameters and returntype undeclared.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      methodName -
      Returns:
    • ofFullyQualifiedMethod

      public static ASTPos ofFullyQualifiedMethod(String fqnSubmission, Class<?> returnType, String methodName, Object... params)
      Declares a method by name and leaves parameters and returntype undeclared.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      methodName -
      Returns:
    • ofMethod

      public static ASTPos ofMethod(Class<?> submission, String methodName)
      Declares a method by name and leaves parameters and returntype undeclared.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of)
      methodName -
      Returns:
    • ofMainMethod

      public static ASTPos ofMainMethod(Class<?> submission)
      Declares the main method
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of)
      Returns:
    • ofToStringMethod

      public static ASTPos ofToStringMethod(Class<?> submission)
      Declares the toString method
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of)
      Returns:
    • ofHashCodeMethod

      public static ASTPos ofHashCodeMethod(Class<?> submission)
      Declares the equals method
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of)
      Returns:
    • ofEqualsMethod

      public static ASTPos ofEqualsMethod(Class<?> submission)
      Declares the equals method
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of)
      Returns:
    • ofMethod

      public static ASTPos ofMethod(String submission, String returnType, String methodName, String... params)
      Declares a method by name, return type and parameter types.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      methodName -
      returnType - if null, the return type matches all found return types
      params - if no parameters are given, the search matches any parameters
      Returns:
    • ofMethod

      public static ASTPos ofMethod(Class<?> submission, Class<?> returnType, String methodName, Class<?>... params)
      Declares a method by name, return type and parameter types.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class.
      methodName -
      returnType - if null, the return type matches all found return types
      params - if no parameters are given, the search matches any parameters
      Returns:
    • ofMethod

      public static ASTPos ofMethod(Class<?> submission, Class<?> returnType, String methodName, Object... params)
      Declares a method by name, return type and parameter types.
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class.
      methodName -
      returnType - if null, the return type matches all found return types
      params - if no parameters are given, the search matches any parameters
      Returns:
    • ofField

      public static ASTPos ofField(String submission, String fieldType, String fieldName)
      Declares a field by name and field type
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      fieldName -
      fieldType - if null, the field type matches all found return types
      Returns:
    • ofField

      public static ASTPos ofField(Class<?> submission, Class<?> fieldType, String fieldName)
      Declares a field by name and field type
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class.
      fieldName -
      fieldType - if null, the field type matches all found return types
      Returns:
    • ofField

      public static ASTPos ofField(Object submission, Class<?> fieldType, String fieldName)
      Declares a field by name and field type
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class defining the type of "submission" is inside a compilation unit of the same name as the class.
      fieldName -
      fieldType - if null, the field type matches all found return types
      Returns:
    • ofField

      public static ASTPos ofField(Object submission, String fieldName)
      Declares a field by name leaving the field type unspecified
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class defining the type of "submission" is inside a compilation unit of the same name as the class.
      fieldName -
      Returns:
    • ofField

      public static ASTPos ofField(String submission, String fieldName)
      Declares a field by name, leaving field type unspecified
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      fieldName -
      Returns:
    • ofField

      public static ASTPos ofField(Class<?> submission, String fieldName)
      Declares a field by name, leaving field type unspecified
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class.
      fieldName -
      Returns:
    • ofVariable

      public static ASTPos ofVariable(String submission, String variableType, String variableName)
      Declares a variable by name and type
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      variableType - if null, the variable type matches all found variable types
      variableName -
      Returns:
    • ofVariable

      public static ASTPos ofVariable(String submission, String variableName)
      Declares a variable by name, leaving variable type unspecified
      Parameters:
      submission - Compilation unit class name (this is the name of the submitted file - .java stripped of) It is assumed that the class is inside a compilation unit of the same name as the class. This parameter denotes the "simple name" of the class.
      variableName -
      Returns: