Skip to content

Commit

Permalink
clean up JPQL parser project
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Sep 6, 2021
1 parent 38592ca commit 1556cd9
Show file tree
Hide file tree
Showing 119 changed files with 1,420 additions and 1,411 deletions.
4 changes: 4 additions & 0 deletions jpa/org.eclipse.persistence.jpa.jpql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<relativePath>../../pom.xml</relativePath>
</parent>

<properties>
<comp.xlint>-Xlint:all</comp.xlint>
</properties>

<dependencies>
<!--Test dependencies-->
<dependency>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected BaseDeclarationIdentificationVariableFinder getVirtualIdentificationVa
@Override
protected void initialize() {
super.initialize();
usedIdentificationVariables = new ArrayList<IdentificationVariable>();
usedIdentificationVariables = new ArrayList<>();
registerIdentificationVariable = true;
}

Expand Down Expand Up @@ -1567,7 +1567,7 @@ protected void validateIdentificationVariableDeclaration(IdentificationVariableD
protected void validateIdentificationVariables() {

// Collect the identification variables from the Declarations
Map<String, List<IdentificationVariable>> identificationVariables = new HashMap<String, List<IdentificationVariable>>();
Map<String, List<IdentificationVariable>> identificationVariables = new HashMap<>();
helper.collectLocalDeclarationIdentificationVariables(identificationVariables);

// Check for duplicate identification variables
Expand Down Expand Up @@ -2124,7 +2124,7 @@ protected void validateSimpleSelectClause(SimpleSelectClause expression) {
protected void validateSimpleSelectStatement(SimpleSelectStatement expression) {

// Keep a copy of the identification variables that are used throughout the parent query
List<IdentificationVariable> oldUsedIdentificationVariables = new ArrayList<IdentificationVariable>(usedIdentificationVariables);
List<IdentificationVariable> oldUsedIdentificationVariables = new ArrayList<>(usedIdentificationVariables);

// Create a context for the subquery
helper.newSubqueryContext(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected BypassParentSubExpressionVisitor getBypassParentSubExpressionVisitor()
protected List<Expression> getChildren(Expression expression) {
ChildrenCollectorVisitor visitor = getChildrenCollectorVisitor();
try {
visitor.expressions = new LinkedList<Expression>();
visitor.expressions = new LinkedList<>();
expression.accept(visitor);
return visitor.expressions;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ protected SubqueryVisitor getSubqueryVisitor() {
* Initializes this validator.
*/
protected void initialize() {
validators = new HashMap<String, JPQLQueryBNFValidator>();
validators = new HashMap<>();
}

/**
Expand Down Expand Up @@ -930,7 +930,7 @@ public void validate(JPQLQueryBNF queryBNF) {
// Retrieve all the children from the "root" JPQLQueryBNF and
// check if the BNF to validate is one of those children
else {
Set<String> allQueryBNFIds = new HashSet<String>();
Set<String> allQueryBNFIds = new HashSet<>();
allJPQLQueryBNFs(allQueryBNFIds, this.queryBNF);
valid = allQueryBNFIds.contains(queryBNF.getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -128,6 +128,8 @@ public static void isValid(Object object, String message, Object... choices) {
*/
public static class AssertException extends RuntimeException {

private static final long serialVersionUID = 0L;

/**
* Creates a new <code>AssertException</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @author Pascal Filion
*/
public class EclipseLinkGrammarValidator extends AbstractGrammarValidator
implements EclipseLinkExpressionVisitor {
implements EclipseLinkExpressionVisitor {

private InExpressionVisitor inExpressionVisitor;
private InExpressionWithNestedArrayVisitor inExpressionWithNestedArrayVisitor;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected String firstExpressionMissingKey() {
protected boolean hasComma(DatabaseType expression) {
// If the second expression is not specified, then the comma is not needed
return expression.hasComma() ||
!expression.hasSecondExpression();
!expression.hasSecondExpression();
}
@Override
protected boolean hasFirstExpression(DatabaseType expression) {
Expand All @@ -121,9 +121,9 @@ public boolean hasLeftParenthesis(DatabaseType expression) {
// The parenthesis are optional unless one the following
// items is specified, then '(' is required
return !(expression.hasFirstExpression() ||
expression.hasComma() ||
expression.hasSecondExpression() ||
expression.hasRightParenthesis());
expression.hasComma() ||
expression.hasSecondExpression() ||
expression.hasRightParenthesis());
}
@Override
public boolean hasRightParenthesis(DatabaseType expression) {
Expand All @@ -133,9 +133,9 @@ public boolean hasRightParenthesis(DatabaseType expression) {
// The parenthesis are optional unless one the following
// items is specified, then ')' is required
return !(expression.hasLeftParenthesis() ||
expression.hasFirstExpression() ||
expression.hasComma() ||
expression.hasSecondExpression());
expression.hasFirstExpression() ||
expression.hasComma() ||
expression.hasSecondExpression());
}
@Override
protected boolean hasSecondExpression(DatabaseType expression) {
Expand Down Expand Up @@ -182,9 +182,9 @@ public String leftParenthesisMissingKey(ExtractExpression expression) {
@Override
protected int lengthBeforeEncapsulatedExpression(ExtractExpression expression) {
return expression.getDatePart().length() +
(expression.hasSpaceAfterDatePart() ? 1 : 0) +
(expression.hasFrom() ? 4 /* FROM */ : 0) +
(expression.hasSpaceAfterFrom() ? 1 : 0);
(expression.hasSpaceAfterDatePart() ? 1 : 0) +
(expression.hasFrom() ? 4 /* FROM */ : 0) +
(expression.hasSpaceAfterFrom() ? 1 : 0);
}
@Override
public String rightParenthesisMissingKey(ExtractExpression expression) {
Expand Down Expand Up @@ -373,8 +373,8 @@ protected void validateAbstractSelectClause(AbstractSelectClause expression,
if (!multipleSelectItemsAllowed) {
Expression parent = expression.getParent();
multipleSelectItemsAllowed = isOwnedByFromClause (parent) ||
isOwnedByUnionClause (parent) ||
isOwnedByInExpression(parent);
isOwnedByUnionClause (parent) ||
isOwnedByInExpression(parent);
}

super.validateAbstractSelectClause(expression, multipleSelectItemsAllowed);
Expand Down Expand Up @@ -402,12 +402,12 @@ public void visit(CastExpression expression) {
if (!expression.hasDatabaseType()) {

int startPosition = position(expression) +
4 /* CAST */ +
(expression.hasLeftParenthesis() ? 1 : 0) +
length(expression.getExpression()) +
(expression.hasSpaceAfterExpression() ? 1 : 0) +
(expression.hasAs() ? 2 : 0) +
(expression.hasSpaceAfterAs() ? 1 : 0);
4 /* CAST */ +
(expression.hasLeftParenthesis() ? 1 : 0) +
length(expression.getExpression()) +
(expression.hasSpaceAfterExpression() ? 1 : 0) +
(expression.hasAs() ? 2 : 0) +
(expression.hasSpaceAfterAs() ? 1 : 0);

addProblem(expression, startPosition, CastExpression_MissingDatabaseType);
}
Expand Down Expand Up @@ -438,14 +438,14 @@ public void visit(ExtractExpression expression) {
}
else {

validateAbstractSingleEncapsulatedExpression(expression, extractExpressionHelper());
validateAbstractSingleEncapsulatedExpression(expression, extractExpressionHelper());

// Missing date part
if (expression.hasLeftParenthesis() && !expression.hasDatePart()) {

int startPosition = position(expression) +
7 /* EXTRACT */ +
(expression.hasLeftParenthesis() ? 1 : 0);
7 /* EXTRACT */ +
(expression.hasLeftParenthesis() ? 1 : 0);

addProblem(expression, startPosition, ExtractExpression_MissingDatePart);
}
Expand Down Expand Up @@ -478,10 +478,10 @@ public void visit(RegexpExpression expression) {
int endPosition = startPosition;

addProblem(
expression,
startPosition,
endPosition,
RegexpExpression_MissingStringExpression
expression,
startPosition,
endPosition,
RegexpExpression_MissingStringExpression
);
}
else {
Expand All @@ -494,10 +494,10 @@ public void visit(RegexpExpression expression) {
int endPosition = startPosition + length(stringExpression);

addProblem(
expression,
startPosition,
endPosition,
RegexpExpression_InvalidStringExpression
expression,
startPosition,
endPosition,
RegexpExpression_InvalidStringExpression
);
}
// Validate string expression
Expand All @@ -510,10 +510,10 @@ public void visit(RegexpExpression expression) {
if (!expression.hasPatternValue()) {

int startPosition = position(expression) +
length(expression.getStringExpression()) +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
6 /* REGEXP */ +
(expression.hasSpaceAfterIdentifier() ? 1 : 0);
length(expression.getStringExpression()) +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
6 /* REGEXP */ +
(expression.hasSpaceAfterIdentifier() ? 1 : 0);

int endPosition = startPosition;

Expand All @@ -526,18 +526,18 @@ public void visit(RegexpExpression expression) {
if (!isValid(patternValue, PatternValueBNF.ID)) {

int startPosition = position(expression) +
length(expression.getStringExpression()) +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
6 /* REGEXP */ +
(expression.hasSpaceAfterIdentifier() ? 1 : 0);
length(expression.getStringExpression()) +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
6 /* REGEXP */ +
(expression.hasSpaceAfterIdentifier() ? 1 : 0);

int endPosition = startPosition + length(patternValue);

addProblem(
expression,
startPosition,
endPosition,
RegexpExpression_InvalidPatternValue
expression,
startPosition,
endPosition,
RegexpExpression_InvalidPatternValue
);
}
// Validate pattern value
Expand Down Expand Up @@ -576,10 +576,10 @@ public void visit(TableVariableDeclaration expression) {
if (!expression.hasIdentificationVariable()) {

int startPosition = position(expression) +
length(tableExpression) +
(expression.hasSpaceAfterTableExpression() ? 1 : 0) +
(expression.hasAs() ? 2 : 0) +
(expression.hasSpaceAfterAs() ? 1 : 0);
length(tableExpression) +
(expression.hasSpaceAfterTableExpression() ? 1 : 0) +
(expression.hasAs() ? 2 : 0) +
(expression.hasSpaceAfterAs() ? 1 : 0);

addProblem(expression, startPosition, TableVariableDeclaration_MissingIdentificationVariable);
}
Expand All @@ -601,10 +601,10 @@ public void visit(UnionClause expression) {
else if (!expression.hasQuery()) {

int startPosition = position(expression) +
expression.getIdentifier().length() +
(expression.hasSpaceAfterIdentifier() ? 1 : 0) +
(expression.hasAll() ? 3 : 0) +
(expression.hasSpaceAfterAll() ? 1 : 0);
expression.getIdentifier().length() +
(expression.hasSpaceAfterIdentifier() ? 1 : 0) +
(expression.hasAll() ? 3 : 0) +
(expression.hasSpaceAfterAll() ? 1 : 0);

addProblem(expression, startPosition, UnionClause_MissingExpression);
}
Expand Down Expand Up @@ -661,4 +661,4 @@ public void visit(SimpleSelectStatement expression) {
expression.getParent().accept(this);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public abstract class ParameterTypeVisitor extends AbstractTraverseParentVisitor
*/
protected ParameterTypeVisitor() {
super();
this.visitedExpressions = new HashSet<Expression>();
this.visitedExpressions = new HashSet<>();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ protected final void addOrderedChildrenTo(List<Expression> children) {
*/
public CollectionExpression buildCollectionExpression() {

List<AbstractExpression> children = new ArrayList<AbstractExpression>(1);
List<AbstractExpression> children = new ArrayList<>(1);
children.add((AbstractExpression) getConditionalExpression());

List<Boolean> commas = new ArrayList<Boolean>(1);
List<Boolean> commas = new ArrayList<>(1);
commas.add(Boolean.FALSE);

List<Boolean> spaces = new ArrayList<Boolean>(1);
List<Boolean> spaces = new ArrayList<>(1);
spaces.add(Boolean.FALSE);

return new CollectionExpression(this, children, commas, spaces, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ protected void addOrderedEncapsulatedExpressionTo(List<Expression> children) {
*/
public final CollectionExpression buildCollectionExpression() {

List<AbstractExpression> children = new ArrayList<AbstractExpression>(3);
List<AbstractExpression> children = new ArrayList<>(3);
children.add((AbstractExpression) getFirstExpression());
children.add((AbstractExpression) getSecondExpression());

List<Boolean> commas = new ArrayList<Boolean>(2);
List<Boolean> commas = new ArrayList<>(2);
commas.add(hasComma);
commas.add(Boolean.FALSE);

List<Boolean> spaces = new ArrayList<Boolean>(2);
List<Boolean> spaces = new ArrayList<>(2);
spaces.add(hasSpaceAfterComma);
spaces.add(Boolean.FALSE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ protected final int calculatePosition(Expression expression, int length) {
@Override
public final ListIterable<Expression> children() {
if (children == null) {
children = new LinkedList<Expression>();
children = new LinkedList<>();
addChildrenTo(children);
}
return new SnapshotCloneListIterable<Expression>(children);
return new SnapshotCloneListIterable<>(children);
}

/**
Expand Down Expand Up @@ -646,10 +646,10 @@ protected boolean isVirtual() {
@Override
public final ListIterable<Expression> orderedChildren() {
if (orderedChildren == null) {
orderedChildren = new LinkedList<Expression>();
orderedChildren = new LinkedList<>();
addOrderedChildrenTo(orderedChildren);
}
return new SnapshotCloneListIterable<Expression>(orderedChildren);
return new SnapshotCloneListIterable<>(orderedChildren);
}

/**
Expand Down Expand Up @@ -1213,19 +1213,19 @@ private void addSpace(ArrayList<Boolean> children) {
}

List<AbstractExpression> buildChildren() {
ArrayList<AbstractExpression> children = new ArrayList<AbstractExpression>();
ArrayList<AbstractExpression> children = new ArrayList<>();
addChild(children);
return children;
}

List<Boolean> buildCommas() {
ArrayList<Boolean> children = new ArrayList<Boolean>();
ArrayList<Boolean> children = new ArrayList<>();
addComma(children);
return children;
}

List<Boolean> buildSpaces() {
ArrayList<Boolean> children = new ArrayList<Boolean>();
ArrayList<Boolean> children = new ArrayList<>();
addSpace(children);
return children;
}
Expand Down

0 comments on commit 1556cd9

Please sign in to comment.