Skip to content

Commit

Permalink
Assume JDK 17 is available, remove diffs with origin in preparation f…
Browse files Browse the repository at this point in the history
…or PR.
  • Loading branch information
ripdajacker committed Oct 17, 2023
1 parent 22627f8 commit 8bdffe3
Show file tree
Hide file tree
Showing 38 changed files with 131 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -79,7 +79,7 @@ public ClientClassnameForMethod(Map<String, String> 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);
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -87,7 +87,7 @@ public ClientClassnameForMethod(Map<String, String> 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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions examples/full-api-edge-cases/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions examples/jackson2-api-lombok/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions examples/jackson2-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions examples/spring-petclinic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,7 +225,7 @@ protected Map<String, JsonType> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -217,7 +216,7 @@ protected void addPotentialJacksonElement(Element declaration, LinkedList<Elemen
}

protected boolean isExplicitTypeDefinition(Element declaration, boolean honorJaxb) {
if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM && declaration.getKind() != ElementKind.INTERFACE && !RecordCompatibility.isRecord(declaration)) {
if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM && declaration.getKind() != ElementKind.INTERFACE && declaration.getKind() != ElementKind.RECORD) {
debug("%s isn't a potential Jackson type because it's not a class or an enum or interface.", declaration);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import com.webcohesion.enunciate.javac.decorations.element.PropertyElement;
import com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;

import com.webcohesion.enunciate.javac.RecordCompatibility;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlTransient;
import java.util.Collections;
Expand Down Expand Up @@ -130,7 +131,7 @@ else if (element instanceof DecoratedVariableElement) {
return true;
}

if(RecordCompatibility.isRecordComponent(element)) {
if(element.getKind() == ElementKind.RECORD_COMPONENT) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright © 2006-2016 Web Cohesion (info@webcohesion.com)
* <p>
*
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* 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.
Expand All @@ -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;
Expand All @@ -45,18 +43,18 @@ 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 {
return JsonTypeFactory.getJsonType(superclass, this.context);
}
}

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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -221,10 +219,10 @@ protected void aggregatePotentialAccessors(AccessorBag bag, DecoratedTypeElement
}
}

List<Element> fieldElements = CompatElementFilter.fieldsOrRecordComponentsIn(clazz);
List<Element> 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);
Expand Down Expand Up @@ -602,7 +600,7 @@ public List<Accessor> getAllAccessors() {

static <A extends Annotation> DeclaredType refineType(DecoratedProcessingEnvironment env, DecoratedElement<?> element, Class<A> annotation, Function<A, Class<?>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Loading

0 comments on commit 8bdffe3

Please sign in to comment.