aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-02-22 19:17:37 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-02-22 19:17:37 -0800
commitf20c7c7e502fcd4df97e6ba2597ccfe3c5962873 (patch)
tree3c171c211d362567cf62b75177e21d23f6db28d7 /eclipse
parentdf060d81cfba0c39465df7c45ccb7d6b8cda2795 (diff)
parenta2d6f8d8cf5142248835c38126d4f6e09d5912a8 (diff)
downloadsdk-f20c7c7e502fcd4df97e6ba2597ccfe3c5962873.zip
sdk-f20c7c7e502fcd4df97e6ba2597ccfe3c5962873.tar.gz
sdk-f20c7c7e502fcd4df97e6ba2597ccfe3c5962873.tar.bz2
Merge "Always use dynamic IDs for unknown project resources."
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/DynamicIdMap.java75
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java51
2 files changed, 86 insertions, 40 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/DynamicIdMap.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/DynamicIdMap.java
new file mode 100644
index 0000000..702f8f6
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/DynamicIdMap.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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.ide.eclipse.adt.internal.resources.manager;
+
+import com.android.resources.ResourceType;
+import com.android.sdklib.util.SparseArray;
+import com.android.util.Pair;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DynamicIdMap {
+
+ private final Map<Pair<ResourceType, String>, Integer> mDynamicIds = new HashMap<Pair<ResourceType, String>, Integer>();
+ private final SparseArray<Pair<ResourceType, String>> mRevDynamicIds = new SparseArray<Pair<ResourceType, String>>();
+ private int mDynamicSeed;
+
+ public DynamicIdMap(int seed) {
+ mDynamicSeed = seed;
+ }
+
+ public void reset(int seed) {
+ mDynamicIds.clear();
+ mRevDynamicIds.clear();
+ mDynamicSeed = seed;
+ }
+
+ /**
+ * Returns a dynamic integer for the given resource type/name, creating it if it doesn't
+ * already exist.
+ *
+ * @param type the type of the resource
+ * @param name the name of the resource
+ * @return an integer.
+ */
+ public Integer getId(ResourceType type, String name) {
+ return getId(Pair.of(type, name));
+ }
+
+ /**
+ * Returns a dynamic integer for the given resource type/name, creating it if it doesn't
+ * already exist.
+ *
+ * @param resource the type/name of the resource
+ * @return an integer.
+ */
+ public Integer getId(Pair<ResourceType, String> resource) {
+ Integer value = mDynamicIds.get(resource);
+ if (value == null) {
+ value = Integer.valueOf(++mDynamicSeed);
+ mDynamicIds.put(resource, value);
+ mRevDynamicIds.put(value, resource);
+ }
+
+ return value;
+ }
+
+ public Pair<ResourceType, String> resolveId(int id) {
+ return mRevDynamicIds.get(id);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java
index 780d72f..e6e3acb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java
@@ -32,7 +32,6 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import java.util.EnumMap;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -61,14 +60,7 @@ public class ProjectResources extends ResourceRepository {
/** Map of (int[], name) for styleable resources coming from R.java */
private Map<IntArrayWrapper, String> mStyleableValueToNameMap;
- /**
- * This list is used by {@link #getResourceId(String, String)} when the resource
- * query is an ID that doesn't exist (for example for ID automatically generated in
- * layout files that are not saved yet).
- */
- private final Map<String, Integer> mDynamicIds = new HashMap<String, Integer>();
- private final Map<Integer, String> mRevDynamicIds = new HashMap<Integer, String>();
- private int mDynamicSeed = DYNAMIC_ID_SEED_START;
+ private final DynamicIdMap mDynamicIdMap = new DynamicIdMap(DYNAMIC_ID_SEED_START);
private final IProject mProject;
@@ -182,9 +174,8 @@ public class ProjectResources extends ResourceRepository {
}
if (result == null) {
- String name = mRevDynamicIds.get(id);
- if (name != null) {
- result = Pair.of(ResourceType.ID, name);
+ synchronized (mDynamicIdMap) {
+ result = mDynamicIdMap.resolveId(id);
}
}
@@ -218,8 +209,10 @@ public class ProjectResources extends ResourceRepository {
}
}
- if (result == null && ResourceType.ID == type) {
- result = getDynamicId(name);
+ if (result == null) {
+ synchronized (mDynamicIdMap) {
+ result = mDynamicIdMap.getId(type, name);
+ }
}
return result;
@@ -233,10 +226,8 @@ public class ProjectResources extends ResourceRepository {
* change.
*/
public void resetDynamicIds() {
- synchronized (mDynamicIds) {
- mDynamicIds.clear();
- mRevDynamicIds.clear();
- mDynamicSeed = DYNAMIC_ID_SEED_START;
+ synchronized (mDynamicIdMap) {
+ mDynamicIdMap.reset(DYNAMIC_ID_SEED_START);
}
}
@@ -246,28 +237,6 @@ public class ProjectResources extends ResourceRepository {
}
/**
- * Returns a dynamic integer for the given resource name, creating it if it doesn't
- * already exist.
- *
- * @param name the name of the resource
- * @return an integer.
- *
- * @see #resetDynamicIds()
- */
- private Integer getDynamicId(String name) {
- synchronized (mDynamicIds) {
- Integer value = mDynamicIds.get(name);
- if (value == null) {
- value = Integer.valueOf(++mDynamicSeed);
- mDynamicIds.put(name, value);
- mRevDynamicIds.put(value, name);
- }
-
- return value;
- }
- }
-
- /**
* Sets compiled resource information.
*
* @param resIdValueToNameMap a map of compiled resource id to resource name.
@@ -283,5 +252,7 @@ public class ProjectResources extends ResourceRepository {
mResourceValueMap = resourceValueMap;
mResIdValueToNameMap = resIdValueToNameMap;
mStyleableValueToNameMap = styleableValueMap;
+
+ resetDynamicIds();
}
}