/** * Makes a copy. Class names are replaced according to the * given <code>Map</code> object. * * @param newCp the constant pool table used by the new copy. * @param classnames pairs of replaced and substituted * class names. */ public AttributeInfo copy(ConstPool newCp, Map classnames) { if (methodIndex() == 0) return new EnclosingMethodAttribute(newCp, className()); else return new EnclosingMethodAttribute(newCp, className(), methodName(), methodDescriptor()); } }
/** * Returns the name of the class specified by <code>class_index</code>. */ public String className() { return getConstPool().getClassInfo(classIndex()); }
/** * Returns the value of <code>class_index</code>. */ public int classIndex() { return ByteArray.readU16bit(get(), 0); }
/** * Returns the method descriptor specified by <code>method_index</code>. */ public String methodDescriptor() { ConstPool cp = getConstPool(); int mi = methodIndex(); int ti = cp.getNameAndTypeDescriptor(mi); return cp.getUtf8Info(ti); }
public CtBehavior getEnclosingBehavior() throws NotFoundException { ClassFile cf = getClassFile2(); EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema == null) return null; else { CtClass enc = classPool.get(ema.className()); String name = ema.methodName(); if (MethodInfo.nameInit.equals(name)) return enc.getConstructor(ema.methodDescriptor()); else if(MethodInfo.nameClinit.equals(name)) return enc.getClassInitializer(); else return enc.getMethod(name, ema.methodDescriptor()); } }
/** * Constructs an EnclosingMethod attribute. * The value of <code>method_index</code> is set to 0. * * @param cp a constant pool table. * @param className the name of the innermost enclosing class. */ public EnclosingMethodAttribute(ConstPool cp, String className) { super(cp, tag); int ci = cp.addClassInfo(className); int ni = 0; byte[] bvalue = new byte[4]; bvalue[0] = (byte)(ci >>> 8); bvalue[1] = (byte)ci; bvalue[2] = (byte)(ni >>> 8); bvalue[3] = (byte)ni; set(bvalue); }
public CtClass getDeclaringClass() throws NotFoundException { ClassFile cf = getClassFile2(); InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute( InnerClassesAttribute.tag); if (ica == null) return null; String name = getName(); int n = ica.tableLength(); for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) { String outName = ica.outerClass(i); if (outName != null) return classPool.get(outName); else { // maybe anonymous or local class. EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema != null) return classPool.get(ema.className()); } } return null; }
return new EnclosingMethodAttribute(cp, name, in); else if (nameStr.equals(ExceptionsAttribute.tag)) return new ExceptionsAttribute(cp, name, in);
@Override public CtBehavior getEnclosingBehavior() throws NotFoundException { ClassFile cf = getClassFile2(); EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema == null) return null; CtClass enc = classPool.get(ema.className()); String name = ema.methodName(); if (MethodInfo.nameInit.equals(name)) return enc.getConstructor(ema.methodDescriptor()); else if(MethodInfo.nameClinit.equals(name)) return enc.getClassInitializer(); else return enc.getMethod(name, ema.methodDescriptor()); }
/** * Returns the method name specified by <code>method_index</code>. * If the method is a class initializer (static constructor), * {@link MethodInfo#nameClinit} is returned. */ public String methodName() { ConstPool cp = getConstPool(); int mi = methodIndex(); if (mi == 0) return MethodInfo.nameClinit; else { int ni = cp.getNameAndTypeName(mi); return cp.getUtf8Info(ni); } }
/** * Constructs an EnclosingMethod attribute. * The value of <code>method_index</code> is set to 0. * * @param cp a constant pool table. * @param className the name of the innermost enclosing class. */ public EnclosingMethodAttribute(ConstPool cp, String className) { super(cp, tag); int ci = cp.addClassInfo(className); int ni = 0; byte[] bvalue = new byte[4]; bvalue[0] = (byte)(ci >>> 8); bvalue[1] = (byte)ci; bvalue[2] = (byte)(ni >>> 8); bvalue[3] = (byte)ni; set(bvalue); }
@Override public CtClass getDeclaringClass() throws NotFoundException { ClassFile cf = getClassFile2(); InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute( InnerClassesAttribute.tag); if (ica == null) return null; String name = getName(); int n = ica.tableLength(); for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) { String outName = ica.outerClass(i); if (outName != null) return classPool.get(outName); // maybe anonymous or local class. EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema != null) return classPool.get(ema.className()); } return null; }
return new EnclosingMethodAttribute(cp, name, in); else if (nameStr.equals(ExceptionsAttribute.tag)) return new ExceptionsAttribute(cp, name, in);
/** * Makes a copy. Class names are replaced according to the * given <code>Map</code> object. * * @param newCp the constant pool table used by the new copy. * @param classnames pairs of replaced and substituted * class names. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { if (methodIndex() == 0) return new EnclosingMethodAttribute(newCp, className()); return new EnclosingMethodAttribute(newCp, className(), methodName(), methodDescriptor()); } }
public CtMethod getEnclosingMethod() throws NotFoundException { ClassFile cf = getClassFile2(); EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema != null) { CtClass enc = classPool.get(ema.className()); return enc.getMethod(ema.methodName(), ema.methodDescriptor()); } return null; }
/** * Returns the method descriptor specified by <code>method_index</code>. */ public String methodDescriptor() { ConstPool cp = getConstPool(); int mi = methodIndex(); int ti = cp.getNameAndTypeDescriptor(mi); return cp.getUtf8Info(ti); }
/** * Returns the name of the class specified by <code>class_index</code>. */ public String className() { return getConstPool().getClassInfo(classIndex()); }
/** * Returns the value of <code>method_index</code>. */ public int methodIndex() { return ByteArray.readU16bit(get(), 2); }
/** * Constructs an EnclosingMethod attribute. * * @param cp a constant pool table. * @param className the name of the innermost enclosing class. * @param methodName the name of the enclosing method. * @param methodDesc the descriptor of the enclosing method. */ public EnclosingMethodAttribute(ConstPool cp, String className, String methodName, String methodDesc) { super(cp, tag); int ci = cp.addClassInfo(className); int ni = cp.addNameAndTypeInfo(methodName, methodDesc); byte[] bvalue = new byte[4]; bvalue[0] = (byte)(ci >>> 8); bvalue[1] = (byte)ci; bvalue[2] = (byte)(ni >>> 8); bvalue[3] = (byte)ni; set(bvalue); }
public CtClass getDeclaringClass() throws NotFoundException { ClassFile cf = getClassFile2(); InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute( InnerClassesAttribute.tag); if (ica == null) return null; String name = getName(); int n = ica.tableLength(); for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) { String outName = ica.outerClass(i); if (outName != null) return classPool.get(outName); else { // maybe anonymous or local class. EnclosingMethodAttribute ema = (EnclosingMethodAttribute)cf.getAttribute( EnclosingMethodAttribute.tag); if (ema != null) return classPool.get(ema.className()); } } return null; }