Examples of FieldAnnotation


Examples of edu.umd.cs.findbugs.FieldAnnotation

     * @return the possibly-rewritten FieldAnnotation
     */
    public static FieldAnnotation convertFieldAnnotation(ClassNameRewriter classNameRewriter, FieldAnnotation annotation) {

        if (classNameRewriter != IdentityClassNameRewriter.instance()) {
            annotation = new FieldAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()),
                    annotation.getFieldName(), rewriteSignature(classNameRewriter, annotation.getFieldSignature()),
                    annotation.isStatic());
        }
        return annotation;
    }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

                stage = 0;
            }
            break;
        case 3:
            if (seen == PUTFIELD || seen == PUTSTATIC) {
                FieldAnnotation f = FieldAnnotation.fromReferencedField(this);
                if (DEBUG) {
                    System.out.println("\t" + f);
                }
                if (twice.contains(f) && !getNameConstantOperand().startsWith("class$")
                        && !getSigConstantOperand().equals("Ljava/lang/String;")) {
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

                        warnings = new LinkedList<BugInstance>();
                        warningsByMethod.put(methodDesc, warnings);
                    }
                    warnings.add(warning);
                }
                FieldAnnotation field = warning.getPrimaryField();
                if (field != null) {
                    if (DEBUG) {
                        System.out.println("primary field of " + field + " for " + warning);
                    }
                    FieldDescriptor fieldDescriptor = field.toFieldDescriptor();
                    Collection<BugInstance> warnings = warningsByField.get(fieldDescriptor);

                    if (warnings == null) {
                        warnings = new LinkedList<BugInstance>();
                        warningsByField.put(fieldDescriptor, warnings);
                    }
                    warnings.add(warning);
                }

                ClassAnnotation clazz = warning.getPrimaryClass();
                if (clazz != null) {
                    ClassDescriptor classDesc = clazz.getClassDescriptor();
                    if(field != null && classDesc.equals(field.getClassDescriptor())) {
                        continue;
                    }
                    if (method != null && classDesc.equals(method.getClassDescriptor())) {
                        continue;
                    }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

                        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));

                    }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

                // TODO: we could distinguish between obscuring a field in the
                // same class
                // vs. obscuring a field in a superclass. Not sure how important
                // that is.
                if (f != null) {
                    FieldAnnotation fa = FieldAnnotation.fromBCELField(getDottedClassName(), f);
                    if (true || var.getStartPC() > 0) {
                        bugReporter.reportBug(new BugInstance(this, "MF_METHOD_MASKS_FIELD", LOW_PRIORITY)
                        .addClassAndMethod(this).addField(fa).addSourceLine(this, var.getStartPC() - 1));
                    }
                }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

        return "Method(" + super.toString() + ")";
    }

    @Override
    public boolean match(BugInstance bugInstance) {
        FieldAnnotation fieldAnnotation = null;
        if (role == null || role.equals("")) {
            fieldAnnotation = bugInstance.getPrimaryField();
        } else {
            for (BugAnnotation a : bugInstance.getAnnotations()) {
                if (a instanceof FieldAnnotation && role.equals(a.getDescription())) {
                    fieldAnnotation = (FieldAnnotation) a;
                    break;
                }
            }
        }
        if (fieldAnnotation == null) {
            return false;
        }
        if (!name.match(fieldAnnotation.getFieldName())) {
            return false;
        }
        if (signature != null && !signature.match(fieldAnnotation.getFieldSignature())) {
            return false;
        }
        return true;
    }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

        // If not, we just provide two values - one for Eclipse, another for
        // FindBugs itself.

        int startLine = -1;
        if (primaryLine <= 0) {
            FieldAnnotation primaryField = bug.getPrimaryField();
            if (primaryField != null && primaryField.getSourceLines() != null) {
                startLine = primaryField.getSourceLines().getStartLine();
                if (startLine < 0) {
                    // We have to provide line number, otherwise editor wouldn't
                    // show it
                    startLine = 1;
                }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

    private static boolean hasLineInfo(SourceLineAnnotation annotation) {
        return annotation != null && annotation.getStartLine() > 0;
    }

    private static void completeFieldInfo(String qualifiedClassName, String innerName, IType type, BugInstance bug) {
        FieldAnnotation field = bug.getPrimaryField();
        if (field == null || type == null) {
            return;
        }

        IField ifield = type.getField(field.getFieldName());
        ISourceRange sourceRange = null;
        IScanner scanner = null;
        JavaModelException ex = null;
        try {
            sourceRange = ifield.getNameRange();
        } catch (JavaModelException e) {
            ex = e;
        }
        try {
            // second try...
            if (sourceRange == null) {
                sourceRange = ifield.getSourceRange();
            }
            scanner = initScanner(type, sourceRange);
        } catch (JavaModelException e) {
            String message = "Can not complete field annotation " + field + " for the field: " + ifield + " in class: "
                    + qualifiedClassName + ", type " + type + ", bug " + bug;
            if (ex != null) {
                // report only first one
                e = ex;
            }
            FindbugsPlugin.getDefault().logMessage(IStatus.WARNING, message, e);
        }
        if (scanner == null || sourceRange == null) {
            return;
        }
        int lineNbr = scanner.getLineNumber(sourceRange.getOffset());
        lineNbr = lineNbr <= 0 ? 1 : lineNbr;
        String sourceFileStr = getSourceFileHint(type, qualifiedClassName);
        field.setSourceLines(new SourceLineAnnotation(qualifiedClassName, sourceFileStr, lineNbr, lineNbr, 0, 0));
    }
View Full Code Here

Examples of edu.umd.cs.findbugs.FieldAnnotation

                        }

                        return;

                    } else if (theAnnotation instanceof FieldAnnotation) {
                        FieldAnnotation fa = (FieldAnnotation) theAnnotation;
                        String className = fa.getClassName();
                        IJavaProject project = getIProject();
                        IType type = project.findType(className);
                        if (type == null) {
                            break findLocation;
                        }

                        IField f = type.getField(fa.getFieldName());
                        if (f != null) {
                            JavaUI.openInEditor(f, true, true);
                        } else {
                            activeEditor = JavaUI.openInEditor(type, true, true);
                            SourceLineAnnotation sla = fa.getSourceLines();
                            EditorUtil.goToLine(activeEditor, sla.getStartLine());
                        }
                        return;
                    } else if (theAnnotation instanceof TypeAnnotation) {
                        TypeAnnotation fa = (TypeAnnotation) theAnnotation;
                        String className = ClassName.fromFieldSignature(fa.getTypeDescriptor());
                        if (className == null) {
                            break findLocation;
                        }
                        IJavaProject project = getIProject();
                        IType type = project.findType(ClassName.toDottedClassName(className));
                        if (type == null) {
                            break findLocation;
                        }
                        JavaUI.openInEditor(type, true, true);
                        return;

                    } else if (theAnnotation instanceof ClassAnnotation) {
                        ClassAnnotation fa = (ClassAnnotation) theAnnotation;
                        String className = fa.getClassName();
                        IJavaProject project = getIProject();
                        IType type = project.findType(className);
                        if (type == null) {
                            break findLocation;
                        }
View Full Code Here

Examples of org.apache.felix.scrplugin.annotations.FieldAnnotation

    private void createReferences(final List<? extends ScannedAnnotation> descs, final ClassDescription describedClass) {
        for (final ScannedAnnotation ad : descs) {
            final ReferenceDescription ref = new ReferenceDescription(ad);

            // check for field annotation
            final FieldAnnotation fieldAnnotation;
            if (ad instanceof FieldAnnotation) {
                fieldAnnotation = (FieldAnnotation) ad;
                ref.setField(fieldAnnotation.getAnnotatedField());
            } else {
                fieldAnnotation = null;
            }

            ref.setName(ad.getStringValue("name",
                            (fieldAnnotation != null ? fieldAnnotation.getAnnotatedField().getName() : null)));
            String defaultInterfaceName = null;
            if ( fieldAnnotation != null ) {
                if ( fieldAnnotation.getAnnotatedField().getType().isArray() ) {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getComponentType().getName();
                } else {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getName();
                }
            }
            ref.setInterfaceName(ad.getStringValue("referenceInterface", defaultInterfaceName));
            ref.setTarget(ad.getStringValue("target", null));
            ref.setCardinality(ReferenceCardinality.valueOf(ad.getEnumValue("cardinality",
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.