Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 959d71c

Browse files
committed
perf(hibernate processor): fix nullable things in processor package
1 parent 9120feb commit 959d71c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/ClassWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.Set;
3131

32+
import static java.util.Objects.requireNonNull;
3233
import static org.hibernate.processor.util.Constants.SPRING_COMPONENT;
3334
import static org.hibernate.processor.util.TypeUtils.getGeneratedClassFullyQualifiedName;
3435
import static org.hibernate.processor.util.TypeUtils.isMemberType;
@@ -270,7 +271,7 @@ private static String getGeneratedSuperclassName(Element superClassElement, bool
270271

271272
private static String getGeneratedClassName(TypeElement typeElement, boolean jakartaDataStyle) {
272273
final String simpleName = typeElement.getSimpleName().toString();
273-
final Element enclosingElement = typeElement.getEnclosingElement();
274+
final Element enclosingElement = requireNonNull( typeElement.getEnclosingElement() );
274275
return (enclosingElement instanceof TypeElement
275276
? getGeneratedSuperclassName( enclosingElement, jakartaDataStyle )
276277
: ((PackageElement) enclosingElement).getQualifiedName().toString())

tooling/metamodel-generator/src/main/java/org/hibernate/processor/Context.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ public final class Context {
8181
* Whether all mapping files are xml-mapping-metadata-complete. In this case no annotation processing will take
8282
* place.
8383
*/
84-
private Boolean fullyXmlConfigured;
84+
private @Nullable Boolean fullyXmlConfigured;
8585
private boolean addInjectAnnotation = false;
8686
private boolean addDependentAnnotation = false;
8787
private boolean addComponentAnnotation = false;
8888
private boolean addNonnullAnnotation = false;
8989
private boolean addGeneratedAnnotation = true;
9090
private boolean addGenerationDate;
91-
private String[] suppressedWarnings;
91+
private String @Nullable [] suppressedWarnings;
9292
private boolean addTransactionScopedAnnotation;
93-
private AccessType persistenceUnitDefaultAccessType;
93+
private @Nullable AccessType persistenceUnitDefaultAccessType;
9494
private boolean generateJakartaDataStaticMetamodel;
9595
private boolean quarkusInjection;
9696
private boolean springInjection;
@@ -213,7 +213,7 @@ public boolean addSuppressWarningsAnnotation() {
213213
return suppressedWarnings != null;
214214
}
215215

216-
public String[] getSuppressedWarnings() {
216+
public String @Nullable [] getSuppressedWarnings() {
217217
return suppressedWarnings;
218218
}
219219

@@ -402,7 +402,7 @@ public void mappingDocumentFullyXmlConfigured(boolean fullyXmlConfigured) {
402402
: this.fullyXmlConfigured && fullyXmlConfigured;
403403
}
404404

405-
public AccessType getPersistenceUnitDefaultAccessType() {
405+
public @Nullable AccessType getPersistenceUnitDefaultAccessType() {
406406
return persistenceUnitDefaultAccessType;
407407
}
408408

tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.function.Function;
4646

4747
import static java.lang.Boolean.parseBoolean;
48+
import static java.util.Objects.requireNonNull;
4849
import static javax.lang.model.util.ElementFilter.fieldsIn;
4950
import static javax.lang.model.util.ElementFilter.methodsIn;
5051
import static org.hibernate.processor.HibernateProcessor.ADD_GENERATED_ANNOTATION;
@@ -711,7 +712,7 @@ && hasAnnotation( element, ENTITY, MAPPED_SUPERCLASS )
711712
}
712713

713714
private static boolean hasHandwrittenMetamodel(Element element) {
714-
return element.getEnclosingElement().getEnclosedElements()
715+
return requireNonNull( element.getEnclosingElement() ).getEnclosedElements()
715716
.stream().anyMatch(e -> e.getSimpleName()
716717
.contentEquals('_' + element.getSimpleName().toString()));
717718
}
@@ -764,7 +765,7 @@ private void indexEnumValues(TypeMirror type) {
764765
if ( fieldType.getKind() == ElementKind.ENUM ) {
765766
for ( Element enumMember : fieldType.getEnclosedElements() ) {
766767
if ( enumMember.getKind() == ElementKind.ENUM_CONSTANT ) {
767-
final Element enclosingElement = fieldType.getEnclosingElement();
768+
final Element enclosingElement = requireNonNull( fieldType.getEnclosingElement() );
768769
final boolean hasOuterType =
769770
enclosingElement.getKind().isClass() || enclosingElement.getKind().isInterface();
770771
context.addEnumValue( fieldType.getQualifiedName().toString(),

0 commit comments

Comments
 (0)