PageRenderTime 30ms CodeModel.GetById 14ms 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
Possible License(s): Apache-2.0
  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. */
  16. package com.google.test.metric.cpp;
  17. import com.google.test.metric.Visibility;
  18. import com.google.test.metric.cpp.dom.ClassDeclaration;
  19. import com.google.test.metric.cpp.dom.Node;
  20. import com.google.test.metric.cpp.dom.VariableDeclaration;
  21. import java.util.List;
  22. class ClassBuilder extends DefaultBuilder {
  23. private final ClassDeclaration node;
  24. private Visibility currentVisibility;
  25. private List<String> sts;
  26. public ClassBuilder(Node parent, String identifier) {
  27. node = new ClassDeclaration(identifier);
  28. parent.addChild(node);
  29. currentVisibility = Visibility.PRIVATE;
  30. }
  31. @Override
  32. void setContext(BuilderContext context) {
  33. super.setContext(context);
  34. context.registerNode(node.getQualifiedName(), node);
  35. }
  36. @Override
  37. public void beginBaseSpecifier() {
  38. pushBuilder(new BaseClassBuilder(node));
  39. }
  40. @Override
  41. public void beginClassDefinition(String type, String identifier) {
  42. pushBuilder(new ClassBuilder(node, identifier));
  43. }
  44. @Override
  45. public void endClassDefinition() {
  46. finished();
  47. }
  48. @Override
  49. public void beginFunctionDefinition(int line) {
  50. pushBuilder(new FunctionDefinitionBuilder(node, line, currentVisibility));
  51. }
  52. @Override
  53. public void beginFunctionDeclaration() {
  54. pushBuilder(new FunctionDeclarationBuilder(node, currentVisibility));
  55. }
  56. @Override
  57. public void accessSpecifier(String accessSpec) {
  58. currentVisibility = visibilityFromCppString(accessSpec);
  59. }
  60. @Override
  61. public void beginMemberDeclaration() {
  62. }
  63. @Override
  64. public void endMemberDeclaration() {
  65. }
  66. private Visibility visibilityFromCppString(String access) {
  67. if (access.equals("public")) {
  68. return Visibility.PUBLIC;
  69. } else if (access.equals("protected")) {
  70. return Visibility.PROTECTED;
  71. } else if (access.equals("private")) {
  72. return Visibility.PRIVATE;
  73. }
  74. throw new IllegalArgumentException("invalid access specifier");
  75. }
  76. @Override
  77. public void simpleTypeSpecifier(List<String> sts) {
  78. this.sts = sts;
  79. }
  80. @Override
  81. public void directDeclarator(String id) {
  82. Node child = new VariableDeclaration(sts.get(0), id);
  83. node.addChild(child);
  84. }
  85. }