Skip to content

Commit b1fb3d2

Browse files
committed
add unsafe generator
1 parent b7c5b8b commit b1fb3d2

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@
148148
<plugin>
149149
<groupId>org.xolstice.maven.plugins</groupId>
150150
<artifactId>protobuf-maven-plugin</artifactId>
151-
<version>0.5.0</version>
151+
<version>0.6.1</version>
152152
<extensions>true</extensions>
153153
<configuration>
154-
<protocArtifact>com.google.protobuf:protoc:2.5.0:exe:${os.detected.classifier}</protocArtifact>
154+
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
155155
</configuration>
156156
<executions>
157157
<execution>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)