Java Code Examples for org.apache.bcel.classfile.Field#getSignature()
The following examples show how to use
org.apache.bcel.classfile.Field#getSignature() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnreadFields.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void visit(Field obj) { super.visit(obj); XField f = XFactory.createXField(this); data.allMyFields.add(f); String signature = obj.getSignature(); if (!"serialVersionUID".equals(getFieldName())) { data.myFields.add(f); if ("_jspx_dependants".equals(obj.getName())) { data.containerFields.add(f); } } if (isSeleniumWebElement(signature)) { data.containerFields.add(f); } }
Example 2
Source File: CheckAnalysisContextContainedAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void visit(Field field) { if (!field.isStatic()) { return; } String signature = field.getSignature(); if (signature.startsWith("Ljava/util/") && !"Ljava/util/regex/Pattern;".equals(signature) && !"Ljava/util/logging/Logger;".equals(signature) && !"Ljava/util/BitSet;".equals(signature) && !"Ljava/util/ResourceBundle;".equals(signature) && !"Ljava/util/Comparator;".equals(signature) && getXField().getAnnotation(ConstantAnnotation) == null) { boolean flagged = analysisContextContained(getXClass()); bugReporter.reportBug(new BugInstance(this, "TESTING", flagged ? NORMAL_PRIORITY : LOW_PRIORITY).addClass(this).addField(this).addType( signature)); } }
Example 3
Source File: ComparatorIdiom.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visit(JavaClass obj) { if (Subtypes2.instanceOf(obj, "java.util.Comparator") && !ClassName.isLocalOrAnonymous(getClassName()) && !Subtypes2.instanceOf(obj, "java.io.Serializable")) { int priority = NORMAL_PRIORITY; if (obj.isInterface() || obj.isAbstract()) { return; } double easilySerializable = 1.0; for (Field f : obj.getFields()) { try { if (f.getName().startsWith("this$")) { return; } String signature = f.getSignature(); char firstChar = signature.charAt(0); if (firstChar == 'L' || firstChar == '[') { easilySerializable *= DeepSubtypeAnalysis.isDeepSerializable(signature); } } catch (ClassNotFoundException e) { easilySerializable = 0.0; break; } } if (easilySerializable < 0.9) { priority = LOW_PRIORITY; } bugReporter.reportBug(new BugInstance(this, "SE_COMPARATOR_SHOULD_BE_SERIALIZABLE", priority).addClass(this)); } }
Example 4
Source File: Naming.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static @CheckForNull String getSignatureOfOuterClass(JavaClass obj) { for (Field f : obj.getFields()) { if (f.getName().startsWith("this$")) { return f.getSignature(); } } return null; }
Example 5
Source File: FindMaskedFields.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@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 || "java/lang/Object".equals(s.getClassName())) { break; } try { c = Global.getAnalysisCache().getClassAnalysis(XClass.class, s); } catch (CheckedAnalysisException e) { break; } for (XField fld : c.getXFields()) { if (!fld.isStatic() && (fld.isPublic() || fld.isProtected())) { fieldName = fld.getName(); if (fieldName.length() == 1) { continue; } if ("serialVersionUID".equals(fieldName)) { continue; } String superClassName = s.getClassName(); if (superClassName.startsWith("java/io") && (superClassName.endsWith("InputStream") && "in".equals(fieldName) || superClassName .endsWith("OutputStream") && "out".equals(fieldName))) { 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); }
Example 6
Source File: GenerateStubDialog.java From j-j-jvm with Apache License 2.0 | 4 votes |
protected String makeFieldName(final String className, final Field field) { return className + '.' + field.getName() + '.' + field.getSignature(); }
Example 7
Source File: ClassParserUsingBCEL.java From spotbugs with GNU Lesser General Public License v2.1 | 2 votes |
/** * @param obj * the field to parse * @return a descriptor for the field */ protected FieldDescriptor parseField(Field obj) { return new FieldDescriptor(slashedClassName, obj.getName(), obj.getSignature(), obj.isStatic()); }
Example 8
Source File: FieldAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 2 votes |
/** * Factory method. Construct from class name and BCEL Field object. * * @param className * the name of the class which defines the field * @param field * the BCEL Field object * @return the FieldAnnotation */ public static FieldAnnotation fromBCELField(@DottedClassName String className, Field field) { return new FieldAnnotation(className, field.getName(), field.getSignature(), field.isStatic()); }
Example 9
Source File: FieldAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 2 votes |
/** * Factory method. Construct from class name and BCEL Field object. * * @param jClass * the class which defines the field * @param field * the BCEL Field object * @return the FieldAnnotation */ public static FieldAnnotation fromBCELField(JavaClass jClass, Field field) { return new FieldAnnotation(jClass.getClassName(), field.getName(), field.getSignature(), field.isStatic()); }