org.fugerit.java.nhg.GenerateReflectConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of native-helper-graalvm Show documentation
Show all versions of native-helper-graalvm Show documentation
Utilities for Graal VM code generation
The newest version!
package org.fugerit.java.nhg;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.nhg.reflect.config.Entry;
import org.fugerit.java.nhg.reflect.config.EntryField;
import org.fugerit.java.nhg.reflect.config.EntryMethod;
import java.io.Writer;
import java.util.*;
public class GenerateReflectConfig {
private ObjectWriter writer;
public GenerateReflectConfig(ObjectWriter writer) {
this.writer = writer;
}
public GenerateReflectConfig() {
this( JacksonHelper.newObjectMapper().writerWithDefaultPrettyPrinter() );
}
private static String keyEntryField( EntryField o ) {
return o.getName();
}
private static String keyEntryMethod( EntryMethod o ) {
return o.getName()+"-"+ StringUtils.concat( ",", o.getParameterTypes() );
}
public void normalizeSort( List reflectConfig ) {
for ( Entry e : reflectConfig ) {
if ( e.getFields() != null ) {
Collections.sort( e.getFields(), Comparator.comparing(GenerateReflectConfig::keyEntryField));
}
if ( e.getMethods() != null ) {
Collections.sort( e.getMethods(), Comparator.comparing(GenerateReflectConfig::keyEntryMethod));
}
}
}
public void generate(Writer out, List reflectConfig ) {
SafeFunction.apply( () -> {
normalizeSort( reflectConfig );
ObjectMapper mapper = JacksonHelper.newObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
writer.writeValue( out, reflectConfig );
} );
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy