From 29c288da5260ac221b941e69b960aa2127cbdef0 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 3 Jan 2011 04:11:03 -0800 Subject: [PATCH] Cherry-pick 9b53dd9d60a01ddb1307177c296c7b4fd6114753 from master Change-Id: I670872542feb62c47fe693eb183b19e2eef2b20d LayoutLib: use new API with log in init method. --- .../com/android/layoutlib/bridge/Bridge.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index 5f4085473550a..7a95c09988664 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -180,12 +180,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { return mCapabilities; } - /* - * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.io.File, java.util.Map) - */ @Override - public boolean init(File fontLocation, Map> enumValueMap) { + public boolean init(File fontLocation, Map> enumValueMap, + LayoutLog log) { sEnumValueMap = enumValueMap; // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version @@ -242,11 +239,6 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { // now parse com.android.internal.R (and only this one as android.R is a subset of // the internal version), and put the content in the maps. try { - // WARNING: this only works because the class is already loaded, and therefore - // the objects returned by Field.get() are the same as the ones used by - // the code accessing the R class. - // int[] does not implement equals/hashCode, and if the parsing used a different class - // loader for the R class, this would NOT work. Class r = com.android.internal.R.class; for (Class inner : r.getDeclaredClasses()) { @@ -262,7 +254,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { if (Modifier.isStatic(modifiers)) { Class type = f.getType(); if (type.isArray() && type.getComponentType() == int.class) { - // if the object is an int[] we put it in sRArrayMap + // if the object is an int[] we put it in sRArrayMap using an IntArray + // wrapper that properly implements equals and hashcode for the array + // objects, as required by the map contract. sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName()); } else if (type == int.class) { Integer value = (Integer) f.get(null); @@ -274,12 +268,12 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } } } - } catch (IllegalArgumentException e) { - // FIXME: log/return the error (there's no logger object at this point!) - e.printStackTrace(); - return false; - } catch (IllegalAccessException e) { - e.printStackTrace(); + } catch (Throwable throwable) { + if (log != null) { + log.error(null, + "Failed to load com.android.internal.R from the layout library jar", + throwable); + } return false; }