Class DefaultContentAssistProposals

java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.DefaultContentAssistProposals
All Implemented Interfaces:
ContentAssistProposals

public final class DefaultContentAssistProposals extends Object implements ContentAssistProposals
The default implementation of ContentAssistProposals which stores the valid proposals.

Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.

Since:
2.3
Version:
2.5
  • Constructor Details

    • DefaultContentAssistProposals

      public DefaultContentAssistProposals(JPQLGrammar jpqlGrammar, ContentAssistExtension extension)
      Creates a new DefaultContentAssistProposals.
      Parameters:
      jpqlGrammar - The JPQLGrammar that defines how the JPQL query was parsed
      extension - This extension can be used to provide additional support to JPQL content assist that is outside the scope of providing proposals related to JPA metadata. It adds support for providing suggestions related to class names, enum constants, table names, column names
  • Method Details

    • abstractSchemaTypes

      public Iterable<IEntity> abstractSchemaTypes()
      Description copied from interface: ContentAssistProposals
      Returns the collection of possible abstract schema types.
      Specified by:
      abstractSchemaTypes in interface ContentAssistProposals
      Returns:
      The entities defined in the persistence context
    • addEntity

      public void addEntity(IEntity abstractSchemaType)
      Adds the given IEntity as a possible abstract schema type.
      Parameters:
      abstractSchemaType - The abstract schema type that is a valid proposal
    • addEnumConstant

      public void addEnumConstant(IType enumType, String enumConstant)
      Adds the constants of the given enum constant as a valid proposal.
      Parameters:
      enumType - The IType of the enum type
      enumConstant - The enum constant to be added as a valid proposal
      Since:
      2.5
    • addIdentificationVariable

      public void addIdentificationVariable(String identificationVariable)
      Adds the given identification variable as a proposal.
      Parameters:
      identificationVariable - The identification variable that is a valid proposal
    • addIdentifier

      public void addIdentifier(String identifier)
      Adds the given JPQL identifier as a proposal.
      Parameters:
      identifier - The JPQL identifier that is a valid proposal
    • addMapping

      public void addMapping(IMapping mapping)
      Adds the given mapping (state field, association field or collection field) as a valid proposal.
      Parameters:
      mapping - The IMapping of the state field, association field or collection field
    • addMappings

      public void addMappings(Collection<IMapping> mappings)
      Adds the given mappings (state fields, association fields or collection fields) as valid proposals.
      Parameters:
      mappings - The mappings of the state fields, association fields or collection fields
    • addRangeIdentificationVariable

      public void addRangeIdentificationVariable(String identificationVariable, IEntity entity)
      Adds the given range identification variable that is mapping the given abstract schema type.
      Parameters:
      identificationVariable - The range identification variable mapping the abstract schema name
      entity - The abstract type name that identifies the type of the variable
    • buildEscapedQuery

      public org.eclipse.persistence.jpa.jpql.tools.DefaultContentAssistProposals.Result buildEscapedQuery(String jpqlQuery, String proposal, int position, boolean insert)
      Description copied from interface: ContentAssistProposals
      Creates a new JPQL query by inserting the given proposal at the given position. The updated JPQL query and position will be adjusted by converting some characters into their corresponding escaped characters, for instance '\r' will be converted to '\\r.

      The replacement will also handle compound JPQL identifiers when updating the JPQL query.

      Example: If the cursor is within "IS NOT N|" and the proposal is "IS NOT NULL", then "IS NOT" will not be added twice. If the word to replace is "IS NULL" and the proposal is "IS NOT NULL", then "NOT" will be inserted between "IS" and "NULL".

      Specified by:
      buildEscapedQuery in interface ContentAssistProposals
      Parameters:
      jpqlQuery - The JPQL query to modify with the given proposal
      proposal - The proposal to insert into the query
      position - The position of insertion
      insert - Flag that determines if the partial word following the cursor should be left intact or should be replaced by the proposal
      Returns:
      The result of inserting the proposal into the query, including the adjust position, if it was required
    • buildPositions

      public int[] buildPositions(WordParser wordParser, String proposal, boolean insert)
      Calculates the start and end position for correctly inserting the proposal into the query.
      Parameters:
      wordParser - This parser can be used to retrieve words from the cursor position
      proposal - The proposal to be inserted into the query
      insert - Flag that determines if the proposal is simply inserted or it should also replace the partial word following the position of the cursor
      Returns:
      The start and end positions
    • buildQuery

      public org.eclipse.persistence.jpa.jpql.tools.DefaultContentAssistProposals.Result buildQuery(String jpqlQuery, String proposal, int position, boolean insert)
      Description copied from interface: ContentAssistProposals
      Creates a new JPQL query by inserting the given proposal at the given position.

      The replacement will also handle compound JPQL identifiers when updating the JPQL query.

      Example: If the cursor is within "IS NOT N|" and the proposal is "IS NOT NULL", then "IS NOT" will not be added twice. If the word to replace is "IS NULL" and the proposal is "IS NOT NULL", then "NOT" will be inserted between "IS" and "NULL".

      Specified by:
      buildQuery in interface ContentAssistProposals
      Parameters:
      jpqlQuery - The JPQL query to modify with the given proposal
      proposal - The proposal to insert into the query
      position - The position of insertion
      insert - Flag that determines if the partial word following the cursor should be left intact or should be replaced by the proposal
      Returns:
      The result of inserting the proposal into the query, including the adjust position, if it was required
    • buildXmlQuery

      public ResultQuery buildXmlQuery(String jpqlQuery, String proposal, int position, boolean insert)
      Description copied from interface: ContentAssistProposals
      Creates a new JPQL query by inserting the given proposal at the given position. The updated JPQL query and position will be adjusted by converting some characters into their corresponding escaped characters, for instance '>' will be converted to '&gt;'.

      The replacement will also handle compound JPQL identifiers when updating the JPQL query.

      Example: If the cursor is within "IS NOT N|" and the proposal is "IS NOT NULL", then "IS NOT" will not be added twice. If the word to replace is "IS NULL" and the proposal is "IS NOT NULL", then "NOT" will be inserted between "IS" and "NULL".

      Specified by:
      buildXmlQuery in interface ContentAssistProposals
      Parameters:
      jpqlQuery - The JPQL query to modify with the given proposal, which should be the non- converted string, i.e. any escaped characters should not be converted
      proposal - The proposal to insert into the query
      position - The position of insertion, which was derived from the parsed tree representation of the JPQL query
      insert - Flag that determines if the partial word following the cursor should be left intact or should be replaced by the proposal
      Returns:
      The result of inserting the proposal into the query, including the adjust position, if it was required
    • classNames

      public Iterable<String> classNames()
      Description copied from interface: ContentAssistProposals
      Returns the filtered list of possible class names. This is usually available when the cursor is within the constructor name of the constructor expression.
      Specified by:
      classNames in interface ContentAssistProposals
      Returns:
      The filtered list of possible class names
      See Also:
    • columnNames

      public Iterable<String> columnNames()
      Description copied from interface: ContentAssistProposals
      Returns the filtered list of possible column names.
      Specified by:
      columnNames in interface ContentAssistProposals
      Returns:
      The filtered list of possible column names
    • enumConstant

      Description copied from interface: ContentAssistProposals
      Returns the filtered list of possible enum constant names. This is usually available when the cursor is after the dot separating a fully qualified enum type and the enum constant.
      Specified by:
      enumConstant in interface ContentAssistProposals
      Returns:
      The filtered list of possible enum constant names associated with its enum type
    • getAbstractSchemaType

      public IEntity getAbstractSchemaType(String identificationVariable)
      Description copied from interface: ContentAssistProposals
      Retrieves the abstract schema type that is mapped with the given identification variable.
      Specified by:
      getAbstractSchemaType in interface ContentAssistProposals
      Parameters:
      identificationVariable - The identification variable that, if defined as a range variable, will be mapped to a managed type
      Returns:
      The abstract schema type mapped with the given identification variable or null if the given variable is mapped to something else or not mapped to anything
    • getClassNamePrefix

      public String getClassNamePrefix()
      Returns the prefix that will be used to filter the list of possible class names.
      Returns:
      The prefix that is used to filter the list of class names or null if it was not set for the cursor position within the JPQL query
      Since:
      2.5
    • getClassType

      public ContentAssistProposals.ClassType getClassType()
      Specified by:
      getClassType in interface ContentAssistProposals
    • getColumnNamePrefix

      public String getColumnNamePrefix()
      Returns the prefix that will be used by ContentAssistExtension to filter the column names if the table name is not null.
      Returns:
      The prefix that is used to filter the list of columns names, which is null if it has not been set along with the table name
      Since:
      2.5
    • getGrammar

      public JPQLGrammar getGrammar()
      Returns the JPQLGrammar that defines how the JPQL query was parsed.
      Returns:
      The JPQLGrammar that was used to parse this Expression
    • getIdentifierRole

      public IdentifierRole getIdentifierRole(String identifier)
      Description copied from interface: ContentAssistProposals
      Returns the role of the given JPQL identifier.
      Specified by:
      getIdentifierRole in interface ContentAssistProposals
      Parameters:
      identifier - The JPQL identifier to retrieve its role
      Returns:
      The IdentifierRole for the given JPQL identifier or null if no role was defined or if the given string is not a valid JPQL identifier
    • getTableName

      public String getTableName()
      Returns the table name that will be used by ContentAssistExtension to retrieve the column names.
      Returns:
      The name of the table for which its column names should be retrieve as possible proposals
      Since:
      2.5
    • getTableNamePrefix

      public String getTableNamePrefix()
      Returns the prefix that will be used to filter the list of possible table names.
      Returns:
      The prefix that is used to filter the list of table names or null if it was not set for the cursor position within the JPQL query
      Since:
      2.5
    • hasProposals

      public boolean hasProposals()
      Description copied from interface: ContentAssistProposals
      Determines whether there is at least one proposals.
      Specified by:
      hasProposals in interface ContentAssistProposals
      Returns:
      true if there is at least one proposal; otherwise false
    • identificationVariables

      public Iterable<String> identificationVariables()
      Description copied from interface: ContentAssistProposals
      Returns the collection of possible identification variables.
      Specified by:
      identificationVariables in interface ContentAssistProposals
      Returns:
      The list of possible identification variables
    • identifiers

      public Iterable<String> identifiers()
      Description copied from interface: ContentAssistProposals
      Returns the collection of possible JPQL identifiers.
      Specified by:
      identifiers in interface ContentAssistProposals
      Returns:
      The list of possible JPQL identifiers
    • initialize

      protected void initialize(JPQLGrammar jpqlGrammar, ContentAssistExtension extension)
    • isColumnName

      public boolean isColumnName(String proposal)
      Determines whether the given proposal is a column name (which should be unqualified).
      Parameters:
      proposal - The proposal that is being inserted into the JPQL query
      Returns:
      true if the given proposal is a column name; false otherwise
      Since:
      2.5
    • isEnumConstant

      public boolean isEnumConstant(String proposal)
      Determines whether the given proposal is an enum constant name (which should be unqualified).
      Parameters:
      proposal - The proposal that is being inserted into the JPQL query
      Returns:
      true if the given proposal is a unqualified enum constant name; false otherwise
      Since:
      2.5
    • isMappingName

      public boolean isMappingName(String proposal)
      Determines whether the given proposal is a mapping name.
      Parameters:
      proposal - The proposal that is being inserted into the JPQL query
      Returns:
      true if the given proposal is a mapping name; false otherwise
      Since:
      2.5
    • longuestIdentifier

      public String longuestIdentifier(String proposal)
      Returns the longest possible JPQL identifier that is related to the given proposal if the proposal is a JPQL identifier and contains multiple words. For instance, the longest form of JOIN or JOIN FETCH is LEFT OUTER JOIN FETCH.
      Parameters:
      proposal - The proposal to retrieve its longest form if one is associated with it
      Returns:
      Either the given proposal if it's not a JPQL identifier or it does not have a longer form or the longest version of the JPQL identifier
    • mappings

      public Iterable<IMapping> mappings()
      Description copied from interface: ContentAssistProposals
      Returns the collection of possible mappings, which can be state fields, association fields and/or collection fields depending on the location used to retrieve the possible proposals.
      Specified by:
      mappings in interface ContentAssistProposals
      Returns:
      The list of possible proposals mappings
    • removeIdentifier

      protected void removeIdentifier(String identifier)
      Removes the given JPQL identifier.
      Parameters:
      identifier - The identifier that was added but actually needs to be removed
    • setClassNamePrefix

      public void setClassNamePrefix(String prefix, ContentAssistProposals.ClassType classType)
      Adds the given prefix that will be used to filter the list of possible class names.
      Parameters:
      prefix - The prefix that is used to filter the list of class names
      classType - Determines how to filter the various types of classes
      Since:
      2.5
    • setTableName

      public void setTableName(String tableName, String prefix)
      Sets the table name and a prefix that will be used to filter the names of the table's columns.
      Parameters:
      tableName - The name of the table for which its column names should be retrieve as possible proposals
      prefix - The prefix that is used to filter the list of columns names, which is never null but can be an empty string
      Since:
      2.5
    • setTableNamePrefix

      public void setTableNamePrefix(String tableNamePrefix)
      Adds the given prefix that will be used to filter the list of possible columns names.
      Parameters:
      tableNamePrefix - The prefix that is used to filter the list of columns names
      Since:
      2.5
    • startPosition

      public int startPosition(WordParser wordParser, String proposal)
    • tableNames

      public Iterable<String> tableNames()
      Description copied from interface: ContentAssistProposals
      Returns the filtered list of possible table names.
      Specified by:
      tableNames in interface ContentAssistProposals
      Returns:
      The filtered list of possible table names
    • toString

      public String toString()
      Overrides:
      toString in class Object