use of org.hotswap.agent.javassist.CtBehavior in project HotswapAgent by HotswapProjects.
the class Javac method compile.
/**
* Compiles a method, constructor, or field declaration
* to a class.
* A field declaration can declare only one field.
*
* <p>In a method or constructor body, $0, $1, ... and $_
* are not available.
*
* @return a <code>CtMethod</code>, <code>CtConstructor</code>,
* or <code>CtField</code> object.
* @see #recordProceed(String,String)
*/
public CtMember compile(String src) throws CompileError {
Parser p = new Parser(new Lex(src));
ASTList mem = p.parseMember1(stable);
try {
if (mem instanceof FieldDecl)
return compileField((FieldDecl) mem);
else {
CtBehavior cb = compileMethod(p, (MethodDecl) mem);
CtClass decl = cb.getDeclaringClass();
cb.getMethodInfo2().rebuildStackMapIf6(decl.getClassPool(), decl.getClassFile2());
return cb;
}
} catch (BadBytecode bb) {
throw new CompileError(bb.getMessage());
} catch (CannotCompileException e) {
throw new CompileError(e.getMessage());
}
}
use of org.hotswap.agent.javassist.CtBehavior in project HotswapAgent by HotswapProjects.
the class Expr method where.
/**
* Returns the constructor or method containing the expression.
*/
public CtBehavior where() {
MethodInfo mi = thisMethod;
CtBehavior[] cb = thisClass.getDeclaredBehaviors();
for (int i = cb.length - 1; i >= 0; --i) if (cb[i].getMethodInfo2() == mi)
return cb[i];
CtConstructor init = thisClass.getClassInitializer();
if (init != null && init.getMethodInfo2() == mi)
return init;
/* getDeclaredBehaviors() returns a list of methods/constructors.
* Although the list is cached in a CtClass object, it might be
* recreated for some reason. Thus, the member name and the signature
* must be also checked.
*/
for (int i = cb.length - 1; i >= 0; --i) {
if (thisMethod.getName().equals(cb[i].getMethodInfo2().getName()) && thisMethod.getDescriptor().equals(cb[i].getMethodInfo2().getDescriptor())) {
return cb[i];
}
}
throw new RuntimeException("fatal: not found");
}
Aggregations