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.reflect.declaration;
019:
020: import java.lang.annotation.Annotation;
021: import java.util.List;
022: import java.util.Set;
023:
024: import spoon.processing.FactoryAccessor;
025: import spoon.reflect.cu.SourcePosition;
026: import spoon.reflect.reference.CtTypeReference;
027: import spoon.reflect.visitor.CtVisitor;
028: import spoon.reflect.visitor.Filter;
029: import spoon.reflect.visitor.Root;
030:
031: /**
032: * This interface is the root interface for the metamodel elements (any program
033: * element).
034: */
035: @Root
036: public interface CtElement extends FactoryAccessor,
037: Comparable<CtElement> {
038: /**
039: * Accepts a visitor.
040: *
041: * @param visitor
042: * to accept
043: */
044: void accept(CtVisitor visitor);
045:
046: /**
047: * Searches for an annotation (proxy) of the given class that annotates the
048: * current element.
049: *
050: * <p>
051: * NOTE: before using an annotation proxy, you have to make sure that all
052: * the types referenced by the annotation have been compiled and are in the
053: * classpath so that accessed values can be converted into the actual types.
054: * Otherwise, use {@link #getAnnotation(CtTypeReference)}.
055: *
056: * @param <A>
057: * the annotation's type
058: * @param annotationType
059: * the annotation's class
060: * @return if found, returns a proxy for this annotation
061: */
062: <A extends Annotation> A getAnnotation(Class<A> annotationType);
063:
064: /**
065: * Gets the annotation element for a given annotation type.
066: *
067: * @param annotationType
068: * the annotation type
069: * @return the annotation if this element is annotated by one annotation of
070: * the given type
071: */
072: <A extends Annotation> CtAnnotation<A> getAnnotation(
073: CtTypeReference<A> annotationType);
074:
075: /**
076: * Returns the annotations that are present on this element.
077: */
078: Set<CtAnnotation<? extends Annotation>> getAnnotations();
079:
080: /**
081: * Returns the text of the documentation ("javadoc") comment of this
082: * element.
083: */
084: String getDocComment();
085:
086: /**
087: * Gets the parent of current element.
088: */
089: CtElement getParent();
090:
091: /**
092: * Gets the signature of the element.
093: */
094: String getSignature();
095:
096: /**
097: * Gets the first parent that matches the given type.
098: */
099: <P extends CtElement> P getParent(Class<P> parentType);
100:
101: /**
102: * Tells if the given element is a direct or indirect parent.
103: */
104: boolean hasParent(CtElement candidate);
105:
106: /**
107: * Gets the position of this element in input source files
108: *
109: * @return Source file and line number of this element or null
110: */
111: SourcePosition getPosition();
112:
113: /**
114: * Replaces this element by another one.
115: */
116: void replace(CtElement element);
117:
118: /**
119: * Replaces the elements that match the filter by the given element.
120: */
121: void replace(Filter<? extends CtElement> replacementPoints,
122: CtElement element);
123:
124: /**
125: * Sets the annotations for this element.
126: */
127: void setAnnotations(
128: Set<CtAnnotation<? extends Annotation>> annotation);
129:
130: /**
131: * Sets the text of the documentation ("javadoc") comment of this
132: * declaration.
133: */
134: void setDocComment(String docComment);
135:
136: /**
137: * Sets the parent element of the current element.
138: *
139: * @param element
140: * parent
141: */
142: void setParent(CtElement element);
143:
144: /**
145: * Sets the position in the Java source file. Note that this information is
146: * used to feed the line numbers in the generated bytecode if any (which is
147: * useful for debugging).
148: *
149: * @param position
150: * of this element in the input source files
151: */
152: void setPosition(SourcePosition position);
153:
154: /**
155: * Sets the position of this element and all its children element. Note that
156: * this information is used to feed the line numbers in the generated
157: * bytecode if any (which is useful for debugging).
158: *
159: * @param position
160: * of this element and all children in the input source file
161: */
162: void setPositions(SourcePosition position);
163:
164: /**
165: * Gets the child elements annotated with the given annotation type's
166: * instances.
167: *
168: * @param <E>
169: * the element's type
170: * @param annotationType
171: * the annotation type
172: * @return all the child elements annotated with an instance of the given
173: * annotation type
174: */
175: <E extends CtElement> List<E> getAnnotatedChildren(
176: Class<? extends Annotation> annotationType);
177:
178: /**
179: * Returns true if this element is implicit and automatically added by the
180: * Java compiler.
181: */
182: boolean isImplicit();
183:
184: /**
185: * Sets this element to be implicit (will not be printed).
186: */
187: void setImplicit(boolean b);
188:
189: /**
190: * Calculates and returns the set of all the types referenced by this
191: * element (and sub-elements in the AST).
192: */
193: Set<CtTypeReference<?>> getReferencedTypes();
194:
195: }
|