/** * Obtains the name of this method. */ public String getName() { return methodInfo.getName(); }
/** * Obtains the name of this method. */ @Override public String getName() { return methodInfo.getName(); }
/** * Returns true if this is a constructor. */ public boolean isConstructor() { return getName().equals(nameInit); }
/** * Returns true if this is a class initializer (static initializer). */ public boolean isStaticInitializer() { return getName().equals(nameClinit); }
/** * Returns true if this is not a constructor or a class initializer (static * initializer). */ public boolean isMethod() { String n = getName(); return !n.equals(nameInit) && !n.equals(nameClinit); }
/** * Returns the method with the specified name. If there are multiple methods * with that name, this method returns one of them. * * @return null if no such method is found. */ public MethodInfo getMethod(String name) { for (MethodInfo minfo:methods) if (minfo.getName().equals(name)) return minfo; return null; }
/** * Returns true if this is a constructor. */ public boolean isConstructor() { return getName().equals(nameInit); }
/** * Returns true if this is a class initializer (static initializer). */ public boolean isStaticInitializer() { return getName().equals(nameClinit); }
/** * Returns the method with the specified name. If there are multiple methods * with that name, this method returns one of them. * * @return null if no such method is found. */ public MethodInfo getMethod(String name) { ArrayList list = methods; int n = list.size(); for (int i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo)list.get(i); if (minfo.getName().equals(name)) return minfo; } return null; }
/** * Returns true if this is not a constructor or a class initializer (static * initializer). */ public boolean isMethod() { String n = getName(); return !n.equals(nameInit) && !n.equals(nameClinit); }
/** * Returns a string representation of the object. */ public String toString() { return getName() + " " + getDescriptor(); }
/** * Returns a string representation of the object. */ @Override public String toString() { return getName() + " " + getDescriptor(); }
final String getStringRep() { if (cachedStringRep == null) cachedStringRep = methodInfo.getName() + Descriptor.getParamDescriptor(methodInfo.getDescriptor()); return cachedStringRep; }
private void testExistingMethod(MethodInfo newMinfo) throws DuplicateMemberException { String name = newMinfo.getName(); String descriptor = newMinfo.getDescriptor(); ListIterator it = methods.listIterator(0); while (it.hasNext()) if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it)) throw new DuplicateMemberException("duplicate method: " + name + " in " + this.getName()); }
private static boolean isDuplicated(MethodInfo newMethod, String newName, String newDesc, MethodInfo minfo, ListIterator it) { if (!minfo.getName().equals(newName)) return false; String desc = minfo.getDescriptor(); if (!Descriptor.eqParamTypes(desc, newDesc)) return false; if (desc.equals(newDesc)) { if (notBridgeMethod(minfo)) return true; else { // if the bridge method with the same signature // already exists, replace it. it.remove(); return false; } } else return false; // return notBridgeMethod(minfo) && notBridgeMethod(newMethod); }
final String getStringRep() { if (cachedStringRep == null) cachedStringRep = methodInfo.getName() + Descriptor.getParamDescriptor(methodInfo.getDescriptor()); return cachedStringRep; }
private void testExistingMethod(MethodInfo newMinfo) throws DuplicateMemberException { String name = newMinfo.getName(); String descriptor = newMinfo.getDescriptor(); ListIterator<MethodInfo> it = methods.listIterator(0); while (it.hasNext()) if (isDuplicated(newMinfo, name, descriptor, it.next(), it)) throw new DuplicateMemberException("duplicate method: " + name + " in " + this.getName()); }
/** * Copies all constant pool items to a given new constant pool * and replaces the original items with the new ones. * This is used for garbage collecting the items of removed fields * and methods. * * @param cp the destination */ void compact(ConstPool cp) { name = cp.addUtf8Info(getName()); descriptor = cp.addUtf8Info(getDescriptor()); attribute = AttributeInfo.copyAll(attribute, cp); constPool = cp; }
private static boolean isMainMethod(MethodInfo method) { int flags = method.getAccessFlags(); return method.getName().equals("main") && Modifier.isPublic(flags) && Modifier.isStatic(flags) && U.eq(method.getDescriptor(), "([Ljava/lang/String;)V"); // TODO find more elegant solution }
private void atFieldAssignCore(CtField f, boolean is_static, int fi, boolean is2byte) throws CompileError { if (fi != 0) { if (is_static) { bytecode.add(PUTSTATIC); bytecode.growStack(is2byte ? -2 : -1); } else { bytecode.add(PUTFIELD); bytecode.growStack(is2byte ? -3 : -2); } bytecode.addIndex(fi); } else { CtClass declClass = f.getDeclaringClass(); AccessorMaker maker = declClass.getAccessorMaker(); // make should be non null. FieldInfo finfo = f.getFieldInfo2(); MethodInfo minfo = maker.getFieldSetter(finfo, is_static); bytecode.addInvokestatic(declClass, minfo.getName(), minfo.getDescriptor()); } }