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

http://testability-explorer.googlecode.com/ · Java · 74 lines · 47 code · 12 blank · 15 comment · 0 complexity · 399b71f23ad6bc8c304fdfc957b5cebf 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. */
  16. package com.google.test.metric.cpp;
  17. import com.google.test.metric.ParameterInfo;
  18. import com.google.test.metric.Visibility;
  19. import com.google.test.metric.cpp.dom.FunctionDefinition;
  20. import com.google.test.metric.cpp.dom.Node;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. class FunctionDefinitionBuilder extends DefaultBuilder {
  24. private final Node parent;
  25. private Node node;
  26. private final int line;
  27. private final List<ParameterInfo> parameters = new ArrayList<ParameterInfo>();
  28. private final Visibility visibility;
  29. public FunctionDefinitionBuilder(Node parent, int line) {
  30. this.parent = parent;
  31. this.line = line;
  32. this.visibility = Visibility.PUBLIC;
  33. }
  34. public FunctionDefinitionBuilder(Node parent, int line, Visibility visibility) {
  35. this.parent = parent;
  36. this.line = line;
  37. this.visibility = visibility;
  38. }
  39. @Override
  40. public void functionDirectDeclarator(String name) {
  41. node = new FunctionDefinition(name, line, parameters, visibility);
  42. parent.addChild(node);
  43. }
  44. @Override
  45. public void endFunctionDefinition() {
  46. finished();
  47. }
  48. @Override
  49. public void beginParameterDeclaration() {
  50. pushBuilder(new ParameterDeclarationBuilder(parameters));
  51. }
  52. @Override
  53. public void directDeclarator(String id) {
  54. }
  55. @Override
  56. public void simpleTypeSpecifier(List<String> sts) {
  57. }
  58. @Override
  59. public void beginCompoundStatement() {
  60. pushBuilder(new StatementBuilder(node));
  61. }
  62. }