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

http://testability-explorer.googlecode.com/ · Java · 76 lines · 52 code · 9 blank · 15 comment · 27 complexity · 732750cd45dc785fd9a7beea088fce7f 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.Type;
  18. public class CppType extends Type {
  19. public static final Type VOID = new CppType("void");
  20. public static final Type BYTE = new CppType("byte");
  21. public static final Type SHORT = new CppType("short");
  22. public static final Type INT = new CppType("int");
  23. public static final Type BOOL = new CppType("bool");
  24. public static final Type CHAR = new CppType("char");
  25. public static final Type LONG = new CppType("long");
  26. public static final Type DOUBLE = new CppType("double");
  27. public static final Type FLOAT = new CppType("float");
  28. private boolean pointer = false;
  29. private CppType(String name) {
  30. super(name, "");
  31. }
  32. private CppType(String name, boolean pointer) {
  33. super(name, "");
  34. this.pointer = pointer;
  35. }
  36. public boolean isPointer() {
  37. return pointer;
  38. }
  39. public static Type fromName(String name) {
  40. if (name == VOID.toString()) {
  41. return VOID;
  42. } else if (name == BYTE.toString()) {
  43. return BYTE;
  44. } else if (name == SHORT.toString()) {
  45. return SHORT;
  46. } else if (name == INT.toString()) {
  47. return INT;
  48. } else if (name == BOOL.toString()) {
  49. return BOOL;
  50. } else if (name == CHAR.toString()) {
  51. return CHAR;
  52. } else if (name == LONG.toString()) {
  53. return LONG;
  54. } else if (name == DOUBLE.toString()) {
  55. return DOUBLE;
  56. } else if (name == FLOAT.toString()) {
  57. return FLOAT;
  58. }
  59. return new CppType(name);
  60. }
  61. public static Type fromName(String name, boolean pointer) {
  62. if (!pointer) {
  63. return fromName(name);
  64. }
  65. return new CppType(name, true);
  66. }
  67. }