Move ProxyBuilder to the .stock subpackage (better names welcome) and kill DexCacheException.
diff --git a/src/main/java/com/google/dexmaker/DexCacheException.java b/src/main/java/com/google/dexmaker/DexCacheException.java
deleted file mode 100644
index 64a950b..0000000
--- a/src/main/java/com/google/dexmaker/DexCacheException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2011 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.google.dexmaker;
-
-import java.io.IOException;
-
-/** Thrown when there is an IOException when writing to the dex cache directory. */
-public final class DexCacheException extends RuntimeException {
- private static final long serialVersionUID = 0L;
-
- public DexCacheException(IOException cause) {
- super(cause);
- }
-}
diff --git a/src/main/java/com/google/dexmaker/ProxyBuilder.java b/src/main/java/com/google/dexmaker/stock/ProxyBuilder.java
similarity index 96%
rename from src/main/java/com/google/dexmaker/ProxyBuilder.java
rename to src/main/java/com/google/dexmaker/stock/ProxyBuilder.java
index ed77d7c..cfaccb3 100644
--- a/src/main/java/com/google/dexmaker/ProxyBuilder.java
+++ b/src/main/java/com/google/dexmaker/stock/ProxyBuilder.java
@@ -14,8 +14,16 @@
* limitations under the License.
*/
-package com.google.dexmaker;
+package com.google.dexmaker.stock;
+import com.google.dexmaker.Code;
+import com.google.dexmaker.Comparison;
+import com.google.dexmaker.DexGenerator;
+import com.google.dexmaker.FieldId;
+import com.google.dexmaker.Label;
+import com.google.dexmaker.Local;
+import com.google.dexmaker.MethodId;
+import com.google.dexmaker.Type;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -158,13 +166,13 @@
*
* @throws UnsupportedOperationException if the class we are trying to create a proxy for is
* not accessible.
- * @throws DexCacheException if an exception occurred writing to the {@code dexCache} directory.
+ * @throws IOException if an exception occurred writing to the {@code dexCache} directory.
* @throws UndeclaredThrowableException if the constructor for the base class to proxy throws
* a declared exception during construction.
* @throws IllegalArgumentException if the handler is null, if the constructor argument types
* do not match the constructor argument values, or if no such constructor exists.
*/
- public T build() {
+ public T build() throws IOException {
check(handler != null, "handler == null");
check(constructorArgTypes.length == constructorArgValues.length,
"constructorArgValues.length != constructorArgTypes.length");
@@ -176,12 +184,7 @@
Method[] methodsToProxy = getMethodsToProxy(baseClass);
generateCodeForAllMethods(generator, generatedType, methodsToProxy, superType);
generator.declare(generatedType, generatedName + ".generated", PUBLIC, superType);
- ClassLoader classLoader;
- try {
- classLoader = generator.load(parentClassLoader, dexCache, dexCache);
- } catch (IOException e) {
- throw new DexCacheException(e);
- }
+ ClassLoader classLoader = generator.load(parentClassLoader, dexCache, dexCache);
Class<? extends T> proxyClass;
try {
proxyClass = loadClass(classLoader, generatedName);
@@ -389,7 +392,7 @@
for (int p = 0; p < argTypes.length; ++p) {
code.loadConstant(intValue, p);
Local<?> parameter = code.getParameter(p, argTypes[p]);
- Local<?> unboxedIfNecessary = boxIfRequired(generator, code, parameter, temp);
+ Local<?> unboxedIfNecessary = boxIfRequired(code, parameter, temp);
code.aput(args, intValue, unboxedIfNecessary);
}
code.invokeInterface(methodInvoke, invokeResult, localHandler,
@@ -440,15 +443,13 @@
}
}
- // This one is tricky to fix, I gave up.
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private static <T> void invokeSuper(MethodId superMethod, Code superCode,
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static void invokeSuper(MethodId superMethod, Code superCode,
Local superThis, Local[] superArgs, Local superResult) {
superCode.invokeSuper(superMethod, superResult, superThis, superArgs);
}
- private static Local<?> boxIfRequired(DexGenerator generator, Code code, Local<?> parameter,
- Local<Object> temp) {
+ private static Local<?> boxIfRequired(Code code, Local<?> parameter, Local<Object> temp) {
MethodId<?, ?> unboxMethod = PRIMITIVE_TYPE_TO_UNBOX_METHOD.get(parameter.getType());
if (unboxMethod == null) {
return parameter;
diff --git a/src/test/java/com/google/dexmaker/ProxyBuilderTest.java b/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
similarity index 99%
rename from src/test/java/com/google/dexmaker/ProxyBuilderTest.java
rename to src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
index 2181b44..a50e8e5 100644
--- a/src/test/java/com/google/dexmaker/ProxyBuilderTest.java
+++ b/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-package com.google.dexmaker;
+package com.google.dexmaker.stock;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
+import com.google.dexmaker.DexGeneratorTest;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Random;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
public class ProxyBuilderTest extends TestCase {
private FakeInvocationHandler fakeHandler = new FakeInvocationHandler();
@@ -400,7 +400,8 @@
try {
proxyFor(Object.class).dexCache(new File("//////")).build();
fail();
- } catch (DexCacheException expected) {}
+ } catch (IOException expected) {
+ }
}
public void testInvalidConstructorSpecification() throws Exception {