|
| 1 | +package com.github.apache9.unsafe; |
| 2 | + |
| 3 | +import java.io.PrintWriter; |
| 4 | +import java.nio.file.Files; |
| 5 | +import java.nio.file.Paths; |
| 6 | +import java.util.regex.Matcher; |
| 7 | +import java.util.regex.Pattern; |
| 8 | +import java.util.stream.Collectors; |
| 9 | +import java.util.stream.Stream; |
| 10 | + |
| 11 | +public class Generator { |
| 12 | + |
| 13 | + private static final Pattern METHOD = Pattern.compile("public (final )?(native )?(\\S+)\\s+(\\S+)\\((.*)\\)"); |
| 14 | + |
| 15 | + public static void main(String[] args) throws Exception { |
| 16 | + try (PrintWriter pw = new PrintWriter("/home/zhangduo/hbase/HBaseUnsafe0")) { |
| 17 | + for (String line : Files.readAllLines(Paths.get("/home/zhangduo/hbase/all_methods"))) { |
| 18 | + Matcher m = METHOD.matcher(line); |
| 19 | + if (m.find()) { |
| 20 | + String returnType = m.group(3); |
| 21 | + String name = m.group(4); |
| 22 | + String params = m.group(5); |
| 23 | + pw.println("public static " + returnType + " " + name + "(" + params + ") {"); |
| 24 | + if (!returnType.equals("void")) { |
| 25 | + pw.print("return "); |
| 26 | + } |
| 27 | + pw.print("HBaseUnsafe0." + name + "("); |
| 28 | + if (params.trim().length() > 0) { |
| 29 | + String[] typeAndNames = params.split(",\\s*"); |
| 30 | + String str = Stream.of(typeAndNames).map(typeAndName -> typeAndName.split("\\s+")[1]) |
| 31 | + .collect(Collectors.joining(", ")); |
| 32 | + pw.print(str); |
| 33 | + } |
| 34 | + pw.println(");"); |
| 35 | + pw.println("}"); |
| 36 | + pw.println(); |
| 37 | + } else { |
| 38 | + System.out.println("error: " + line); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments