@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
@Override public void visitField( final Field field ) { _out.println(); _out.println(" field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", " + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);"); final ConstantValue cv = field.getConstantValue(); if (cv != null) { final String value = cv.toString(); _out.println(" field.setInitValue(" + value + ")"); } _out.println(" _cg.addField(field.getField());"); }
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field, including the signature. */ @Override public final String toString() { String name; String signature; String access; // Short cuts to constant pool // Get names from constant pool access = Utility.accessToString(super.getAccessFlags()); access = access.isEmpty() ? "" : (access + " "); signature = Utility.signatureToString(getSignature()); name = getName(); final StringBuilder buf = new StringBuilder(64); // CHECKSTYLE IGNORE MagicNumber buf.append(access).append(signature).append(" ").append(name); final ConstantValue cv = getConstantValue(); if (cv != null) { buf.append(" = ").append(cv); } for (final Attribute attribute : super.getAttributes()) { if (!(attribute instanceof ConstantValue)) { buf.append(" [").append(attribute).append("]"); } } return buf.toString(); }
public void visitField(Field field) { _out.println("\n field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", " + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);"); ConstantValue cv = field.getConstantValue(); if(cv != null) { String value = cv.toString(); _out.println(" field.setInitValue(" + value + ")"); } _out.println(" _cg.addField(field.getField());"); }
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field, including the signature. */ public final String toString() { String name, signature, access; // Short cuts to constant pool // Get names from constant pool access = Utility.accessToString(access_flags); access = access.equals("")? "" : (access + " "); signature = Utility.signatureToString(getSignature()); name = getName(); StringBuffer buf = new StringBuffer(access + signature + " " + name); ConstantValue cv = getConstantValue(); if(cv != null) buf.append(" = " + cv); for(int i=0; i < attributes_count; i++) { Attribute a = attributes[i]; if(!(a instanceof ConstantValue)) buf.append(" [" + a.toString() + "]"); } return buf.toString(); }
private boolean looksLikeStaticFieldValue(String constant) { if (staticConstants == null) { staticConstants = new HashSet<>(); Field[] fields = getClassContext().getJavaClass().getFields(); for (Field f : fields) { if (((f.getAccessFlags() & (Const.ACC_FINAL | Const.ACC_STATIC)) == (Const.ACC_FINAL | Const.ACC_STATIC)) && Values.SIG_JAVA_LANG_STRING.equals(f.getSignature())) { ConstantValue cv = f.getConstantValue(); if (cv != null) { int cvIndex = cv.getConstantValueIndex(); staticConstants.add(getConstantPool().getConstantString(cvIndex, Const.CONSTANT_String)); } } } } return staticConstants.contains(constant); }
private boolean looksLikeStaticFieldValue(String constant) { if (staticConstants == null) { staticConstants = new HashSet<>(); Field[] fields = getClassContext().getJavaClass().getFields(); for (Field f : fields) { if (((f.getAccessFlags() & (Constants.ACC_FINAL | Constants.ACC_STATIC)) == (Constants.ACC_FINAL | Constants.ACC_STATIC)) && Values.SIG_JAVA_LANG_STRING.equals(f.getSignature())) { ConstantValue cv = f.getConstantValue(); if (cv != null) { int cvIndex = cv.getConstantValueIndex(); staticConstants.add(getConstantPool().getConstantString(cvIndex, Constants.CONSTANT_String)); } } } } return staticConstants.contains(constant); }
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
if ("serialVersionUID".equals(f.getName()) && getClassContext().getJavaClass().instanceOf(serializableClass)) { ConstantValue cv = f.getConstantValue(); if (cv != null) { Constant c = cv.getConstantPool().getConstant(cv.getConstantValueIndex());