01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon.support.reflect.declaration;
19:
20: import java.util.Set;
21: import java.util.TreeSet;
22:
23: import spoon.reflect.code.CtBlock;
24: import spoon.reflect.declaration.CtAnonymousExecutable;
25: import spoon.reflect.declaration.CtClass;
26: import spoon.reflect.declaration.ModifierKind;
27: import spoon.reflect.visitor.CtVisitor;
28:
29: public class CtAnonymousExecutableImpl extends CtElementImpl implements
30: CtAnonymousExecutable {
31: private static final long serialVersionUID = 1L;
32:
33: CtBlock<?> body;
34:
35: Set<ModifierKind> modifiers = new TreeSet<ModifierKind>();
36:
37: public void accept(CtVisitor visitor) {
38: visitor.visitCtAnonymousExecutable(this );
39: }
40:
41: public CtBlock<?> getBody() {
42: return body;
43: }
44:
45: public Set<ModifierKind> getModifiers() {
46: return modifiers;
47: }
48:
49: public CtClass<?> getOwnerClass() {
50: return (CtClass<?>) parent;
51: }
52:
53: public ModifierKind getVisibility() {
54: if (getModifiers().contains(ModifierKind.PUBLIC))
55: return ModifierKind.PUBLIC;
56: if (getModifiers().contains(ModifierKind.PROTECTED))
57: return ModifierKind.PROTECTED;
58: if (getModifiers().contains(ModifierKind.PRIVATE))
59: return ModifierKind.PRIVATE;
60: return null;
61: }
62:
63: public boolean hasModifier(ModifierKind modifier) {
64: return modifiers.contains(modifier);
65: }
66:
67: public void setBody(CtBlock<?> block) {
68: body = block;
69: }
70:
71: public void setModifiers(Set<ModifierKind> modifiers) {
72: this .modifiers = modifiers;
73: }
74:
75: public void setVisibility(ModifierKind visibility) {
76: getModifiers().remove(ModifierKind.PUBLIC);
77: getModifiers().remove(ModifierKind.PROTECTED);
78: getModifiers().remove(ModifierKind.PRIVATE);
79: getModifiers().add(visibility);
80: }
81:
82: }
|