1 package spoon.support.reflect.declaration; 2 3 import java.util.Set ; 4 import java.util.TreeSet ; 5 6 import spoon.reflect.code.CtBlock; 7 import spoon.reflect.declaration.CtAnonymousExecutable; 8 import spoon.reflect.declaration.CtClass; 9 import spoon.reflect.declaration.ModifierKind; 10 import spoon.reflect.visitor.CtVisitor; 11 12 public class CtAnonymousExecutableImpl extends CtElementImpl implements 13 CtAnonymousExecutable { 14 private static final long serialVersionUID = 1L; 15 16 CtBlock body; 17 18 Set <ModifierKind> modifiers = new TreeSet <ModifierKind>(); 19 20 public void accept(CtVisitor visitor) { 21 visitor.visitCtAnonymousExecutable(this); 22 } 23 24 public CtBlock getBody() { 25 return body; 26 } 27 28 public Set <ModifierKind> getModifiers() { 29 return modifiers; 30 } 31 32 public CtClass getOwnerClass() { 33 return (CtClass) parent; 34 } 35 36 public ModifierKind getVisibility() { 37 if (getModifiers().contains(ModifierKind.PUBLIC)) 38 return ModifierKind.PUBLIC; 39 if (getModifiers().contains(ModifierKind.PROTECTED)) 40 return ModifierKind.PROTECTED; 41 if (getModifiers().contains(ModifierKind.PRIVATE)) 42 return ModifierKind.PRIVATE; 43 return null; 44 } 45 46 public boolean hasModifier(ModifierKind modifier) { 47 return modifiers.contains(modifier); 48 } 49 50 public void setBody(CtBlock block) { 51 body = block; 52 } 53 54 public void setModifiers(Set <ModifierKind> modifiers) { 55 this.modifiers = modifiers; 56 } 57 58 public void setVisibility(ModifierKind visibility) { 59 getModifiers().remove(ModifierKind.PUBLIC); 60 getModifiers().remove(ModifierKind.PROTECTED); 61 getModifiers().remove(ModifierKind.PRIVATE); 62 getModifiers().add(visibility); 63 } 64 65 } 66 | Popular Tags |