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

COVERAGE SUMMARY FOR SOURCE FILE [SingleOptionalIdentifierQuasiNode.java]

nameclass, %method, %block, %line, %
SingleOptionalIdentifierQuasiNode.java100% (1/1)100% (3/3)96%  (53/55)96%  (10.6/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SingleOptionalIdentifierQuasiNode100% (1/1)100% (3/3)96%  (53/55)96%  (10.6/11)
SingleOptionalIdentifierQuasiNode (QuasiNode): void 100% (1/1)100% (8/8)100% (1/1)
consumeSpecimens (List, Map): boolean 100% (1/1)93%  (27/29)93%  (5.6/6)
createSubstitutes (List, Map): boolean 100% (1/1)100% (18/18)100% (4/4)

1// Copyright (C) 2008 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.quasiliteral;
16 
17import com.google.caja.lexer.FilePosition;
18import com.google.caja.parser.ParseTreeNode;
19import com.google.caja.parser.js.Identifier;
20 
21import java.util.List;
22import java.util.Map;
23 
24/**
25 * A quasi-hole that matches an identifier with a null value.
26 * @author mikesamuel@gmail.com
27 */
28final class SingleOptionalIdentifierQuasiNode extends QuasiNode {
29  private final QuasiNode qn;
30 
31  SingleOptionalIdentifierQuasiNode(QuasiNode qn) { this.qn = qn; }
32 
33  @Override
34  protected boolean consumeSpecimens(
35      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
36    if (specimens.isEmpty()) { return false; }
37    ParseTreeNode specimen = specimens.get(0);
38    if (specimen instanceof Identifier && null == specimen.getValue()) {
39      specimens.remove(0);
40      return true;
41    }
42    return qn.consumeSpecimens(specimens, bindings);
43  }
44 
45  @Override
46  protected boolean createSubstitutes(
47      List<ParseTreeNode> substitutes, Map<String, ParseTreeNode> bindings) {
48    // Do we need to back out changes to bindings?
49    if (qn.createSubstitutes(substitutes, bindings)) {
50      return true;
51    } else {
52      substitutes.add(new Identifier(FilePosition.UNKNOWN, null));
53      return true;
54    }
55  }
56}

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