use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class Type method getComponent.
/**
* Returns the array component if this type is an array. If the type
* is not an array null is returned.
*
* @return the array component if an array, otherwise null
*/
public Type getComponent() {
if (this.clazz == null || !this.clazz.isArray())
return null;
CtClass component;
try {
component = this.clazz.getComponentType();
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
Type type = (Type) prims.get(component);
return (type != null) ? type : new Type(component);
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class AnnotationImpl method getDefault.
private Object getDefault(String name, Method method) throws ClassNotFoundException, RuntimeException {
String classname = annotation.getTypeName();
if (pool != null) {
try {
CtClass cc = pool.get(classname);
ClassFile cf = cc.getClassFile2();
MethodInfo minfo = cf.getMethod(name);
if (minfo != null) {
AnnotationDefaultAttribute ainfo = (AnnotationDefaultAttribute) minfo.getAttribute(AnnotationDefaultAttribute.tag);
if (ainfo != null) {
MemberValue mv = ainfo.getDefaultValue();
return mv.getValue(classLoader, pool, method);
}
}
} catch (NotFoundException e) {
throw new RuntimeException("cannot find a class file: " + classname);
}
}
throw new RuntimeException("no default value: " + classname + "." + name + "()");
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class Javac method compileBody.
/**
* Compiles a method (or constructor) body.
*
* @param src a single statement or a block.
* If null, this method produces a body returning zero or null.
*/
public Bytecode compileBody(CtBehavior method, String src) throws CompileError {
try {
int mod = method.getModifiers();
recordParams(method.getParameterTypes(), Modifier.isStatic(mod));
CtClass rtype;
if (method instanceof CtMethod) {
gen.setThisMethod((CtMethod) method);
rtype = ((CtMethod) method).getReturnType();
} else
rtype = CtClass.voidType;
recordReturnType(rtype, false);
boolean isVoid = rtype == CtClass.voidType;
if (src == null)
makeDefaultBody(bytecode, rtype);
else {
Parser p = new Parser(new Lex(src));
SymbolTable stb = new SymbolTable(stable);
Stmnt s = p.parseStatement(stb);
if (p.hasMore())
throw new CompileError("the method/constructor body must be surrounded by {}");
boolean callSuper = false;
if (method instanceof CtConstructor)
callSuper = !((CtConstructor) method).isClassInitializer();
gen.atMethodBody(s, callSuper, isVoid);
}
return bytecode;
} catch (NotFoundException e) {
throw new CompileError(e.toString());
}
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class TypeChecker method fieldAccess.
/* if EXPR is to access a static field, fieldAccess() translates EXPR
* into an expression using '#' (MEMBER). For example, it translates
* java.lang.Integer.TYPE into java.lang.Integer#TYPE. This translation
* speeds up type resolution by MemberCodeGen.
*/
protected CtField fieldAccess(ASTree expr) throws CompileError {
if (expr instanceof Member) {
Member mem = (Member) expr;
String name = mem.get();
try {
CtField f = thisClass.getField(name);
if (Modifier.isStatic(f.getModifiers()))
mem.setField(f);
return f;
} catch (NotFoundException e) {
// EXPR might be part of a static member access?
throw new NoFieldException(name, expr);
}
} else if (expr instanceof Expr) {
Expr e = (Expr) expr;
int op = e.getOperator();
if (op == MEMBER) {
Member mem = (Member) e.oprand2();
CtField f = resolver.lookupField(((Symbol) e.oprand1()).get(), mem);
mem.setField(f);
return f;
} else if (op == '.') {
try {
e.oprand1().accept(this);
} catch (NoFieldException nfe) {
if (nfe.getExpr() != e.oprand1())
throw nfe;
/* EXPR should be a static field.
* If EXPR might be part of a qualified class name,
* lookupFieldByJvmName2() throws NoFieldException.
*/
return fieldAccess2(e, nfe.getField());
}
CompileError err = null;
try {
if (exprType == CLASS && arrayDim == 0)
return resolver.lookupFieldByJvmName(className, (Symbol) e.oprand2());
} catch (CompileError ce) {
err = ce;
}
/* If a filed name is the same name as a package's,
* a static member of a class in that package is not
* visible. For example,
*
* class Foo {
* int javassist;
* }
*
* It is impossible to add the following method:
*
* String m() { return javassist.CtClass.intType.toString(); }
*
* because javassist is a field name. However, this is
* often inconvenient, this compiler allows it. The following
* code is for that.
*/
ASTree oprnd1 = e.oprand1();
if (oprnd1 instanceof Symbol)
return fieldAccess2(e, ((Symbol) oprnd1).get());
if (err != null)
throw err;
}
}
throw new CompileError("bad filed access");
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class JettyPlugin method patchWebXmlConfiguration.
/**
* Plugin initialization step needs to be fine tuned. It can be intialized only AFTER the classloader
* already knows about hotswap-agent.properties file (i.e. after webapp basic path is added to the classloader),
* but BEFORE first servlet is initialized.
*
* WebXmlConfiguration seems to be good place which should work in most setups. The plugin is intialized before
* web.xml file is processed - basic paths should be known, but nothing is processed yet.
*
* Application classloader is processed during plugin initialization. It means that other plugins triggered
* on plugin init should fire as well - for jetty is important core watchResources plugin, which will handle
* extraClassPath and watchResources configuration properties (jetty fortunately depends only on basic
* URLClassLoader behaviour which is handled by that plugin).
*/
@OnClassLoadEvent(classNameRegexp = "org.eclipse.jetty.webapp.WebXmlConfiguration")
public static void patchWebXmlConfiguration(CtClass ctClass) throws NotFoundException, CannotCompileException, ClassNotFoundException {
try {
// after application context initialized, but before processing started
CtMethod doStart = ctClass.getDeclaredMethod("configure");
// init the plugin
String src = PluginManagerInvoker.buildInitializePlugin(JettyPlugin.class, "context.getClassLoader()");
src += PluginManagerInvoker.buildCallPluginMethod("context.getClassLoader()", JettyPlugin.class, "init", "context", "java.lang.Object");
doStart.insertBefore(src);
} catch (NotFoundException e) {
LOGGER.warning("org.eclipse.jetty.webapp.WebAppContext does not contain startContext method. Jetty plugin will be disabled.\n" + "*** This is Ok, Jetty plugin handles only special properties ***");
return;
}
}
Aggregations