All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javaetmoi.javabean.util.JavapoetHelper Maven / Gradle / Ivy

Go to download

The JavaBeanMarshaller class is responsible for serializing an object (graph) to it's Java code.

There is a newer version: 1.0.3
Show newest version
package com.javaetmoi.javabean.util;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;

import java.util.List;

public class JavapoetHelper {

    private JavapoetHelper() {
        // Helper class
    }

    public static MethodSpec findMethod(TypeSpec.Builder typeBuilder, String methodName) {
        // https://github.com/square/javapoet/issues/416
        List methodSpecs = typeBuilder.build().methodSpecs;
        for (MethodSpec methodSpec : methodSpecs) {
            if (methodSpec.name.equals(methodName)) {
                return methodSpec;
            }
        }
        return null;
    }

    public static void addExceptionIfNotDeclared(MethodSpec.Builder methodBuilder, Class exception) {
        // See https://github.com/square/javapoet/issues/438
        ClassName ex = ClassName.get(exception);
        if (!methodBuilder.build().exceptions.contains(ex)) methodBuilder.addException(ex);
    }
}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy