Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / scripts / jsdoc-validator / src / org / chromium / devtools / jsdoc / checks / FunctionRecord.java
1 package org.chromium.devtools.jsdoc.checks;
2
3 import com.google.javascript.jscomp.NodeUtil;
4 import com.google.javascript.rhino.JSDocInfo;
5 import com.google.javascript.rhino.Node;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 public class FunctionRecord {
11     final Node functionNode;
12     final JSDocInfo info;
13     final String name;
14     final List<String> parameterNames;
15     final TypeRecord enclosingType;
16     final FunctionRecord enclosingFunctionRecord;
17
18     public FunctionRecord(Node functionNode, String name,
19             List<String> parameterNames, TypeRecord parentType,
20             FunctionRecord enclosingFunctionRecord) {
21         this.functionNode = functionNode;
22         this.info = NodeUtil.getBestJSDocInfo(functionNode);
23         this.name = name;
24         this.parameterNames = parameterNames;
25         this.enclosingType = parentType;
26         this.enclosingFunctionRecord = enclosingFunctionRecord;
27     }
28
29     public FunctionRecord() {
30         this.functionNode = null;
31         this.info = null;
32         this.name = "";
33         this.parameterNames = new ArrayList<>();
34         this.enclosingType = null;
35         this.enclosingFunctionRecord = null;
36     }
37
38     public boolean isConstructor() {
39         return info != null && info.isConstructor();
40     }
41
42     public boolean isTopLevelFunction() {
43         return enclosingFunctionRecord == null;
44     }
45
46     public boolean hasReturnAnnotation() {
47         return info != null && info.getReturnType() != null;
48     }
49
50     public boolean hasThisAnnotation() {
51         return info != null && info.getThisType() != null;
52     }
53
54     public boolean suppressesReceiverCheck() {
55         return info != null && info.getOriginalCommentString().contains("@suppressReceiverCheck");
56     }
57
58     public boolean suppressesGlobalPropertiesCheck() {
59         return info != null
60             && info.getOriginalCommentString().contains("@suppressGlobalPropertiesCheck");
61     }
62
63     @Override
64     public String toString() {
65         return (info == null ? "" : info.getOriginalCommentString() + "\n") +
66                 (name == null ? "<anonymous>" : name) + "() @" +
67                 functionNode.getLineno();
68     }
69 }