Skip to content

Commit

Permalink
Merge branch 'ripdajacker-jdk-17-build-success'
Browse files Browse the repository at this point in the history
  • Loading branch information
stoicflame committed Oct 17, 2023
2 parents 1b86ec6 + 8bdffe3 commit 2ee8b47
Show file tree
Hide file tree
Showing 32 changed files with 142 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.webcohesion.enunciate.modules.c_client;

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 @@ -27,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 @@ -78,6 +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(Record.class.getName(), "struct xmlBasicNode");
classConversions.putAll(conversions);
}

Expand All @@ -95,7 +97,7 @@ else if (isCollection(declaration)) {
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
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 Expand Up @@ -194,4 +196,4 @@ public String convert(TypeVariable typeVariable) throws TemplateModelException {
return conversion;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void removeByName(E memberDeclaration) {
}
}

public final ElementList<VariableElement> fields = new ElementList<>();
public final ElementList<Element> fields = new ElementList<>();
public final ElementList<PropertyElement> properties = new ElementList<>();
public String typeIdProperty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,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) && !"java.lang.Record".equals(conversion)) {
if (typeMirror instanceof DeclaredType && !Object.class.getName().equals(conversion) && !Record.class.getName().equals(conversion)) {
conversion += convertDeclaredTypeArguments(((DeclaredType) typeMirror).getTypeArguments());
}

Expand Down Expand Up @@ -162,4 +162,4 @@ protected String getPackageSeparator() {
public String convert(PackageElement packageDeclaration) {
throw new UnsupportedOperationException("packages don't have a classname.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.webcohesion.enunciate.api.resources.Entity;
import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
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 @@ -34,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 @@ -86,6 +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(Record.class.getName(), "object");
}

@Override
Expand Down Expand Up @@ -124,7 +126,7 @@ else if (isCollection(declaration)) {
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
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 @@ -19,11 +19,11 @@
import com.webcohesion.enunciate.api.resources.Entity;
import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
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 @@ -117,7 +117,7 @@ else if (isCollection(declaration)) {
if (adaptingType != null) {
return convert(adaptingType);
}
if (declaration.getKind() == ElementKind.CLASS) {
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 Expand Up @@ -202,4 +202,4 @@ else if (decorated.isPrimitive()) {
return super.convert(typeMirror);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import com.webcohesion.enunciate.module.EnunciateModuleContext;
import com.webcohesion.enunciate.modules.jackson.javac.InterfaceJacksonDeclaredType;
import com.webcohesion.enunciate.modules.jackson.javac.InterfaceJacksonTypeElement;
import com.webcohesion.enunciate.modules.jackson.javac.ParameterizedJacksonDeclaredType;
import com.webcohesion.enunciate.modules.jackson.javac.SyntheticJacksonArrayType;
import com.webcohesion.enunciate.modules.jackson.model.*;
Expand Down Expand Up @@ -226,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(java.lang.Record.class.getName(), 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 @@ -216,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) {
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,7 +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 jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlTransient;
import java.util.Collections;
Expand Down Expand Up @@ -128,6 +131,10 @@ else if (element instanceof DecoratedVariableElement) {
return true;
}

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

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
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.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;

/**
* A type definition for a json type.
Expand All @@ -43,14 +43,20 @@ public JsonType getSupertype() {
if (superclass == null || superclass.getKind() == TypeKind.NONE) {
return null;
}
else if (superclass instanceof DeclaredType && (((TypeElement)((DeclaredType)superclass).asElement()).getQualifiedName().toString().equals(Object.class.getName()) || ((TypeElement)((DeclaredType)superclass).asElement()).getQualifiedName().toString().equals(Record.class.getName()) || 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 isClassOrRecord(TypeMirror superclass) {
TypeElement typeElement = (TypeElement) ((DeclaredType) superclass).asElement();
String qualifiedName = typeElement.getQualifiedName().toString();
return qualifiedName.equals(Object.class.getName()) || qualifiedName.equals(Record.class.getName());
}

@Override
public boolean isSimple() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,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)) {
if (Object.class.getName().equals(fqn) || Enum.class.getName().equals(fqn) || Record.class.getName().equals(fqn)) {
return;
}

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

List<VariableElement> fieldElements = new ArrayList<VariableElement>(ElementFilter.fieldsIn(clazz.getEnclosedElements()));
List<Element> fieldElements = ElementUtils.fieldsOrRecordComponentsIn(clazz);
if (mixin != null) {
//replace all mixin fields.
for (VariableElement mixinField : ElementFilter.fieldsIn(mixin.getEnclosedElements())) {
for (Element mixinField : ElementUtils.fieldsOrRecordComponentsIn(mixin)) {
int index = indexOf(fieldElements, mixinField.getSimpleName().toString());
if (index >= 0) {
fieldElements.set(index, mixinField);
Expand All @@ -234,7 +234,7 @@ protected void aggregatePotentialAccessors(AccessorBag bag, DecoratedTypeElement
}

Set<String> propsIgnore = new HashSet<String>();
for (VariableElement fieldDeclaration : fieldElements) {
for (Element fieldDeclaration : fieldElements) {
JsonUnwrapped unwrapped = fieldDeclaration.getAnnotation(JsonUnwrapped.class);
if (unwrapped != null && unwrapped.enabled()) {
DecoratedTypeElement element;
Expand Down Expand Up @@ -274,7 +274,7 @@ else if (!filter.accept((DecoratedElement) fieldDeclaration)) {
}

JacksonPropertySpec propertySpec = new JacksonPropertySpec(this.env);
List<PropertyElement> propertyElements = new ArrayList<PropertyElement>(clazz.getProperties(propertySpec));
List<PropertyElement> propertyElements = new ArrayList<>(clazz.getProperties(propertySpec));
if (mixin != null) {
//replace all mixin properties.
for (PropertyElement mixinProperty : ((DecoratedTypeElement)mixin).getProperties(propertySpec)) {
Expand Down Expand Up @@ -600,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) {
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 @@ -120,9 +120,7 @@ public JsonType visitDeclared(DeclaredType declaredType, Context context) {
}
else {
switch (declaredElement.getKind()) {
case ENUM:
case CLASS:
case INTERFACE:
case ENUM, CLASS, INTERFACE, RECORD -> {
JsonType knownType = context.getContext().getKnownType(declaredElement);
if (knownType != null) {
jsonType = knownType;
Expand All @@ -134,7 +132,7 @@ public JsonType visitDeclared(DeclaredType declaredType, Context context) {
jsonType = new JsonClassType(typeDefinition);
}
}
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.webcohesion.enunciate.api.resources.Entity;
import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
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;
Expand Down Expand Up @@ -94,7 +95,7 @@ public String convert(TypeElement declaration) throws TemplateModelException {
if (adaptingType != null) {
return convert(adaptingType);
}
if (declaration.getKind() == ElementKind.CLASS) {
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 @@ -19,6 +19,7 @@
import com.webcohesion.enunciate.api.resources.Entity;
import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
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 Down Expand Up @@ -110,7 +111,7 @@ public String convert(TypeElement declaration) throws TemplateModelException {
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
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 @@ -22,10 +22,13 @@
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.javadoc.JavaDoc;
import com.webcohesion.enunciate.javac.javadoc.ParamDocComment;

import javax.lang.model.element.*;
import javax.lang.model.util.Elements;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -70,6 +73,12 @@ public String getDocComment(Element e) {
e = ((DecoratedElement) e).getDelegate();
}

String recordComponentName = null;
if (e.getKind() == ElementKind.RECORD_COMPONENT) {
recordComponentName = e.getSimpleName().toString();
e = e.getEnclosingElement();
}

String docComment;
if (e instanceof ElementAdaptor) {
docComment = ((ElementAdaptor) e).getDocComment();
Expand All @@ -78,6 +87,12 @@ public String getDocComment(Element e) {
docComment = delegate.getDocComment(e);
}

if (recordComponentName != null) {
JavaDoc recordDoc = new JavaDoc(docComment, null, null, this.env);
HashMap<String, String> params = ParamDocComment.loadParamsComments("param", recordDoc);
docComment = params.get(recordComponentName);
}

return docComment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public List<VariableElement> enumValues() {
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
A annotation = super.getAnnotation(annotationType);

if (isClass() && (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);
Expand Down Expand Up @@ -213,10 +213,6 @@ protected List<VariableElement> loadEnumConstants() {
return constants;
}

public boolean isClass() {
return getKind() == ElementKind.CLASS;
}

public boolean isInterface() {
return getKind() == ElementKind.INTERFACE;
}
Expand Down
Loading

0 comments on commit 2ee8b47

Please sign in to comment.