Procyon is a suite of Java metaprogramming tools focused on code generation and analysis. It includes the following libraries:
The Procyon libraries are available from Maven Central under group ID org.bitbucket.mstrobel
.
The procyon-core
framework contains common support classes used by the other Procyon APIs. Its facilities include string manipulation, collection extensions, filesystem/path utilities, freezable objects and collections, attached data stores, and some runtime type helpers.
The procyon-reflection
framework provides a rich reflection and code generation API with full support for generics, wildcards, and other high-level Java type concepts. It is based on .NET's System.Reflection
and System.Reflection.Emit
APIs and is meant to address many of the shortcomings of the core Java reflection API, which offers rather limited and cumbersome support for generic type inspection. Its code generation facilities include a TypeBuilder
, MethodBuilder
, and a bytecode emitter.
For more information, see the Reflection Framework topic.
:::java
final Type<Map> map = Type.of(Map.class);
final Type<?> rawMap = map.getErasedType();
final Type<Map<String, Integer>> boundMap = map.makeGenericType(Types.String, Types.Integer);
System.out.println(map.getDeclaredMethods().get(1));
System.out.println(rawMap.getDeclaredMethods().get(1));
System.out.println(boundMap.getDeclaredMethods().get(1));
System.out.println(boundMap.getGenericTypeParameters());
System.out.println(boundMap.getTypeArguments());
:::text
public abstract V put(K, V)
public abstract Object put(Object, Object)
public abstract Integer put(String, Integer)
[K, V]
[java.lang.String, java.lang.Integer]
The procyon-expressions
framework provides a more natural form of code generation.
Rather than requiring bytecode to be emitted directly, as with procyon-reflection
and other popular libraries like ASM, procyon-expressions
enables code composition
using declarative expression trees. These expression trees may then be compiled directly
into callbacks or coupled with a MethodBuilder
. The procyon-expressions
API is
almost a direct port of System.Linq.Expressions
from .NET's Dynamic Language Runtime,
minus the dynamic callsite support (and with more relaxed rules regarding type conversions).
:::java
//
// This lambda closes over a complex constant (a String array).
//
final ConstantExpression items = constant(
new String[] { "one", "two", "three", "four", "five" }
);
//
// If written in Java, the constructed expression would look something like this:
//
// () -> {
// for (String item : <closure>items)
// System.out.printf("Got item: %s\n", item);
// }
//
final ParameterExpression item = variable(Types.String, "item");
final LambdaExpression<Runnable> runnable = lambda(
Type.of(Runnable.class),
forEach(
item,
items,
call(
field(null, Types.System.getField("out")),
"printf",
constant("Got item: %s\n"),
item
)
)
);
System.out.println(runnable);
final Runnable delegate = runnable.compile();
delegate.run();
:::text
() => for (String item : [one, two, three, four, five])
System.out.printf("Got item: %s\n", new Object[] { item })
Got item: one
Got item: two
Got item: three
Got item: four
Got item: five
The procyon-compilertools
project is a work in progress that includes:
Mono.Cecil
ILSpy
The Compiler Toolset is still early in development and subject to change.
procyon-decompiler
is a standalone front-end for the Java decompiler included in
procyon-compilertools
. All dependencies are embedded in the JAR for easy redistribution.
For more information about the decompiler, see the Java Decompiler wiki page.
Check out these third party products based on Procyon! Are you using Procyon in one of your projects? Contact me (email / twitter) if you would like it listed here.
SecureTeam Java Decompiler A JavaFX-based decompiler front-end with fast and convenient code navigation. Download it, or launch it directly from your browser.
Bytecode Viewer is an open source Java decompilation, disassembly, and debugging suite by @Konloch. It can produce decompiled sources from several modern Java decompilers, including Procyon, CFR, and FernFlower.
./gradle build
Maybe you will get error bellow:
* What went wrong:
Execution failed for task ':Procyon.CompilerTools:signArchives'.
> Cannot perform signing task ':Procyon.CompilerTools:signArchives' because it has no configured signatory
then you can get the resolution to fix it link http://www.voidcn.com/article/p-usxorvno-nh.html.
If you get the error, it means you hava no configuration of the GPG key, follow as:
1: Generating the GPG key
gpg --gen-key
2: Get GPG secret key
gpg --list-secret-keys --list-options show-keyring
may be we will get the result:
/home/david/.gnupg/secring.gpg
------------------------------
sec 2048R/A76F0DA4 2017-12-28
uid YangDawei <david.0122@163.com>
ssb 2048R/A1192B78 2017-12-28
from the result, we can know
keyId=A76F0DA4
secretKeyRingFile=/home/david/.gnupg/secring.gpg
3: Create file ~/.gradle/gradle.properties if not exist, and write text info as:
signing.keyId=A76F0DA4
signing.password=secret
signing.secretKeyRingFile=/home/david/.gnupg/secring.gpg
all right, ./gradle build now, and you can success!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。