@Override public String getSignature() { return super.getType().getSignature(); }
@Override public String getSignature() { return Type.getMethodSignature(super.getType(), arg_types); }
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field */ @Override public final String toString() { String name; String signature; String access; // Short cuts to constant pool access = Utility.accessToString(super.getAccessFlags()); access = access.isEmpty() ? "" : (access + " "); signature = super.getType().toString(); name = getName(); final StringBuilder buf = new StringBuilder(32); // CHECKSTYLE IGNORE MagicNumber buf.append(access).append(signature).append(" ").append(name); final String value = getInitValue(); if (value != null) { buf.append(" = ").append(value); } return buf.toString(); }
/** * Return string representation close to declaration format, * `public static void main(String[]) throws IOException', e.g. * * @return String representation of the method. */ @Override public final String toString() { final String access = Utility.accessToString(super.getAccessFlags()); String signature = Type.getMethodSignature(super.getType(), arg_types); signature = Utility.methodSignatureToString(signature, super.getName(), access, true, getLocalVariableTable(super.getConstantPool())); final StringBuilder buf = new StringBuilder(signature); for (final Attribute a : getAttributes()) { if (!((a instanceof Code) || (a instanceof ExceptionTable))) { buf.append(" [").append(a).append("]"); } } if (throws_vec.size() > 0) { for (final String throwsDescriptor : throws_vec) { buf.append("\n\t\tthrows ").append(throwsDescriptor); } } return buf.toString(); }
private int addConstant() { switch (super.getType().getType()) { // sic case Const.T_INT: case Const.T_CHAR: case Const.T_BYTE: case Const.T_BOOLEAN: case Const.T_SHORT: return super.getConstantPool().addInteger(((Integer) value).intValue()); case Const.T_FLOAT: return super.getConstantPool().addFloat(((Float) value).floatValue()); case Const.T_DOUBLE: return super.getConstantPool().addDouble(((Double) value).doubleValue()); case Const.T_LONG: return super.getConstantPool().addLong(((Long) value).longValue()); case Const.T_REFERENCE: return super.getConstantPool().addString((String) value); default: throw new RuntimeException("Oops: Unhandled : " + super.getType().getType()); // sic } }
private void checkType( final Type atype ) { final Type superType = super.getType(); if (superType == null) { throw new ClassGenException("You haven't defined the type of the field yet"); } if (!isFinal()) { throw new ClassGenException("Only final fields may have an initial value!"); } if (!superType.equals(atype)) { throw new ClassGenException("Types are not compatible: " + superType + " vs. " + atype); } }
/** * Get field object after having set up all necessary values. */ public Field getField() { final String signature = getSignature(); final int name_index = super.getConstantPool().addUtf8(super.getName()); final int signature_index = super.getConstantPool().addUtf8(signature); if (value != null) { checkType(super.getType()); final int index = addConstant(); addAttribute(new ConstantValue(super.getConstantPool().addUtf8("ConstantValue"), 2, index, super.getConstantPool().getConstantPool())); // sic } addAnnotationsAsAttribute(super.getConstantPool()); return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(), super.getConstantPool().getConstantPool()); // sic }