~ohdeno/+junk/closure-compiler-svn-trunk

« back to all changes in this revision

Viewing changes to src/com/google/javascript/jscomp/FunctionTypeBuilder.java

  • Committer: dimvar at google
  • Date: 2012-09-11 18:10:32 UTC
  • Revision ID: svn-v4:b0f006be-c8cd-11de-a2e8-8d36a3108c74:trunk:2181

New @struct and @dict annotations for constructors.
With these annotations, one can enforce only dot or only bracket access on object properties.

R=nicksantos
DELTA=476  (391 added, 34 deleted, 51 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5488

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
  private ObjectType baseType = null;
86
86
  private ObjectType thisType = null;
87
87
  private boolean isConstructor = false;
 
88
  private boolean makesStructs = false;
 
89
  private boolean makesDicts = false;
88
90
  private boolean isInterface = false;
89
91
  private Node parametersNode = null;
90
92
  private ImmutableList<String> templateTypeNames = ImmutableList.of();
106
108
          "JSC_IMPLEMENTS_WITHOUT_CONSTRUCTOR",
107
109
          "@implements used without @constructor or @interface for {0}");
108
110
 
 
111
  static final DiagnosticType CONSTRUCTOR_REQUIRED =
 
112
      DiagnosticType.warning("JSC_CONSTRUCTOR_REQUIRED",
 
113
                             "{0} used without @constructor for {1}");
 
114
 
109
115
  static final DiagnosticType VAR_ARGS_MUST_BE_LAST = DiagnosticType.warning(
110
116
      "JSC_VAR_ARGS_MUST_BE_LAST",
111
117
      "variable length argument must be last");
322
328
  FunctionTypeBuilder inferInheritance(@Nullable JSDocInfo info) {
323
329
    if (info != null) {
324
330
      isConstructor = info.isConstructor();
 
331
      makesStructs = info.makesStructs();
 
332
      makesDicts = info.makesDicts();
325
333
      isInterface = info.isInterface();
326
334
 
 
335
      if (makesStructs && !isConstructor) {
 
336
        reportWarning(CONSTRUCTOR_REQUIRED, "@struct", fnName);
 
337
      } else if (makesDicts && !isConstructor) {
 
338
        reportWarning(CONSTRUCTOR_REQUIRED, "@dict", fnName);
 
339
      }
 
340
 
327
341
      // base type
328
342
      if (info.hasBaseType()) {
329
343
        if (isConstructor) {
349
363
          }
350
364
        }
351
365
      } else if (info.getImplementedInterfaceCount() > 0) {
352
 
        reportWarning(IMPLEMENTS_WITHOUT_CONSTRUCTOR, fnName);
 
366
        reportWarning(CONSTRUCTOR_REQUIRED, "@implements", fnName);
353
367
      }
354
368
 
355
369
      // extended interfaces (for interface only)
664
678
        fnName, contents.getSourceNode(), parametersNode, returnType);
665
679
    JSType existingType = typeRegistry.getType(fnName);
666
680
 
 
681
    if (makesStructs) {
 
682
      fnType.setStruct();
 
683
    } else if (makesDicts) {
 
684
      fnType.setDict();
 
685
    }
667
686
    if (existingType != null) {
668
687
      boolean isInstanceObject = existingType.isInstanceType();
669
688
      if (isInstanceObject || fnName.equals("Function")) {