Debian Codegraph @

src/com/google/javascript/rhino/JSDocInfoBuilder.java

raw symbols SCIP
1 /*
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Rhino code, released
17 * May 6, 1999.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1997-1999
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 * Bob Jervis
26 * Google Inc.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU General Public License Version 2 or later (the "GPL"), in which
30 * case the provisions of the GPL are applicable instead of those above. If
31 * you wish to allow use of your version of this file only under the terms of
32 * the GPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replacing
34 * them with the notice and other provisions required by the GPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the GPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 package com.google.javascript.rhino;
41
42 import com.google.javascript.rhino.JSDocInfo.Visibility;
43 import com.google.javascript.rhino.jstype.StaticSourceFile;
44
45 import java.util.List;
46 import java.util.Set;
47
48 /**
49 * A builder for {@link JSDocInfo} objects. This builder abstracts the
50 * construction process of {@link JSDocInfo} objects whilst minimizing the
51 * number of instances of {@link JSDocInfo} objects. It provides early
52 * incompatibility detection among properties stored on the {@code JSDocInfo}
53 * object being created.
54 *
55 */
56 final public class JSDocInfoBuilder {
57 // the current JSDoc which is being populated
58 private JSDocInfo currentInfo;
59
60 // whether the current JSDocInfo has valuable information
61 private boolean populated = false;
62
63 // whether to include the documentation itself when parsing the JsDoc
64 private boolean parseDocumentation = false;
65
66 // the current marker, if any.
67 private JSDocInfo.Marker currentMarker = null;
68
69 public JSDocInfoBuilder(boolean parseDocumentation) {
70 this.currentInfo = new JSDocInfo(parseDocumentation);
71 this.parseDocumentation = parseDocumentation;
72 }
73
74 /**
75 * Sets the original JSDoc comment string. This is a no-op if the builder
76 * isn't configured to record documentation.
77 */
78 public void recordOriginalCommentString(String sourceComment) {
79 if (parseDocumentation) {
80 currentInfo.setOriginalCommentString(sourceComment);
81 }
82 }
83
84 public boolean shouldParseDocumentation() {
85 return parseDocumentation;
86 }
87
88 /**
89 * Returns whether this builder is populated with information that can be
90 * used to {@link #build} a {@link JSDocInfo} object.
91 */
92 public boolean isPopulated() {
93 return populated;
94 }
95
96 /**
97 * Returns whether this builder is populated with information that can be
98 * used to {@link #build} a {@link JSDocInfo} object that has a
99 * fileoverview tag.
100 */
101 public boolean isPopulatedWithFileOverview() {
102 return isPopulated() &&
103 (currentInfo.hasFileOverview() || currentInfo.isExterns() ||
104 currentInfo.isNoCompile());
105 }
106
107 /**
108 * Returns whether this builder recorded a description.
109 */
110 public boolean isDescriptionRecorded() {
111 return currentInfo.getDescription() != null;
112 }
113
114 /**
115 * Builds a {@link JSDocInfo} object based on the populated information and
116 * returns it. Once this method is called, the builder can be reused to build
117 * another {@link JSDocInfo} object.
118 *
119 * @param associatedNode The source node containing the JSDoc.
120 * @return a {@link JSDocInfo} object populated with the values given to this
121 * builder. If no value was populated, this method simply returns
122 * {@code null}
123 */
124 public JSDocInfo build(Node associatedNode) {
125 if (populated) {
126 JSDocInfo built = currentInfo;
127 built.setAssociatedNode(associatedNode);
128 populateDefaults(built);
129 populated = false;
130 currentInfo = new JSDocInfo(this.parseDocumentation);
131 return built;
132 } else {
133 return null;
134 }
135 }
136
137 /** Generate defaults when certain parameters are not specified. */
138 private static void populateDefaults(JSDocInfo info) {
139 if (info.getVisibility() == null) {
140 info.setVisibility(Visibility.INHERITED);
141 }
142 }
143
144 /**
145 * Adds a marker to the current JSDocInfo and populates the marker with the
146 * annotation information.
147 */
148 public void markAnnotation(String annotation, int lineno, int charno) {
149 JSDocInfo.Marker marker = currentInfo.addMarker();
150
151 if (marker != null) {
152 JSDocInfo.TrimmedStringPosition position =
153 new JSDocInfo.TrimmedStringPosition();
154 position.setItem(annotation);
155 position.setPositionInformation(lineno, charno, lineno,
156 charno + annotation.length());
157 marker.setAnnotation(position);
158 populated = true;
159 }
160
161 currentMarker = marker;
162 }
163
164 /**
165 * Adds a textual block to the current marker.
166 */
167 public void markText(String text, int startLineno, int startCharno,
168 int endLineno, int endCharno) {
169 if (currentMarker != null) {
170 JSDocInfo.StringPosition position = new JSDocInfo.StringPosition();
171 position.setItem(text);
172 position.setPositionInformation(startLineno, startCharno,
173 endLineno, endCharno);
174 currentMarker.setDescription(position);
175 }
176 }
177
178 /**
179 * Adds a type declaration to the current marker.
180 */
181 public void markTypeNode(Node typeNode, int lineno, int startCharno,
182 int endLineno, int endCharno, boolean hasLC) {
183 if (currentMarker != null) {
184 JSDocInfo.TypePosition position = new JSDocInfo.TypePosition();
185 position.setItem(typeNode);
186 position.setHasBrackets(hasLC);
187 position.setPositionInformation(lineno, startCharno,
188 endLineno, endCharno);
189 currentMarker.setType(position);
190 }
191 }
192
193 /**
194 * Adds a name declaration to the current marker.
195 * @deprecated Use #markName(String, StaticSourceFile, int, int)
196 */
197 @Deprecated
198 public void markName(String name, int lineno, int charno) {
199 markName(name, null, lineno, charno);
200 }
201
202 /**
203 * Adds a name declaration to the current marker.
204 */
205 public void markName(String name, StaticSourceFile file,
206 int lineno, int charno) {
207 if (currentMarker != null) {
208 // Record the name as both a SourcePosition<String> and a
209 // SourcePosition<Node>. The <String> form is deprecated,
210 // because <Node> is more consistent with how other name
211 // references are handled (see #markTypeNode)
212 //
213 // TODO(nicksantos): Remove all uses of the Name position
214 // and replace them with the NameNode position.
215 JSDocInfo.TrimmedStringPosition position =
216 new JSDocInfo.TrimmedStringPosition();
217 position.setItem(name);
218 position.setPositionInformation(lineno, charno,
219 lineno, charno + name.length());
220 currentMarker.setName(position);
221
222 SourcePosition<Node> nodePos =
223 new JSDocInfo.NamePosition();
224 Node node = Node.newString(Token.NAME, name, lineno, charno);
225 node.setLength(name.length());
226 node.setStaticSourceFile(file);
227 nodePos.setItem(node);
228 nodePos.setPositionInformation(lineno, charno,
229 lineno, charno + name.length());
230 currentMarker.setNameNode(nodePos);
231 }
232 }
233
234 /**
235 * Records a block-level description.
236 *
237 * @return {@code true} if the description was recorded.
238 */
239 public boolean recordBlockDescription(String description) {
240 populated = true;
241 return currentInfo.documentBlock(description);
242 }
243
244 /**
245 * Records a visibility.
246 *
247 * @return {@code true} if the visibility was recorded and {@code false}
248 * if it was already defined
249 */
250 public boolean recordVisibility(Visibility visibility) {
251 if (currentInfo.getVisibility() == null) {
252 populated = true;
253 currentInfo.setVisibility(visibility);
254 return true;
255 } else {
256 return false;
257 }
258 }
259
260 /**
261 * Records a typed parameter.
262 *
263 * @return {@code true} if the typed parameter was recorded and
264 * {@code false} if a parameter with the same name was already defined
265 */
266 public boolean recordParameter(String parameterName, JSTypeExpression type) {
267 if (!hasAnySingletonTypeTags() &&
268 currentInfo.declareParam(type, parameterName)) {
269 populated = true;
270 return true;
271 } else {
272 return false;
273 }
274 }
275
276 /**
277 * Records a parameter's description.
278 *
279 * @return {@code true} if the parameter's description was recorded and
280 * {@code false} if a parameter with the same name was already defined
281 */
282 public boolean recordParameterDescription(
283 String parameterName, String description) {
284 if (currentInfo.documentParam(parameterName, description)) {
285 populated = true;
286 return true;
287 } else {
288 return false;
289 }
290 }
291
292 /**
293 * Records a template type name.
294 *
295 * @return {@code true} if the template type name was recorded and
296 * {@code false} if a template type name was already defined.
297 */
298 public boolean recordTemplateTypeNames(List<String> names) {
299 if (currentInfo.declareTemplateTypeNames(names)) {
300 populated = true;
301 return true;
302 } else {
303 return false;
304 }
305 }
306
307 /**
308 * Records a template type name.
309 *
310 * @return {@code true} if the template type name was recorded and
311 * {@code false} if a template type name was already defined.
312 */
313 public boolean recordClassTemplateTypeNames(List<String> names) {
314 if (currentInfo.declareClassTemplateTypeNames(names)) {
315 populated = true;
316 return true;
317 } else {
318 return false;
319 }
320 }
321
322
323 /**
324 * Records a thrown type.
325 */
326 public boolean recordThrowType(JSTypeExpression type) {
327 if (!hasAnySingletonTypeTags()) {
328 currentInfo.declareThrows(type);
329 populated = true;
330 return true;
331 }
332 return false;
333 }
334
335 /**
336 * Records a throw type's description.
337 *
338 * @return {@code true} if the type's description was recorded and
339 * {@code false} if a description with the same type was already defined
340 */
341 public boolean recordThrowDescription(
342 JSTypeExpression type, String description) {
343 if (currentInfo.documentThrows(type, description)) {
344 populated = true;
345 return true;
346 } else {
347 return false;
348 }
349 }
350
351
352 /**
353 * Adds an author to the current information.
354 */
355 public boolean addAuthor(String author) {
356 if (currentInfo.documentAuthor(author)) {
357 populated = true;
358 return true;
359 } else {
360 return false;
361 }
362 }
363
364
365 /**
366 * Adds a reference ("@see") to the current information.
367 */
368 public boolean addReference(String reference) {
369 if (currentInfo.documentReference(reference)) {
370 populated = true;
371 return true;
372 } else {
373 return false;
374 }
375 }
376
377 /**
378 * Records that the {@link JSDocInfo} being built should have its
379 * {@link JSDocInfo#isConsistentIdGenerator()} flag set to
380 * {@code true}.
381 *
382 * @return {@code true} if the consistentIdGenerator flag was recorded and
383 * {@code false} if it was already recorded
384 */
385 public boolean recordConsistentIdGenerator() {
386 if (!currentInfo.isConsistentIdGenerator()) {
387 currentInfo.setConsistentIdGenerator(true);
388 populated = true;
389 return true;
390 } else {
391 return false;
392 }
393 }
394
395 /**
396 * Records that the {@link JSDocInfo} being built should have its {@link
397 * JSDocInfo#isStableIdGenerator()} flag set to {@code true}.
398 *
399 * @return {@code true} if the stableIdGenerator flag was recorded and {@code false} if it was
400 * already recorded.
401 */
402 public boolean recordStableIdGenerator() {
403 if (!currentInfo.isStableIdGenerator()) {
404 currentInfo.setStableIdGenerator(true);
405 populated = true;
406 return true;
407 } else {
408 return false;
409 }
410 }
411
412 /**
413 * Records the version.
414 */
415 public boolean recordVersion(String version) {
416 if (currentInfo.documentVersion(version)) {
417 populated = true;
418 return true;
419 } else {
420 return false;
421 }
422 }
423
424 /**
425 * Records the deprecation reason.
426 */
427 public boolean recordDeprecationReason(String reason) {
428 if (currentInfo.setDeprecationReason(reason)) {
429 populated = true;
430 return true;
431 } else {
432 return false;
433 }
434 }
435
436 /**
437 * Records the list of suppressed warnings.
438 */
439 public boolean recordSuppressions(Set<String> suppressions) {
440 if (currentInfo.setSuppressions(suppressions)) {
441 populated = true;
442 return true;
443 } else {
444 return false;
445 }
446 }
447
448 /**
449 * Records the list of modifies warnings.
450 */
451 public boolean recordModifies(Set<String> modifies) {
452 if (!hasAnySingletonSideEffectTags()
453 && currentInfo.setModifies(modifies)) {
454 populated = true;
455 return true;
456 } else {
457 return false;
458 }
459 }
460
461 /**
462 * Records a type.
463 *
464 * @return {@code true} if the type was recorded and {@code false} if
465 * it is invalid or was already defined
466 */
467 public boolean recordType(JSTypeExpression type) {
468 if (type != null && !hasAnyTypeRelatedTags()) {
469 currentInfo.setType(type);
470 populated = true;
471 return true;
472 } else {
473 return false;
474 }
475 }
476
477 /**
478 * Records that the {@link JSDocInfo} being built should be populated
479 * with a {@code typedef}'d type.
480 */
481 public boolean recordTypedef(JSTypeExpression type) {
482 if (type != null && !hasAnyTypeRelatedTags()) {
483 currentInfo.setTypedefType(type);
484 populated = true;
485 return true;
486 }
487 return false;
488 }
489
490 /**
491 * Records that the {@link JSDocInfo} being built should have its
492 * {@link JSDocInfo#isIdGenerator()} flag set to
493 * {@code true}.
494 *
495 * @return {@code true} if the idGenerator flag was recorded and {@code false}
496 * if it was already recorded
497 */
498 public boolean recordIdGenerator() {
499 if (!currentInfo.isIdGenerator()) {
500 currentInfo.setIdGenerator(true);
501 populated = true;
502 return true;
503 } else {
504 return false;
505 }
506 }
507
508 /**
509 * Records a return type.
510 *
511 * @return {@code true} if the return type was recorded and {@code false} if
512 * it is invalid or was already defined
513 */
514 public boolean recordReturnType(JSTypeExpression jsType) {
515 if (jsType != null && currentInfo.getReturnType() == null &&
516 !hasAnySingletonTypeTags()) {
517 currentInfo.setReturnType(jsType);
518 populated = true;
519 return true;
520 } else {
521 return false;
522 }
523 }
524
525 /**
526 * Records a return description
527 *
528 * @return {@code true} if the return description was recorded and
529 * {@code false} if it is invalid or was already defined
530 */
531 public boolean recordReturnDescription(String description) {
532 if (currentInfo.documentReturn(description)) {
533 populated = true;
534 return true;
535 } else {
536 return false;
537 }
538 }
539
540 /**
541 * Records the type of a define.
542 *
543 * 'Define' values are special constants that may be manipulated by
544 * the compiler. They are designed to mimic the #define command in
545 * the C preprocessor.
546 */
547 public boolean recordDefineType(JSTypeExpression type) {
548 if (type != null &&
549 !currentInfo.isConstant() &&
550 !currentInfo.isDefine() &&
551 recordType(type)) {
552 currentInfo.setDefine(true);
553 populated = true;
554 return true;
555 } else {
556 return false;
557 }
558 }
559
560 /**
561 * Records a parameter type to an enum.
562 *
563 * @return {@code true} if the enum's parameter type was recorded and
564 * {@code false} if it was invalid or already defined
565 */
566 public boolean recordEnumParameterType(JSTypeExpression type) {
567 if (type != null && !hasAnyTypeRelatedTags()) {
568 currentInfo.setEnumParameterType(type);
569 populated = true;
570 return true;
571 } else {
572 return false;
573 }
574 }
575
576 /**
577 * Records a type for {@code @this} annotation.
578 *
579 * @return {@code true} if the type was recorded and
580 * {@code false} if it is invalid or if it collided with {@code @enum} or
581 * {@code @type} annotations
582 */
583 public boolean recordThisType(JSTypeExpression type) {
584 if (type != null && !hasAnySingletonTypeTags() &&
585 !currentInfo.hasThisType()) {
586 currentInfo.setThisType(type);
587 populated = true;
588 return true;
589 } else {
590 return false;
591 }
592 }
593
594 /**
595 * Records a base type.
596 *
597 * @return {@code true} if the base type was recorded and {@code false}
598 * if it was already defined
599 */
600 public boolean recordBaseType(JSTypeExpression jsType) {
601 if (jsType != null && !hasAnySingletonTypeTags() &&
602 !currentInfo.hasBaseType()) {
603 currentInfo.setBaseType(jsType);
604 populated = true;
605 return true;
606 } else {
607 return false;
608 }
609 }
610
611 /**
612 * Records that the {@link JSDocInfo} being built should have its
613 * {@link JSDocInfo#isConstant()} flag set to {@code true}.
614 *
615 * @return {@code true} if the constancy was recorded and {@code false}
616 * if it was already defined
617 */
618 public boolean recordConstancy() {
619 if (!currentInfo.isConstant()) {
620 currentInfo.setConstant(true);
621 populated = true;
622 return true;
623 } else {
624 return false;
625 }
626 }
627
628 /**
629 * Records a description giving context for translation (i18n).
630 *
631 * @return {@code true} if the description was recorded and {@code false}
632 * if the description was invalid or was already defined
633 */
634 public boolean recordDescription(String description) {
635 if (description != null && currentInfo.getDescription() == null) {
636 currentInfo.setDescription(description);
637 populated = true;
638 return true;
639 } else {
640 return false;
641 }
642 }
643
644 /**
645 * Records a meaning giving context for translation (i18n). Different
646 * meanings will result in different translations.
647 *
648 * @return {@code true} If the meaning was successfully updated.
649 */
650 public boolean recordMeaning(String meaning) {
651 if (meaning != null && currentInfo.getMeaning() == null) {
652 currentInfo.setMeaning(meaning);
653 populated = true;
654 return true;
655 } else {
656 return false;
657 }
658 }
659
660 /**
661 * Records a fileoverview description.
662 *
663 * @return {@code true} if the description was recorded and {@code false}
664 * if the description was invalid or was already defined.
665 */
666 public boolean recordFileOverview(String description) {
667 if (currentInfo.documentFileOverview(description)) {
668 populated = true;
669 return true;
670 } else {
671 return false;
672 }
673 }
674
675 /**
676 * Records that the {@link JSDocInfo} being built should have its
677 * {@link JSDocInfo#isHidden()} flag set to {@code true}.
678 *
679 * @return {@code true} if the hiddenness was recorded and {@code false}
680 * if it was already defined
681 */
682 public boolean recordHiddenness() {
683 if (!currentInfo.isHidden()) {
684 currentInfo.setHidden(true);
685 populated = true;
686 return true;
687 } else {
688 return false;
689 }
690 }
691
692 /**
693 * Records that the {@link JSDocInfo} being built should have its
694 * {@link JSDocInfo#isNoCompile()} flag set to {@code true}.
695 *
696 * @return {@code true} if the no compile flag was recorded and {@code false}
697 * if it was already recorded
698 */
699 public boolean recordNoCompile() {
700 if (!currentInfo.isNoCompile()) {
701 currentInfo.setNoCompile(true);
702 populated = true;
703 return true;
704 } else {
705 return false;
706 }
707 }
708
709 /**
710 * Records that the {@link JSDocInfo} being built should have its
711 * {@link JSDocInfo#isNoTypeCheck()} flag set to {@code true}.
712 *
713 * @return {@code true} if the no check flag was recorded and {@code false}
714 * if it was already recorded
715 */
716 public boolean recordNoTypeCheck() {
717 if (!currentInfo.isNoTypeCheck()) {
718 currentInfo.setNoCheck(true);
719 populated = true;
720 return true;
721 } else {
722 return false;
723 }
724 }
725
726 /**
727 * Records that the {@link JSDocInfo} being built should have its
728 * {@link JSDocInfo#isConstructor()} flag set to {@code true}.
729 *
730 * @return {@code true} if the constructor was recorded and {@code false}
731 * if it was already defined or it was incompatible with the existing
732 * flags
733 */
734 public boolean recordConstructor() {
735 if (!hasAnySingletonTypeTags() &&
736 !currentInfo.isConstructor() && !currentInfo.isInterface()) {
737 currentInfo.setConstructor(true);
738 populated = true;
739 return true;
740 } else {
741 return false;
742 }
743 }
744
745 /**
746 * Whether the {@link JSDocInfo} being built will have its
747 * {@link JSDocInfo#isConstructor()} flag set to {@code true}.
748 */
749 public boolean isConstructorRecorded() {
750 return currentInfo.isConstructor();
751 }
752
753 /**
754 * Records that the {@link JSDocInfo} being built should have its
755 * {@link JSDocInfo#makesStructs()} flag set to {@code true}.
756 *
757 * @return {@code true} if the struct was recorded and {@code false}
758 * if it was already defined or it was incompatible with the existing flags
759 */
760 public boolean recordStruct() {
761 if (hasAnySingletonTypeTags() || currentInfo.isInterface() ||
762 currentInfo.makesDicts() || currentInfo.makesStructs()) {
763 return false;
764 }
765 currentInfo.setStruct();
766 populated = true;
767 return true;
768 }
769
770 /**
771 * Records that the {@link JSDocInfo} being built should have its
772 * {@link JSDocInfo#makesDicts()} flag set to {@code true}.
773 *
774 * @return {@code true} if the dict was recorded and {@code false}
775 * if it was already defined or it was incompatible with the existing flags
776 */
777 public boolean recordDict() {
778 if (hasAnySingletonTypeTags() || currentInfo.isInterface() ||
779 currentInfo.makesDicts() || currentInfo.makesStructs()) {
780 return false;
781 }
782 currentInfo.setDict();
783 populated = true;
784 return true;
785 }
786
787 /**
788 * Records that the {@link JSDocInfo} being built should have its
789 * {@link JSDocInfo#isJavaDispatch()} flag set to {@code true}.
790 *
791 * @return {@code true} if the javadispatch was recorded and {@code false}
792 * if it was already defined or it was incompatible with the existing
793 * flags
794 */
795 public boolean recordJavaDispatch() {
796 if (!currentInfo.isJavaDispatch()) {
797 currentInfo.setJavaDispatch(true);
798 populated = true;
799 return true;
800 } else {
801 return false;
802 }
803 }
804
805 /**
806 * Whether the {@link JSDocInfo} being built will have its
807 * {@link JSDocInfo#isJavaDispatch()} flag set to {@code true}.
808 */
809 public boolean isJavaDispatch() {
810 return currentInfo.isJavaDispatch();
811 }
812
813 /**
814 * Records that the {@link JSDocInfo} being built should have its
815 * {@link JSDocInfo#shouldPreserveTry()} flag set to {@code true}.
816 */
817 public boolean recordPreserveTry() {
818 if (!currentInfo.shouldPreserveTry()) {
819 currentInfo.setShouldPreserveTry(true);
820 populated = true;
821 return true;
822 } else {
823 return false;
824 }
825 }
826
827 /**
828 * Records that the {@link JSDocInfo} being built should have its
829 * {@link JSDocInfo#isOverride()} flag set to {@code true}.
830 */
831 public boolean recordOverride() {
832 if (!currentInfo.isOverride()) {
833 currentInfo.setOverride(true);
834 populated = true;
835 return true;
836 } else {
837 return false;
838 }
839 }
840
841 /**
842 * Records that the {@link JSDocInfo} being built should have its
843 * {@link JSDocInfo#isNoAlias()} flag set to {@code true}.
844 */
845 public boolean recordNoAlias() {
846 if (!currentInfo.isNoAlias()) {
847 currentInfo.setNoAlias(true);
848 populated = true;
849 return true;
850 } else {
851 return false;
852 }
853 }
854
855 /**
856 * Records that the {@link JSDocInfo} being built should have its
857 * {@link JSDocInfo#isDeprecated()} flag set to {@code true}.
858 */
859 public boolean recordDeprecated() {
860 if (!currentInfo.isDeprecated()) {
861 currentInfo.setDeprecated(true);
862 populated = true;
863 return true;
864 } else {
865 return false;
866 }
867 }
868
869 /**
870 * Records that the {@link JSDocInfo} being built should have its
871 * {@link JSDocInfo#isInterface()} flag set to {@code true}.
872 *
873 * @return {@code true} if the flag was recorded and {@code false}
874 * if it was already defined or it was incompatible with the existing flags
875 */
876 public boolean recordInterface() {
877 if (hasAnySingletonTypeTags() ||
878 currentInfo.makesStructs() || currentInfo.makesDicts() ||
879 currentInfo.isConstructor() || currentInfo.isInterface()) {
880 return false;
881 }
882 currentInfo.setInterface(true);
883 populated = true;
884 return true;
885 }
886
887 /**
888 * Records that the {@link JSDocInfo} being built should have its
889 * {@link JSDocInfo#isExport()} flag set to {@code true}.
890 */
891 public boolean recordExport() {
892 if (!currentInfo.isExport()) {
893 currentInfo.setExport(true);
894 populated = true;
895 return true;
896 } else {
897 return false;
898 }
899 }
900
901 /**
902 * Records that the {@link JSDocInfo} being built should have its
903 * {@link JSDocInfo#isExpose()} flag set to {@code true}.
904 */
905 public boolean recordExpose() {
906 if (!currentInfo.isExpose()) {
907 currentInfo.setExpose(true);
908 populated = true;
909 return true;
910 } else {
911 return false;
912 }
913 }
914
915 /**
916 * Records that the {@link JSDocInfo} being built should have its
917 * {@link JSDocInfo#isNoShadow()} flag set to {@code true}.
918 */
919 public boolean recordNoShadow() {
920 if (!currentInfo.isNoShadow()) {
921 currentInfo.setNoShadow(true);
922 populated = true;
923 return true;
924 } else {
925 return false;
926 }
927 }
928
929 /**
930 * Records that the {@link JSDocInfo} being built should have its
931 * {@link JSDocInfo#isImplicitCast()} flag set to {@code true}.
932 */
933 public boolean recordImplicitCast() {
934 if (!currentInfo.isImplicitCast()) {
935 currentInfo.setImplicitCast(true);
936 populated = true;
937 return true;
938 } else {
939 return false;
940 }
941 }
942
943 /**
944 * Records that the {@link JSDocInfo} being built should have its
945 * {@link JSDocInfo#isNoSideEffects()} flag set to {@code true}.
946 */
947 public boolean recordNoSideEffects() {
948 if (!hasAnySingletonSideEffectTags()
949 && !currentInfo.isNoSideEffects()) {
950 currentInfo.setNoSideEffects(true);
951 populated = true;
952 return true;
953 } else {
954 return false;
955 }
956 }
957
958 /**
959 * Records that the {@link JSDocInfo} being built should have its
960 * {@link JSDocInfo#isExterns()} flag set to {@code true}.
961 */
962 public boolean recordExterns() {
963 if (!currentInfo.isExterns()) {
964 currentInfo.setExterns(true);
965 populated = true;
966 return true;
967 } else {
968 return false;
969 }
970 }
971
972 /**
973 * Whether the {@link JSDocInfo} being built will have its
974 * {@link JSDocInfo#isInterface()} flag set to {@code true}.
975 */
976 public boolean isInterfaceRecorded() {
977 return currentInfo.isInterface();
978 }
979
980 /**
981 * @return Whether a parameter of the given name has already been recorded.
982 */
983 public boolean hasParameter(String name) {
984 return currentInfo.hasParameter(name);
985 }
986
987 /**
988 * Records an implemented interface.
989 */
990 public boolean recordImplementedInterface(JSTypeExpression interfaceName) {
991 if (currentInfo.addImplementedInterface(interfaceName)) {
992 populated = true;
993 return true;
994 } else {
995 return false;
996 }
997 }
998
999 /**
1000 * Records an extended interface type.
1001 */
1002 public boolean recordExtendedInterface(JSTypeExpression interfaceType) {
1003 if (currentInfo.addExtendedInterface(interfaceType)) {
1004 populated = true;
1005 return true;
1006 } else {
1007 return false;
1008 }
1009 }
1010
1011 /**
1012 * Records that we're lending to another name.
1013 */
1014 public boolean recordLends(String name) {
1015 if (!hasAnyTypeRelatedTags()) {
1016 currentInfo.setLendsName(name);
1017 populated = true;
1018 return true;
1019 } else {
1020 return false;
1021 }
1022 }
1023
1024 /**
1025 * Returns whether current JSDoc is annotated with {@code @ngInject}.
1026 */
1027 public boolean isNgInjectRecorded() {
1028 return currentInfo.isNgInject();
1029 }
1030
1031 /**
1032 * Records that we'd like to add {@code $inject} property inferred from
1033 * parameters.
1034 */
1035 public boolean recordNgInject(boolean ngInject) {
1036 if (!isNgInjectRecorded()) {
1037 currentInfo.setNgInject(ngInject);
1038 populated = true;
1039 return true;
1040 } else {
1041 return false;
1042 }
1043 }
1044
1045 /**
1046 * Whether the current doc info has other type tags, like
1047 * {@code @param} or {@code @return} or {@code @type} or etc.
1048 */
1049 private boolean hasAnyTypeRelatedTags() {
1050 return currentInfo.isConstructor() ||
1051 currentInfo.isInterface() ||
1052 currentInfo.getParameterCount() > 0 ||
1053 currentInfo.hasReturnType() ||
1054 currentInfo.hasBaseType() ||
1055 currentInfo.getExtendedInterfacesCount() > 0 ||
1056 currentInfo.getLendsName() != null ||
1057 currentInfo.hasThisType() ||
1058 hasAnySingletonTypeTags();
1059 }
1060
1061 /**
1062 * Whether the current doc info has any of the singleton type
1063 * tags that may not appear with other type tags, like
1064 * {@code @type} or {@code @typedef}.
1065 */
1066 private boolean hasAnySingletonTypeTags() {
1067 return currentInfo.hasType() ||
1068 currentInfo.hasTypedefType() ||
1069 currentInfo.hasEnumParameterType();
1070 }
1071
1072 /**
1073 * Whether the current doc info has any of the singleton type
1074 * tags that may not appear with other type tags, like
1075 * {@code @type} or {@code @typedef}.
1076 */
1077 private boolean hasAnySingletonSideEffectTags() {
1078 return currentInfo.isNoSideEffects() ||
1079 currentInfo.hasModifies();
1080 }
1081
1082 }