diff --git a/tools/layoutlib/create/README.txt b/tools/layoutlib/create/README.txt index 72fc9329669b7..ef2b185b2e478 100644 --- a/tools/layoutlib/create/README.txt +++ b/tools/layoutlib/create/README.txt @@ -169,9 +169,9 @@ This is the easiest: we currently inject the following classes: their return value. - CreateInfo class, which configured the generator. Not used yet, but could in theory help us track what the generator changed. -- AutoCloseable is part of Java 7. To enable us to still run on Java 6, a new class is - injected. The implementation for the class has been taken from Android's libcore - (platform/libcore/luni/src/main/java/java/lang/AutoCloseable.java). +- AutoCloseable and Objects are part of Java 7. To enable us to still run on Java 6, new + classes are injected. The implementation for these classes has been taken from + Android's libcore (platform/libcore/luni/src/main/java/java/...). - Charsets, IntegralToString and UnsafeByteSequence are not part of the standard JAVA VM. They are added to the Dalvik VM for performance reasons. An implementation that is very close to the original (which is at platform/libcore/luni/src/main/java/...) is injected. diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 75e4480be5777..f6779e38ccfa6 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -20,6 +20,7 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import com.android.tools.layoutlib.java.AutoCloseable; import com.android.tools.layoutlib.java.Charsets; import com.android.tools.layoutlib.java.IntegralToString; +import com.android.tools.layoutlib.java.Objects; import com.android.tools.layoutlib.java.UnsafeByteSequence; /** @@ -111,6 +112,7 @@ public final class CreateInfo implements ICreateInfo { LayoutlibDelegate.class, /* Java package classes */ AutoCloseable.class, + Objects.class, IntegralToString.class, UnsafeByteSequence.class, Charsets.class, @@ -222,6 +224,7 @@ public final class CreateInfo implements ICreateInfo { private final static String[] JAVA_PKG_CLASSES = new String[] { "java.lang.AutoCloseable", "com.android.tools.layoutlib.java.AutoCloseable", + "java.util.Objects", "com.android.tools.layoutlib.java.Objects", "java.nio.charset.Charsets", "com.android.tools.layoutlib.java.Charsets", "java.lang.IntegralToString", "com.android.tools.layoutlib.java.IntegralToString", "java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence", diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java new file mode 100644 index 0000000000000..eb1ef727dea72 --- /dev/null +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/Objects.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tools.layoutlib.java; + +import java.util.Arrays; +import java.util.Comparator; + +/** + * Defines the same class as the java.util.Objects which is added in Java 7. + * This hack makes it possible to run the Android code which uses Java 7 features + * (API 18 and beyond) to run on Java 6. + *
+ * Extracted from API level 19, file: + * platform/libcore/luni/src/main/java/java/util/Objects.java + */ +public final class Objects { + private Objects() {} + + /** + * Returns 0 if {@code a == b}, or {@code c.compare(a, b)} otherwise. + * That is, this makes {@code c} null-safe. + */ + public static