Java Code Examples for javassist.bytecode.Descriptor#toJavaName()

The following examples show how to use javassist.bytecode.Descriptor#toJavaName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeBuilder.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public CodeBuilder insertMethod(String name, Class<?>[] params) {
	CtClass cc = klass.getCtClass();
	String className = Descriptor.toJavaName(Descriptor.toJvmName(cc));
	List<Class<?>> list = Arrays.asList(params);
	CodeBuilder cb = klass.getCodeBuilder();
	Map<List<Class<?>>, String> map = cb.methodTemplateVars.get(name);
	if (map == null) {
		cb.methodTemplateVars.put(name, map = new HashMap());
	} else {
		if (map.containsKey(list)) {
			body.append(map.get(list));
			return this;
		}
	}
	String parameterTypes = declareVar(params, cb);
	String var = cb.getVarName("Method");
	CodeBuilder field = klass.assignStaticField(Method.class, var);
	field.insertObjectClass(className);
	field.code(".getDeclaredMethod(").insert(name);
	field.code(", ").code(parameterTypes).code(")").end();
	map.put(list, var);
	body.append(var);
	return this;
}
 
Example 2
Source File: ClassFactory.java    From anno4j with Apache License 2.0 6 votes vote down vote up
Class<?> getJavaClass(CtClass cc) throws ClassNotFoundException {
	if (cc.isPrimitive()) {
		if (cc.equals(CtClass.booleanType))
			return Boolean.TYPE;
		if (cc.equals(CtClass.byteType))
			return Byte.TYPE;
		if (cc.equals(CtClass.charType))
			return Character.TYPE;
		if (cc.equals(CtClass.doubleType))
			return Double.TYPE;
		if (cc.equals(CtClass.floatType))
			return Float.TYPE;
		if (cc.equals(CtClass.intType))
			return Integer.TYPE;
		if (cc.equals(CtClass.longType))
			return Long.TYPE;
		if (cc.equals(CtClass.shortType))
			return Short.TYPE;
		throw new AssertionError();
	}
	String name = Descriptor.toJavaName(Descriptor.toJvmName(cc));
	return classForName(name);
}