001: /*
002: * Spoon - http://spoon.gforge.inria.fr/
003: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004: *
005: * This software is governed by the CeCILL-C License under French law and
006: * abiding by the rules of distribution of free software. You can use, modify
007: * and/or redistribute the software under the terms of the CeCILL-C license as
008: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013: *
014: * The fact that you are presently reading this means that you have had
015: * knowledge of the CeCILL-C license and that you accept its terms.
016: */
017:
018: package spoon.support.reflect.code;
019:
020: import java.util.Set;
021: import java.util.TreeSet;
022:
023: import spoon.reflect.code.CtExpression;
024: import spoon.reflect.code.CtLocalVariable;
025: import spoon.reflect.declaration.ModifierKind;
026: import spoon.reflect.reference.CtLocalVariableReference;
027: import spoon.reflect.reference.CtTypeReference;
028: import spoon.reflect.visitor.CtVisitor;
029:
030: public class CtLocalVariableImpl<T> extends CtStatementImpl implements
031: CtLocalVariable<T> {
032: private static final long serialVersionUID = 1L;
033:
034: CtExpression<T> defaultExpression;
035:
036: String docComment;
037:
038: Set<ModifierKind> modifiers = new TreeSet<ModifierKind>();
039:
040: String name;
041:
042: CtTypeReference<T> type;
043:
044: public void accept(CtVisitor visitor) {
045: visitor.visitCtLocalVariable(this );
046: }
047:
048: public CtExpression<T> getDefaultExpression() {
049: return defaultExpression;
050: }
051:
052: @Override
053: public String getDocComment() {
054: return docComment;
055: }
056:
057: public Set<ModifierKind> getModifiers() {
058: return modifiers;
059: }
060:
061: public CtLocalVariableReference<T> getReference() {
062: return getFactory().Code().createLocalVariableReference(this );
063: }
064:
065: public String getSimpleName() {
066: return name;
067: }
068:
069: public CtTypeReference<T> getType() {
070: return type;
071: }
072:
073: public ModifierKind getVisibility() {
074: if (getModifiers().contains(ModifierKind.PUBLIC)) {
075: return ModifierKind.PUBLIC;
076: }
077: if (getModifiers().contains(ModifierKind.PROTECTED)) {
078: return ModifierKind.PROTECTED;
079: }
080: if (getModifiers().contains(ModifierKind.PRIVATE)) {
081: return ModifierKind.PRIVATE;
082: }
083: return null;
084: }
085:
086: public boolean hasModifier(ModifierKind modifier) {
087: return modifiers.contains(modifier);
088: }
089:
090: public void setDefaultExpression(CtExpression<T> defaultExpression) {
091: this .defaultExpression = defaultExpression;
092: }
093:
094: @Override
095: public void setDocComment(String docComment) {
096: this .docComment = docComment;
097: }
098:
099: public void setModifiers(Set<ModifierKind> modifiers) {
100: this .modifiers = modifiers;
101: }
102:
103: public void setSimpleName(String simpleName) {
104: this .name = simpleName;
105: }
106:
107: public void setType(CtTypeReference<T> type) {
108: this .type = type;
109: }
110:
111: public void setVisibility(ModifierKind visibility) {
112: getModifiers().remove(ModifierKind.PUBLIC);
113: getModifiers().remove(ModifierKind.PROTECTED);
114: getModifiers().remove(ModifierKind.PRIVATE);
115: getModifiers().add(visibility);
116: }
117:
118: }
|