Skip to content

Commit

Permalink
clean up jpa/jpql parser, turn warnings into errors
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 22, 2021
1 parent 9c66f7e commit 48f84fe
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ public static void fixOROXAccessors(Project orProject, Project oxProject) {
if (!XRDynamicEntity.class.isAssignableFrom(desc.getJavaClass())) {
continue;
}
@SuppressWarnings({"unchecked"})
Class<? extends XRDynamicEntity> clz = (Class<? extends XRDynamicEntity>) desc.getJavaClass();
Class<?> clz = desc.getJavaClass();
ClassDescriptor xdesc = null;
if (oxProject != null) {
xdesc = oxProject.getDescriptorForAlias(desc.getAlias());
}
XRDynamicPropertiesManager xrDPM = null;
if (!clz.getName().endsWith(COLLECTION_WRAPPER_SUFFIX)) {
try {
XRDynamicEntity newInstance = clz.getConstructor().newInstance();
XRDynamicEntity newInstance = (XRDynamicEntity) clz.getConstructor().newInstance();
xrDPM = newInstance.fetchPropertiesManager();
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2517,8 +2517,9 @@ public InterfacePolicy getInterfacePolicyOrNull() {
* Return the java class.
*/
@Override
public Class getJavaClass() {
return javaClass;
@SuppressWarnings({"unchecked"})
public <T> Class<T> getJavaClass() {
return (Class<T>) javaClass;
}

/**
Expand All @@ -2537,7 +2538,7 @@ public String getJavaClassName() {
*/
public List<DatabaseMapping> getLockableMappings() {
if (this.lockableMappings == null) {
this.lockableMappings = new ArrayList();
this.lockableMappings = new ArrayList<>();
}
return this.lockableMappings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Object[] getConstructors(Object type) {

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List getDeclarations() {
public List<? extends JPQLQueryDeclaration> getDeclarations() {
return queryContext.getDeclarations();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ public void visit(NumericLiteral expression) {
text = text.substring(0, text.length() - 1);
}

@SuppressWarnings({"unchecked"})
Number number = queryContext.newInstance((Class<? extends Number>) type[0], String.class, text);

// Now create the numeric expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ private Class<?> loadTypeImp(String typeName) {
* @return A new instance or <code>null</code> if a problem was encountered during instantiation
*/
<T> T newInstance(Class<T> type, Class<?> parameterType, Object parameter) {
return newInstance(type, new Class[] { parameterType }, new Object[] { parameter });
return newInstance(type, new Class<?>[] { parameterType }, new Object[] { parameter });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public interface Descriptor <
/**
* Return the java class.
*/
Class<?> getJavaClass();
<T> Class<T> getJavaClass();

/**
* Return the class name, used by the MW.
Expand Down
10 changes: 10 additions & 0 deletions jpa/org.eclipse.persistence.jpa.jpql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

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

<dependencies>
Expand All @@ -50,6 +51,15 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
<!--Run specified tests/test suite-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected boolean isComparingEntityTypeLiteral(IdentificationVariable expression
protected boolean isIdentificationVariableDeclaredAfter(String variableName,
int variableNameIndex,
int joinIndex,
List<JPQLQueryDeclaration> declarations) {
List<? extends JPQLQueryDeclaration> declarations) {

for (int index = variableNameIndex, declarationCount = declarations.size(); index < declarationCount; index++) {

Expand Down Expand Up @@ -525,7 +525,7 @@ protected void validateAbstractFromClause(AbstractFromClause expression,
// The identification variable declarations are evaluated from left to right in
// the FROM clause, and an identification variable declaration can use the result
// of a preceding identification variable declaration of the query string
List<JPQLQueryDeclaration> declarations = helper.getDeclarations();
List<? extends JPQLQueryDeclaration> declarations = helper.getDeclarations();

for (int index = 0, count = declarations.size(); index < count; index++) {

Expand Down Expand Up @@ -1682,7 +1682,7 @@ protected void validateJoin(Join expression) {
}

protected void validateJoinsIdentificationVariable(AbstractFromClause expression,
List<JPQLQueryDeclaration> declarations,
List<? extends JPQLQueryDeclaration> declarations,
JPQLQueryDeclaration declaration,
int index) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public interface SemanticValidatorHelper {
*
* @return The list of {@link JPQLQueryDeclaration} of the current query that was parsed
*/
List<JPQLQueryDeclaration> getDeclarations();
List<? extends JPQLQueryDeclaration> getDeclarations();

/**
* Retrieves the embeddable with the given type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,16 @@ public T in(String... inItems) {
}

@Override
public T in(T... inItems) {
checkBuilders(inItems);
in(false, inItems);
public T in(T builder) {
checkBuilders(builder);
in(false, builder);
return (T) this;
}

@Override
public T in(T builder1, T builder2) {
checkBuilders(builder1, builder2);
in(false, builder1, builder2);
return (T) this;
}

Expand Down Expand Up @@ -476,9 +483,16 @@ public T notIn(String... inItems) {
}

@Override
public T notIn(T... inItems) {
checkBuilders(inItems);
in(true, inItems);
public T notIn(T builder) {
checkBuilders(builder);
in(true, builder);
return (T) this;
}

@Override
public T notIn(T builder1, T builder2) {
checkBuilders(builder1, builder2);
in(true, builder1, builder2);
return (T) this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@ public IConditionalExpressionStateObjectBuilder greaterThanOrEqual(String litera
}

@Override
public IConditionalExpressionStateObjectBuilder in(IConditionalExpressionStateObjectBuilder... inItems) {
return delegate.in(inItems);
public IConditionalExpressionStateObjectBuilder in(IConditionalExpressionStateObjectBuilder builder1, IConditionalExpressionStateObjectBuilder builder2) {
return delegate.in(builder1, builder2);
}

@Override
public IConditionalExpressionStateObjectBuilder in(IConditionalExpressionStateObjectBuilder builder) {
return delegate.in(builder);
}

@Override
Expand Down Expand Up @@ -379,8 +384,13 @@ public IConditionalExpressionStateObjectBuilder notExists(SimpleSelectStatementS
}

@Override
public IConditionalExpressionStateObjectBuilder notIn(IConditionalExpressionStateObjectBuilder... inItems) {
return delegate.notIn(inItems);
public IConditionalExpressionStateObjectBuilder notIn(IConditionalExpressionStateObjectBuilder builder1, IConditionalExpressionStateObjectBuilder builder2) {
return delegate.notIn(builder1, builder2);
}

@Override
public IConditionalExpressionStateObjectBuilder notIn(IConditionalExpressionStateObjectBuilder builder) {
return delegate.notIn(builder);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
package org.eclipse.persistence.jpa.jpql.tools.model;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -175,7 +176,12 @@ public T case_(ICaseExpressionStateObjectBuilder builder) {
}

@Override
public T coalesce(T builder1, T builder2, T... builders) {
public T coalesce(T builder1, T builder2) {
return coalesce(builder1, builder2, (T[]) Array.newInstance(builder1.getClass(), 0));
}

@Override
public T coalesce(T builder1, T builder2, T[] builders) {

checkBuilders(builder1, builder2);
checkBuilders(builders);
Expand All @@ -191,7 +197,12 @@ public T coalesce(T builder1, T builder2, T... builders) {
}

@Override
public T concat(T builder1, T builder2, T... builders) {
public T concat(T builder1, T builder2) {
return concat(builder1, builder2, (T[]) Array.newInstance(builder1.getClass(), 0));
}

@Override
public T concat(T builder1, T builder2, T[] builders) {

checkBuilders(builder1, builder2);
checkBuilders(builders);
Expand Down Expand Up @@ -292,15 +303,28 @@ public T function(String identifier, String functionName, String... arguments) {
}

@Override
public T function(String identifier, String functionName, T... arguments) {
public T function(String identifier, String functionName) {
StateObject stateObject = new FunctionExpressionStateObject(
getParent(),
identifier,
functionName,
stateObjects(0)
);

add(stateObject);
return (T) this;
}

@Override
public T function(String identifier, String functionName, T[] arguments) {

checkBuilders(arguments);

StateObject stateObject = new FunctionExpressionStateObject(
getParent(),
identifier,
functionName,
stateObjects(arguments)
getParent(),
identifier,
functionName,
stateObjects(arguments)
);

add(stateObject);
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 @@ -83,7 +83,8 @@ public interface IAbstractConditionalExpressionStateObjectBuilder<T extends ISca
T greaterThanOrEqual(T builder);
T in(SimpleSelectStatementStateObject subquery);
T in(String... inItems);
T in(T... inItems);
T in(T builder);
T in(T builder1, T builder2);
T isEmpty(String path);
T isNotEmpty(String path);
T isNotNull(String path);
Expand All @@ -104,7 +105,8 @@ public interface IAbstractConditionalExpressionStateObjectBuilder<T extends ISca
T notExists(SimpleSelectStatementStateObject subquery);
T notIn(SimpleSelectStatementStateObject subquery);
T notIn(String... inItems);
T notIn(T... inItems);
T notIn(T builder);
T notIn(T builder1, T builder2);
T notLike(String patternValue);
T notLike(T builder);
T notLike(T builder, String escapeCharacter);
Expand Down

0 comments on commit 48f84fe

Please sign in to comment.