本文整理汇总了Java中org.apache.bcel.classfile.Field.isFinal方法的典型用法代码示例。如果您正苦于以下问题:Java Field.isFinal方法的具体用法?Java Field.isFinal怎么用?Java Field.isFinal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Field
的用法示例。
在下文中一共展示了Field.isFinal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visit(Field obj) {
if (getFieldName().length() == 1) return;
if (!obj.isFinal()
&& Character.isLetter(getFieldName().charAt(0))
&& !Character.isLowerCase(getFieldName().charAt(0))
&& getFieldName().indexOf("_") == -1
&& Character.isLetter(getFieldName().charAt(1))
&& Character.isLowerCase(getFieldName().charAt(1)))
bugReporter.reportBug(new BugInstance(this,
"NM_FIELD_NAMING_CONVENTION",
classIsPublicOrProtected
&& (obj.isPublic() || obj.isProtected())
? NORMAL_PRIORITY
: LOW_PRIORITY)
.addClass(this)
.addVisitedField(this)
);
}
示例2: leaveSet
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void leaveSet(Set aJavaClasses)
{
final Iterator it = aJavaClasses.iterator();
while (it.hasNext()) {
final JavaClass javaClass = (JavaClass) it.next();
final String className = javaClass.getClassName();
final JavaClassDefinition classDef = findJavaClassDef(javaClass);
final FieldDefinition[] fieldDefs = classDef.getFieldDefs();
for (int i = 0; i < fieldDefs.length; i++) {
if (fieldDefs[i].getReadReferenceCount() == 0) {
final Field field = fieldDefs[i].getField();
if (!field.isFinal()
&& (!ignore(className, field))
)
{
log(
javaClass,
0,
"unread.field",
new Object[] {fieldDefs[i]});
}
}
}
}
}
示例3: field2str
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
protected String field2str(final Field field) {
String modifier = "";
if (field.isPrivate()) {
modifier = "private ";
} else if (field.isProtected()) {
modifier = "protected ";
} else if (field.isPublic()) {
modifier = "public ";
}
if (field.isStatic()) {
modifier += "static ";
}
if (field.isFinal()) {
modifier += "final ";
}
modifier += field.getType().toString();
modifier += ' ' + field.getName();
return modifier;
}
示例4: handleLoad
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
private void handleLoad(FieldInstruction obj) {
consumeStack(obj);
Type type = obj.getType(getCPG());
if (type.getSignature().equals(STRING_SIGNATURE)) {
try {
String className = obj.getClassName(getCPG());
String fieldName = obj.getName(getCPG());
Field field = Hierarchy.findField(className, fieldName);
if (field != null) {
// If the field is final, we'll assume that the String value
// is static.
if (field.isFinal())
pushValue(staticStringTypeInstance);
else
pushValue(type);
return;
}
} catch (ClassNotFoundException ex) {
lookupFailureCallback.reportMissingClass(ex);
}
}
pushValue(type);
}
示例5: searchForFields
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* Searches the given class for the static final fields type of which
* is a primitive data type.
*
* @param clss - a searched class.
*/
private void searchForFields(JavaClass clss) {
Field field[] = clss.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
if (f.isStatic() && f.isFinal()) {
if (Type.getReturnType(f.getSignature()) instanceof BasicType) {
fields.addElement(new ClazzField(this, f));
}
}
}
}
示例6: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* Checks if the visited field is of type {@link java.util.Calendar} or
* {@link java.text.DateFormat} or a subclass of either one. If so and the
* field is static and non-private it is suspicious and will be reported.
*/
@Override
public void visit(Field aField) {
if (aField.isPrivate()) {
/*
* private fields are harmless, as long as they are used correctly
* inside their own class. This should be something the rest of this
* detector can find out, so do not report them, they might be false
* positives.
*/
return;
}
String superclassName = getSuperclassName();
if (!aField.isStatic() && !superclassName.equals("java/lang/Enum"))
return;
if (!aField.isPublic() && !aField.isProtected())
return;
ClassDescriptor classOfField = DescriptorFactory.createClassDescriptorFromFieldSignature(aField.getSignature());
String tBugType = null;
int priority = aField.isPublic() && aField.isFinal() && aField.getName().equals(aField.getName().toUpperCase())
&& getThisClass().isPublic() ? HIGH_PRIORITY : NORMAL_PRIORITY;
if (classOfField != null)
try {
if (subtypes2.isSubtype(classOfField, calendarType)) {
tBugType = "STCAL_STATIC_CALENDAR_INSTANCE";
priority++;
} else if (subtypes2.isSubtype(classOfField, dateFormatType)) {
tBugType = "STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE";
}
if (getClassContext().getXClass().usesConcurrency())
priority--;
if (tBugType != null) {
pendingBugs.put(getXField(), new BugInstance(this, tBugType, priority).addClass(currentClass).addField(this));
}
} catch (ClassNotFoundException e) {
AnalysisContext.reportMissingClass(e);
}
}
示例7: badFieldName
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* @param obj
* @return
*/
private boolean badFieldName(Field obj) {
String fieldName = obj.getName();
return !obj.isFinal() && Character.isLetter(fieldName.charAt(0)) && !Character.isLowerCase(fieldName.charAt(0))
&& fieldName.indexOf("_") == -1 && Character.isLetter(fieldName.charAt(1))
&& Character.isLowerCase(fieldName.charAt(1));
}
示例8: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
if (obj.getName().equals("this$0"))
isInnerClass = true;
if (!obj.isFinal() && !obj.isStatic() && !obj.isSynthetic())
hasNonFinalFields = true;
}
示例9: handleLoad
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
private void handleLoad(FieldInstruction obj) {
consumeStack(obj);
Type type = obj.getType(getCPG());
if (!type.getSignature().equals(STRING_SIGNATURE))
throw new IllegalArgumentException("type is not String: " + type);
try {
String className = obj.getClassName(getCPG());
String fieldName = obj.getName(getCPG());
Field field = Hierarchy.findField(className, fieldName);
if (field != null) {
// If the field is final, we'll assume that the String value
// is static.
if (field.isFinal() && field.isFinal()) {
pushValue(staticStringTypeInstance);
} else {
pushValue(type);
}
return;
}
} catch (ClassNotFoundException ex) {
lookupFailureCallback.reportMissingClass(ex);
}
pushValue(type);
}
示例10: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
if (obj.getName().equals("this$0"))
isInnerClass = true;
if (!obj.isFinal() && !obj.isStatic() && !BCELUtil.isSynthetic(obj))
hasNonFinalFields = true;
}
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:8,代码来源:FunctionsThatMightBeMistakenForProcedures.java
示例11: visitPUTSTATIC
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitPUTSTATIC(PUTSTATIC o){
try {
String field_name = o.getFieldName(cpg);
JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
Field[] fields = jc.getFields();
Field f = null;
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
f = fields[i];
break;
}
}
if (f == null){
throw new AssertionViolatedException("Field not found?!?");
}
if (f.isFinal()){
if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){
constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'.");
}
}
if (! (f.isStatic())){
constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
}
String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();
// If it's an interface, it can be set only in <clinit>.
if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){
constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method.");
}
} catch (ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
throw new AssertionViolatedException("Missing class: " + e.toString());
}
}
示例12: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(JavaClass obj) {
classFields.clear();
Field[] fields = obj.getFields();
String fieldName;
for (Field field : fields)
if (!field.isStatic() && !field.isPrivate()) {
fieldName = field.getName();
classFields.put(fieldName, field);
}
// Walk up the super class chain, looking for name collisions
XClass c = getXClass();
while (true) {
ClassDescriptor s = c.getSuperclassDescriptor();
if (s == null || s.getClassName().equals("java/lang/Object"))
break;
try {
c = Global.getAnalysisCache().getClassAnalysis(XClass.class, s);
} catch (CheckedAnalysisException e) {
break;
}
XClass superClass = c;
for (XField fld : c.getXFields()) {
if (!fld.isStatic() && (fld.isPublic() || fld.isProtected())) {
fieldName = fld.getName();
if (fieldName.length() == 1)
continue;
if (fieldName.equals("serialVersionUID"))
continue;
String superClassName = s.getClassName();
if (superClassName.startsWith("java/io")
&& (superClassName.endsWith("InputStream") && fieldName.equals("in") || superClassName
.endsWith("OutputStream") && fieldName.equals("out")))
continue;
if (classFields.containsKey(fieldName)) {
Field maskingField = classFields.get(fieldName);
String mClassName = getDottedClassName();
FieldAnnotation fa = new FieldAnnotation(mClassName, maskingField.getName(), maskingField.getSignature(),
maskingField.isStatic());
int priority = NORMAL_PRIORITY;
if (maskingField.isStatic() || maskingField.isFinal())
priority++;
else if (fld.getSignature().charAt(0) == 'L' && !fld.getSignature().startsWith("Ljava/lang/")
|| fld.getSignature().charAt(0) == '[')
priority--;
if (!fld.getSignature().equals(maskingField.getSignature()))
priority += 2;
else if (fld.getAccessFlags() != maskingField.getAccessFlags())
priority++;
if (fld.isSynthetic() || fld.getName().indexOf('$') >= 0)
priority++;
FieldAnnotation maskedFieldAnnotation = FieldAnnotation.fromFieldDescriptor(fld.getFieldDescriptor());
BugInstance bug = new BugInstance(this, "MF_CLASS_MASKS_FIELD", priority).addClass(this).addField(fa)
.describe("FIELD_MASKING").addField(maskedFieldAnnotation).describe("FIELD_MASKED");
rememberedBugs.add(new RememberedBug(bug, fa, maskedFieldAnnotation));
}
}
}
}
super.visit(obj);
}
示例13: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
super.visit(obj);
if (obj.isFinal())
finalFields.add(obj.getName());
}
示例14: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
if (!obj.isFinal() && !obj.isTransient() && !obj.isVolatile())
bugReporter.reportBug(new BugInstance(this, "JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS", NORMAL_PRIORITY).addClass(
this).addVisitedField(this));
}
示例15: visitField
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visitField(Field obj){
if (jc.isClass()){
int maxone=0;
if (obj.isPrivate()) {
maxone++;
}
if (obj.isProtected()) {
maxone++;
}
if (obj.isPublic()) {
maxone++;
}
if (maxone > 1){
throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
}
if (obj.isFinal() && obj.isVolatile()){
throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
}
}
else{ // isInterface!
if (!obj.isPublic()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
}
if (!obj.isStatic()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
}
if (!obj.isFinal()){
throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
}
}
if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
}
checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
String name = obj.getName();
if (! validFieldName(name)){
throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
}
// A descriptor is often named signature in BCEL
checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
try{
Type.getType(sig); /* Don't need the return value */
}
catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
String nameanddesc = (name+sig);
if (field_names_and_desc.contains(nameanddesc)){
throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
}
if (field_names.contains(name)){
addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
}
field_names_and_desc.add(nameanddesc);
field_names.add(name);
Attribute[] atts = obj.getAttributes();
for (int i=0; i<atts.length; i++){
if ((! (atts[i] instanceof ConstantValue)) &&
(! (atts[i] instanceof Synthetic)) &&
(! (atts[i] instanceof Deprecated))){
addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is unknown and will therefore be ignored.");
}
if (! (atts[i] instanceof ConstantValue)){
addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is not a ConstantValue and is therefore only of use for debuggers and such.");
}
}
}