/** * Returns a TypeDesc for the type of this ClassFile. */ public TypeDesc getType() { if (mType == null) { mType = TypeDesc.forClass(mClassName); } return mType; }
public static MethodDesc forMethod(Method method) { Class[] paramClasses = method.getParameterTypes(); TypeDesc[] paramTypes; if (paramClasses == null || paramClasses.length == 0) { paramTypes = EMPTY_PARAMS; } else { paramTypes = new TypeDesc[paramClasses.length]; for (int i=paramClasses.length; --i>=0; ) { paramTypes[i] = TypeDesc.forClass(paramClasses[i]); } } return forArguments(TypeDesc.forClass(method.getReturnType()), paramTypes); }
public void invokeSuper(Method method) { TypeDesc ret = TypeDesc.forClass(method.getReturnType()); Class[] paramClasses = method.getParameterTypes(); TypeDesc[] params = new TypeDesc[paramClasses.length]; for (int i=0; i<params.length; i++) { params[i] = TypeDesc.forClass(paramClasses[i]); } invokeSuper(method.getDeclaringClass().getName(), method.getName(), ret, params); }
public ConstantClassInfo(ConstantPool cp, String className) { super(TAG_CLASS); String desc = className.replace('.', '/'); mType = TypeDesc.forClass(className); mNameConstant = cp.addConstantUTF(desc); }
/** * Returns an annotation descriptor that has no parameters. */ public static String makePlainDescriptor(Class<? extends Annotation> annotationType) { return "" + TAG_ANNOTATION + TypeDesc.forClass(annotationType).getDescriptor(); }
public void invoke(Constructor constructor) { Class[] paramClasses = constructor.getParameterTypes(); TypeDesc[] params = new TypeDesc[paramClasses.length]; for (int i=0; i<params.length; i++) { params[i] = TypeDesc.forClass(paramClasses[i]); } invokeConstructor(constructor.getDeclaringClass().getName().toString(), params); } }
public void invokeConstructor(String className, TypeDesc[] params) { invokeConstructor(className, TypeDesc.forClass(className), params); }
public Object visit(String name, int pos, Class value, Object param) { appendName(name, pos, TAG_CLASS); if (value == String.class) { mBuilder.append(TAG_STRING); } else if (value == Class.class) { mBuilder.append(TAG_CLASS); } else { mBuilder.append(TypeDesc.forClass(value).getDescriptor()); } return null; }
public ConstantClassInfo(ConstantUTFInfo nameConstant) { super(TAG_CLASS); String name = nameConstant.getValue(); if (!name.endsWith(";") && !name.startsWith("[")) { mType = TypeDesc.forClass(name); } else { mType = TypeDesc.forDescriptor(name); } mNameConstant = nameConstant; }
public Object visit(String name, int pos, Enum value, Annotation ann) { put(ann, name, pos, ann.makeMemberValue(TypeDesc.forClass(value.getDeclaringClass()), value.name())); return null; }
public Object visit(String name, int pos, Annotation value, Object param) { if (appendName(name, pos, TAG_ANNOTATION)) { mBuilder.append(TypeDesc.forClass(value.annotationType()).getDescriptor()); } super.visit(name, pos, value, param); mBuilder.append(';'); return null; }
public void invoke(Method method) { TypeDesc ret = TypeDesc.forClass(method.getReturnType()); Class[] paramClasses = method.getParameterTypes(); TypeDesc[] params = new TypeDesc[paramClasses.length]; for (int i=0; i<params.length; i++) { params[i] = TypeDesc.forClass(paramClasses[i]); } Class clazz = method.getDeclaringClass(); if (Modifier.isStatic(method.getModifiers())) { invokeStatic(clazz.getName(), method.getName(), ret, params); } else if (clazz.isInterface()) { invokeInterface(clazz.getName(), method.getName(), ret, params); } else { invokeVirtual(clazz.getName(), method.getName(), ret, params); } }
public Object visit(String name, int pos, Class value, Annotation ann) { put(ann, name, pos, ann.makeMemberValue(TypeDesc.forClass(value))); return null; }
return TypeDesc.forClass(src.substring(startPos, i));
/** * Add a method to this class. This method is handy for implementing * methods defined by a pre-existing interface. */ public MethodInfo addMethod(Method method) { Modifiers modifiers = Modifiers.getInstance(method.getModifiers()).toAbstract(false); MethodInfo mi = addMethod(modifiers, method.getName(), MethodDesc.forMethod(method)); // exception stuff... Class[] exceptions = method.getExceptionTypes(); for (int i=0; i<exceptions.length; i++) { mi.addException(TypeDesc.forClass(exceptions[i])); } return mi; }
/** * Used to describe an array class. */ public ConstantClassInfo(ConstantPool cp, String className, int dim) { super(TAG_CLASS); TypeDesc type = TypeDesc.forClass(className); String desc; if (dim > 0) { while (--dim >= 0) { type = type.toArrayType(); } desc = type.getDescriptor(); } else { desc = className.replace('.', '/'); } mType = type; mNameConstant = cp.addConstantUTF(desc); }
public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
public Object visit(String name, int pos, java.lang.annotation.Annotation value, Annotation ann) { if (name == null && mStack.size() == 0) { // Root annotation. super.visit(name, pos, value, ann); } else { // Nested annotation. Annotation nested = ann.makeAnnotation(); nested.setType(TypeDesc.forClass(value.annotationType())); super.visit(name, pos, value, nested); put(ann, name, pos, ann.makeMemberValue(nested)); } return null; }
private static ThrowUnchecked generateImpl() { RuntimeClassFile cf = new RuntimeClassFile(null, ThrowUnchecked.class.getName()); cf.addDefaultConstructor(); CodeBuilder b = new CodeBuilder (cf.addMethod(Modifiers.PROTECTED, "doFire", null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)})); b.loadLocal(b.getParameter(0)); b.throwObject(); try { return (ThrowUnchecked) cf.defineClass().newInstance(); } catch (Exception e) { throw new Error(e); } }
private Class<?> generateClass(ScoreFormulaLexer lexer, int funcNum) throws Exception { // initialize the code generator RuntimeClassFile cf = new RuntimeClassFile("UserDefinedFunction_"+funcNum); cf.addInterface("com.flaptor.indextank.index.scorer.ScoreFunction"); cf.addDefaultConstructor(); docVarType = TypeDesc.forClass("com.flaptor.indextank.index.scorer.Boosts"); // DocVariables queryVarType = TypeDesc.forClass("com.flaptor.indextank.query.QueryVariables"); // Variables params = new TypeDesc[] {TypeDesc.DOUBLE, TypeDesc.INT, docVarType, queryVarType}; MethodInfo mi = cf.addMethod(Modifiers.PUBLIC, "score", TypeDesc.DOUBLE, params); b = new CodeBuilder(mi); scoreParam = b.getParameter(0); ageParam = b.getParameter(1); docVarParam = b.getParameter(2); queryVarParam = b.getParameter(3); // parse and generate code start(); error = error == null ? lexer.getError() : error; if (null != error) { throw error; } // return the generated class Class<?> clazz = cf.defineClass(); return clazz; }