Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Main {
    public static String getSetMethod(Class<?> c, String prefix, String postfix) {
        StringWriter sw = new StringWriter();
        if (prefix == null)
            prefix = "";
        if (postfix == null)
            postfix = "";
        Method[] ms = c.getDeclaredMethods();
        if (ms != null && ms.length > 0) {
            for (Method m : ms) {
                String name = m.getName();
                if (name.startsWith("set") && isPublicNoStatic(m.getModifiers())) {
                    sw.append(prefix).append(name).append("(").append(postfix).append(");\r\n");
                }
            }
        }
        return sw.toString();
    }

    private static boolean isPublicNoStatic(int i) {
        return ((i & Modifier.PUBLIC) == Modifier.PUBLIC) && ((i & Modifier.STATIC) != Modifier.STATIC);
    }
}