01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2003-2007 University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.ba.jsr305;
21:
22: import edu.umd.cs.findbugs.ba.XMethod;
23: import edu.umd.cs.findbugs.ba.ch.OverriddenMethodsVisitor;
24:
25: /**
26: * Accumulate type qualifier annotations on method,
27: * taking supertype methods into account.
28: *
29: * @author David Hovemeyer
30: */
31: public abstract class AbstractMethodAnnotationAccumulator extends
32: OverriddenMethodsVisitor {
33: private final TypeQualifierValue typeQualifierValue;
34:
35: protected AbstractMethodAnnotationAccumulator(
36: TypeQualifierValue typeQualifierValue, XMethod xmethod) {
37: super (xmethod);
38: this .typeQualifierValue = typeQualifierValue;
39: }
40:
41: /**
42: * @return Returns the typeQualifierValue.
43: */
44: public TypeQualifierValue getTypeQualifierValue() {
45: return typeQualifierValue;
46: }
47:
48: /* (non-Javadoc)
49: * @see edu.umd.cs.findbugs.ba.ch.OverriddenMethodsVisitor#visitOverriddenMethod(edu.umd.cs.findbugs.ba.XMethod)
50: */
51: @Override
52: protected boolean visitOverriddenMethod(XMethod xmethod) {
53:
54: // If xmethod is the method where the visitation begins,
55: // then we don't want to try to compute the effective annotation
56: // (since that would cause an infinite recursion).
57: // Instead, continue to supertype methods.
58: if (xmethod == getXmethod()) {
59: return true;
60: }
61:
62: // See if matching method is annotated
63: TypeQualifierAnnotation tqa = lookupAnnotation(xmethod);
64: if (tqa == null) {
65: // continue search in supertype
66: return true;
67: } else {
68: // This branch of search ends here.
69: // Add partial result.
70: getResult()
71: .addPartialResult(
72: new TypeQualifierAnnotationLookupResult.PartialResult(
73: xmethod, tqa));
74: return false;
75: }
76: }
77:
78: public abstract TypeQualifierAnnotationLookupResult getResult();
79:
80: protected abstract TypeQualifierAnnotation lookupAnnotation(
81: XMethod xm);
82: }
|