use of org.hotswap.agent.javassist.CtClass 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.CtClass in project HotswapAgent by HotswapProjects.
the class Descriptor method toCtClass.
private static int toCtClass(ClassPool cp, String desc, int i, CtClass[] args, int n) throws NotFoundException {
int i2;
String name;
int arrayDim = 0;
char c = desc.charAt(i);
while (c == '[') {
++arrayDim;
c = desc.charAt(++i);
}
if (c == 'L') {
i2 = desc.indexOf(';', ++i);
name = desc.substring(i, i2++).replace('/', '.');
} else {
CtClass type = toPrimitiveClass(c);
if (type == null)
// error
return -1;
i2 = i + 1;
if (arrayDim == 0) {
args[n] = type;
// neither an array type or a class type
return i2;
} else
name = type.getName();
}
if (arrayDim > 0) {
StringBuffer sbuf = new StringBuffer(name);
while (arrayDim-- > 0) sbuf.append("[]");
name = sbuf.toString();
}
args[n] = cp.get(name);
return i2;
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class TypeChecker method atNewExpr.
public void atNewExpr(NewExpr expr) throws CompileError {
if (expr.isArray())
atNewArrayExpr(expr);
else {
CtClass clazz = resolver.lookupClassByName(expr.getClassName());
String cname = clazz.getName();
ASTList args = expr.getArguments();
atMethodCallCore(clazz, MethodInfo.nameInit, args);
exprType = CLASS;
arrayDim = 0;
className = MemberResolver.javaToJvmName(cname);
}
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class TypeChecker method atCallExpr.
public void atCallExpr(CallExpr expr) throws CompileError {
String mname = null;
CtClass targetClass = null;
ASTree method = expr.oprand1();
ASTList args = (ASTList) expr.oprand2();
if (method instanceof Member) {
mname = ((Member) method).get();
targetClass = thisClass;
} else if (method instanceof Keyword) {
// constructor
// <init>
mname = MethodInfo.nameInit;
if (((Keyword) method).get() == SUPER)
targetClass = MemberResolver.getSuperclass(thisClass);
else
targetClass = thisClass;
} else if (method instanceof Expr) {
Expr e = (Expr) method;
mname = ((Symbol) e.oprand2()).get();
int op = e.getOperator();
if (// static method
op == MEMBER)
targetClass = resolver.lookupClass(((Symbol) e.oprand1()).get(), false);
else if (op == '.') {
ASTree target = e.oprand1();
String classFollowedByDotSuper = isDotSuper(target);
if (classFollowedByDotSuper != null)
targetClass = MemberResolver.getSuperInterface(thisClass, classFollowedByDotSuper);
else {
try {
target.accept(this);
} catch (NoFieldException nfe) {
if (nfe.getExpr() != target)
throw nfe;
// it should be a static method.
exprType = CLASS;
arrayDim = 0;
// JVM-internal
className = nfe.getField();
e.setOperator(MEMBER);
e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(className)));
}
if (arrayDim > 0)
targetClass = resolver.lookupClass(javaLangObject, true);
else if (exprType == CLASS)
/* && arrayDim == 0 */
targetClass = resolver.lookupClassByJvmName(className);
else
badMethod();
}
} else
badMethod();
} else
fatal();
MemberResolver.Method minfo = atMethodCallCore(targetClass, mname, args);
expr.setMethod(minfo);
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class TransformAccessArrayField method getTopType.
private String getTopType(int pos) throws BadBytecode {
Frame frame = getFrame(pos);
if (frame == null)
return null;
CtClass clazz = frame.peek().getCtClass();
return clazz != null ? Descriptor.toJvmName(clazz) : null;
}
Aggregations