/** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } }
/** * Returns true if this method is static. */ protected final boolean withinStatic() { return (thisMethod.getAccessFlags() & AccessFlag.STATIC) != 0; }
private static boolean notBridgeMethod(MethodInfo minfo) { return (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0; }
/** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } }
/** * Returns true if this method is static. */ protected final boolean withinStatic() { return (thisMethod.getAccessFlags() & AccessFlag.STATIC) != 0; }
private static boolean notBridgeMethod(MethodInfo minfo) { return (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0; }
/** * Obtains the modifiers of the method/constructor. * * @return modifiers encoded with * <code>javassist.Modifier</code>. * @see Modifier */ public int getModifiers() { return AccessFlag.toModifier(methodInfo.getAccessFlags()); }
/** * Obtains the modifiers of the method/constructor. * * @return modifiers encoded with * <code>javassist.Modifier</code>. * @see Modifier */ @Override public int getModifiers() { return AccessFlag.toModifier(methodInfo.getAccessFlags()); }
private void override(String thisClassname, Method meth, String prefix, int index, String desc, ClassFile cf, ConstPool cp, ArrayList forwarders) throws CannotCompileException { Class declClass = meth.getDeclaringClass(); String delegatorName = prefix + index + meth.getName(); if (Modifier.isAbstract(meth.getModifiers())) delegatorName = null; else { MethodInfo delegator = makeDelegator(meth, desc, cp, declClass, delegatorName); // delegator is not a bridge method. See Sec. 15.12.4.5 of JLS 3rd Ed. delegator.setAccessFlags(delegator.getAccessFlags() & ~AccessFlag.BRIDGE); cf.addMethod(delegator); } MethodInfo forwarder = makeForwarder(thisClassname, meth, desc, cp, declClass, delegatorName, index, forwarders); cf.addMethod(forwarder); }
public String getMethodModifier(MethodInfo method) { int accessFlags = method.getAccessFlags(); return isPrivate(accessFlags) ? "private" : isProtected(accessFlags) ? "protected" : isPublic(accessFlags) ? "public" : ""; }
public boolean isPublic(Object o) { Integer accessFlags = o instanceof ClassFile ? ((ClassFile) o).getAccessFlags() : o instanceof FieldInfo ? ((FieldInfo) o).getAccessFlags() : o instanceof MethodInfo ? ((MethodInfo) o).getAccessFlags() : null; return accessFlags != null && AccessFlag.isPublic(accessFlags); }
public boolean isPublic(Object o) { Integer accessFlags = o instanceof ClassFile ? ((ClassFile) o).getAccessFlags() : o instanceof FieldInfo ? ((FieldInfo) o).getAccessFlags() : o instanceof MethodInfo ? ((MethodInfo) o).getAccessFlags() : null; return accessFlags != null && AccessFlag.isPublic(accessFlags); }
public String getMethodModifier(MethodInfo method) { int accessFlags = method.getAccessFlags(); return isPrivate(accessFlags) ? "private" : isProtected(accessFlags) ? "protected" : isPublic(accessFlags) ? "public" : ""; }
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 }
@Override public void scan(Object cls) { final MetadataAdapter md = getMetadataAdapter(); for (Object method : md.getMethods(cls)) { String key = md.getMethodFullKey(cls, method); if (acceptResult(key)) { LocalVariableAttribute table = (LocalVariableAttribute) ((MethodInfo) method).getCodeAttribute().getAttribute(LocalVariableAttribute.tag); int length = table.tableLength(); int i = Modifier.isStatic(((MethodInfo) method).getAccessFlags()) ? 0 : 1; //skip this if (i < length) { List<String> names = new ArrayList<String>(length - i); while (i < length) names.add(((MethodInfo) method).getConstPool().getUtf8Info(table.nameIndex(i++))); getStore().put(key, Joiner.on(", ").join(names)); } } } } }
static void setBody0(CtClass srcClass, MethodInfo srcInfo, CtClass destClass, MethodInfo destInfo, ClassMap map) throws CannotCompileException { destClass.checkModify(); map = new ClassMap(map); map.put(srcClass.getName(), destClass.getName()); try { CodeAttribute cattr = srcInfo.getCodeAttribute(); if (cattr != null) { ConstPool cp = destInfo.getConstPool(); CodeAttribute ca = (CodeAttribute)cattr.copy(cp, map); destInfo.setCodeAttribute(ca); // a stack map table is copied to destInfo. } } catch (CodeAttribute.RuntimeCopyException e) { /* the exception may be thrown by copy() in CodeAttribute. */ throw new CannotCompileException(e); } destInfo.setAccessFlags(destInfo.getAccessFlags() & ~AccessFlag.ABSTRACT); destClass.rebuildClassFile(); }
private Frame firstFrame(MethodInfo method, int maxLocals, int maxStack) { int pos = 0; Frame first = new Frame(maxLocals, maxStack); if ((method.getAccessFlags() & AccessFlag.STATIC) == 0) { first.setLocal(pos++, Type.get(clazz)); } CtClass[] parameters; try { parameters = Descriptor.getParameterTypes(method.getDescriptor(), clazz.getClassPool()); } catch (NotFoundException e) { throw new RuntimeException(e); } for (int i = 0; i < parameters.length; i++) { Type type = zeroExtend(Type.get(parameters[i])); first.setLocal(pos++, type); if (type.getSize() == 2) first.setLocal(pos++, Type.TOP); } return first; }
private static String addBodyMethod(CtClassType clazz, ClassFile classfile, CtMethod src) throws BadBytecode, CannotCompileException { Hashtable bodies = clazz.getHiddenMethods(); String bodyname = (String)bodies.get(src); if (bodyname == null) { do { bodyname = addedWrappedMethod + clazz.getUniqueNumber(); } while (classfile.getMethod(bodyname) != null); ClassMap map = new ClassMap(); map.put(src.getDeclaringClass().getName(), clazz.getName()); MethodInfo body = new MethodInfo(classfile.getConstPool(), bodyname, src.getMethodInfo2(), map); int acc = body.getAccessFlags(); body.setAccessFlags(AccessFlag.setPrivate(acc)); body.addAttribute(new SyntheticAttribute(classfile.getConstPool())); // a stack map is copied. rebuilding it is not needed. classfile.addMethod(body); bodies.put(src, bodyname); CtMember.Cache cache = clazz.hasMemberCache(); if (cache != null) cache.addMethod(new CtMethod(body, clazz)); } return bodyname; }
/** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; }
ConstPool cp = declaring.getClassFile2().getConstPool(); MethodInfo minfo = new MethodInfo(cp, methodName, desc); minfo.setAccessFlags(deleInfo.getAccessFlags());