1// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.tools.findbugs.plugin;
6
7import org.apache.bcel.classfile.Code;
8
9import edu.umd.cs.findbugs.BugInstance;
10import edu.umd.cs.findbugs.BugReporter;
11import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
12
13/**
14 * This class detects the synchronized method.
15 */
16public class SynchronizedMethodDetector extends OpcodeStackDetector {
17    private BugReporter mBugReporter;
18
19    public SynchronizedMethodDetector(BugReporter bugReporter) {
20        this.mBugReporter = bugReporter;
21    }
22
23    @Override
24    public void visit(Code code) {
25        if (getMethod().isSynchronized()) {
26            mBugReporter.reportBug(new BugInstance(this, "CHROMIUM_SYNCHRONIZED_METHOD",
27                                                   NORMAL_PRIORITY)
28                    .addClassAndMethod(this)
29                    .addSourceLine(this));
30        }
31        super.visit(code);
32    }
33
34    @Override
35    public void sawOpcode(int arg0) {
36    }
37}
38