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

COVERAGE SUMMARY FOR SOURCE FILE [LabeledStatement.java]

nameclass, %method, %block, %line, %
LabeledStatement.java100% (1/1)75%  (6/8)74%  (69/93)65%  (12.4/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LabeledStatement100% (1/1)75%  (6/8)74%  (69/93)65%  (12.4/19)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
LabeledStatement (FilePosition, String, Class): void 100% (1/1)75%  (12/16)92%  (3.7/4)
breaks (Map): void 0%   (0/1)0%   (0/9)0%   (0/3)
continues (Map): void 0%   (0/1)0%   (0/9)0%   (0/3)
getLabel (): String 100% (1/1)100% (3/3)100% (1/1)
getRenderedLabel (RenderContext): String 100% (1/1)100% (23/23)100% (4/4)
getValue (): Object 100% (1/1)100% (3/3)100% (1/1)
wrapIfLabelled (JsonML): JsonML 100% (1/1)100% (22/22)100% (2/2)

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.escaping.Escaping;
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.TagAttr;
23import com.google.javascript.jscomp.jsonml.TagType;
24 
25import java.util.List;
26import java.util.Map;
27 
28/**
29 * A statement with a label, such as
30 * <code>label: for (...) { ... }</code>.
31 *
32 * <p>Javascript bizarrely allows labels on any statements, but the labels are
33 * only useful when applied to loops or switches.</p>
34 *
35 * <p>The empty string is the default label, so <code>break;</code> breaks with
36 * label <code>""</code>.</p>
37 *
38 * @author mikesamuel@gmail.com
39 */
40public abstract class LabeledStatement extends AbstractStatement {
41  private final String label;
42 
43  protected LabeledStatement(
44      FilePosition pos,
45      String label, Class<? extends ParseTreeNode> childClass) {
46    super(pos, childClass);
47    assert label != null;
48    this.label = label;
49  }
50 
51  public String getLabel() { return label; }
52 
53  /**
54   * Is the statement a target for a {@link ContinueStmt continue}?
55   * For example, {@code switch} statements can be broken from, but since they
56   * are not loops, they cannot be continued to.
57   */
58  public abstract boolean isTargetForContinue();
59 
60  @Override
61  public void breaks(Map<String, List<BreakStmt>> labels) {
62    super.breaks(labels);
63    labels.remove(this.label);
64  }
65 
66  @Override
67  public void continues(Map<String, List<ContinueStmt>> labels) {
68    super.continues(labels);
69    labels.remove(this.label);
70  }
71 
72  @Override
73  public final Object getValue() { return this.label; }
74 
75  /** @return null if no label to render. */
76  protected final String getRenderedLabel(RenderContext rc) {
77    if (label == null || "".equals(label)) { return null; }
78    StringBuilder escapedLabel = new StringBuilder();
79    Escaping.escapeJsIdentifier(label, rc.isAsciiOnly(), escapedLabel);
80    return escapedLabel.toString();
81  }
82 
83  protected JsonML wrapIfLabelled(JsonML unlabelled) {
84    if (label == null || "".equals(label)) { return unlabelled; }
85    return JsonMLBuilder.builder(TagType.LabelledStmt, getFilePosition())
86        .setAttribute(TagAttr.LABEL, label)
87        .addChild(unlabelled)
88        .build();
89  }
90}

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