PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/cpp/src/main/java/com/google/test/metric/cpp/ClassBuilder.java

http://testability-explorer.googlecode.com/
Java | 101 lines | 70 code | 16 blank | 15 comment | 5 complexity | 8f34cd1e9b06f331f4fd9d5e90cc5f59 MD5 | raw file
  1/*
  2 * Copyright 2008 Google Inc.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 * use this file except in compliance with the License. You may obtain a copy of
  6 * the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13 * License for the specific language governing permissions and limitations under
 14 * the License.
 15 */
 16package com.google.test.metric.cpp;
 17
 18import com.google.test.metric.Visibility;
 19import com.google.test.metric.cpp.dom.ClassDeclaration;
 20import com.google.test.metric.cpp.dom.Node;
 21import com.google.test.metric.cpp.dom.VariableDeclaration;
 22
 23import java.util.List;
 24
 25class ClassBuilder extends DefaultBuilder {
 26  private final ClassDeclaration node;
 27  private Visibility currentVisibility;
 28  private List<String> sts;
 29
 30  public ClassBuilder(Node parent, String identifier) {
 31    node = new ClassDeclaration(identifier);
 32    parent.addChild(node);
 33    currentVisibility = Visibility.PRIVATE;
 34  }
 35
 36  @Override
 37  void setContext(BuilderContext context) {
 38    super.setContext(context);
 39    context.registerNode(node.getQualifiedName(), node);
 40  }
 41
 42  @Override
 43  public void beginBaseSpecifier() {
 44    pushBuilder(new BaseClassBuilder(node));
 45  }
 46
 47  @Override
 48  public void beginClassDefinition(String type, String identifier) {
 49    pushBuilder(new ClassBuilder(node, identifier));
 50  }
 51
 52  @Override
 53  public void endClassDefinition() {
 54    finished();
 55  }
 56
 57  @Override
 58  public void beginFunctionDefinition(int line) {
 59    pushBuilder(new FunctionDefinitionBuilder(node, line, currentVisibility));
 60  }
 61
 62  @Override
 63  public void beginFunctionDeclaration() {
 64    pushBuilder(new FunctionDeclarationBuilder(node, currentVisibility));
 65  }
 66
 67  @Override
 68  public void accessSpecifier(String accessSpec) {
 69    currentVisibility = visibilityFromCppString(accessSpec);
 70  }
 71
 72  @Override
 73  public void beginMemberDeclaration() {
 74  }
 75
 76  @Override
 77  public void endMemberDeclaration() {
 78  }
 79
 80  private Visibility visibilityFromCppString(String access) {
 81    if (access.equals("public")) {
 82      return Visibility.PUBLIC;
 83    } else if (access.equals("protected")) {
 84      return Visibility.PROTECTED;
 85    } else if (access.equals("private")) {
 86      return Visibility.PRIVATE;
 87    }
 88    throw new IllegalArgumentException("invalid access specifier");
 89  }
 90
 91  @Override
 92  public void simpleTypeSpecifier(List<String> sts) {
 93    this.sts = sts;
 94  }
 95
 96  @Override
 97  public void directDeclarator(String id) {
 98    Node child = new VariableDeclaration(sts.get(0), id);
 99    node.addChild(child);
100  }
101}