本文整理汇总了Java中javassist.compiler.Javac.compile方法的典型用法代码示例。如果您正苦于以下问题:Java Javac.compile方法的具体用法?Java Javac.compile怎么用?Java Javac.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.compiler.Javac
的用法示例。
在下文中一共展示了Javac.compile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import javassist.compiler.Javac; //导入方法依赖的package包/类
/**
* Compiles the given source code and creates a constructor.
* The source code must include not only the constructor body
* but the whole declaration.
*
* @param src the source text.
* @param declaring the class to which the created constructor is added.
*/
public static CtConstructor make(String src, CtClass declaring)
throws CannotCompileException
{
Javac compiler = new Javac(declaring);
try {
CtMember obj = compiler.compile(src);
if (obj instanceof CtConstructor) {
// a stack map table has been already created.
return (CtConstructor)obj;
}
}
catch (CompileError e) {
throw new CannotCompileException(e);
}
throw new CannotCompileException("not a constructor");
}
示例2: make
import javassist.compiler.Javac; //导入方法依赖的package包/类
/**
* Compiles the given source code and creates a method.
* The source code must include not only the method body
* but the whole declaration, for example,
*
* <ul><pre>"public Object id(Object obj) { return obj; }"</pre></ul>
*
* <p>If the source code includes <code>$proceed()</code>, then
* it is compiled into a method call on the specified object.
*
* @param src the source text.
* @param declaring the class to which the created method is added.
* @param delegateObj the source text specifying the object
* that is called on by <code>$proceed()</code>.
* @param delegateMethod the name of the method
* that is called by <code>$proceed()</code>.
*/
public static CtMethod make(String src, CtClass declaring,
String delegateObj, String delegateMethod)
throws CannotCompileException
{
Javac compiler = new Javac(declaring);
try {
if (delegateMethod != null)
compiler.recordProceed(delegateObj, delegateMethod);
CtMember obj = compiler.compile(src);
if (obj instanceof CtMethod)
return (CtMethod)obj;
}
catch (CompileError e) {
throw new CannotCompileException(e);
}
throw new CannotCompileException("not a method");
}
示例3: make
import javassist.compiler.Javac; //导入方法依赖的package包/类
/**
* Compiles the given source code and creates a field.
* Examples of the source code are:
*
* <ul><pre>
* "public String name;"
* "public int k = 3;"</pre></ul>
*
* <p>Note that the source code ends with <code>';'</code>
* (semicolon).
*
* @param src the source text.
* @param declaring the class to which the created field is added.
*/
public static CtField make(String src, CtClass declaring)
throws CannotCompileException
{
Javac compiler = new Javac(declaring);
try {
CtMember obj = compiler.compile(src);
if (obj instanceof CtField)
return (CtField)obj; // an instance of Javac.CtFieldWithInit
}
catch (CompileError e) {
throw new CannotCompileException(e);
}
throw new CannotCompileException("not a field");
}