EMMA Coverage Report (generated Mon Nov 01 16:48:29 PDT 2010)
[all classes][com.google.caja.parser.js]

COVERAGE SUMMARY FOR SOURCE FILE [FunctionDeclaration.java]

nameclass, %method, %block, %line, %
FunctionDeclaration.java100% (1/1)100% (7/7)92%  (109/119)94%  (29/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FunctionDeclaration100% (1/1)100% (7/7)92%  (109/119)94%  (29/31)
FunctionDeclaration (FilePosition, Void, List): void 100% (1/1)100% (6/6)100% (2/2)
FunctionDeclaration (FunctionConstructor): void 100% (1/1)100% (10/10)100% (2/2)
childrenChanged (): void 100% (1/1)60%  (15/25)71%  (5/7)
getInitializer (): FunctionConstructor 100% (1/1)100% (4/4)100% (1/1)
isTerminal (): boolean 100% (1/1)100% (5/5)100% (1/1)
render (RenderContext): void 100% (1/1)100% (54/54)100% (15/15)
toJsonML (): JsonML 100% (1/1)100% (15/15)100% (3/3)

1// Copyright (C) 2005 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package com.google.caja.parser.js;
16 
17import com.google.caja.lexer.FilePosition;
18import com.google.caja.lexer.TokenConsumer;
19import com.google.caja.parser.ParseTreeNode;
20import com.google.caja.reporting.RenderContext;
21import com.google.javascript.jscomp.jsonml.JsonML;
22import com.google.javascript.jscomp.jsonml.TagType;
23 
24import java.util.List;
25 
26/**
27 * A top level statement that declares a variable and assigns a function to it.
28 *
29 * @author mikesamuel@gmail.com
30 */
31public final class FunctionDeclaration extends Declaration {
32  @ReflectiveCtor
33  public FunctionDeclaration(
34      FilePosition pos, Void value, List<? extends ParseTreeNode> children) {
35    super(pos, value, children);
36  }
37 
38  public FunctionDeclaration(
39      FunctionConstructor initializer) {
40    super(initializer.getFilePosition(),
41          (Identifier) initializer.getIdentifier().clone(),
42          initializer);
43  }
44 
45  @Override
46  protected void childrenChanged() {
47    super.childrenChanged();
48    FunctionConstructor initializer = getInitializer();  // Checks class.
49    if (null == initializer) {
50      throw new NullPointerException(
51          "Function declaration missing function");
52    }
53    if (!getIdentifierName().equals(initializer.getIdentifierName())) {
54      throw new IllegalStateException("Name mismatch");
55    }
56  }
57 
58  @Override
59  public FunctionConstructor getInitializer() {
60    return (FunctionConstructor) super.getInitializer();
61  }
62 
63  @Override
64  public boolean isTerminal() {
65    return getInitializer().getBody().isTerminal();
66  }
67 
68  @Override
69  public void render(RenderContext rc) {
70    FunctionConstructor fc = getInitializer();
71    TokenConsumer out = rc.getOut();
72    out.mark(getFilePosition());
73    out.consume("function");
74    getIdentifier().render(rc);
75    out.consume("(");
76    boolean seen = false;
77    for (FormalParam p : fc.getParams()) {
78      if (seen) {
79        out.consume(",");
80      } else {
81        seen = true;
82      }
83      p.render(rc);
84    }
85    out.consume(")");
86    fc.getBody().renderBlock(rc, false);
87  }
88 
89  @Override
90  public JsonML toJsonML() {
91    FunctionConstructor fc = getInitializer();
92    JsonML exprJsonMl = fc.toJsonML();
93    return new JsonML(
94        TagType.FunctionDecl, exprJsonMl.getAttributes(),
95        exprJsonMl.getChildren());
96  }
97}

[all classes][com.google.caja.parser.js]
EMMA 2.0.5312 (C) Vladimir Roubtsov