EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.bnf]

COVERAGE SUMMARY FOR SOURCE FILE [RuleElement.java]

nameclass, %method, %block, %line, %
RuleElement.java100% (1/1)100% (4/4)88%  (152/173)94%  (34/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RuleElement100% (1/1)100% (4/4)88%  (152/173)94%  (34/36)
setLinks (HashMap): void 100% (1/1)62%  (35/56)83%  (10/12)
RuleElement (String, String): void 100% (1/1)100% (32/32)100% (6/6)
accept (BnfVisitor): void 100% (1/1)100% (9/9)100% (2/2)
autoComplete (Sentence): boolean 100% (1/1)100% (76/76)100% (16/16)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.bnf;
7 
8import java.util.HashMap;
9 
10import org.h2.util.StringUtils;
11 
12/**
13 * A single terminal rule in a BNF object.
14 */
15public class RuleElement implements Rule {
16 
17    private final boolean keyword;
18    private final String name;
19    private Rule link;
20    private final int type;
21 
22    public RuleElement(String name, String topic) {
23        this.name = name;
24        this.keyword = name.length() == 1 ||
25                name.equals(StringUtils.toUpperEnglish(name));
26        topic = StringUtils.toLowerEnglish(topic);
27        this.type = topic.startsWith("function") ?
28                Sentence.FUNCTION : Sentence.KEYWORD;
29    }
30 
31    @Override
32    public void accept(BnfVisitor visitor) {
33        visitor.visitRuleElement(keyword, name, link);
34    }
35 
36    @Override
37    public void setLinks(HashMap<String, RuleHead> ruleMap) {
38        if (link != null) {
39            link.setLinks(ruleMap);
40        }
41        if (keyword) {
42            return;
43        }
44        String test = Bnf.getRuleMapKey(name);
45        for (int i = 0; i < test.length(); i++) {
46            String t = test.substring(i);
47            RuleHead r = ruleMap.get(t);
48            if (r != null) {
49                link = r.getRule();
50                return;
51            }
52        }
53        throw new AssertionError("Unknown " + name + "/" + test);
54    }
55 
56    @Override
57    public boolean autoComplete(Sentence sentence) {
58        sentence.stopIfRequired();
59        if (keyword) {
60            String query = sentence.getQuery();
61            String q = query.trim();
62            String up = sentence.getQueryUpper().trim();
63            if (up.startsWith(name)) {
64                query = query.substring(name.length());
65                while (!"_".equals(name) && Bnf.startWithSpace(query)) {
66                    query = query.substring(1);
67                }
68                sentence.setQuery(query);
69                return true;
70            } else if (q.length() == 0 || name.startsWith(up)) {
71                if (q.length() < name.length()) {
72                    sentence.add(name, name.substring(q.length()), type);
73                }
74            }
75            return false;
76        }
77        return link.autoComplete(sentence);
78    }
79 
80}

[all classes][org.h2.bnf]
EMMA 2.0.5312 (C) Vladimir Roubtsov