Examples of MethodAnnotation


Examples of edu.umd.cs.findbugs.MethodAnnotation

            }
            if (classPattern != null && !classPattern.matcher(bug.getPrimaryClass().getClassName()).find()) {
                return false;
            }
            if (callsPattern != null) {
                MethodAnnotation m = bug.getAnnotationWithRole(MethodAnnotation.class, MethodAnnotation.METHOD_CALLED);
                if (m == null) {
                    return false;
                }
                if (!callsPattern.matcher(m.getClassName()).find()  && !callsPattern.matcher(m.getMethodName()).find()) {
                    return false;
                }
            }

            if (maybeMutatedAsString != null && !(atMutationPoint(bug) && mutationPoints.contains(getBugLocation(bug)))) {
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

         * @param b
         * @return
         */
        private String getBugLocation(BugInstance b) {
            String point;
            MethodAnnotation m = b.getPrimaryMethod();
            FieldAnnotation f = b.getPrimaryField();
            if (m != null) {
                point = m.toString();
            } else if (f != null) {
                point = f.toString();
            } else {
                point = null;
            }
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

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

        if (classNameRewriter != IdentityClassNameRewriter.instance()) {
            annotation = new MethodAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()),
                    annotation.getMethodName(), rewriteMethodSignature(classNameRewriter, annotation.getMethodSignature()),
                    annotation.isStatic());
        }
        return annotation;
    }
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

                        }
                        if (DEBUG) {
                            System.out.println(" priority f: " + priority);
                        }
                        if (source instanceof MethodAnnotation) {
                            MethodAnnotation m = (MethodAnnotation) source;
                            XMethod xm = m.toXMethod();
                            if (xm != null && (xm.isPrivate() || xm.isStatic()) && priority == Priorities.LOW_PRIORITY) {
                                continue;
                            }
                        }
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

            warningsByMethod = new HashMap<MethodDescriptor, Collection<BugInstance>>();
            warningsByField = new HashMap<FieldDescriptor, Collection<BugInstance>>();

            for (Iterator<BugInstance> i = bugCollection.iterator(); i.hasNext();) {
                BugInstance warning = i.next();
                MethodAnnotation method = warning.getPrimaryMethod();
                if (method != null) {
                    MethodDescriptor methodDesc = method.toMethodDescriptor();
                    Collection<BugInstance> warnings = warningsByMethod.get(methodDesc);
                    if (warnings == null) {
                        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;
                    }
                    Collection<BugInstance> warnings = warningsByClass.get(classDesc);
                    if (warnings == null) {
                        warnings = new LinkedList<BugInstance>();
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

    }

    @Override
    public boolean match(BugInstance bugInstance) {

        MethodAnnotation methodAnnotation = null;
        if (role == null || role.equals("")) {
            methodAnnotation = bugInstance.getPrimaryMethod();
        } else {
            for (BugAnnotation a : bugInstance.getAnnotations()) {
                if (a instanceof MethodAnnotation && role.equals(a.getDescription())) {
                    methodAnnotation = (MethodAnnotation) a;
                    break;
                }
            }
        }
        if (methodAnnotation == null) {
            return false;
        }
        if (!name.match(methodAnnotation.getMethodName())) {
            return false;
        }
        if (signature != null && !signature.match(methodAnnotation.getMethodSignature())) {
            return false;
        }
        return true;
    }
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

        if (lhsType_.getType() == T_TOP || lhsType_.getType() == T_BOTTOM || rhsType_.getType() == T_TOP
                || rhsType_.getType() == T_BOTTOM) {
            return;
        }
        InvokeInstruction inv = (InvokeInstruction) handle.getInstruction();
        MethodAnnotation calledMethodAnnotation = getMethodCalledAnnotation(cpg, inv);
        boolean looksLikeTestCase = TestCaseDetector.likelyTestCase(XFactory.createXMethod(methodGen));
        int priorityModifier = 0;
        if (looksLikeTestCase) {
            priorityModifier = 1;
        }

        if (rhsType_.getType() == T_NULL) {
            // A literal null value was passed directly to equals().
            if (!looksLikeTestCase) {

                try {
                    IsNullValueDataflow isNullDataflow = classContext.getIsNullValueDataflow(method);
                    IsNullValueFrame isNullFrame = isNullDataflow.getFactAtLocation(location);
                    BugAnnotation a = BugInstance.getSourceForTopStackValue(classContext, method, location);
                    int priority = NORMAL_PRIORITY;
                    if (a instanceof FieldAnnotation && ((FieldAnnotation) a).isStatic()) {
                        priority = LOW_PRIORITY;
                    }
                    if (isNullFrame.isValid() && isNullFrame.getTopValue().isDefinitelyNull()) {
                        String type = "EC_NULL_ARG";
                        if (calledMethodAnnotation != null && calledMethodAnnotation.isStatic()){
                            type = "DMI_DOH";
                            priority = LOW_PRIORITY;
                        }
                        BugInstance bug = new BugInstance(this, type, priority + priorityModifier).addClassAndMethod(methodGen, sourceFile)
                                .addOptionalAnnotation(calledMethodAnnotation);
                        if (type.equals("DMI_DOH")) {
                            bug.addString("Use \"== null\" to check for a value being null");
                        }
                        bugAccumulator.accumulateBug(
                                bug,
                                SourceLineAnnotation.fromVisitedInstruction(this.classContext, methodGen, sourceFile,
                                        location.getHandle()));
                    }
                } catch (CFGBuilderException e) {
                    AnalysisContext.logError("Error getting null value analysis", e);
                }

            }
            return;
        } else if (lhsType_.getType() == T_NULL) {
            // Hmm...in this case, equals() is being invoked on
            // a literal null value. This is really the
            // purview of FindNullDeref. So, we'll just do nothing.
            return;
        } else if (!(lhsType_ instanceof ReferenceType) || !(rhsType_ instanceof ReferenceType)) {
            bugReporter.logError("equals() used to compare non-object type(s) " + lhsType_ + " and " + rhsType_ + " in "
                    + SignatureConverter.convertMethodSignature(methodGen) + " at " + location.getHandle());
            return;
        }
        IncompatibleTypes result = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType_, rhsType_);

        if (lhsType_ instanceof ArrayType && rhsType_ instanceof ArrayType) {
            String pattern = "EC_BAD_ARRAY_COMPARE";
            IncompatibleTypes result2 = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType_, rhsType_, true);
            if (result2.getPriority() <= Priorities.NORMAL_PRIORITY) {
                pattern = "EC_INCOMPATIBLE_ARRAY_COMPARE";
            } else if (calledMethodAnnotation != null && calledMethodAnnotation.getClassName().equals("org.testng.Assert")) {
                return;
            }
            bugAccumulator.accumulateBug(new BugInstance(this, pattern, NORMAL_PRIORITY).addClassAndMethod(methodGen, sourceFile)
                    .addFoundAndExpectedType(rhsType_, lhsType_)
                    .addSomeSourceForTopTwoStackValues(classContext, method, location)
View Full Code Here

Examples of edu.umd.cs.findbugs.MethodAnnotation

                        int line = sla.getStartLine();
                        EditorUtil.goToLine(activeEditor, line);
                        return;

                    } else if (theAnnotation instanceof MethodAnnotation) {
                        MethodAnnotation ma = (MethodAnnotation) theAnnotation;
                        String className = ma.getClassName();
                        IJavaProject project = getIProject();
                        IType type = project.findType(className);
                        if (type == null) {
                            break findLocation;
                        }
                        IMethod m = getIMethod(type, ma);
                        if (m != null) {
                            JavaUI.openInEditor(m, true, true);

                        } else {
                            activeEditor = JavaUI.openInEditor(type, true, true);
                            SourceLineAnnotation sla = ma.getSourceLines();
                            EditorUtil.goToLine(activeEditor, sla.getStartLine());
                        }

                        return;
View Full Code Here

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

            }
        }

        final ScannedAnnotation a;
        if (annotatedObject instanceof Method) {
            a = new MethodAnnotation(name, values, (Method) annotatedObject);
            ((Method) annotatedObject).setAccessible(true);
        } else if (annotatedObject instanceof Field) {
            a = new FieldAnnotation(name, values, (Field) annotatedObject);
            ((Field) annotatedObject).setAccessible(true);
        } else {
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.