PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/eclipse_SDK-3.7.1/plugins/org.eclipse.jdt.core.source_3.7.1.v_B76_R37x/org/eclipse/jdt/core/dom/Javadoc.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 320 lines | 132 code | 28 blank | 160 comment | 20 complexity | 1a97ab8416fb76bd53890c49ce05a460 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2010 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.jdt.core.dom;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.eclipse.jdt.core.compiler.InvalidInputException;
  15. import org.eclipse.jdt.internal.compiler.parser.Scanner;
  16. import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
  17. /**
  18. * AST node for a Javadoc-style doc comment.
  19. * <pre>
  20. * Javadoc:
  21. * <b>/** </b> { TagElement } <b>*</b><b>/</b>
  22. * </pre>
  23. *
  24. * @since 2.0
  25. * @noinstantiate This class is not intended to be instantiated by clients.
  26. */
  27. public class Javadoc extends Comment {
  28. /**
  29. * The "comment" structural property of this node type (type: {@link String}) (JLS2 API only).
  30. * @since 3.0
  31. * @deprecated Replaced by {@link #TAGS_PROPERTY} in the JLS3 API.
  32. */
  33. public static final SimplePropertyDescriptor COMMENT_PROPERTY =
  34. new SimplePropertyDescriptor(Javadoc.class, "comment", String.class, MANDATORY); //$NON-NLS-1$
  35. /**
  36. * The "tags" structural property of this node type (element type: {@link TagElement}).
  37. * @since 3.1
  38. */
  39. public static final ChildListPropertyDescriptor TAGS_PROPERTY =
  40. new ChildListPropertyDescriptor(Javadoc.class, "tags", TagElement.class, CYCLE_RISK); //$NON-NLS-1$
  41. /**
  42. * A list of property descriptors (element type:
  43. * {@link StructuralPropertyDescriptor}),
  44. * or null if uninitialized.
  45. * @since 3.0
  46. */
  47. private static final List PROPERTY_DESCRIPTORS_2_0;
  48. /**
  49. * A list of property descriptors (element type:
  50. * {@link StructuralPropertyDescriptor}),
  51. * or null if uninitialized.
  52. * @since 3.1
  53. */
  54. private static final List PROPERTY_DESCRIPTORS_3_0;
  55. static {
  56. List properyList = new ArrayList(3);
  57. createPropertyList(Javadoc.class, properyList);
  58. addProperty(COMMENT_PROPERTY, properyList);
  59. addProperty(TAGS_PROPERTY, properyList);
  60. PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList);
  61. properyList = new ArrayList(2);
  62. createPropertyList(Javadoc.class, properyList);
  63. addProperty(TAGS_PROPERTY, properyList);
  64. PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList);
  65. }
  66. /**
  67. * Returns a list of structural property descriptors for this node type.
  68. * Clients must not modify the result.
  69. *
  70. * @param apiLevel the API level; one of the
  71. * <code>AST.JLS*</code> constants
  72. * @return a list of property descriptors (element type:
  73. * {@link StructuralPropertyDescriptor})
  74. * @since 3.0
  75. */
  76. public static List propertyDescriptors(int apiLevel) {
  77. if (apiLevel == AST.JLS2_INTERNAL) {
  78. return PROPERTY_DESCRIPTORS_2_0;
  79. } else {
  80. return PROPERTY_DESCRIPTORS_3_0;
  81. }
  82. }
  83. /**
  84. * Canonical minimal doc comment.
  85. * @since 3.0
  86. */
  87. private static final String MINIMAL_DOC_COMMENT = "/** */";//$NON-NLS-1$
  88. /**
  89. * The doc comment string, including opening and closing comment
  90. * delimiters; defaults to a minimal Javadoc comment.
  91. * @deprecated The comment string was replaced in the 3.0 release
  92. * by a representation of the structure of the doc comment.
  93. * For backwards compatibility, it is still funcational as before.
  94. */
  95. private String comment = MINIMAL_DOC_COMMENT;
  96. /**
  97. * The list of tag elements (element type: {@link TagElement}).
  98. * Defaults to an empty list.
  99. * @since 3.0
  100. */
  101. private ASTNode.NodeList tags =
  102. new ASTNode.NodeList(TAGS_PROPERTY);
  103. /**
  104. * Creates a new AST node for a doc comment owned by the given AST.
  105. * The new node has an empty list of tag elements (and, for backwards
  106. * compatability, an unspecified, but legal, doc comment string).
  107. * <p>
  108. * N.B. This constructor is package-private; all subclasses must be
  109. * declared in the same package; clients are unable to declare
  110. * additional subclasses.
  111. * </p>
  112. *
  113. * @param ast the AST that is to own this node
  114. */
  115. Javadoc(AST ast) {
  116. super(ast);
  117. }
  118. /* (omit javadoc for this method)
  119. * Method declared on ASTNode.
  120. */
  121. final List internalStructuralPropertiesForType(int apiLevel) {
  122. return propertyDescriptors(apiLevel);
  123. }
  124. /* (omit javadoc for this method)
  125. * Method declared on ASTNode.
  126. */
  127. final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) {
  128. if (property == COMMENT_PROPERTY) {
  129. if (get) {
  130. return getComment();
  131. } else {
  132. setComment((String) value);
  133. return null;
  134. }
  135. }
  136. // allow default implementation to flag the error
  137. return super.internalGetSetObjectProperty(property, get, value);
  138. }
  139. /* (omit javadoc for this method)
  140. * Method declared on ASTNode.
  141. */
  142. final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
  143. if (property == TAGS_PROPERTY) {
  144. return tags();
  145. }
  146. // allow default implementation to flag the error
  147. return super.internalGetChildListProperty(property);
  148. }
  149. /* (omit javadoc for this method)
  150. * Method declared on ASTNode.
  151. */
  152. final int getNodeType0() {
  153. return JAVADOC;
  154. }
  155. /* (omit javadoc for this method)
  156. * Method declared on ASTNode.
  157. */
  158. ASTNode clone0(AST target) {
  159. Javadoc result = new Javadoc(target);
  160. result.setSourceRange(getStartPosition(), getLength());
  161. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  162. result.setComment(getComment());
  163. }
  164. result.tags().addAll(ASTNode.copySubtrees(target, tags()));
  165. return result;
  166. }
  167. /* (omit javadoc for this method)
  168. * Method declared on ASTNode.
  169. */
  170. final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
  171. // dispatch to correct overloaded match method
  172. return matcher.match(this, other);
  173. }
  174. /* (omit javadoc for this method)
  175. * Method declared on ASTNode.
  176. */
  177. void accept0(ASTVisitor visitor) {
  178. boolean visitChildren = visitor.visit(this);
  179. if (visitChildren) {
  180. // visit children in normal left to right reading order
  181. acceptChildren(visitor, this.tags);
  182. }
  183. visitor.endVisit(this);
  184. }
  185. /**
  186. * Returns the doc comment string, including the starting
  187. * and ending comment delimiters, and any embedded line breaks.
  188. *
  189. * @return the doc comment string
  190. * @exception UnsupportedOperationException if this operation is used in
  191. * an AST later than JLS2
  192. * @deprecated The comment string was replaced in the 3.0 release
  193. * by a representation of the structure of the doc comment.
  194. * See {@link #tags() tags}.
  195. */
  196. public String getComment() {
  197. supportedOnlyIn2();
  198. return this.comment;
  199. }
  200. /**
  201. * Sets or clears the doc comment string. The documentation
  202. * string must include the starting and ending comment delimiters,
  203. * and any embedded line breaks.
  204. *
  205. * @param docComment the doc comment string
  206. * @exception IllegalArgumentException if the Java comment string is invalid
  207. * @exception UnsupportedOperationException if this operation is used in
  208. * an AST later than JLS2
  209. * @deprecated The comment string was replaced in the 3.0 release
  210. * by a representation of the structure of the doc comment.
  211. * See {@link #tags() tags}.
  212. */
  213. public void setComment(String docComment) {
  214. supportedOnlyIn2();
  215. if (docComment == null) {
  216. throw new IllegalArgumentException();
  217. }
  218. char[] source = docComment.toCharArray();
  219. Scanner scanner = this.ast.scanner;
  220. scanner.resetTo(0, source.length);
  221. scanner.setSource(source);
  222. try {
  223. int token;
  224. boolean onlyOneComment = false;
  225. while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  226. switch(token) {
  227. case TerminalTokens.TokenNameCOMMENT_JAVADOC :
  228. if (onlyOneComment) {
  229. throw new IllegalArgumentException();
  230. }
  231. onlyOneComment = true;
  232. break;
  233. default:
  234. onlyOneComment = false;
  235. }
  236. }
  237. if (!onlyOneComment) {
  238. throw new IllegalArgumentException();
  239. }
  240. } catch (InvalidInputException e) {
  241. throw new IllegalArgumentException();
  242. }
  243. preValueChange(COMMENT_PROPERTY);
  244. this.comment = docComment;
  245. postValueChange(COMMENT_PROPERTY);
  246. }
  247. /**
  248. * Returns the live list of tag elements that make up this doc
  249. * comment.
  250. * <p>
  251. * The tag elements cover everything except the starting and ending
  252. * comment delimiters, and generally omit leading whitespace
  253. * (including a leading "*") and embedded line breaks.
  254. * The first tag element of a typical doc comment represents
  255. * all the material before the first explicit doc tag; this
  256. * first tag element has a <code>null</code> tag name and
  257. * generally contains 1 or more {@link TextElement}s,
  258. * and possibly interspersed with tag elements for nested tags
  259. * like "{@link String String}".
  260. * Subsequent tag elements represent successive top-level doc
  261. * tag (e.g., "@param", "@return", "@see").
  262. * </p>
  263. * <p>
  264. * Adding and removing nodes from this list affects this node
  265. * dynamically.
  266. * </p>
  267. *
  268. * @return the live list of tag elements in this doc comment
  269. * (element type: {@link TagElement})
  270. * @since 3.0
  271. */
  272. public List tags() {
  273. return this.tags;
  274. }
  275. /* (omit javadoc for this method)
  276. * Method declared on ASTNode.
  277. */
  278. int memSize() {
  279. int size = super.memSize() + 2 * 4;
  280. if (this.comment != MINIMAL_DOC_COMMENT) {
  281. // anything other than the default string takes space
  282. size += stringSize(this.comment);
  283. }
  284. return size;
  285. }
  286. /* (omit javadoc for this method)
  287. * Method declared on ASTNode.
  288. */
  289. int treeSize() {
  290. return memSize() + this.tags.listSize();
  291. }
  292. }