PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package com.google.test.metric.cpp;
17
18import com.google.test.metric.Type;
19
20public class CppType extends Type {
21
22  public static final Type VOID = new CppType("void");
23  public static final Type BYTE = new CppType("byte");
24  public static final Type SHORT = new CppType("short");
25  public static final Type INT = new CppType("int");
26  public static final Type BOOL = new CppType("bool");
27  public static final Type CHAR = new CppType("char");
28  public static final Type LONG = new CppType("long");
29  public static final Type DOUBLE = new CppType("double");
30  public static final Type FLOAT = new CppType("float");
31
32  private boolean pointer = false;
33
34  private CppType(String name) {
35    super(name, "");
36  }
37
38  private CppType(String name, boolean pointer) {
39    super(name, "");
40    this.pointer = pointer;
41  }
42
43  public boolean isPointer() {
44    return pointer;
45  }
46
47  public static Type fromName(String name) {
48    if (name == VOID.toString()) {
49      return VOID;
50    } else if (name == BYTE.toString()) {
51      return BYTE;
52    } else if (name == SHORT.toString()) {
53      return SHORT;
54    } else if (name == INT.toString()) {
55      return INT;
56    } else if (name == BOOL.toString()) {
57      return BOOL;
58    } else if (name == CHAR.toString()) {
59      return CHAR;
60    } else if (name == LONG.toString()) {
61      return LONG;
62    } else if (name == DOUBLE.toString()) {
63      return DOUBLE;
64    } else if (name == FLOAT.toString()) {
65      return FLOAT;
66    }
67    return new CppType(name);
68  }
69
70  public static Type fromName(String name, boolean pointer) {
71    if (!pointer) {
72      return fromName(name);
73    }
74    return new CppType(name, true);
75  }
76}