/** * Makes an empty class initializer (static constructor). * If the class already includes a class initializer, * this method returns it. * * @see #getClassInitializer() */ public CtConstructor makeClassInitializer() throws CannotCompileException { throw new CannotCompileException("not a class"); }
/** * Converts this class to a class file. * Once this method is called, further modifications are not * possible any more. * * <p>This method dose not close the output stream in the end. * * @param out the output stream that a class file is written to. */ public void toBytecode(DataOutputStream out) throws CannotCompileException, IOException { throw new CannotCompileException("not a class"); }
void check(String desc) throws CannotCompileException { char c = desc.charAt(0); if (c != 'I' && c != 'S' && c != 'B' && c != 'C' && c != 'Z') throw new CannotCompileException("type mismatch"); }
static final boolean checkResultValue(CtClass retType, String prog) throws CannotCompileException { /* * Is $_ included in the source code? */ boolean hasIt = (prog.indexOf(Javac.resultVarName) >= 0); if (!hasIt && retType != CtClass.voidType) throw new CannotCompileException( "the resulting value is not stored in " + Javac.resultVarName); return hasIt; }
void check(String desc) throws CannotCompileException { if (desc.charAt(0) != '[') throw new CannotCompileException("type mismatch"); }
void check(String desc) throws CannotCompileException { if (!desc.equals("D")) throw new CannotCompileException("type mismatch"); }
void check(String desc) throws CannotCompileException { if (!desc.equals("F")) throw new CannotCompileException("type mismatch"); }
void check(String desc) throws CannotCompileException { if (!desc.equals("J")) throw new CannotCompileException("type mismatch"); }
/** * Writes a class file. */ public static void writeFile(ClassFile cf, String directoryName) throws CannotCompileException { try { writeFile0(cf, directoryName); } catch (IOException e) { throw new CannotCompileException(e); } }
public void toBytecode(DataOutputStream out) throws CannotCompileException, IOException { if (!hasConstructor) try { inheritAllConstructors(); hasConstructor = true; } catch (NotFoundException e) { throw new CannotCompileException(e); } super.toBytecode(out); }
private CtField(String typeDesc, String name, CtClass clazz) throws CannotCompileException { super(clazz); ClassFile cf = clazz.getClassFile2(); if (cf == null) throw new CannotCompileException("bad declaring class: " + clazz.getName()); fieldInfo = new FieldInfo(cf.getConstPool(), name, typeDesc); }
private static void checkSignature(CtMethod wrappedBody, String descriptor) throws CannotCompileException { if (!descriptor.equals(wrappedBody.getMethodInfo2().getDescriptor())) throw new CannotCompileException( "wrapped method with a bad signature: " + wrappedBody.getDeclaringClass().getName() + '.' + wrappedBody.getName()); }
int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException { CodeIterator ci = ca.iterator(); try { ci.skipConstructor(); return ci.next(); } catch (BadBytecode e) { throw new CannotCompileException(e); } }
int compileIfStatic(CtClass type, String name, Bytecode code, Javac drv) throws CannotCompileException { try { compileExpr(drv); code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type)); return code.getMaxStack(); } catch (CompileError e) { throw new CannotCompileException(e); } }
/** * Creates a method from a <code>MethodInfo</code> object. * * @param declaring the class declaring the method. * @throws CannotCompileException if the the <code>MethodInfo</code> * object and the declaring class have different * <code>ConstPool</code> objects * @since 3.6 */ public static CtMethod make(MethodInfo minfo, CtClass declaring) throws CannotCompileException { if (declaring.getClassFile2().getConstPool() != minfo.getConstPool()) throw new CannotCompileException("bad declaring class"); return new CtMethod(minfo, declaring); }
int compile(CtClass type, String name, Bytecode code, CtClass[] parameters, Javac drv) throws CannotCompileException { try { code.addAload(0); compileExpr(drv); code.addPutfield(Bytecode.THIS, name, Descriptor.of(type)); return code.getMaxStack(); } catch (CompileError e) { throw new CannotCompileException(e); } }
public void addConstructor(CtConstructor c) throws CannotCompileException { checkModify(); if (c.getDeclaringClass() != this) throw new CannotCompileException("cannot add"); getMembers().addConstructor(c); getClassFile2().addMethod(c.getMethodInfo2()); }
/** * Inserts a new parameter, which becomes the first parameter. */ public void insertParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.insertParameter(type, desc); try { addParameter2(Modifier.isStatic(getModifiers()) ? 0 : 1, type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
public void addMethod(CtMethod m) throws CannotCompileException { checkModify(); if (m.getDeclaringClass() != this) throw new CannotCompileException("bad declaring class"); int mod = m.getModifiers(); if ((getModifiers() & Modifier.INTERFACE) != 0) { if (Modifier.isProtected(mod) || Modifier.isPrivate(mod)) throw new CannotCompileException( "an interface method must be public: " + m.toString()); m.setModifiers(mod | Modifier.PUBLIC); } getMembers().addMethod(m); getClassFile2().addMethod(m.getMethodInfo2()); if ((mod & Modifier.ABSTRACT) != 0) setModifiers(getModifiers() | Modifier.ABSTRACT); }
/** * Appends a new parameter, which becomes the last parameter. */ public void addParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.appendParameter(type, desc); int offset = Modifier.isStatic(getModifiers()) ? 0 : 1; try { addParameter2(offset + Descriptor.paramSize(desc), type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }