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
{
27 public String
getDescription(ModelClass modelClass
) {
28 return modelClass
.getCanonicalName().replace('.', '/');
32 public String
getDescription(ModelMethod modelMethod
) {
33 Method method
= ((JavaMethod
) modelMethod
).mMethod
;
34 StringBuilder sb
= new StringBuilder();
35 sb
.append(method
.getName());
37 for (Class param
: method
.getParameterTypes()) {
38 sb
.append(getDescription(param
));
41 sb
.append(getDescription(method
.getReturnType()));
45 private String
getDescription(Class klass
) {
47 throw new UnsupportedOperationException();
49 if (boolean.class.equals(klass
)) {
52 if (byte.class.equals(klass
)) {
55 if (short.class.equals(klass
)) {
58 if (int.class.equals(klass
)) {
61 if (long.class.equals(klass
)) {
64 if (char.class.equals(klass
)) {
67 if (float.class.equals(klass
)) {
70 if (double.class.equals(klass
)) {
73 if (void.class.equals(klass
)) {
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());