Skip to content

Commit

Permalink
Clean up work: remove unused code, improve comments (#4536)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored May 18, 2024
1 parent 0a77792 commit c95c2ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ public JsonFormat.Value getFormatOverrides() {
}

/*
/**********************************************************
/**********************************************************************
/* Public API: main-level collection
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -481,9 +481,9 @@ protected void collectAll()
}

/*
/**********************************************************
/* Overridable internal methods, adding members
/**********************************************************
/**********************************************************************
/* Property introspection: Fields
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -615,6 +615,12 @@ protected void _addFields(Map<String, POJOPropertyBuilder> props)
}
}

/*
/**********************************************************************
/* Property introspection: Creators (constructors, factory methods)
/**********************************************************************
*/

// Completely rewritten in 2.18
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
{
Expand Down Expand Up @@ -816,134 +822,7 @@ private void _addCreatorParams(Map<String, POJOPropertyBuilder> props,

/*
/**********************************************************************
/* Deprecated (in 2.18) creator detection
/**********************************************************************
*/

/**
* Method for collecting basic information on constructor(s) found
*/
@Deprecated
protected void _addCreatorsOLD(Map<String, POJOPropertyBuilder> props)
{
// can be null if annotation processing is disabled...
if (_useAnnotations) {
for (AnnotatedConstructor ctor : _classDef.getConstructors()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<>();
}
for (int i = 0, len = ctor.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, ctor.getParameter(i));
}
}
for (AnnotatedMethod factory : _classDef.getFactoryMethods()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<>();
}
for (int i = 0, len = factory.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, factory.getParameter(i));
}
}
}
if (isRecordType()) {
List<String> recordComponentNames = new ArrayList<>();
AnnotatedConstructor canonicalCtor = JDK14Util.findRecordConstructor(
_classDef, _annotationIntrospector, _config, recordComponentNames);

if (canonicalCtor != null) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<>();
}

Set<AnnotatedParameter> registeredParams = new HashSet<>();
for (POJOPropertyBuilder creatorProperty : _creatorProperties) {
Iterator<AnnotatedParameter> iter = creatorProperty.getConstructorParameters();
while (iter.hasNext()) {
AnnotatedParameter param = iter.next();
if (param.getOwner().equals(canonicalCtor)) {
registeredParams.add(param);
}
}
}

if (_creatorProperties.isEmpty() || !registeredParams.isEmpty()) {
for (int i = 0; i < canonicalCtor.getParameterCount(); i++) {
AnnotatedParameter param = canonicalCtor.getParameter(i);
if (!registeredParams.contains(param)) {
_addCreatorParam(props, param, recordComponentNames.get(i));
}
}
}
}
}
}

/**
* @since 2.4
*/
protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param)
{
_addCreatorParam(props, param, null);
}

private void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param, String recordComponentName)
{
String impl;
if (recordComponentName != null) {
impl = recordComponentName;
} else {
// JDK 8, paranamer, Scala can give implicit name
impl = _annotationIntrospector.findImplicitPropertyName(param);
if (impl == null) {
impl = "";
}
}

PropertyName pn = _annotationIntrospector.findNameForDeserialization(param);
boolean expl = (pn != null && !pn.isEmpty());
if (!expl) {
if (impl.isEmpty()) {
// Important: if neither implicit nor explicit name, cannot make use of
// this creator parameter -- may or may not be a problem, verified at a later point.
return;
}

// Also: if this occurs, there MUST be explicit annotation on creator itself...
JsonCreator.Mode creatorMode = _annotationIntrospector.findCreatorAnnotation(_config, param.getOwner());
// ...or is a Records canonical constructor
boolean isCanonicalConstructor = recordComponentName != null;

if ((creatorMode == null
|| creatorMode == JsonCreator.Mode.DISABLED
// 12-Mar-2024: [databind#2543] need to skip delegating as well
|| creatorMode == JsonCreator.Mode.DELEGATING)
&& !isCanonicalConstructor) {
return;
}
pn = PropertyName.construct(impl);
}

// 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
impl = _checkRenameByField(impl);

// shouldn't need to worry about @JsonIgnore, since creators only added
// if so annotated

/* 13-May-2015, tatu: We should try to start with implicit name, similar to how
* fields and methods work; but unlike those, we don't necessarily have
* implicit name to use (pre-Java8 at least). So:
*/
POJOPropertyBuilder prop = (expl && impl.isEmpty())
? _property(props, pn) : _property(props, impl);
prop.addCtor(param, pn, expl, true, false);
_creatorProperties.add(prop);
}

/*
/**********************************************************************
/* Method (getter, setter etc) introspection
/* Property introspection: Methods (getters, setters etc)
/**********************************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ public static PotentialCreator findCanonicalRecordConstructor(MapperConfig<?> co
+ClassUtil.getTypeDescription(recordClass.getType()));
}

@Deprecated // since 2.18
public static AnnotatedConstructor findRecordConstructor(DeserializationContext ctxt,
BeanDescription beanDesc, List<String> names) {
return findRecordConstructor(beanDesc.getClassInfo(), ctxt.getAnnotationIntrospector(), ctxt.getConfig(), names);
}

@Deprecated // since 2.18
public static AnnotatedConstructor findRecordConstructor(AnnotatedClass recordClass,
AnnotationIntrospector intr, MapperConfig<?> config, List<String> names) {
return new CreatorLocator(config, recordClass)
Expand Down Expand Up @@ -194,6 +196,7 @@ protected Object[] recordComponents(Class<?> recordType) throws IllegalArgumentE

}

@Deprecated // since 2.18
static class RawTypeName {
public final Class<?> rawType;
public final String name;
Expand All @@ -204,6 +207,7 @@ public RawTypeName(Class<?> rt, String n) {
}
}

@Deprecated // since 2.18
static class CreatorLocator {
protected final AnnotatedClass _recordClass;
protected final MapperConfig<?> _config;
Expand Down

0 comments on commit c95c2ca

Please sign in to comment.