Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / android / databinding / tool / reflection / java / JavaTypeUtil.java
blob33bff3b4690e70def6ce1ca144e409493421df75
1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
14 package android.databinding.tool.reflection.java;
16 import android.databinding.tool.reflection.ModelClass;
17 import android.databinding.tool.reflection.ModelMethod;
18 import android.databinding.tool.reflection.TypeUtil;
19 import android.databinding.tool.util.L;
21 import java.lang.reflect.Array;
22 import java.lang.reflect.Method;
24 public class JavaTypeUtil extends TypeUtil {
26 @Override
27 public String getDescription(ModelClass modelClass) {
28 return modelClass.getCanonicalName().replace('.', '/');
31 @Override
32 public String getDescription(ModelMethod modelMethod) {
33 Method method = ((JavaMethod) modelMethod).mMethod;
34 StringBuilder sb = new StringBuilder();
35 sb.append(method.getName());
36 sb.append("(");
37 for (Class param : method.getParameterTypes()) {
38 sb.append(getDescription(param));
40 sb.append(")");
41 sb.append(getDescription(method.getReturnType()));
42 return sb.toString();
45 private String getDescription(Class klass) {
46 if (klass == null) {
47 throw new UnsupportedOperationException();
49 if (boolean.class.equals(klass)) {
50 return BOOLEAN;
52 if (byte.class.equals(klass)) {
53 return BYTE;
55 if (short.class.equals(klass)) {
56 return SHORT;
58 if (int.class.equals(klass)) {
59 return INT;
61 if (long.class.equals(klass)) {
62 return LONG;
64 if (char.class.equals(klass)) {
65 return CHAR;
67 if (float.class.equals(klass)) {
68 return FLOAT;
70 if (double.class.equals(klass)) {
71 return DOUBLE;
73 if (void.class.equals(klass)) {
74 return VOID;
76 if (Object.class.isAssignableFrom(klass)) {
77 return CLASS_PREFIX + klass.getCanonicalName().replace('.', '/') + CLASS_SUFFIX;
79 if (Array.class.isAssignableFrom(klass)) {
80 return ARRAY + getDescription(klass.getComponentType());
83 UnsupportedOperationException ex
84 = new UnsupportedOperationException("cannot understand type "
85 + klass.toString() + ", kind:");
86 L.e(ex, "cannot create JNI type for %s", klass.getCanonicalName());
87 throw ex;