Skip to content

Instantly share code, notes, and snippets.

@cfirmo33
Created March 16, 2016 14:42
Show Gist options
  • Save cfirmo33/3a74cd3521bb7d1cbeb9 to your computer and use it in GitHub Desktop.
Save cfirmo33/3a74cd3521bb7d1cbeb9 to your computer and use it in GitHub Desktop.
public class GeradorDeSets {
public static void main(String[] args) {
try {
gerarArquivoSets(Operacao.class);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
public static void gerarArquivoSets(Class<?> c) throws NoSuchFieldException{
String path =
"C:" + File.separator
+ "Users" + File.separator
+ "Carlos" + File.separator
+ "Desktop" + File.separator
+ "MetodosSet.txt";
Method[] methods = c.getDeclaredMethods();
List<String> srtMethods = new ArrayList<>();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getReturnType().getName().equals("void") &&
method.getName().startsWith("set")){
srtMethods.add(method.getName());
}
}
String[] stockArr = new String[srtMethods.size()];
stockArr = srtMethods.toArray(stockArr);
Arrays.sort(stockArr);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < stockArr.length; i++) {
String str = stockArr[i];
sb.append(str+"() \n");
}
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path), "utf-8"))) {
writer.write(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment