[Clirr-devel] CVS: clirr/src/java/net/sf/clirr/checks FieldSetCheck.java,1.6,1.7
Status: Alpha
Brought to you by:
lkuehne
From: Lars K?h. <lk...@us...> - 2004-05-23 13:52:37
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23098/src/java/net/sf/clirr/checks Modified Files: FieldSetCheck.java Log Message: warn about changing the value of a compile time constant (RFE #958818) Index: FieldSetCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/FieldSetCheck.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FieldSetCheck.java 23 May 2004 07:54:17 -0000 1.6 +++ FieldSetCheck.java 23 May 2004 13:52:27 -0000 1.7 @@ -29,6 +29,7 @@ import net.sf.clirr.event.Severity; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Field; +import org.apache.bcel.classfile.ConstantValue; /** * Checks the fields of a class. @@ -100,6 +101,7 @@ checkForModifierChange(bField, cField, currentClass); checkForVisibilityChange(bField, cField, currentClass); checkForReturnTypeChange(bField, cField, currentClass); + checkForConstantValueChange(bField, cField, currentClass); } } @@ -113,10 +115,39 @@ fireDiff("Added " + scope + " field " + fieldName, Severity.INFO, currentClass, field); } } + } + + private void checkForConstantValueChange(Field bField, Field cField, JavaClass currentClass) + { + if (!(bField.isStatic() && bField.isFinal() && cField.isStatic() && cField.isFinal())) + { + return; + } + + final ConstantValue bVal = bField.getConstantValue(); - // TODO: Check field types + if (bVal != null) + { + final String bValRep = bVal.toString(); + final ConstantValue cVal = cField.getConstantValue(); + if (cVal == null) + { + fireDiff("Value of " + bField.getName() + + " is no longer a compile time constant", + Severity.WARNING, currentClass, cField); + return; + } - // TODO: warn about constant value changes (see JLS, section 13.4.8) + final String cValRep = String.valueOf(cVal); + if (!bValRep.equals(cValRep)) + { + // TODO: print out old and new value + // How can that be done with BCEL, esp. for boolean values? + fireDiff("Value of compile time constant " + bField.getName() + + " has been changed", + Severity.WARNING, currentClass, cField); + } + } } private void checkForReturnTypeChange(Field bField, Field cField, JavaClass currentClass) |