From 8bdffe313e405d0ca411fac77b8ad16caffdeb84 Mon Sep 17 00:00:00 2001 From: Jesenko Mehmedbasic Date: Tue, 17 Oct 2023 13:42:01 +0200 Subject: [PATCH] Assume JDK 17 is available, remove diffs with origin in preparation for PR. --- .../c_client/ClientClassnameForMethod.java | 8 ++-- .../freemarker/ClientClassnameForMethod.java | 3 +- .../ClientClassnameForMethod.java | 8 ++-- examples/full-api-edge-cases/pom.xml | 5 -- examples/jackson2-api-lombok/pom.xml | 5 -- examples/jackson2-api/pom.xml | 5 -- examples/spring-petclinic/pom.xml | 5 -- .../ClientClassnameForMethod.java | 5 +- .../jackson/EnunciateJacksonContext.java | 4 +- .../modules/jackson/JacksonModule.java | 3 +- .../modules/jackson/model/AccessorFilter.java | 5 +- .../jackson/model/ObjectTypeDefinition.java | 26 +++++------ .../modules/jackson/model/TypeDefinition.java | 10 ++-- .../jackson/model/types/JsonTypeVisitor.java | 26 +++++------ .../ClientClassnameForMethod.java | 4 +- .../ClientClassnameForMethod.java | 4 +- .../enunciate/javac/CompatElementFilter.java | 36 --------------- .../enunciate/javac/RecordCompatibility.java | 46 ------------------- .../javac/decorations/DecoratedElements.java | 3 +- .../element/DecoratedTypeElement.java | 4 +- .../decorations/element/ElementUtils.java | 35 ++++++++++++++ .../decorations/type/DecoratedTypeMirror.java | 4 +- .../ClientClassnameForMethod.java | 3 +- .../modules/jaxb/EnunciateJaxbContext.java | 8 ++-- .../enunciate/modules/jaxb/JaxbModule.java | 3 +- .../modules/jaxb/model/Accessor.java | 4 +- .../jaxb/model/ComplexTypeDefinition.java | 3 +- .../modules/jaxb/model/TypeDefinition.java | 4 +- .../jaxb/model/types/XmlTypeVisitor.java | 26 +++++------ .../modules/jaxrs/model/Resource.java | 11 ++--- .../jaxrs/model/ResourceParameter.java | 6 +-- .../jaxws/model/EndpointInterface.java | 8 ++-- .../objc_client/ClientClassnameForMethod.java | 6 +-- pom.xml | 1 - rt-util/pom.xml | 1 - .../model/RequestParameterFactory.java | 7 ++- .../spring_web/model/SpringController.java | 4 +- .../model/SpringControllerAdvice.java | 4 +- 38 files changed, 131 insertions(+), 222 deletions(-) delete mode 100644 javac-support/src/main/java/com/webcohesion/enunciate/javac/CompatElementFilter.java delete mode 100644 javac-support/src/main/java/com/webcohesion/enunciate/javac/RecordCompatibility.java diff --git a/c-xml-client/src/main/java/com/webcohesion/enunciate/modules/c_client/ClientClassnameForMethod.java b/c-xml-client/src/main/java/com/webcohesion/enunciate/modules/c_client/ClientClassnameForMethod.java index 5aa9081d0..1fd2ea318 100644 --- a/c-xml-client/src/main/java/com/webcohesion/enunciate/modules/c_client/ClientClassnameForMethod.java +++ b/c-xml-client/src/main/java/com/webcohesion/enunciate/modules/c_client/ClientClassnameForMethod.java @@ -15,8 +15,8 @@ */ package com.webcohesion.enunciate.modules.c_client; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; @@ -28,7 +28,7 @@ import freemarker.template.TemplateModelException; import jakarta.activation.DataHandler; -import javax.lang.model.element.ElementKind; + import javax.lang.model.element.TypeElement; import javax.lang.model.type.*; import jakarta.xml.bind.JAXBElement; @@ -79,7 +79,7 @@ public ClientClassnameForMethod(Map conversions, EnunciateJaxbCo classConversions.put(javax.xml.datatype.Duration.class.getName(), "xmlChar"); classConversions.put(jakarta.xml.bind.JAXBElement.class.getName(), "struct xmlBasicNode"); classConversions.put(Object.class.getName(), "struct xmlBasicNode"); - classConversions.put(RecordCompatibility.CLASS_RECORD, "struct xmlBasicNode"); + classConversions.put(Record.class.getName(), "struct xmlBasicNode"); classConversions.putAll(conversions); } @@ -97,7 +97,7 @@ else if (isCollection(declaration)) { if (adapterType != null) { return convert(adapterType.getAdaptingType()); } - if (RecordCompatibility.isClassOrRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/core/src/main/java/com/webcohesion/enunciate/util/freemarker/ClientClassnameForMethod.java b/core/src/main/java/com/webcohesion/enunciate/util/freemarker/ClientClassnameForMethod.java index 2685afdc3..6ce3cb516 100644 --- a/core/src/main/java/com/webcohesion/enunciate/util/freemarker/ClientClassnameForMethod.java +++ b/core/src/main/java/com/webcohesion/enunciate/util/freemarker/ClientClassnameForMethod.java @@ -16,7 +16,6 @@ package com.webcohesion.enunciate.util.freemarker; import com.webcohesion.enunciate.EnunciateContext; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.util.HasClientConvertibleType; import freemarker.template.TemplateModelException; @@ -94,7 +93,7 @@ else if (typeMirror instanceof TypeVariable) { conversion = super.convert(typeMirror); boolean isArray = typeMirror.getKind() == TypeKind.ARRAY; - if (typeMirror instanceof DeclaredType && !"java.lang.Object".equals(conversion) && !RecordCompatibility.CLASS_RECORD.equals(conversion)) { + if (typeMirror instanceof DeclaredType && !Object.class.getName().equals(conversion) && !Record.class.getName().equals(conversion)) { conversion += convertDeclaredTypeArguments(((DeclaredType) typeMirror).getTypeArguments()); } diff --git a/csharp-xml-client/src/main/java/com/webcohesion/enunciate/modules/csharp_client/ClientClassnameForMethod.java b/csharp-xml-client/src/main/java/com/webcohesion/enunciate/modules/csharp_client/ClientClassnameForMethod.java index e1e9ff253..d60141b5a 100644 --- a/csharp-xml-client/src/main/java/com/webcohesion/enunciate/modules/csharp_client/ClientClassnameForMethod.java +++ b/csharp-xml-client/src/main/java/com/webcohesion/enunciate/modules/csharp_client/ClientClassnameForMethod.java @@ -18,8 +18,8 @@ import com.webcohesion.enunciate.api.datatype.DataTypeReference; import com.webcohesion.enunciate.api.resources.Entity; import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; @@ -35,9 +35,9 @@ import freemarker.template.TemplateModelException; import jakarta.activation.DataHandler; + import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; -import javax.lang.model.element.TypeParameterElement; import javax.lang.model.type.*; import jakarta.xml.bind.JAXBElement; import javax.xml.datatype.XMLGregorianCalendar; @@ -87,7 +87,7 @@ public ClientClassnameForMethod(Map conversions, EnunciateJaxbCo classConversions.put(javax.xml.datatype.Duration.class.getName(), "TimeSpan?"); classConversions.put(jakarta.xml.bind.JAXBElement.class.getName(), "object"); classConversions.put(Object.class.getName(), "object"); - classConversions.put(RecordCompatibility.CLASS_RECORD, "object"); + classConversions.put(Record.class.getName(), "object"); } @Override @@ -126,7 +126,7 @@ else if (isCollection(declaration)) { if (adapterType != null) { return convert(adapterType.getAdaptingType()); } - if (RecordCompatibility.isRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/examples/full-api-edge-cases/pom.xml b/examples/full-api-edge-cases/pom.xml index ea06decd5..5998df174 100644 --- a/examples/full-api-edge-cases/pom.xml +++ b/examples/full-api-edge-cases/pom.xml @@ -15,11 +15,6 @@ - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - org.apache.maven.plugins maven-surefire-plugin diff --git a/examples/jackson2-api-lombok/pom.xml b/examples/jackson2-api-lombok/pom.xml index 227518fb7..4392658fd 100644 --- a/examples/jackson2-api-lombok/pom.xml +++ b/examples/jackson2-api-lombok/pom.xml @@ -15,11 +15,6 @@ - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - com.webcohesion.enunciate enunciate-maven-plugin diff --git a/examples/jackson2-api/pom.xml b/examples/jackson2-api/pom.xml index 80e28ac18..96a7a027f 100644 --- a/examples/jackson2-api/pom.xml +++ b/examples/jackson2-api/pom.xml @@ -15,11 +15,6 @@ - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - com.webcohesion.enunciate enunciate-maven-plugin diff --git a/examples/spring-petclinic/pom.xml b/examples/spring-petclinic/pom.xml index c0f906344..ca5adde07 100644 --- a/examples/spring-petclinic/pom.xml +++ b/examples/spring-petclinic/pom.xml @@ -21,11 +21,6 @@ - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - com.webcohesion.enunciate enunciate-maven-plugin diff --git a/gwt-json-overlay/src/main/java/com/webcohesion/enunciate/modules/gwt_json_overlay/ClientClassnameForMethod.java b/gwt-json-overlay/src/main/java/com/webcohesion/enunciate/modules/gwt_json_overlay/ClientClassnameForMethod.java index e3c888317..b4b7972e9 100644 --- a/gwt-json-overlay/src/main/java/com/webcohesion/enunciate/modules/gwt_json_overlay/ClientClassnameForMethod.java +++ b/gwt-json-overlay/src/main/java/com/webcohesion/enunciate/modules/gwt_json_overlay/ClientClassnameForMethod.java @@ -18,13 +18,12 @@ import com.webcohesion.enunciate.api.datatype.DataTypeReference; import com.webcohesion.enunciate.api.resources.Entity; import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.metadata.qname.XmlQNameEnumRef; -import com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext; import com.webcohesion.enunciate.modules.jackson.api.impl.SyntaxImpl; import com.webcohesion.enunciate.util.HasClientConvertibleType; import freemarker.template.TemplateModelException; @@ -118,7 +117,7 @@ else if (isCollection(declaration)) { if (adaptingType != null) { return convert(adaptingType); } - if (RecordCompatibility.isRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/EnunciateJacksonContext.java b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/EnunciateJacksonContext.java index ad32795f0..af1bf5044 100644 --- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/EnunciateJacksonContext.java +++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/EnunciateJacksonContext.java @@ -24,9 +24,7 @@ import com.webcohesion.enunciate.CompletionFailureException; import com.webcohesion.enunciate.EnunciateContext; import com.webcohesion.enunciate.EnunciateException; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; -import com.webcohesion.enunciate.javac.decorations.SourcePosition; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; import com.webcohesion.enunciate.javac.decorations.element.PropertyElement; import com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType; @@ -227,7 +225,7 @@ protected Map loadKnownTypes() { knownTypes.put(java.net.URI.class.getName(), KnownJsonType.STRING); knownTypes.put(java.net.URL.class.getName(), KnownJsonType.STRING); knownTypes.put(java.lang.Object.class.getName(), KnownJsonType.OBJECT); - knownTypes.put(RecordCompatibility.CLASS_RECORD, KnownJsonType.OBJECT); + knownTypes.put(Record.class.getName(), KnownJsonType.OBJECT); knownTypes.put(java.io.Serializable.class.getName(), KnownJsonType.OBJECT); knownTypes.put(byte[].class.getName(), KnownJsonType.STRING); knownTypes.put(java.nio.ByteBuffer.class.getName(), KnownJsonType.STRING); diff --git a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/JacksonModule.java b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/JacksonModule.java index a9fe37b55..5e154beab 100644 --- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/JacksonModule.java +++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/JacksonModule.java @@ -21,7 +21,6 @@ import com.webcohesion.enunciate.CompletionFailureException; import com.webcohesion.enunciate.EnunciateContext; import com.webcohesion.enunciate.api.ApiRegistry; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.Ignore; import com.webcohesion.enunciate.module.*; @@ -217,7 +216,7 @@ protected void addPotentialJacksonElement(Element declaration, LinkedList + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,14 +16,12 @@ package com.webcohesion.enunciate.modules.jackson.model; import com.fasterxml.jackson.annotation.JsonRootName; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext; import com.webcohesion.enunciate.modules.jackson.model.types.JsonType; import com.webcohesion.enunciate.modules.jackson.model.types.JsonTypeFactory; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; -import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; @@ -45,7 +43,7 @@ public JsonType getSupertype() { if (superclass == null || superclass.getKind() == TypeKind.NONE) { return null; } - else if (superclass instanceof DeclaredType && (isClasOrRecord(superclass) || context.isIgnored(((DeclaredType) superclass).asElement()) || context.isCollapseTypeHierarchy())) { + else if (superclass instanceof DeclaredType && (isClassOrRecord(superclass) || context.isIgnored(((DeclaredType) superclass).asElement()) || context.isCollapseTypeHierarchy())) { return null; } else { @@ -53,10 +51,10 @@ else if (superclass instanceof DeclaredType && (isClasOrRecord(superclass) || co } } - private boolean isClasOrRecord(TypeMirror superclass) { + private boolean isClassOrRecord(TypeMirror superclass) { TypeElement typeElement = (TypeElement) ((DeclaredType) superclass).asElement(); String qualifiedName = typeElement.getQualifiedName().toString(); - return qualifiedName.equals(Object.class.getName()) || qualifiedName.equals(RecordCompatibility.CLASS_RECORD); + return qualifiedName.equals(Object.class.getName()) || qualifiedName.equals(Record.class.getName()); } @Override @@ -78,11 +76,11 @@ public boolean isBaseObject() { TypeElement superDeclaration = (TypeElement) this.env.getTypeUtils().asElement(superclass); return superDeclaration == null - || Object.class.getName().equals(superDeclaration.getQualifiedName().toString()) - || Enum.class.getName().equals(superDeclaration.getQualifiedName().toString()) - || RecordCompatibility.CLASS_RECORD.equals(superDeclaration.getQualifiedName().toString()) - || this.context.isCollapseTypeHierarchy() - || this.context.isIgnored(superDeclaration); + || Object.class.getName().equals(superDeclaration.getQualifiedName().toString()) + || Enum.class.getName().equals(superDeclaration.getQualifiedName().toString()) + || Record.class.getName().equals(superDeclaration.getQualifiedName().toString()) + || this.context.isCollapseTypeHierarchy() + || this.context.isIgnored(superDeclaration); } public String getJsonRootName() { diff --git a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/TypeDefinition.java b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/TypeDefinition.java index bd8b99574..ff328339b 100644 --- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/TypeDefinition.java +++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/TypeDefinition.java @@ -21,7 +21,6 @@ import com.webcohesion.enunciate.EnunciateException; import com.webcohesion.enunciate.facets.Facet; import com.webcohesion.enunciate.facets.HasFacets; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.Annotations; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; @@ -33,7 +32,6 @@ import com.webcohesion.enunciate.modules.jackson.javac.ToStringValueProperty; import com.webcohesion.enunciate.util.AccessorBag; import com.webcohesion.enunciate.util.AnnotationUtils; -import com.webcohesion.enunciate.javac.CompatElementFilter; import com.webcohesion.enunciate.util.SortedList; import javax.lang.model.element.*; @@ -193,7 +191,7 @@ protected AccessorBag loadPotentialAccessors(AccessorFilter filter) { */ protected void aggregatePotentialAccessors(AccessorBag bag, DecoratedTypeElement clazz, AccessorFilter filter, boolean inlineAccessorsOfSuperclasses) { String fqn = clazz.getQualifiedName().toString(); - if (Object.class.getName().equals(fqn) || Enum.class.getName().equals(fqn) || RecordCompatibility.CLASS_RECORD.equals(fqn)) { + if (Object.class.getName().equals(fqn) || Enum.class.getName().equals(fqn) || Record.class.getName().equals(fqn)) { return; } @@ -221,10 +219,10 @@ protected void aggregatePotentialAccessors(AccessorBag bag, DecoratedTypeElement } } - List fieldElements = CompatElementFilter.fieldsOrRecordComponentsIn(clazz); + List fieldElements = ElementUtils.fieldsOrRecordComponentsIn(clazz); if (mixin != null) { //replace all mixin fields. - for (Element mixinField : CompatElementFilter.fieldsOrRecordComponentsIn(mixin)) { + for (Element mixinField : ElementUtils.fieldsOrRecordComponentsIn(mixin)) { int index = indexOf(fieldElements, mixinField.getSimpleName().toString()); if (index >= 0) { fieldElements.set(index, mixinField); @@ -602,7 +600,7 @@ public List getAllAccessors() { static DeclaredType refineType(DecoratedProcessingEnvironment env, DecoratedElement element, Class annotation, Function> refiner) { Element elt = element; - while (elt != null && elt.getKind() != ElementKind.CLASS && elt.getKind() != ElementKind.INTERFACE && !RecordCompatibility.isRecord(elt)) { + while (elt != null && elt.getKind() != ElementKind.CLASS && elt.getKind() != ElementKind.INTERFACE && elt.getKind() != ElementKind.RECORD) { elt = elt.getEnclosingElement(); } if (elt == null) { diff --git a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonTypeVisitor.java b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonTypeVisitor.java index f52781e34..9b43d70ac 100644 --- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonTypeVisitor.java +++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonTypeVisitor.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.Annotations; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; @@ -31,11 +30,9 @@ import com.webcohesion.enunciate.util.TypeHintUtils; import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.*; import javax.lang.model.util.SimpleTypeVisitor6; -import java.util.Arrays; import java.util.LinkedList; import static com.webcohesion.enunciate.javac.decorations.type.TypeMirrorUtils.getComponentType; @@ -122,17 +119,18 @@ public JsonType visitDeclared(DeclaredType declaredType, Context context) { return wrapAsNeeded(componentType.accept(this, new Context(context.context, false, true, context.stack)), context); } else { - String[] kinds = {ElementKind.CLASS.name(), ElementKind.ENUM.name(), ElementKind.INTERFACE.name(), RecordCompatibility.KIND_RECORD}; - if (Arrays.binarySearch(kinds, declaredElement.getKind().name()) >= 0) { - JsonType knownType = context.getContext().getKnownType(declaredElement); - if (knownType != null) { - jsonType = knownType; - } - else { - //type not known, not specified. Last chance: look for the type definition. - TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement); - if (typeDefinition != null) { - jsonType = new JsonClassType(typeDefinition); + switch (declaredElement.getKind()) { + case ENUM, CLASS, INTERFACE, RECORD -> { + JsonType knownType = context.getContext().getKnownType(declaredElement); + if (knownType != null) { + jsonType = knownType; + } + else { + //type not known, not specified. Last chance: look for the type definition. + TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement); + if (typeDefinition != null) { + jsonType = new JsonClassType(typeDefinition); + } } } } diff --git a/java-json-client/src/main/java/com/webcohesion/enunciate/modules/java_json_client/ClientClassnameForMethod.java b/java-json-client/src/main/java/com/webcohesion/enunciate/modules/java_json_client/ClientClassnameForMethod.java index 895a544e5..b210da7ff 100644 --- a/java-json-client/src/main/java/com/webcohesion/enunciate/modules/java_json_client/ClientClassnameForMethod.java +++ b/java-json-client/src/main/java/com/webcohesion/enunciate/modules/java_json_client/ClientClassnameForMethod.java @@ -18,8 +18,8 @@ import com.webcohesion.enunciate.api.datatype.DataTypeReference; import com.webcohesion.enunciate.api.resources.Entity; import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.metadata.qname.XmlQNameEnumRef; @@ -95,7 +95,7 @@ public String convert(TypeElement declaration) throws TemplateModelException { if (adaptingType != null) { return convert(adaptingType); } - if (RecordCompatibility.isClassOrRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/ClientClassnameForMethod.java b/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/ClientClassnameForMethod.java index b5a94ca8d..08e853ced 100644 --- a/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/ClientClassnameForMethod.java +++ b/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/ClientClassnameForMethod.java @@ -18,8 +18,8 @@ import com.webcohesion.enunciate.api.datatype.DataTypeReference; import com.webcohesion.enunciate.api.resources.Entity; import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; @@ -111,7 +111,7 @@ public String convert(TypeElement declaration) throws TemplateModelException { if (adapterType != null) { return convert(adapterType.getAdaptingType()); } - if (RecordCompatibility.isClassOrRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/CompatElementFilter.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/CompatElementFilter.java deleted file mode 100644 index 3da4f6a01..000000000 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/CompatElementFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.webcohesion.enunciate.javac; - -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import javax.lang.model.util.ElementFilter; -import java.util.ArrayList; -import java.util.List; - -/** - * Unified utility for handling java.lang.Record on JDK < 16. - */ -public final class CompatElementFilter { - private CompatElementFilter() { - } - - /** - * Get all fields in the class. If it is a java.lang.Record then get all the record components. - * - * @param clazz the class to - * @return a list of elements - */ - public static List fieldsOrRecordComponentsIn(TypeElement clazz) { - if (RecordCompatibility.isRecord(clazz)) { - List elements = new ArrayList<>(); - for (Element element : clazz.getEnclosedElements()) { - if (RecordCompatibility.isRecordComponent(element)) { - elements.add(element); - } - } - return elements; - } - else { - return new ArrayList<>(ElementFilter.fieldsIn(clazz.getEnclosedElements())); - } - } -} diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/RecordCompatibility.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/RecordCompatibility.java deleted file mode 100644 index bdf03926c..000000000 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/RecordCompatibility.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.webcohesion.enunciate.javac; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; - -/** - * Aids in adding record compatibility for JDK < 16. - */ -public final class RecordCompatibility { - public static final String KIND_RECORD = "RECORD"; - public static final String KIND_RECORD_COMPONENT = "RECORD_COMPONENT"; - public static final String CLASS_RECORD = "java.lang.Record"; - - private RecordCompatibility() { - } - - /** - * Check if the element is a record component. - * - * @param element the element to test - * @return true if it's a record component - */ - public static boolean isRecordComponent(Element element) { - return element != null && element.getKind().name().equals(KIND_RECORD_COMPONENT); - } - - /** - * Check if the element is a record. - * - * @param element the element to test - * @return true if it's a record - */ - public static boolean isRecord(Element element) { - return element.getKind().name().equals(KIND_RECORD); - } - - /** - * Check if the element is a class or record. - * - * @param element the element to test - * @return true if it's a class or record - */ - public static boolean isClassOrRecord(Element element) { - return element.getKind() == ElementKind.CLASS || isRecord(element); - } -} diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/DecoratedElements.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/DecoratedElements.java index dfd68e531..351e69951 100644 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/DecoratedElements.java +++ b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/DecoratedElements.java @@ -15,7 +15,6 @@ */ package com.webcohesion.enunciate.javac.decorations; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor; import com.webcohesion.enunciate.javac.decorations.adaptors.ExecutableElementAdaptor; import com.webcohesion.enunciate.javac.decorations.adaptors.TypeElementAdaptor; @@ -75,7 +74,7 @@ public String getDocComment(Element e) { } String recordComponentName = null; - if (RecordCompatibility.isRecordComponent(e)) { + if (e.getKind() == ElementKind.RECORD_COMPONENT) { recordComponentName = e.getSimpleName().toString(); e = e.getEnclosingElement(); } diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/DecoratedTypeElement.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/DecoratedTypeElement.java index 1e75c4251..83e6b83f3 100644 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/DecoratedTypeElement.java +++ b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/DecoratedTypeElement.java @@ -15,7 +15,6 @@ */ package com.webcohesion.enunciate.javac.decorations.element; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.ElementDecorator; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; @@ -152,7 +151,7 @@ public List enumValues() { public A getAnnotation(Class annotationType) { A annotation = super.getAnnotation(annotationType); - if (RecordCompatibility.isRecord(this) && annotation == null && (annotationType.getAnnotation(Inherited.class) != null) && (getSuperclass() instanceof DeclaredType)) { + if (ElementUtils.isClassOrRecord(this) && annotation == null && (annotationType.getAnnotation(Inherited.class) != null) && (getSuperclass() instanceof DeclaredType)) { TypeElement superDecl = (TypeElement) ((DeclaredType) getSuperclass()).asElement(); if ((superDecl != null) && (!Object.class.getName().equals(superDecl.getQualifiedName().toString()))) { return superDecl.getAnnotation(annotationType); @@ -165,7 +164,6 @@ public A getAnnotation(Class annotationType) { protected List loadProperties(PropertySpec spec) { HashMap getters = new HashMap(); HashMap setters = new HashMap(); - // TODO for (ExecutableElement method : getMethods()) { DecoratedExecutableElement decoratedMethod = (DecoratedExecutableElement) method; boolean getter = spec.isGetter(decoratedMethod); diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/ElementUtils.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/ElementUtils.java index 37043edca..85c5b4062 100644 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/ElementUtils.java +++ b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/element/ElementUtils.java @@ -19,10 +19,14 @@ import com.webcohesion.enunciate.javac.javadoc.JavaDoc; import com.webcohesion.enunciate.javac.javadoc.JavaDocTagHandler; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -131,6 +135,37 @@ public static String capitalize(String string) { return Character.toUpperCase(string.charAt(0)) + string.substring(1); } + /** + * Check if the element is a class or record. + * + * @param element the element to test + * @return true if it's a class or record + */ + public static boolean isClassOrRecord(Element element) { + return element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.RECORD; + } + + /** + * Get all fields in the class. If it is a java.lang.Record then get all the record components. + * + * @param clazz the element to inspect + * @return a list of elements + */ + public static List fieldsOrRecordComponentsIn(TypeElement clazz) { + if (clazz.getKind() == ElementKind.RECORD) { + List elements = new ArrayList<>(); + for (Element element : clazz.getEnclosedElements()) { + if (element.getKind() == ElementKind.RECORD_COMPONENT) { + elements.add(element); + } + } + return elements; + } + else { + return new ArrayList<>(ElementFilter.fieldsIn(clazz.getEnclosedElements())); + } + } + public static class DefaultPropertySpec implements PropertySpec { protected final DecoratedProcessingEnvironment env; diff --git a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/type/DecoratedTypeMirror.java b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/type/DecoratedTypeMirror.java index 2faf34785..ae35dd092 100644 --- a/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/type/DecoratedTypeMirror.java +++ b/javac-support/src/main/java/com/webcohesion/enunciate/javac/decorations/type/DecoratedTypeMirror.java @@ -15,10 +15,10 @@ */ package com.webcohesion.enunciate.javac.decorations.type; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.ElementDecorator; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecoration; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.javadoc.DefaultJavaDocTagHandler; import com.webcohesion.enunciate.javac.javadoc.DocComment; import com.webcohesion.enunciate.javac.javadoc.JavaDocTagHandler; @@ -149,7 +149,7 @@ public boolean isClass() { private boolean isClassOrRecord() { Element element = ((DeclaredType) this.delegate).asElement(); - return RecordCompatibility.isClassOrRecord(element); + return ElementUtils.isClassOrRecord(element); } public boolean isDeclared() { diff --git a/javascript-client/src/main/java/com/webcohesion/enunciate/modules/javascript_client/ClientClassnameForMethod.java b/javascript-client/src/main/java/com/webcohesion/enunciate/modules/javascript_client/ClientClassnameForMethod.java index 73aa76ece..b46f1d145 100644 --- a/javascript-client/src/main/java/com/webcohesion/enunciate/modules/javascript_client/ClientClassnameForMethod.java +++ b/javascript-client/src/main/java/com/webcohesion/enunciate/modules/javascript_client/ClientClassnameForMethod.java @@ -19,7 +19,6 @@ import com.webcohesion.enunciate.api.datatype.DataTypeReference; import com.webcohesion.enunciate.api.resources.Entity; import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.ClientName; @@ -85,7 +84,7 @@ public ClientClassnameForMethod(Map conversions, EnunciateJackso classConversions.put(javax.xml.datatype.Duration.class.getName(), "String"); classConversions.put(jakarta.xml.bind.JAXBElement.class.getName(), "Object"); classConversions.put(Object.class.getName(), "Object"); - classConversions.put(RecordCompatibility.CLASS_RECORD, "Object"); + classConversions.put(Record.class.getName(), "Object"); } @Override diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/EnunciateJaxbContext.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/EnunciateJaxbContext.java index befc22404..ac20d62aa 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/EnunciateJaxbContext.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/EnunciateJaxbContext.java @@ -18,8 +18,8 @@ import com.webcohesion.enunciate.CompletionFailureException; import com.webcohesion.enunciate.EnunciateContext; import com.webcohesion.enunciate.EnunciateException; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.qname.XmlQNameEnum; @@ -192,7 +192,7 @@ protected Map loadKnownTypes() { knownTypes.put(java.net.URI.class.getName(), KnownXmlType.STRING); knownTypes.put(javax.xml.datatype.Duration.class.getName(), KnownXmlType.DURATION); knownTypes.put(java.lang.Object.class.getName(), KnownXmlType.ANY_TYPE); - knownTypes.put(RecordCompatibility.CLASS_RECORD, KnownXmlType.ANY_TYPE); + knownTypes.put(Record.class.getName(), KnownXmlType.ANY_TYPE); knownTypes.put(java.io.Serializable.class.getName(), KnownXmlType.ANY_TYPE); knownTypes.put(byte[].class.getName(), KnownXmlType.BASE64_BINARY); knownTypes.put(java.nio.ByteBuffer.class.getName(), KnownXmlType.BASE64_BINARY); @@ -474,7 +474,7 @@ protected void add(LocalElementDeclaration led, LinkedList stack) { protected void addReferencedTypeDefinitions(LocalElementDeclaration led, LinkedList stack) { addSeeAlsoTypeDefinitions(led, stack); DecoratedTypeElement scope = led.getElementScope(); - if (scope != null && (RecordCompatibility.isClassOrRecord(scope)) && !isKnownTypeDefinition(scope)) { + if (scope != null && ElementUtils.isClassOrRecord(scope) && !isKnownTypeDefinition(scope)) { add(createTypeDefinition(scope), stack); } TypeElement typeElement = null; @@ -486,7 +486,7 @@ protected void addReferencedTypeDefinitions(LocalElementDeclaration led, LinkedL } } - if (scope != null && (RecordCompatibility.isClassOrRecord(scope)) && !isKnownTypeDefinition(typeElement)) { + if (scope != null && ElementUtils.isClassOrRecord(scope) && !isKnownTypeDefinition(typeElement)) { add(createTypeDefinition(typeElement), stack); } } diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/JaxbModule.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/JaxbModule.java index 0a6f74090..f9057f63e 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/JaxbModule.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/JaxbModule.java @@ -18,7 +18,6 @@ import com.webcohesion.enunciate.CompletionFailureException; import com.webcohesion.enunciate.EnunciateContext; import com.webcohesion.enunciate.api.ApiRegistry; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.metadata.Ignore; import com.webcohesion.enunciate.module.*; @@ -161,7 +160,7 @@ else if (!this.jaxbContext.isKnownTypeDefinition((TypeElement) declaration) && i } protected boolean isExplicitTypeDefinition(Element declaration) { - if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM && !RecordCompatibility.isRecord(declaration)) { + if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM && !(declaration.getKind() == ElementKind.RECORD)) { debug("%s isn't a potential JAXB type because it's not a class or an enum.", declaration); return false; } diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/Accessor.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/Accessor.java index e01652207..2bf5dc676 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/Accessor.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/Accessor.java @@ -21,6 +21,7 @@ import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; import com.webcohesion.enunciate.javac.decorations.element.DecoratedElement; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.element.PropertyElement; import com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; @@ -35,7 +36,6 @@ import com.webcohesion.enunciate.modules.jaxb.model.types.XmlTypeFactory; import com.webcohesion.enunciate.modules.jaxb.model.util.JAXBUtil; import com.webcohesion.enunciate.modules.jaxb.model.util.MapType; -import com.webcohesion.enunciate.javac.CompatElementFilter; import com.webcohesion.enunciate.util.HasClientConvertibleType; import com.webcohesion.enunciate.util.OptionalUtils; @@ -378,7 +378,7 @@ private DecoratedElement getXmlIDAccessor(DecoratedDeclaredType classType) { return null; } - for (Element field : CompatElementFilter.fieldsOrRecordComponentsIn(declaration)) { + for (Element field : ElementUtils.fieldsOrRecordComponentsIn(declaration)) { if (field.getAnnotation(XmlID.class) != null) { return (DecoratedElement) field; } diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/ComplexTypeDefinition.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/ComplexTypeDefinition.java index ccc352921..1770dd94a 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/ComplexTypeDefinition.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/ComplexTypeDefinition.java @@ -15,7 +15,6 @@ */ package com.webcohesion.enunciate.modules.jaxb.model; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; import com.webcohesion.enunciate.modules.jaxb.model.types.KnownXmlType; import com.webcohesion.enunciate.modules.jaxb.model.types.XmlType; @@ -115,7 +114,7 @@ public boolean isBaseObject() { TypeElement superDeclaration = (TypeElement) this.env.getTypeUtils().asElement(superclass); return superDeclaration == null || Object.class.getName().equals(superDeclaration.getQualifiedName().toString()) - || RecordCompatibility.CLASS_RECORD.equals(superDeclaration.getQualifiedName().toString()) + || Record.class.getName().equals(superDeclaration.getQualifiedName().toString()) || isXmlTransient(superDeclaration); } diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/TypeDefinition.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/TypeDefinition.java index ee25d8605..b11c28c14 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/TypeDefinition.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/TypeDefinition.java @@ -23,6 +23,7 @@ import com.webcohesion.enunciate.javac.decorations.element.DecoratedElement; import com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.element.PropertyElement; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.metadata.qname.XmlQNameEnumRef; @@ -37,7 +38,6 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import com.webcohesion.enunciate.javac.CompatElementFilter; import jakarta.xml.bind.annotation.*; import javax.xml.namespace.QName; import java.beans.Introspector; @@ -200,7 +200,7 @@ protected void aggregatePotentialAccessors(AccessorBag bag, DecoratedTypeElement aggregatePotentialAccessors(bag, superDeclaration, filter, true); } - for (javax.lang.model.element.Element fieldDeclaration : CompatElementFilter.fieldsOrRecordComponentsIn(clazz)) { + for (javax.lang.model.element.Element fieldDeclaration : ElementUtils.fieldsOrRecordComponentsIn(clazz)) { if (!filter.accept((DecoratedElement) fieldDeclaration)) { bag.fields.removeByName(fieldDeclaration); } diff --git a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/types/XmlTypeVisitor.java b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/types/XmlTypeVisitor.java index 8e9684163..b4832045f 100644 --- a/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/types/XmlTypeVisitor.java +++ b/jaxb/src/main/java/com/webcohesion/enunciate/modules/jaxb/model/types/XmlTypeVisitor.java @@ -16,7 +16,6 @@ package com.webcohesion.enunciate.modules.jaxb.model.types; import com.webcohesion.enunciate.EnunciateException; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; import com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition; import com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType; @@ -24,11 +23,9 @@ import com.webcohesion.enunciate.modules.jaxb.model.util.MapType; import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.*; import javax.lang.model.util.SimpleTypeVisitor6; -import java.util.Arrays; import java.util.LinkedList; /** @@ -76,17 +73,18 @@ public XmlType visitDeclared(DeclaredType declaredType, Context context) { return new MapXmlType(keyType, valueType); } else { - String[] kinds = {ElementKind.CLASS.name(), ElementKind.ENUM.name(), RecordCompatibility.KIND_RECORD}; - if(Arrays.binarySearch(kinds,declaredElement.getKind().name()) >=0) { - XmlType knownType = context.getContext().getKnownType(declaredElement); - if (knownType != null) { - return knownType; - } - else { - //type not known, not specified. Last chance: look for the type definition. - TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement); - if (typeDefinition != null) { - return new XmlClassType(typeDefinition); + switch (declaredElement.getKind()) { + case CLASS, ENUM, RECORD -> { + XmlType knownType = context.getContext().getKnownType(declaredElement); + if (knownType != null) { + return knownType; + } + else { + //type not known, not specified. Last chance: look for the type definition. + TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement); + if (typeDefinition != null) { + return new XmlClassType(typeDefinition); + } } } } diff --git a/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/Resource.java b/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/Resource.java index d6b74c8af..fa4bc4857 100644 --- a/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/Resource.java +++ b/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/Resource.java @@ -17,15 +17,14 @@ import com.webcohesion.enunciate.facets.Facet; import com.webcohesion.enunciate.facets.HasFacets; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.element.PropertyElement; import com.webcohesion.enunciate.javac.decorations.type.TypeVariableContext; import com.webcohesion.enunciate.modules.jaxrs.EnunciateJaxrsContext; import com.webcohesion.enunciate.modules.jaxrs.model.util.JaxrsUtil; import com.webcohesion.enunciate.util.AnnotationUtils; -import com.webcohesion.enunciate.javac.CompatElementFilter; import jakarta.annotation.security.RolesAllowed; import javax.lang.model.element.*; import javax.lang.model.type.DeclaredType; @@ -122,7 +121,7 @@ protected List getSubresourceLocators(TypeElement delegate, } - if (RecordCompatibility.isClassOrRecord(delegate)) { + if (ElementUtils.isClassOrRecord(delegate)) { TypeMirror superclass = delegate.getSuperclass(); if (superclass instanceof DeclaredType && ((DeclaredType)superclass).asElement() != null) { List superMethods = getSubresourceLocators((TypeElement) ((DeclaredType) superclass).asElement(), variableContext, context); @@ -182,7 +181,7 @@ protected List getResourceMethods(final TypeElement delegate, Ty } } - if (RecordCompatibility.isRecordComponent(delegate)) { + if (ElementUtils.isClassOrRecord(delegate)) { TypeMirror superclass = delegate.getSuperclass(); if (superclass instanceof DeclaredType && ((DeclaredType)superclass).asElement() != null) { DeclaredType declared = (DeclaredType) superclass; @@ -212,7 +211,7 @@ protected Set getResourceParameters(TypeElement delegate, Enu } Set resourceParameters = new TreeSet(); - for (Element field : CompatElementFilter.fieldsOrRecordComponentsIn(delegate)) { + for (Element field : ElementUtils.fieldsOrRecordComponentsIn(delegate)) { if (ResourceParameter.isResourceParameter(field, this.context)) { resourceParameters.add(new ResourceParameter(field, this)); } @@ -224,7 +223,7 @@ protected Set getResourceParameters(TypeElement delegate, Enu } } - if (RecordCompatibility.isClassOrRecord(delegate) && delegate.getSuperclass() instanceof DeclaredType) { + if (ElementUtils.isClassOrRecord(delegate) && delegate.getSuperclass() instanceof DeclaredType) { Set superParams = getResourceParameters((TypeElement) ((DeclaredType) delegate.getSuperclass()).asElement(), context); for (ResourceParameter superParam : superParams) { if (!isHidden(superParam, resourceParameters)) { diff --git a/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/ResourceParameter.java b/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/ResourceParameter.java index 69d9ebfe9..63a5a39c9 100644 --- a/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/ResourceParameter.java +++ b/jaxrs/src/main/java/com/webcohesion/enunciate/modules/jaxrs/model/ResourceParameter.java @@ -15,7 +15,6 @@ */ package com.webcohesion.enunciate.modules.jaxrs.model; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.ElementDecorator; import com.webcohesion.enunciate.javac.decorations.element.*; @@ -26,7 +25,6 @@ import com.webcohesion.enunciate.metadata.rs.TypeHint; import com.webcohesion.enunciate.modules.jaxrs.EnunciateJaxrsContext; import com.webcohesion.enunciate.util.AnnotationUtils; -import com.webcohesion.enunciate.javac.CompatElementFilter; import com.webcohesion.enunciate.util.TypeHintUtils; import jakarta.annotation.Nullable; @@ -247,7 +245,7 @@ public static List getFormBeanParameters(VariableElement para private static void gatherFormBeanParameters(TypeMirror type, ArrayList beanParams, PathContext context) { if (type instanceof DeclaredType) { DecoratedTypeElement typeDeclaration = (DecoratedTypeElement) ElementDecorator.decorate(((DeclaredType) type).asElement(), context.getContext().getContext().getProcessingEnvironment()); - for (Element field : CompatElementFilter.fieldsOrRecordComponentsIn(typeDeclaration)) { + for (Element field : ElementUtils.fieldsOrRecordComponentsIn(typeDeclaration)) { if (isResourceParameter(field, context.getContext())) { beanParams.add(new ResourceParameter(field, context)); } @@ -266,7 +264,7 @@ else if (isBeanParameter(property)) { } } - if (RecordCompatibility.isClassOrRecord(typeDeclaration)) { + if (ElementUtils.isClassOrRecord(typeDeclaration)) { gatherFormBeanParameters(typeDeclaration.getSuperclass(), beanParams, context); } } diff --git a/jaxws/src/main/java/com/webcohesion/enunciate/modules/jaxws/model/EndpointInterface.java b/jaxws/src/main/java/com/webcohesion/enunciate/modules/jaxws/model/EndpointInterface.java index 4b5cc9495..5fca584a7 100644 --- a/jaxws/src/main/java/com/webcohesion/enunciate/modules/jaxws/model/EndpointInterface.java +++ b/jaxws/src/main/java/com/webcohesion/enunciate/modules/jaxws/model/EndpointInterface.java @@ -18,9 +18,9 @@ import com.webcohesion.enunciate.EnunciateException; import com.webcohesion.enunciate.facets.Facet; import com.webcohesion.enunciate.facets.HasFacets; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.TypeElementComparator; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.TypeVariableContext; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.metadata.soap.SoapBindingName; @@ -77,7 +77,7 @@ public EndpointInterface(TypeElement delegate, Set implementa annotation = getAnnotation(jakarta.jws.WebService.class); impls = new ArrayList(); if (annotation != null) { - if (RecordCompatibility.isClassOrRecord(this)) { + if (ElementUtils.isClassOrRecord(this)) { //if the declaration is a class, the endpoint interface is implied... impls.add(new EndpointImplementation(getDelegate(), this, context)); } @@ -106,7 +106,7 @@ public EndpointInterface(TypeElement delegate, Set implementa } } - if (RecordCompatibility.isClassOrRecord(delegate)) { + if (ElementUtils.isClassOrRecord(delegate)) { //the spec says we need to consider superclass methods, too... TypeMirror superclass = delegate.getSuperclass(); if (superclass instanceof DeclaredType) { @@ -311,7 +311,7 @@ public Collection getEndpointImplementations() { * A quick check to see if a declaration is an endpoint implementation. */ protected boolean isEndpointImplementation(TypeElement declaration) { - if (RecordCompatibility.isClassOrRecord(declaration) && !declaration.getQualifiedName().equals(getQualifiedName())) { + if (ElementUtils.isClassOrRecord(declaration) && !declaration.getQualifiedName().equals(getQualifiedName())) { WebService webServiceInfo = declaration.getAnnotation(WebService.class); return webServiceInfo != null && getQualifiedName().toString().equals(webServiceInfo.endpointInterface()); } diff --git a/obj-c-xml-client/src/main/java/com/webcohesion/enunciate/modules/objc_client/ClientClassnameForMethod.java b/obj-c-xml-client/src/main/java/com/webcohesion/enunciate/modules/objc_client/ClientClassnameForMethod.java index b0d29f0fc..fa19f5f7a 100644 --- a/obj-c-xml-client/src/main/java/com/webcohesion/enunciate/modules/objc_client/ClientClassnameForMethod.java +++ b/obj-c-xml-client/src/main/java/com/webcohesion/enunciate/modules/objc_client/ClientClassnameForMethod.java @@ -15,8 +15,8 @@ */ package com.webcohesion.enunciate.modules.objc_client; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.metadata.ClientName; import com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext; import com.webcohesion.enunciate.modules.jaxb.model.Accessor; @@ -28,7 +28,7 @@ import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import jakarta.activation.DataHandler; -import javax.lang.model.element.ElementKind; + import javax.lang.model.element.TypeElement; import javax.lang.model.type.*; import jakarta.xml.bind.JAXBElement; @@ -96,7 +96,7 @@ else if (isCollection(declaration)) { if (adapterType != null) { return convert(adapterType.getAdaptingType()); } - if (RecordCompatibility.isClassOrRecord(declaration)) { + if (ElementUtils.isClassOrRecord(declaration)) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement diff --git a/pom.xml b/pom.xml index 518f16ead..464fea744 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,6 @@ 3.3.0 3.3.0 1.6.0 - 3.3.2 https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HXSXBXUT63RCG diff --git a/rt-util/pom.xml b/rt-util/pom.xml index c2a7a41a8..093d4a3c9 100644 --- a/rt-util/pom.xml +++ b/rt-util/pom.xml @@ -59,7 +59,6 @@ org.mockito mockito-core - 5.6.0 test diff --git a/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/RequestParameterFactory.java b/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/RequestParameterFactory.java index f70bf3d99..7e063cd86 100644 --- a/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/RequestParameterFactory.java +++ b/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/RequestParameterFactory.java @@ -15,17 +15,16 @@ */ package com.webcohesion.enunciate.modules.spring_web.model; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment; import com.webcohesion.enunciate.javac.decorations.ElementDecorator; import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; import com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.element.PropertyElement; import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror; import com.webcohesion.enunciate.javac.decorations.type.TypeVariableContext; import com.webcohesion.enunciate.util.AnnotationUtils; -import com.webcohesion.enunciate.javac.CompatElementFilter; import org.springframework.web.bind.annotation.*; import javax.lang.model.element.*; @@ -184,7 +183,7 @@ private static void gatherFormObjectParameters(TypeMirror type, ArrayList methods = context.getHttpMethods(); ResourceParameterType defaultType = methods.contains("POST") ? ResourceParameterType.FORM : ResourceParameterType.QUERY; DecoratedTypeElement typeDeclaration = (DecoratedTypeElement) ElementDecorator.decorate(((DeclaredType) type).asElement(), context.getContext().getContext().getProcessingEnvironment()); - for (Element field : CompatElementFilter.fieldsOrRecordComponentsIn(typeDeclaration)) { + for (Element field : ElementUtils.fieldsOrRecordComponentsIn(typeDeclaration)) { DecoratedVariableElement decorated = (DecoratedVariableElement) field; if (!decorated.isFinal() && !decorated.isTransient() && decorated.isPublic()) { params.add(new SimpleRequestParameter(decorated, context, defaultType)); @@ -197,7 +196,7 @@ private static void gatherFormObjectParameters(TypeMirror type, ArrayList getRequestMappings(final TypeElement delegate, Ty } } - if (RecordCompatibility.isClassOrRecord(delegate)) { + if (ElementUtils.isClassOrRecord(delegate)) { TypeMirror superclass = delegate.getSuperclass(); if (superclass instanceof DeclaredType && ((DeclaredType) superclass).asElement() != null) { DeclaredType declared = (DeclaredType) superclass; diff --git a/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/SpringControllerAdvice.java b/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/SpringControllerAdvice.java index 8cd8195b4..8778ad550 100644 --- a/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/SpringControllerAdvice.java +++ b/spring-web/src/main/java/com/webcohesion/enunciate/modules/spring_web/model/SpringControllerAdvice.java @@ -15,8 +15,8 @@ */ package com.webcohesion.enunciate.modules.spring_web.model; -import com.webcohesion.enunciate.javac.RecordCompatibility; import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement; +import com.webcohesion.enunciate.javac.decorations.element.ElementUtils; import com.webcohesion.enunciate.javac.decorations.type.TypeVariableContext; import com.webcohesion.enunciate.modules.spring_web.EnunciateSpringWebContext; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -188,7 +188,7 @@ protected List findRequestMappingAdvice(RequestMapping req } } - if (RecordCompatibility.isClassOrRecord(controllerAdvice)) { + if (ElementUtils.isClassOrRecord(controllerAdvice)) { TypeMirror superclass = controllerAdvice.getSuperclass(); if (superclass instanceof DeclaredType && ((DeclaredType)superclass).asElement() != null) { DeclaredType declared = (DeclaredType) superclass;